TechEarl

How to Reverse a Video with ffmpeg

Reverse a video with ffmpeg using the reverse filter for picture and areverse for sound. Why you must write to a new output file, and why you trim before you reverse.

Ishan Karunaratne⏱️ 6 min readUpdated
Share thisCopied
Reverse a video from the command line with ffmpeg: the reverse video filter, the areverse audio filter, and the new-output-file rule that keeps the source intact.

To reverse a video with ffmpeg, use the reverse video filter for the picture and the areverse audio filter for the sound, and write the result to a new file. To reverse both picture and sound:

bash
ffmpeg -i in.mp4 -vf reverse -af areverse out.mp4

The one caveat to know up front: the reverse filter buffers the entire clip into memory before it can write a single frame, so it is fine for short clips but memory-heavy on long videos. For anything more than a few seconds, trim the segment you want first and reverse that (more on this below).

If you only want the picture reversed and don't care about the audio, drop -af areverse:

bash
ffmpeg -i in.mp4 -vf reverse out.mp4

That plays the picture backwards but leaves the audio untouched, so the sound runs forward over a reversed image. Adding -af areverse flips the audio samples too, so picture and sound play end-to-start together.

The single most important thing on this page is the output filename. Use a name that is different from the input. A common copy-pasted command reverses a file onto itself (ffmpeg -i clip.mp4 -vf reverse clip.mp4), and ffmpeg opens that same file for writing while it is still reading from it. The result is a truncated, corrupted clip and a lost original. There is no undo. Always reverse into a fresh path.

Reverse the picture only (drop the audio)

If you want a silent reversed clip, do not reverse the audio backwards, just discard it. -an means "no audio":

bash
ffmpeg -i input.mp4 -vf reverse -an reversed.mp4

This is the right command for a reversed loop, a boomerang-style effect, or any clip where the original audio would be noise played backwards. Dropping the track is also faster and uses less memory than reversing it.

Reverse both the picture and the sound

For a clip where the reversed audio is the point (speech played backwards, a sound effect run in reverse), pair the two filters. -vf is the video filter chain, -af is the audio filter chain:

bash
ffmpeg -i input.mp4 -vf reverse -af areverse reversed.mp4

reverse flips the order of the video frames; areverse flips the order of the audio samples. Run them together and the whole clip plays end-to-start, picture and sound in step.

Why you should trim first: the memory trap

Here is the catch that bites people on anything longer than a short clip: the reverse filter buffers the entire video stream into memory before it can write the first reversed frame. It has to, because the last frame of the input becomes the first frame of the output, so ffmpeg cannot emit anything until it has read everything. A few seconds of 1080p is fine. A feature-length file will exhaust your RAM, swap hard, or get killed outright.

So reverse a segment, not the whole movie. Trim the part you actually want first, then reverse that. Seeking before -i makes the cut fast, and the trimmed file is what you reverse:

bash
# Cut a ~4 second segment from around 12 seconds, no re-encode
# -c copy snaps to the nearest keyframe, so the cut is fast but not frame-exact
ffmpeg -ss 00:00:12 -t 4 -i input.mp4 -c copy segment.mp4

# Reverse the short segment (cheap on memory)
ffmpeg -i segment.mp4 -vf reverse -af areverse reversed.mp4

You can also do it in one command with the trim filters, but the two-step version is easier to reason about and lets you check the segment before you commit to reversing it. See trim and cut a video with ffmpeg for the full set of trimming options, including -to for an absolute end timestamp and the keyframe-versus-frame-accurate tradeoff.

areverse is cheaper on memory than reverse because audio samples are tiny next to decoded video frames, but it still buffers the whole audio stream. The video side is the one that hurts, so the trim-first rule is about the picture.

If a video genuinely must be reversed in full and it does not fit in RAM, the workaround is to split it into chunks, reverse each chunk, then concatenate them back together in reverse chunk order. That is a real technique but a rare need; for almost everything, trim the segment you want and reverse that.

A note on quality

-vf reverse re-encodes the video (you cannot stream-copy a filtered stream), so the output is a fresh encode at ffmpeg's defaults. If you care about the encode, add the usual libx264 controls:

bash
ffmpeg -i segment.mp4 -vf reverse -af areverse -c:v libx264 -crf 18 -preset slow reversed.mp4

Lower -crf is higher quality (18 is visually near-lossless for x264); -preset slow spends more time for a smaller file. These are the same knobs covered in the ffmpeg commands cheat sheet.

FAQ

You almost certainly used the same filename for input and output, for example ffmpeg -i clip.mp4 -vf reverse clip.mp4. ffmpeg opens that file for writing while still reading it, which truncates the source. Always write to a new path like reversed.mp4, and there is no recovery once the original is overwritten.

Add the areverse audio filter next to the video reverse filter: ffmpeg -i input.mp4 -vf reverse -af areverse reversed.mp4. The reverse filter flips the video frames and areverse flips the audio samples, so both play end-to-start together.

Drop the audio with -an instead of reversing it: ffmpeg -i input.mp4 -vf reverse -an reversed.mp4. This is the right choice for loops and boomerang effects where backwards audio would just be noise.

The reverse filter has to read the entire stream into memory before it can write the first reversed frame, because the last input frame becomes the first output frame. On a long file that exhausts your RAM. Trim the segment you want first, then reverse the short clip.

Yes, and you should. Cut the segment first with -ss and -t (or -c copy for a fast lossless cut), then run the reverse filter on that segment. This is both the correct way to get a partial reversal and the way to avoid the memory problem.

See also

Sources

Authoritative references this article was fact-checked against.

Tagsffmpegreverse videoareversevideo filterCLIcommand linevideo editing

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Software Systems Architect · Senior Software Engineer · Engineering Leadership

Software systems architect and senior software engineer with more than two decades designing, building, and running production software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Now a CTO, though what I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

Crop a video with ffmpeg using the crop filter: width:height:x:y from the top-left origin, centered and square crops with in_w/in_h, and cropdetect for black bars.

How to Crop a Video with ffmpeg

Crop a video with ffmpeg's crop filter: crop=w:h:x:y from the top-left origin, centered crops with in_w/in_h expressions, square crops for social, and cropdetect to strip black bars automatically.

Trim or cut a video from the command line with ffmpeg using -ss and -to or -t, the fast lossless stream-copy way and the frame-accurate re-encode.

How to Trim or Cut a Video with ffmpeg

Trim or cut a video from the command line with ffmpeg: the fast lossless -c copy way, the keyframe gotcha that makes your cut land early, and the frame-accurate re-encode. With -ss and -to/-t explained.

Speed up or slow down a video with ffmpeg using the setpts video filter and the atempo audio filter, including the atempo 0.5 to 100 range and why you still chain it in steps of 2.0 for larger factors.

How to Speed Up or Slow Down a Video with ffmpeg

Change a video's speed from the command line with ffmpeg: setpts for the video, atempo for the audio, why you still chain atempo in steps of 2.0 even though it now accepts up to 100, and keeping both tracks in sync.