How to Reverse a Video Using FFmpeg in Linux
Reversing a video to play backward is a common editing task that can be easily accomplished in Linux using FFmpeg, a powerful command-line tool for handling multimedia files. This article provides a quick overview of the process, demonstrating the core commands needed to reverse both video and audio streams. We will cover the basic command for short clips, an advanced method for handling large files without running out of system memory, and how to properly re-encode the audio so it matches the reversed visuals.
The Basic Command for Short Videos
For relatively short video clips, FFmpeg can process the reversal
entirely in your system’s memory. The reverse video filter
(-vf) flips the video frames, while the
areverse audio filter (-af) reverses the audio
track so that the sound stays synced with the reversed video.
ffmpeg -i input.mp4 -vf reverse -af areverse output.mp4In this command:
-i input.mp4specifies your source video file.-vf reverseapplies the video filter to play the frames backward.-af areverseapplies the audio filter to play the sound backward.output.mp4is the name of your newly created reversed file.
Handling Large Videos Safely
Because the standard reverse filter stores the entire
video in your RAM before processing it, attempting to use it on long or
high-definition videos can freeze your system or cause FFmpeg to crash.
To safely reverse a large video, you should first convert it into an
intra-frame-only format (like Motion JPEG or raw video), split it into
raw frames, or use an intermediate format that doesn’t rely heavily on
temporal compression.
A reliable workaround for large files involves re-encoding the video into a format where every frame is independent, or using segmenting techniques to process the video in smaller chunks before joining them back together. However, if you have sufficient memory and just need to avoid codec-related stuttering, converting to an uncompressed intermediate file first is highly recommended:
# Step 1: Convert to an intermediate intra-frame file
ffmpeg -i input.mp4 -qscale:v 0 intermediate.avi
# Step 2: Reverse the intermediate file
ffmpeg -i intermediate.avi -vf reverse -af areverse output.mp4Reversing Video Only (No Audio)
If your video does not have an audio track, or if you want to discard
the audio entirely, you can omit the audio filter and use the
-an flag to disable audio recording in the output file.
This speeds up the processing time significantly.
ffmpeg -i input.mp4 -vf reverse -an output_no_audio.mp4