1

I'm trying to create a series of split screen videos for students to work on remotely using ffmpeg. I need to create an ffmpeg split screen "template" for 5 videos, 1 in portrait and the other 4 in landscape. All the videos have the same resolution: 1280x720. One is 720x1280 (portrait) and the other 4 are 1280 x 720 (landscape) I want to create a split screen of dimensions 1680x720 out of the 5 videos so the portrait video is 400x720 and the 4 landscape videos as 640x360. How do I modify this 2x2 grid ffmpeg code to allow this?:

ffmpeg -i input0.mp4 -i input1.mp4 -i input2.mp4 -i input3.mp4 -filter_complex "[0:v][1:v][2:v][3:v]xstack=inputs=4:layout=0_0|w0_0|0_h0|w0_h0[v]" -map "[v]" output.mp4

Split screen dimensions

2 Answers 2

2

Assuming you want a layout of:

0 1 2
0 3 4

Command is:

ffmpeg -i input0.mp4 -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -filter_complex "[0]scale=-1:720[v0];[1]scale=-1:360[v1];[2]scale=-1:360[v2];[3]scale=-1:360[v3];[4]scale=-1:360[v4];[v0][v1][v2][v3][v4]xstack=inputs=5:layout=0_0|w0_0|w0+w1_0|w0_h1|w0+w1_h1[v]" -map "[v]" output.mp4

2
  • Great llogan This works if I put in the exact resolutions of each video output. Thanks for your help
    – Ben Hardy
    Apr 20, 2020 at 0:02
  • Here's the code I used to get the 5 grid working properly ffmpeg -i input0.mp4 -i input1.mp4 -i input2.mp4 -i input3.mp4 -i input4.mp4 -filter_complex "[0]scale=400x720[v0];[1]scale=640x360[v1];[2]scale=640x360[v2];[3]scale=640x360[v3];[4]scale=640x360[v4];[v0][v1][v2][v3][v4]xstack=inputs=5:layout=0_0|w0_0|w0+w1_0|w0_h1|w0+w1_h1[v]" -map "[v]" output.mp4
    – Ben Hardy
    Apr 26, 2020 at 17:30
0

An alternative to xstack is using two vstacks to build the portrait columns out of the grid and then hstacking all three together at the end:

ffmpeg -y -i p1.png -i g1.png -i g2.png  -i g3.png -i g4.png -filter_complex "[1][2]vstack=inputs=2[p2];[3][4]vstack=inputs=2[p3];[0][p2][p3]hstack=inputs=3" output.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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