1

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?

1 Answer 1

1

I think I managed to do the audio part at least (after that I combine the audio track with the video):

ffmpeg -f lavfi -t 5 -i anullsrc=channel_layout=stereo:sample_rate=192000 -i file1.mp3 -filter_complex "[1:a][0:a]concat=n=2:v=0:a=1[audio_silence],amovie=file2.mp3:loop=0,asetpts=N/SR/TB,volume=0.1[music];[audio_silence][music]amix=duration=shortest,volume=1" out.mp3

But one thing is not quite as expected: The audio quality go really bad. There is hissing and some higher frequency noice ... i tried some low pass filtering but doesn't seem to help. Any ideas on that topic? I think I'll open another question for that.

Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.