4

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?

4
  • You mention that, "they won't always be the same width"; I assume you mean each set may vary, but will each individual video in the set also vary? Commented Feb 11, 2016 at 21:27
  • So I will have a single video that will come in with varying resolutions, then that will be processed multiple times with different filters and then I wanted to combine the different filters to a single stream. So once they are being cropped, each should have the same dimensions. Commented Feb 11, 2016 at 21:54
  • 1
    rather than give a general description "they won't always be the same width", please edit your Q to include some sample sizes that you expect to process. (They don't have to be exact, just data that will illustrate your problem specifically). GOod luck Commented Feb 11, 2016 at 21:59
  • Thanks, but I was hoping to build a PHP page that would allow users to upload their videos and then apply filters to it, as such there aren't "expected sizes" as it would be whatever users uploaded. Commented Feb 11, 2016 at 22:03

2 Answers 2

17

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'm commenting on an old answer, but nevertheless: how would one achieve a diagonal split from bottom left to upper right?
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.