softpcapps Software CODE HELP BLOG

Shareware and Freeware Open Source Windows Software Applications and Free Online Tools

How to add background music to video with audio with FFmpeg

To add background music (with user-specified volume) to a video that already has audio, use the following code.

ffmpeg.exe -i VIDEO_FILE -i BACKGROUND_AUDIO_FILE -filter_complex
"[1:0]volume=0.5[a1];[0:a][a1]amix=inputs=2:duration=first" -map 0:v:0 out.mp4

VIDEO_FILE : video file path

BACKGROUND_AUDIO_FILE : background audio file path

You can set your own volume. 100% corresponds to volume=1 so 50% volume corresponds to 50%/100%=0.5.