Muting and Replacing Audio Tracks in Videos
There are many practical scenarios where you need to mute the original audio in a video, or replace it with a different track.
1. Removing Audio (Creating a Silent Video)
To remove the audio track completely and output a video with no sound:
# Remove all audio streams from the output
ffmpeg -i input.mp4 -an -c:v copy output_silent.mp4-an: Disable audio stream in the output.-c:v copy: Copy the video stream without re-encoding.
2. Replacing Audio with a New Track
To mute the original audio and add a new background music track:
# Replace original audio with background_music.mp3
ffmpeg -i input.mp4 -i background_music.mp3 \
-map 0:v -map 1:a \
-c:v copy -shortest \
output_with_music.mp4-map 0:v: Take the video stream from the first input file.-map 1:a: Take the audio stream from the second input file (the music file).-shortest: Stop encoding when the shortest input stream ends, preventing silent padding.
3. Mixing Original and New Audio
To blend the original video audio with background music (lower the music volume):
# Mix original audio with background music at 30% volume
ffmpeg -i input.mp4 -i background_music.mp3 \
-filter_complex "[1:a]volume=0.3[music];[0:a][music]amix=inputs=2[aout]" \
-map 0:v -map "[aout]" -c:v copy output_mixed.mp4Published on Last updated: