Skip to content

Instantly share code, notes, and snippets.

@soerface
Created June 23, 2019 21:08
Show Gist options
  • Save soerface/a8c21c52cc25194f54967b6eb3e9361e to your computer and use it in GitHub Desktop.
Save soerface/a8c21c52cc25194f54967b6eb3e9361e to your computer and use it in GitHub Desktop.
Splits up to four videos into a grid and starts them at different timemarks using ffmpeg
#!/bin/bash
# timestamps in trim filter can be used to sync the videos
# The duration of the first color filter specifies the length of the output video
# Scale / crop may be adjusted for the individual files
ffmpeg -i a.mp4 -i b.mp4 -i c.mp4 -filter_complex \
"color=
d='02\:50\:00':
c=0x161618:
s='1366x768'
[placeholder];
[placeholder]
drawtext=
fontfile=/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf:
text='%{pts\:hms\:-3}':
fontcolor=0xabacad:
x=(w-text_w)/2:
y=(h-text_h)/2:
shadowx=5:
shadowy=5:
fontsize=112
[timestamp];
[timestamp]
split=4
[t0][t1][t2][t3];
[0:v]
trim=
start='00\:01\:55.8',
setpts=PTS-STARTPTS
[v0];
[1:v]
trim=
start='00\:00\:45.6',
setpts=PTS-STARTPTS,
crop=1366:768:0:0
[v1];
[2:v]
trim=
start='00\:00\:40.433',
setpts=PTS-STARTPTS,
scale=1366:768
[v2];
[t0][v0]
overlay=
repeatlast=0
[t0];
[t1][v1]
overlay=
repeatlast=0
[t1];
[t2][v2]
overlay=
repeatlast=0
[t2];
[t0][t1][t2][t3]
xstack=
inputs=4:
layout=0_0|w0_0|0_h0|w0_h0,
format=yuv420p,
fps=30
[v]" \
-map "[v]" output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment