user38683: 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?

user38683: 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

38683: <p>What I'm trying to accomplish is the following:
I want to use <code>ffmpeg</code> (preferably a single command) to combine a video (<code>video.mp4</code>) file with an audio file (<code>audio.mp3</code>) and have some background music (<code>music.mp3</code>) playing.
The output should end after the length of <code>audio.mp3</code> (or even better after the end of <code>audio.mp3</code> + 5 seconds). So music and video are allowed to be cut.</p>
<p>All separate tasks work in a way but putting everything together just doesn't work.</p>
<p>My approach (with some extras like fading in video and audio volume control):</p>
<pre><code>ffmpeg -i video.mp4 -i audio.mp3 -i music.mp3 -vf &quot;fade=t=in:st=0:d=5&quot; -filter_complex
&quot;[1:a]volume=1[audio]; [2:a]volume=0.25[music];
[audio][music]amix=inputs=2[mix]&quot;
-map 0:v -map &quot;[mix]&quot; -c:v h264 -c:a aac -shortest output.mp4
</code></pre>
<p>That works but the output is not cut after the the duration of the shortest file (which is always the <code>audio.mp3</code>)</p>
<p><strong>Second question:</strong>
Is it possible to refine that command so <code>video.mp4</code> and <code>music.mp3</code> don't need to be very long but are looped until the end of <code>audio.mp3</code> + 5s?</p>
 38683: <p>I think I managed to do the audio part at least (after that I combine the audio track with the video):</p>
<pre><code>ffmpeg -f lavfi -t 5 -i anullsrc=channel_layout=stereo:sample_rate=192000 -i file1.mp3 -filter_complex &quot;[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&quot; out.mp3
</code></pre>
<p>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.</p>
<p>Cheers</p>
