Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG Crop with side by side merge

Tags:

shell

ffmpeg

I am trying to create a shell/ffmpeg script that can show multiple files after they have been processed using different filters in a side by side / tiled way. An example of desired output would be: https://www.youtube.com/watch?v=DoPuhMRYem4.

In order to create the desired output I need to crop off the right half of video1 and the left half of video2 and then join them back with [video1+video2] side by side. I have played around with a bunch of different ways of joining them, this does OK:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex "
nullsrc=size=800x400 [background];
[0:v] setpts=PTS-STARTPTS, scale=400x400 [left];
[1:v] setpts=PTS-STARTPTS, scale=400x400 [right];
[background][left]       overlay=shortest=1       [background+left];
[background+left][right] overlay=shortest=1:x=400 [left+right]
" -map '[left+right]' joined.mp4

How can I modify this to detect the video width (they won't always be the same width), divide the width in half and crop either the left or right sides off?

like image 882
Alan Avatar asked Dec 14 '22 08:12

Alan


1 Answers

Split screen

left and right

enter image description here

 ffmpeg -i input0 -i input1 -filter_complex \
"[0:v]crop=iw/2:ih:0:0[left]; \
 [1:v]crop=iw/2:ih:ow:0[right]; \
 [left][right]hstack" output

top and bottom

enter image description here

 ffmpeg -i input0 -i input1 -filter_complex \
"[0:v]crop=iw:ih/2:0:0[top]; \
 [1:v]crop=iw:ih/2:0:oh[bottom]; \
 [top][bottom]vstack" output

diagonal

enter image description here

ffmpeg -i input0 -i input1 -filter_complex \
"[1:v][0:v]blend=all_expr=if(gt(X\,Y*(W/H))\,A\,B)" output

Also see

  • FFmpeg Filters Documentation
like image 127
llogan Avatar answered Jan 03 '23 23:01

llogan