16

My OS is Debian 8.

I have a file named clip01.mp4 that I would like to reverse, so it plays backwards. Audio can be discarded or reversed as well, doesn't matter.

Apparently ffmpeg is deprecated in favor of avconv, but I can't seem to find a solution that uses either tool!

I would like to keep the same video codec to avoid any sort of losses, if possible.

Command line tools are preferred, for ease of scripting.

4
  • 3
    To do this with ffmpeg / avconv you have to split the video into single frames, rename the frames so they are in reverse order, then build a new video. Take a look at encode video in reverse?
    – PM 2Ring
    Jul 7, 2015 at 6:55
  • Have you tried with avidemux or kino?
    – YoMismo
    Jul 7, 2015 at 8:42
  • 6
    ffmpeg is not, in fact, deprecated (though that's a common misunderstanding thanks to some poor wording on avconv's part…).
    – n.st
    Jul 25, 2015 at 20:33
  • 3
    Ffmpeg is not deprecated anymore lwn.net/Articles/650495
    – gena2x
    Jul 27, 2015 at 12:28

6 Answers 6

17
+25

From https://stackoverflow.com/questions/2553448:

Dump all video frames

$ ffmpeg -i input.mkv -an -qscale 1 %06d.jpg

Dump audio

$ ffmpeg -i input.mkv -vn -ac 2 audio.wav

Reverse audio

$ sox -V audio.wav backwards.wav reverse

Cat video frames in reverse order to FFmpeg as input

$ cat $(ls -t *jpg) | ffmpeg -f image2pipe -vcodec mjpeg -r 25 -i - -i backwards.wav -vcodec libx264 -vpre slow -crf 20 -threads 0 -acodec flac output.mkv

Use mencoder to deinterlace PAL dv and double the frame rate from 25 to 50, then pipe to FFmpeg.

$ mencoder input.dv -of rawvideo -ofps 50 -ovc raw -vf yadif=3,format=i420 -nosound -really-quiet -o - | ffmpeg -vsync 0 -f rawvideo -s 720x576 -r 50 -pix_fmt yuv420p -i - -vcodec libx264 -vpre slow -crf 20 -threads 0 video.mkv
6
  • 2
    cat $(ls -t *jpg) caused trouble, but this worked great cat $(ls *jpg |sort -n) Apr 13, 2016 at 1:36
  • 3
    Ateempting to use -vpre slow resulted in File for preset 'slow' not found. Jan 26, 2017 at 7:57
  • 1
    Also, I am not sure is it problem of vlc/mplayer or presented process but produced file is unplayable - in mplayer only left half is displayed and video display is very laggy, vlc crashes on opening video file. Jan 26, 2017 at 7:58
  • It's possible to extract the frame rate into a variable using the command FRAME_RATE=$(ffmpeg -i "$VIDEO_FILE" 2>&1 | grep -o -P '[0-9\\. ]+fps' | grep -o -P '[0-9\\.]+') (basically get the number in front of fps in ffmpeg). Then you can pass the actual frame rate instead of hard-coding 25. I know this question says sound can be discarded, but in stackoverflow.com/questions/2553448/encode-video-in-reverse/… I posted a bash script that reverses the audio and keeps it synchronized (based on the fps), if someone wants to keep audio.
    – Stan Hatko
    Jul 25, 2021 at 14:48
  • ls -r *.jpg is even better
    – teknoraver
    Sep 16, 2021 at 11:31
6

kdenlive reverse clip https://userbase.kde.org/Kdenlive/Manual/Project_Menu/Reverse_Clip

right-click on the clip: clip jobs / reverse clip

3
  • 2
    Indeed kdenlive 15.12.3 on Ubuntu 16.04 has this feature and it works. Apr 22, 2017 at 9:50
  • I am using Kdenlive Version 17.12.3 and there is no "reverse clip" option anymore
    – Leevi L
    Sep 2, 2019 at 18:19
  • No, but there's "duplicate with speed change" and "-100%" is reverse in normal speed. May 2, 2020 at 11:33
4

In Debian there's Avidemux program, with Reverse video filter. Just tested - works perfectly.

GTK, QT and command line versions available.

Edit: this plugin has been removed in Avidemux ver. 2.6. Use 2.5.6 and older.

1
4

You could also use Openshot it's a very intuitive an easy to use video editor.

You have to right click on the imported clip then properties -> speed tab, change the direction of the clip.

2
  • 1
    In my case openshot refused to import .mp4 as video. Jan 26, 2017 at 6:55
  • 1
    In recent OpenShots (mine is 2.4.1), the setting is now called Time and it is not in the video clip properties; you have to right-click the clip itself in the timeline and then choose Time -> Backwards -> 1X or similar.
    – anol
    May 12, 2018 at 20:13
2

All the other answers were seemingly written in the time before had a video filter called reverse.

So, on any standard Linux system, a recentish ffmpeg allows:

ffmpeg -i input.video.file.name -vf reverse -o output.file.mkv
1

AviSynth has a Reverse() command, which could be used ...

also see: "how do I make a video play backwards on virtual dub?"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .