malbolge
malbolge

Reputation: 13

Adding background music that fades out with ffmpeg

I have a piece of video that is 30fps and simply want to add overlay faint background music starting at 10 seconds. Then I want it to fade out during the last 15 seconds. I can't find any good examples of this other than weird hacks.

ffmpeg -i main.mp4 -i outro.mp3 -t 10 \
  -filter_complex "[a0][1:a]acrossfade=d=15[a];weight1:0.5" \
  -map '[v]' -map '[a]' out.mp4

I get bad arguments in the filter_complex. Somethings off right there. in terms of the duration. Any help is greatly appreciated!!

Upvotes: 1

Views: 569

Answers (1)

Gyan
Gyan

Reputation: 93329

Use

ffmpeg -i main.mp4 -i outro.mp3 \ -filter_complex "[0:a]volume=0,asplit[0a][0acf];[1:a]adelay=10s|10s[1a];\ [0a][1a]amix=inputs=2:duration=first:dropout_transition=0,volume=2,afifo[outro];\ [0acf]atrim=0:16,afifo[0acf];[outro][0acf]acrossfade=d=15[outro];\ [0:a][outro]amix=duration=first:weights='2 1'[a]" \ -map 0:v -c:v copy -map '[a]' out.mp4

The main audio is muted and then cloned to two copies. It is then mixed with the delayed music so that the music duration matches the main audio. It is then crossfaded with the other copy of the muted main audio. This result is then mixed with the original main audio.

Upvotes: 1

Related Questions