'FFMPEG trouble with concatenating Video + Video[+Audio]

i need to concatenate (1-st Video) without changes + (2-nd video with replaced audio), but my command skips 2-nd video (but duration shows normally)

my code:

ffmpeg.exe -y -i "1st.mp4" -i "2nd.mp4" -i "audio.mp3" -map 0:v:0 -map 1:v:0 -map 1:a:0 -c copy "output"

what's wrong? =(



Solution 1:[1]

Your command places the 2 videos in parallel (as in you can play one or the other at a time)

To concatenate (e.g., play one video after another), you need to use a concat filter and must re-encode (cannot copy):

ffmpeg.exe -y -i "1st.mp4" -i "2nd.mp4" -i "audio.mp3" \
   -filter_complex [0:v][0:a][1:v][2:a]concat=n=2:v=1:a=1[vout][aout] \
   -map [vout] -map [aout] "output.mp4"

If you must copy the streams without re-encoding, you can explore concat demuxer but requires an additional step to form concat-ready 2nd input (video+audio). Furthermore, it is finicky as their formats must match exactly to work. If you'd like to go this route, do some research first.

Edit: Adding scaling on 0:v

You need to create a separate filter chain like this:

ffmpeg.exe -y -i "1st.mp4" -i "2nd.mp4" -i "audio.mp3" \
   -filter_complex [0:v]scale=1920x1080[scaled];\
                   [scaled][0:a][1:v][2:a]concat=n=2:v=1:a=1[vout][aout] \
   -map [vout] -map [aout] "output.mp4"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1