Function Repository Resource:

VideoReverse

Source Notebook

Reverse a video

Contributed by: Michael Sollami

ResourceFunction["VideoReverse"][video]

creates a new version of video that plays in reverse.

Details and Options

ResourceFunction["VideoReverse"] returns a Video object.
ResourceFunction["VideoReverse"] will attempt to automatically download any video given as a URL object.
ResourceFunction["VideoReverse"] takes the following options:
"AudioTrack""Drop"what to do with the audio track
FrameRateAutomaticthe frame rate to use
PerformanceGoal"Speed"aspects of performance to optimize
ResourceFunction["VideoReverse"] will drop audio tracks and use the first video track found, unless otherwise specified using the "AudioTrack" option.
Possible settings for "AudioTrack" include:
"Drop"drop the audio track (default)
"Keep"keep the audio track as is
"Reverse"use a reversed version of the audio track
The option FrameRate can be set to a positive integer or a Scaled value. When this is specified, ResourceFunction["VideoReverse"] will take much longer (it overrides PerformanceGoal).
Scaled[1] (or Automatic) corresponds to the rate of the input video.

Examples

Basic Examples (4) 

Reverse a local file-backed video:

In[1]:=
v = VideoTrim[Video@"ExampleData/Caminandes.mp4", 5]
Out[1]=
In[2]:=
r = ResourceFunction["VideoReverse"][v]
Out[3]=

Play a video forward and backward simultaneously:

In[4]:=
v = VideoTrim[Video@"ExampleData/Caminandes.mp4", {2, 6}];
strms = Map[
   VideoPlay@Video[#, Appearance -> "Basic", ImageSize -> 200] &, {v, ResourceFunction["VideoReverse"]@v}];
TextGrid@{Dynamic[#["CurrentFrame"]] & /@ strms, {"Normal", "Reversed"}}
Out[5]=

Apply VideoReverse to a URL backed Video:

In[6]:=
v = Video[URL@"https://www.w3schools.com/html/mov_bbb.mp4", Appearance -> "Basic", ImageSize -> 300]
Out[6]=
In[7]:=
Video[ResourceFunction["VideoReverse"][v], Appearance -> "Basic", ImageSize -> 300]
Out[7]=

Changing the FrameRate makes videos more or less smooth:

In[8]:=
v = VideoTrim[Video@"ExampleData/Caminandes.mp4", {10, 15}]; 
reversed = Map[ResourceFunction["VideoReverse"][v, FrameRate -> #] &, {1, 8, 32}];

At lower frame rates playback is choppier:

In[9]:=
strms = VideoPlay[#, Looping -> True] & /@ Map[Video[#, Appearance -> "Minimal", ImageSize -> 150] &, reversed];
Grid@{Dynamic[#["CurrentFrame"]] & /@ strms}
Out[10]=

Options (3) 

AudioTrack (1) 

Keep the original audio or mirror it with the "AudioTrack" option:

In[11]:=
v = VideoTrim[Import@"ExampleData/Caminandes.mp4", {45, 50}]; 
ResourceFunction["VideoReverse"][v, "AudioTrack" -> #] & /@ {"Drop", "Keep", "Reverse"}
Out[12]=

FrameRate (2) 

Change the FrameRate in the reversed video:

In[13]:=
v = VideoTrim[Video@"ExampleData/Caminandes.mp4", {30, 50}]; 
Information@ResourceFunction["VideoReverse"][v, FrameRate -> 32]
Out[13]=

FrameRate also takes Scaled objects:

In[14]:=
s = VideoPlay@
   ResourceFunction["VideoReverse"][v, FrameRate -> Scaled[1/8]];
Dynamic[s["CurrentFrame"]]
Out[15]=

Possible Issues (1) 

In principle, FrameRate should not affect duration, but it may differ slightly due to resampling:

In[16]:=
v = VideoTrim[Video@"ExampleData/Caminandes.mp4", 5];
Map[Duration@
   ResourceFunction["VideoReverse"][v, FrameRate -> #] &, {12, Automatic, 48}]
Out[17]=

Publisher

Michael Sollami

Version History

  • 1.1.0 – 22 February 2023
  • 1.0.0 – 14 December 2020

Related Resources

License Information