Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat a video with itself, but in reverse, using ffmpeg

Tags:

I was able to reverse with:

ffmpeg -i input.mp4 -vf reverse output_reversed.mp4 

And I can concat with:

ffmpeg -i input.mp4 -i input.mp4 -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4 

But can I concat with a reverse version of the video, with a single command?

What I am trying to achieve is a ping pong effect, where the video plays once, then plays backwards right after.

Thanks!

like image 236
Vitam Avatar asked Feb 15 '17 18:02

Vitam


People also ask

How do you reverse a video on Android?

Use TikTok app (Android & iOS)To play a video backwards with this mobile tool, simply choose a video from your library or do a fresh recording. After that, go to the Effects tab, look for time effects and then choose “Reverse” and then press “Save” to keep the changes made.

What can you do with FFmpeg?

FFmpeg can handle the entire process of transcoding, video and image manipulation (resizing, denoising, etc.), packaging, streaming, and playback. It is the most popular video and image processing software by a mile and is used by many companies across various industries.


1 Answers

Technically, you can do it using

ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][0:a][r] [0:a]concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.mp4 

But the reverse filter will use a lot of memory for large videos. I've added a fifo filter to avoid frame drops. But test and see. (I haven't reversed the audio)

If your clip has no audio, the above command will throw an error – instead, use:

ffmpeg -i input.mp4 -filter_complex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map "[v]" output.mp4 
like image 66
Gyan Avatar answered Oct 23 '22 01:10

Gyan