In what way can I join these four videos side by side (with 10px margin between the left and the right side. No margin between top and bottom)?
top_left.mp4
top_right.mp4
bottom_left.mp4
bottom_right.mp4
Kdenlive is so buggy and drove me crazy. Any command line method is welcome.
11 Answer
Video only
10px border between left & right
There are several methods to do this, but using hstack, vstack, and pad is probably the easiest:
ffmpeg -i top_left.mp4 -i bottom_left.mp4 -i top_right.mp4 -i bottom_right.mp4 -filter_complex \
"[0:v][1:v]vstack,pad=iw+10:ih[l]; \ [2:v][3:v]vstack[r]; \ [l][r]hstack" \
output.mp4Inputs must be the same width, height, and "pixel format". If they are not use the scale and/or format filters to prepare the streams for the *stack filters.
Use
*stack=shortest=1if you want the filter output to terminate when the shortest input terminates.
10px border between left & right, 3px border between top & bottom
ffmpeg -i top_left.mp4 -i bottom_left.mp4 -i top_right.mp4 -i bottom_right.mp4 -filter_complex \
"[0:v]pad=iw:ih+3[tl]; \ [tl][1:v]vstack,pad=iw+10:ih[l]; \ [2:v]pad=iw:ih+3[tr]; \ [tr][3:v]vstack[r]; \ [l][r]hstack" \
output.mp4With combined audio
The amerge filter will combine all input channels, then -ac 2 will downmix them to stereo:
ffmpeg -i top_left.mp4 -i bottom_left.mp4 -i top_right.mp4 -i bottom_right.mp4 -filter_complex \
"[0:v][1:v]vstack,pad=iw+10:ih[l]; \ [2:v][3:v]vstack[r]; \ [l][r]hstack[v]; \ [0:a][1:a][2:a][3:a]amerge=inputs=4[a]"
-map "[v]" -map "[a]" -ac 2 output.mp4- Using amerge, the combined audio will only be as long as the shortest input. If that is a problem then use amix.