How to Match Reverse Audio and Video in FFmpeg

Reversing a video in FFmpeg requires reversing its corresponding audio track to maintain perfect synchronization. This article explains how to use the areverse filter alongside the asetpts filter to reset presentation timestamps, ensuring your reversed audio matches the reversed video stream seamlessly without playback or sync issues.

To reverse both video and audio in FFmpeg, you must apply the reverse filter to the video stream and the areverse filter to the audio stream. When reversing audio, the original presentation timestamps (PTS) can become corrupted or disjointed. To fix this, you chain the asetpts=PTS-STARTPTS filter immediately after reversing the audio. This resets the timeline of the reversed audio packets so they start cleanly at zero.

The Standard FFmpeg Command

Use the following command to reverse both streams and correct the audio timestamps:

ffmpeg -i input.mp4 -vf reverse -af "areverse,asetpts=PTS-STARTPTS" output.mp4

Command Breakdown

Handling Video Timestamps (Optional)

While resetting audio timestamps is usually sufficient, you can also reset the video timestamps using setpts to ensure complete synchronization across all media players:

ffmpeg -i input.mp4 -vf "reverse,setpts=PTS-STARTPTS" -af "areverse,asetpts=PTS-STARTPTS" output.mp4

By resetting both the video (setpts=PTS-STARTPTS) and audio (asetpts=PTS-STARTPTS) timestamps, you guarantee that the reversed output file behaves exactly like a standard video file during playback and editing.