What I'm trying to accomplish is the following:
I want to use ffmpeg
(preferably a single command) to combine a video (video.mp4
) file with an audio file (audio.mp3
) and have some background music (music.mp3
) playing.
The output should end after the length of audio.mp3
(or even better after the end of audio.mp3
+ 5 seconds). So music and video are allowed to be cut.
All separate tasks work in a way but putting everything together just doesn't work.
My approach (with some extras like fading in video and audio volume control):
ffmpeg -i video.mp4 -i audio.mp3 -i music.mp3 -vf "fade=t=in:st=0:d=5" -filter_complex
"[1:a]volume=1[audio]; [2:a]volume=0.25[music];
[audio][music]amix=inputs=2[mix]"
-map 0:v -map "[mix]" -c:v h264 -c:a aac -shortest output.mp4
That works but the output is not cut after the the duration of the shortest file (which is always the audio.mp3
)
Second question:
Is it possible to refine that command so video.mp4
and music.mp3
don't need to be very long but are looped until the end of audio.mp3
+ 5s?