Reverse Audio Using FFmpeg areverse Filter
Reversing an audio stream is a common task in audio and video
editing, and the command-line utility FFmpeg makes this process simple
using its built-in areverse filter. This article provides a
direct, step-by-step guide on how to reverse audio-only files, how to
reverse the audio track within a video file while keeping the video
playing forward, and how to reverse both the audio and video
together.
Reversing an Audio File
To reverse a standard audio file (such as an MP3, WAV, or M4A), you
need to apply the areverse filter using the
-af (audio filter) flag.
Run the following command in your terminal:
ffmpeg -i input.mp3 -af areverse output.mp3Command Breakdown:
-i input.mp3: Specifies the input audio file.-af areverse: Applies the audio filter namedareverse.output.mp3: The name of the newly created, reversed audio file.
Note: The areverse filter buffers the entire audio
clip in system memory to reverse it. While this works perfectly for
songs and short clips, extremely long audio files may require a
significant amount of RAM.
Reversing Audio Inside a Video File
If you have a video file (like an MP4) and want to reverse only its audio track while keeping the video playing normally in forward motion, use this command:
ffmpeg -i input.mp4 -c:v copy -af areverse output.mp4Command Breakdown:
-c:v copy: Copies the video stream directly without re-encoding it, which saves time and preserves the original video quality.-af areverse: Reverses the audio stream before re-encoding it into the final container.
Reversing Both Video and Audio Together
To reverse both the video stream and the audio stream so that the
entire media file plays backward, combine the video reverse
filter with the audio areverse filter:
ffmpeg -i input.mp4 -vf reverse -af areverse output.mp4Command Breakdown:
-vf reverse: Reverses the video frames.-af areverse: Reverses the audio samples.