Skip to content

Instantly share code, notes, and snippets.

@uotw
Last active August 7, 2019 04:00
Show Gist options
  • Save uotw/878d04974566b78433759422af17368c to your computer and use it in GitHub Desktop.
Save uotw/878d04974566b78433759422af17368c to your computer and use it in GitHub Desktop.
combine 4 clips into one 2 x 2 grid video mosaic
#!/usr/bin/env bash
finalwidth=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=p=0 $1)
finalheight=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of csv=p=0 $1)
halfwidth=$(echo "$finalwidth/2" | bc)
halfheight=$(echo "$finalheight/2" | bc)
x="x"
ffmpeg -i $1 -i $2 -i $3 -i $4 -filter_complex "nullsrc=size=$finalwidth$x$finalheight [base]; [0:v] setpts=PTS-STARTPTS, scale=$halfwidth$x$halfheight [upperleft]; [1:v] setpts=PTS-STARTPTS, scale=$halfwidth$x$halfheight [upperright]; [2:v] setpts=PTS-STARTPTS, scale=$halfwidth$x$halfheight [lowerleft]; [3:v] setpts=PTS-STARTPTS, scale=$halfwidth$x$halfheight [lowerright]; [base][upperleft] overlay=shortest=1 [tmp1]; [tmp1][upperright] overlay=shortest=1:x=$halfwidth [tmp2]; [tmp2][lowerleft] overlay=shortest=1:y=$halfheight [tmp3]; [tmp3][lowerright] overlay=shortest=1:x=$halfwidth:y=$halfheight" -c:v libx264 quad_vid.mp4
@uotw
Copy link
Author

uotw commented Aug 7, 2019

Here's an online version of the tool
https://sonoclipshare.com/quad_video/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment