Video grids with ffmpeg

  • You are here: Free PHP » Uncategorized » Video grids with ffmpeg

I wanted to create a video that is a 3x2 grid of 6 other videos. This one to be precise:

I was hoping I can use ffmpeg, because the thought of using a proper video editing software gives me the chills. In fact at some point I thought things will require iMovie and went to install it. But it required OS update. Screw that! FFMPEG it is.

Turns out there's more than one way to skin that particular cat. One is using xstack filter

ffmpeg -i 1.m4v  -i 2.m4v -i 3.m4v -i 4.m4v -i 5.m4v -i 6.m4v \
-filter_complex "xstack=inputs=6:layout=0_0|0_h0|w0_0|w0_h0|w0+w3_0|w0+w3_h0" \
-map "[out]" output.m4v

The other is to use hstack and vstack:

ffmpeg -i 1.m4v  -i 2.m4v -i 3.m4v -i 4.m4v -i 5.m4v -i 6.m4v \
-filter_complex "[0:v][2:v][4:v]hstack=inputs=3[top];[1:v][3:v][5:v]hstack=inputs=3[bottom];[top][bottom]vstack=inputs=2[v]" \
-map "[v]" output.m4v

I'm no ffmpeg expert so I cannot afford the luxury of even pretending to begin to explain this syntax. But it works!

Side note: video editing with Reaper

How do I trim and time-align video without a video editor? I use my music editing software Reaper (unlimitted trial, $60 otherwise). I record the audio in Reaper and the video on an oldish iPhone. Then I drop the video in Reaper and cut it as regular audio file. And visually align the waveforms from the audio recording and the video. Then turn down the volume of the video.

Powered by Gewgley