Wolfram Research

Function Repository Resource:

VideoReverse (1.0.0) current version: 1.1.0 »

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.
By default ResourceFunction["VideoReverse"] will ignore any audio tracks present and use the first video track found.
ResourceFunction["VideoReverse"] takes the option FrameRate which can be a positive integer or a Scaled value.
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[2]=

Play a video forward and backward simultaneously:

In[3]:=
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 (1) 

FrameRate also takes Scaled objects, in this case Scaled[1] (or Automatic) corresponds to the rate of the given video:

In[11]:=
v = VideoTrim[Video@"ExampleData/Caminandes.mp4", {30, 50}]; 
s = VideoPlay@
   ResourceFunction["VideoReverse"][v, FrameRate -> Scaled[1/8]];
Dynamic[s["CurrentFrame"]]
Out[13]=

Possible Issues (1) 

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

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

Publisher

Michael Sollami

Version History

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

Related Resources

License Information