Merge audio and video from separate files

concatenation

// what it does

Muxes a video and a separate audio file into one container, copying the video stream untouched (-c:v copy) while re-encoding the audio to AAC (-c:a aac) — AAC is the standard, broadly-compatible audio codec for the MP4 container (MP3-in-MP4 is spec-valid but less universally handled by hardware/browser players). -shortest ends the output when the shorter of the two inputs runs out, preventing a trailing stretch of video with no sound (or vice versa). Reach for this to swap in a music track or attach a separately-recorded audio bed.

// shell

$ ffmpeg -i input.mp4 -i audio.mp3 -c:v copy -c:a aac -shortest output.mp4

// gotcha

Without an explicit -map, ffmpeg auto-selects one 'best' video and one 'best' audio stream (audio ties broken toward the lowest index), so if input.mp4 already contains audio it can be chosen over audio.mp3 — add -map 0:v:0 -map 1:a:0 to force the intended streams. -shortest's cut point is decided at mux time and can land a fraction of a frame short of what you expect.