<p>Assuming you want a layout of:</p>

<pre><code>0 1 2
0 3 4
</code></pre>

<p>Command is:</p>

<p><code>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</code></p>

CC BY-SA 4.0
2020-04-20T00:02:03.427Z
Great llogan This works if I put in the exact resolutions of each video output. Thanks for your help
Ben Hardy
CC BY-SA 4.0
2020-04-26T17:30:42.557Z
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
CC BY-SA 4.0
2020-04-19T19:26:52.280Z
2020-04-19T19:26:52.280Z
llogan
<p>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:</p>

<pre><code>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
</code></pre>

CC BY-SA 4.0
2020-04-19T19:35:20.187Z
2020-04-19T19:35:20.187Z
Baxter
<p>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?:</p>

<pre><code>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
</code></pre>

<p><a href="https://i.sstatic.net/V0EaG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/V0EaG.png" alt="Split screen dimensions"></a></p>

<video><ffmpeg><editing>
Use ffmpeg to create a split screen video out of 5 videos- 4 videos in landscape one in portrait
Ben Hardy
# Use ffmpeg to create a split screen video out of 5 videos- 4 videos in landscape one in portrait

(Asked by: username_0 on 2020-04-19)

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

**Tags:** video, ffmpeg, editing


---

## 2 answers

### Answer by username_1 on 2020-04-19. Score: 2 | Accepted answer

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

> **Comments:**
> **username_0**: Great username_1 This works if I put in the exact resolutions of each video output. Thanks for your help  
> **username_0**: 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  

---

### Answer by username_2 on 2020-04-19. Score: 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


---

