Replace audio
ffmpeg -i video.mp4 -i audio.wav -map 0:v -map 1:a -c:v copy -shortest output.mp4
- The
-map
option allows you to manually select streams / tracks. See FFmpeg Wiki: Map for more info. - This example uses
-c:v copy
to stream copy (mux) the video. No re-encoding of the video occurs. Quality is preserved and the process is fast.- If your input audio format is compatible with the output format then change
-c:v copy
to-c copy
to stream copy both the video and audio. - If you want to re-encode video and audio then remove
-c:v copy
/-c copy
.
- If your input audio format is compatible with the output format then change
- The
-shortest
option will make the output the same duration as the shortest input.
Add audio
ffmpeg -i video.mkv -i audio.mp3 -map 0 -map 1:a -c:v copy -shortest output.mkv
- The
-map
option allows you to manually select streams / tracks. See FFmpeg Wiki: Map for more info. - This example uses
-c:v copy
to stream copy (mux) the video. No re-encoding of the video occurs. Quality is preserved and the process is fast.- If your input audio format is compatible with the output format then change
-c:v copy
to-c copy
to stream copy both the video and audio. - If you want to re-encode video and audio then remove
-c:v copy
/-c copy
.
- If your input audio format is compatible with the output format then change
- The
-shortest
option will make the output the same duration as the shortest input.
Mixing/combining two audio inputs into one
Use video from video.mkv
. Mix audio from video.mkv
and audio.m4a
using the amerge filter:
ffmpeg -i video.mkv -i audio.m4a -filter_complex "[0:a][1:a]amerge=inputs=2[a]" -map 0:v -map "[a]" -c:v copy -ac 2 -shortest output.mkv
See FFmpeg Wiki: Audio Channels for more info.
Generate silent audio
You can use the anullsrc filter to make a silent audio stream. The filter allows you to choose the desired channel layout (mono, stereo, 5.1, etc) and the sample rate.
ffmpeg -i video.mp4 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 \ -c:v copy -shortest output.mp4