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.

рüффп
  • 1,707
cat pants
  • 435

6 Answers6

17

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
Jodka Lemon
  • 3,173
  • 2
    cat $(ls -t *jpg) caused trouble, but this worked great cat $(ls *jpg |sort -n) – Aquarius Power Apr 13 '16 at 01:36
  • 3
    Ateempting to use -vpre slow resulted in File for preset 'slow' not found. – reducing activity Jan 26 '17 at 07: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. – reducing activity Jan 26 '17 at 07: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 https://stackoverflow.com/questions/2553448/encode-video-in-reverse/68519663#68519663 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 '21 at 14:48
  • ls -r *.jpg is even better – teknoraver Sep 16 '21 at 11:31
  • There is a specific tool to extract file information, ffprobe

    ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "$src"

    – teknoraver Sep 16 '21 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

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.

  • 2
    There's currently no avidemux package in official Debian repositories as per https://packages.debian.org/search?keywords=avidemux&searchon=names&suite=all§ion=all – Stéphane Gourichon Apr 22 '17 at 09:52
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.

J.Serra
  • 141
  • 1
    In my case openshot refused to import .mp4 as video. – reducing activity Jan 26 '17 at 06: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 '18 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?"