To put new audio on a video, such as music or a voiceover, tell FFmpeg to take the picture from one file and the sound from another. The two are combined into one output, and the video is copied without loss.
1. The Basic Command
Give FFmpeg two inputs, and use -map to take the video from the first and the audio from the second:
ffmpeg -i input.mp4 -i input.mp3 -map 0:v:0 -map 1:a:0 -c:v copy -c:a aac -shortest output.mp4
-i input.mp4… input 0 (the video)-i input.mp3… input 1 (the new audio)-map 0:v:0… take the video stream from input 0-map 1:a:0… take the audio stream from input 1-c:v copy… copy the video without re-encoding (no quality loss)-c:a aac… encode the new audio as AAC, which suits MP4-shortest… stop at the end of the shorter of the two streams
| Token | Reads as |
|---|---|
0:v:0 |
input 0, first video stream |
1:a:0 |
input 1, first audio stream |
-c:v copy |
keep video bit-for-bit |
-c:a aac |
re-encode audio to AAC |
The FFmpeg wiki page on -map explains the syntax in full.
2. Matching Durations with -shortest
The video and the new audio are rarely the same length. -shortest ends the output when the shorter one runs out, so you do not get silent video at the end, or audio playing over a frozen last frame.
- If the audio is longer than the video, the extra audio is cut off.
- If the video is longer than the audio, the video is cut to the audio’s length.
To keep the full video and let the music end early, leave out -shortest. The end of the video then has no sound.
3. Remove the Old Audio First (Single-Input Step)
You can also work in two steps: remove the original audio, then add the new one. The first step needs only one input:
ffmpeg -i input.mp4 -c:v copy -an output.mp4
-c:v copy… copy the video unchanged-an… drop all audio
This gives you a silent video. To add the new soundtrack, use the two-input command from section 1. For more on removing audio, see the remove audio guide.
4. Re-encode Audio vs Copy It
Section 1 re-encodes the audio to AAC because MP4 plays best with AAC. If your new audio is already AAC (for example an .m4a file), you can copy it and skip the encoding:
ffmpeg -i input.mp4 -i input.m4a -map 0:v:0 -map 1:a:0 -c copy -shortest output.mp4
-c copy… copy both video and audio with no re-encoding
| Source audio | Recommended | Why |
|---|---|---|
| WAV / FLAC | -c:a aac |
MP4 can hold them, but AAC plays in more places |
| MP3 | -c:a aac (or -c copy) |
MP3 can be copied into MP4, but AAC plays in the most places |
| AAC / M4A | -c copy |
Already fits MP4; copy without loss |
5. Add an Audio Delay or Offset
If the new audio should start a little later than the video, delay the audio input with -itsoffset before its -i:
ffmpeg -i input.mp4 -itsoffset 1.5 -i input.mp3 -map 0:v:0 -map 1:a:0 -c:v copy -c:a aac -shortest output.mp4
-itsoffset 1.5… shift the next input (the audio) 1.5 seconds later
Adjust the number until the audio lines up. A negative value pulls the audio earlier.
6. Troubleshooting
Issue 1: The output keeps the original audio, not the new one
Cause: Without -map, FFmpeg picks one audio stream by itself. It takes one candidate from each input (within a file, a track marked as default comes first), then uses the candidate with the most channels, or, if they are equal, the one from the earlier input (the video file).
Fix: Add -map 0:v:0 -map 1:a:0 to choose the streams yourself (section 1).
Issue 2: Audio and video drift out of sync
Cause: The new audio is slightly longer or shorter than the video (for example, when it was recorded on a separate device).
Fix: Change the audio speed with the atempo filter. The factor is audio length ÷ video length: to fit 100.1 s of audio to a 100 s video, add -af atempo=1.001. -itsoffset (section 5) shifts the whole track by the same amount, so it only helps when the gap is the same from start to end.
Issue 3: “Could not find tag for codec” when copying audio
Cause: MP4 cannot hold the source audio codec.
Fix: Re-encode with -c:a aac instead of -c copy (section 1).
FAQ
Q1. Do I have to remove the old audio first? A. No. The two-input command in section 1 replaces it in one run. Removing it first (section 3) is only an alternative.
Q2. Does replacing audio reduce video quality?
A. No. -c:v copy copies the video unchanged; only the audio is new.
Q3. My music is longer than the video — how do I cut it?
A. Keep -shortest; it ends the output when the video ends.
Q4. Can I keep the original audio and add the new one? A. Yes. Map both audio streams instead of replacing one. That makes a file with two audio tracks; see working with multiple audio tracks.