0
votes

My input file has 5 video and 1 picture. I want to merge all video to one video, play video at the same time. The layout of the output video like this: enter image description here

Im using ffmpeg to merge video. this is my ffmpeg command:

ffmpeg 
-i C:\VID\test1.mp4 
-i C:\VID\test2.mp4 
-i C:\VID\test3.mp4 
-i C:\VID\test4.mp4 
-i C:\VID\test5.mp4 
-i C:\VID\background.jpg 
-filter_complex 
" nullsrc=size=1280x720 [base]; 
[0] setpts=PTS-STARTPTS, scale=560x360 [video0];
 [1] setpts=PTS-STARTPTS, scale=280x180 [video1]; 
[2] setpts=PTS-STARTPTS, scale=280x180 [video2];
 [3] setpts=PTS-STARTPTS, scale=280x180 [video3];
 [4] setpts=PTS-STARTPTS, scale=280x180 [video4]; 
[5:v] scale=700x700 [image]; 
[base][video0] overlay=shortest=1 [tmp1]; 
[tmp1][video1] overlay=shortest=1:y=360 [tmp2];
 [tmp2][video2] overlay=shortest=1:x=280:y=360 [tmp3]; 
[tmp3][video3] overlay=shortest=1:y=540 [tmp4]; 
[tmp4][video4] overlay=shortest=1:x=280:y=540 [tmp5];
 [tmp5][image] overlay=570:10:enable='between(t,0,30)'"
 -t 30 -c:v libx264 output.mkv

The output video layout is working fine but no audio in the output video. I want all audio off each video will be keep on the output video. play audio at the same time together. I'm using tutorial on this link: Create a mosaic out of several input videos Thanks for reading

1

1 Answers

3
votes

You can use the amix or amerge audio filters. Assuming each MP4 input file also contains audio:

ffmpeg 
-i C:\VID\test1.mp4 
-i C:\VID\test2.mp4 
-i C:\VID\test3.mp4 
-i C:\VID\test4.mp4 
-i C:\VID\test5.mp4 
-i C:\VID\background.jpg 
-filter_complex 
"nullsrc=size=1280x720 [base]; 
[0] setpts=PTS-STARTPTS, scale=560x360 [video0];
[1] setpts=PTS-STARTPTS, scale=280x180 [video1]; 
[2] setpts=PTS-STARTPTS, scale=280x180 [video2];
[3] setpts=PTS-STARTPTS, scale=280x180 [video3];
[4] setpts=PTS-STARTPTS, scale=280x180 [video4]; 
[5:v] scale=700x700 [image]; 
[base][video0] overlay=shortest=1 [tmp1]; 
[tmp1][video1] overlay=shortest=1:y=360 [tmp2];
[tmp2][video2] overlay=shortest=1:x=280:y=360 [tmp3]; 
[tmp3][video3] overlay=shortest=1:y=540 [tmp4]; 
[tmp4][video4] overlay=shortest=1:x=280:y=540 [tmp5];
[tmp5][image] overlay=570:10:enable='between(t,0,30)'[v];
[0:a][1:a][2:a][3:a][4:a]amix=inputs=5[a]"
-map "[v]" -map "[a]" -t 30 -c:v libx264 output.mkv