Reverse a video with FFmpeg
reverse flips the frame order and areverse the audio. Both keep every frame in memory until the input ends, so the commands below cut the clip first and the memory cost of not doing so was measured.
Verified with FFmpeg 9.0.1 on 26 August 2026. Search intent: ffmpeg reverse video.
ffmpeg -ss 0 -t 4 -i input.mp4 -vf reverse -af areverse -c:v libx264 -preset veryfast -crf 20 -c:a aac -b:a 128k reversed.mp4Takes the first 4 s and writes them backwards, video and audio: 120 frames, 4.0 s. The first frame of the output matched the last frame of the input (SSIM 0.98 after re-encoding).
Flags, explained
- -vf reverse
- Output the video frames in reverse order. Buffers the whole input first.
- -af areverse
- Same for audio. Without it the picture runs backwards over forward sound.
- -t 4
- Read only 4 s of the input. This is what keeps memory under control.
- trim=start=2:end=5 / atrim
- Select a range inside the filter graph, in seconds.
- setpts=PTS-STARTPTS
- Restart the timestamps at 0 after trimming so the output does not begin with a gap.
- split / concat=n=2:v=1:a=0
- Duplicate the stream, then join two video-only segments back to back.
- -stream_loop 2
- Input option: repeat the file two extra times.
Variants
Video only, no sound
ffmpeg -t 4 -i input.mp4 -vf reverse -an -c:v libx264 -preset veryfast -crf 20 reversed.mp4-an drops the audio, which is usually what you want for a reversed clip. Same 120 frames.
Reverse a segment from the middle
ffmpeg -i input.mp4 -vf "trim=start=2:end=5,reverse,setpts=PTS-STARTPTS" -af "atrim=start=2:end=5,areverse,asetpts=PTS-STARTPTS" -c:v libx264 -preset veryfast -crf 20 -c:a aac -b:a 128k reversed.mp4trim and atrim select 2 s to 5 s inside the filter graph, reverse flips them, setpts restarts the timestamps at 0. Output: 90 frames, 3.0 s.
Boomerang: forward then backward
ffmpeg -t 3 -i input.mp4 -filter_complex "[0:v]split[a][b];[b]reverse[r];[a][r]concat=n=2:v=1:a=0,setpts=N/FRAME_RATE/TB[v]" -map "[v]" -an -c:v libx264 -preset veryfast -crf 20 boomerang.mp4Splits the 3 s clip in two copies, reverses one and concatenates them: 6 s, 180 frames, muted. setpts rebuilds a clean timeline after concat.
Loop the boomerang three times
ffmpeg -stream_loop 2 -i boomerang.mp4 -c copy boomerang-loop.mp4-stream_loop 2 plays the input three times in total and -c copy makes it instant: 18 s, 540 frames.
Pitfalls we hit
- reverse holds every decoded frame in RAM: reversing the full 12 s 720p test file peaked at 776 MB. A minute of 1080p will not fit on most machines; cut with -t or trim first.
- Forgetting -af areverse leaves the audio playing forwards under a backwards picture.
- -c copy is impossible: reversing needs decoded frames, so the video is always re-encoded.
- After concat, timestamps of the second half continue from the first only if you reset them; setpts=N/FRAME_RATE/TB avoids a jump.
- A boomerang doubles the length. Three seconds in, six seconds out; loop with -stream_loop rather than a longer source.
How we verified it
Run with FFmpeg 9.0.1 on 26 August 2026 against a 12 s 1280x720 H.264/AAC file. Primary command on the first 4 s: 120 frames, 4.000 s, 1.8 MB; SSIM between the first output frame and the last input frame 0.979. Mute variant: 120 frames. Middle segment 2 to 5 s: 90 frames, 3.000 s. Boomerang from 3 s: 180 frames, 6.000 s. -stream_loop 2 with copy: 540 frames, 18.000 s. Full 12 s reverse: 776,290,304 bytes maximum resident memory.
The same edit as a typed operation
create_boomerang renders the forward and reversed halves in one pass for clips up to 30 s and returns a muted MP4 through a signed URL. A plain reversal is the reverse operation of create_video_job, with the same 30 s limit so memory never becomes your problem.
{
"inputs": [{ "id": "main", "url": "https://example.com/clip.mp4" }]
}FAQ
Why does FFmpeg run out of memory when reversing?
The reverse filter cannot emit the last frame first without holding all the others, so it buffers the entire input. Limit what it sees with -t or -ss before -i, or trim inside the filter graph.
How do I reverse only the video and keep the audio normal?
Drop -af areverse. The picture runs backwards while the sound stays as recorded, which is sometimes the effect you want for music clips.
How do I make a boomerang loop?
Split the clip, reverse one copy and concatenate both, as in the boomerang variant, then repeat the result with -stream_loop. Keep the source short: the output is twice its length.
Can I reverse a video without re-encoding?
No. Compressed video frames depend on the frames before them, so they must be decoded, reordered and encoded again. Expect the usual re-encode cost and a small quality loss.
Related commands
- ffmpeg trim videoTrim a video with FFmpegRead
- ffmpeg video to gifConvert a video to GIF with FFmpegRead
- ffmpeg split video into partsSplit a video into parts with FFmpegRead