FFMPEG Crop with side by side merge

我只是一个虾纸丫 提交于 2021-02-04 15:59:05

问题


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?


回答1:


Split screen

left and right

 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

 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

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



回答2:


Slightly different, but if you want to center crop the input videos and put them side-by-side, use this:

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


来源:https://stackoverflow.com/questions/35349935/ffmpeg-crop-with-side-by-side-merge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!