0

I used the following line to create a mosaic video output with four videos each starting at a particular location and time. Following is the line of code I used

ffmpeg -i lead_1.mp4 -i lead_2.mp4 -i lead_3.mp4 -i lead_4.mp4 
-filter_complex 
"color=s=1280x720:c=black [base]; 
[0:v] setpts=PTS-STARTPTS, scale= 640x360 [upperleft1]; 
[1:v] setpts=PTS+35/TB, scale=640x360 [lowerright1]; 
[2:v] setpts=PTS+87/TB, scale=640x360 [upperleft2]; 
[3:v] setpts=PTS+183/TB, scale=640x360 [lowerright2]; 
[base][upperleft1] overlay=1 [tmp1]; 
[tmp1][lowerright1] overlay=1:x=640:y=360 [tmp2]; 
[tmp2] [upperleft2] overlay=1 [tmp3]; 
[tmp3][lowerright2] overlay=1:x=640:y=360" 

-c:v libx264 lead_1_2_3_4.mp4

So the output file does not contain the audio streams from all the videos. I am new to FFMPEG so can someone suggest how do I get even the audio streams of all the input files in the output?

1 Answer 1

0

Add the adelay and amix filters:

ffmpeg -i lead_1.mp4 -i lead_2.mp4 -i lead_3.mp4 -i lead_4.mp4 
-filter_complex 
"color=s=1280x720:c=black [base]; 
[0:v] setpts=PTS-STARTPTS, scale= 640x360 [upperleft1]; 
[1:v] setpts=PTS+35/TB, scale=640x360 [lowerright1]; 
[2:v] setpts=PTS+87/TB, scale=640x360 [upperleft2]; 
[3:v] setpts=PTS+183/TB, scale=640x360 [lowerright2]; 
[base][upperleft1] overlay[tmp1]; 
[tmp1][lowerright1] overlay=x=overlay_w:y=overlay_h [tmp2]; 
[tmp2] [upperleft2] overlay [tmp3]; 
[tmp3][lowerright2] overlay=x=overlay_w:y=overlay_h[v];
[1]adelay=35s:all=1[a1];
[2]adelay=87s:all=1[a2];
[3]adelay=183s:all=1[a3];
[0:a][a1][a2][a3]amix=inputs=4[a]" 
-map "[v]" -map "[a]"
-c:v libx264 lead_1_2_3_4.mp4

If your ffmpeg is old use adelay=35000|35000 instead (assuming stereo input).

2
  • Hi, So it gave me an error, I tried adding -c:a aac after libx264, but even that edit did not work for some reason Jul 24, 2020 at 3:55
  • @DhulipalaChandrasekhar You should always provide the actual error instead of just mentioning that you got an error. Without the actual error I am unable to suggest anything. It would be most helpful if you provide the command you used and the complete log from the command. This will allow you to receive an answer much faster. You can use a pastebin site and provide a link in a comment.
    – llogan
    Jul 24, 2020 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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