Join videos with split screen

5

6

I am looking for a command to join two video files, however I want the videos joined split-screen, frame by frame, instead of one after another.

Any ideas? Seems this is not possible with ffmpeg.

hoju

Posted 2010-06-16T11:04:48.520

Reputation: 849

Answers

11

With a recent version of ffmpeg (assuming both videos are the same resolution):

ffmpeg -i input1.mp4 -i input2.mp4 \
 -filter_complex \
    "[0:v]pad=iw*2:ih[int]; \
     [int][1:v]overlay=W/2:0[vid]" \
-map "[vid]" \
-c:v libx264 -crf 23 \
output.mp4

This essentially doubles the size of input1.mp4 by padding the right side with black the same size as the original video, and then places input2.mp4 over the top of that black area with the overlay filter.

If one of your videos has an audio track that you need to add to the output, add the option -map 0:a for the first file's audio, or -map 1:a for the second file's audio.

If you have two audio tracks that you would like to mix, use the amix filter:

ffmpeg -i input1.mp4 -i input2.mp4 \
 -filter_complex \
    "[0:v]pad=iw*2:ih[int]; \
     [int][1:v]overlay=W/2:0[vid]; \
     [0:a][1:a]amix=inputs=2:duration=longest[aud]" \
-map "[vid]" \
-map "[aud]" \
-c:v libx264 -crf 23 \
-c:a aac -b:a 192k \
output.mp4

evilsoup

Posted 2010-06-16T11:04:48.520

Reputation: 10 085

I'm getting Unrecognized option 'crf'. Error splitting the argument list: Option not found. If I remove cr then unrecognized option 'preset' – R S – 2018-03-10T16:58:42.130

You might get the following error if your videos have an odd number of pixels on a given size:

`[Parsed_pad_0 @ 0x1e6e1c0] Input area 0:0:445:369 not within the padded area 0:0:890:368 or zero-sized`

Simply adding 1 to the width and height of the output gets rid of this problem:

ffmpeg -i left.avi -i right.avi -filter_complex \ '[0:v]pad=iw*2+1:ih+1[int];[int][1:v]overlay=W/2:0[vid]' \ -map [vid] -c:v libx264 -crf 23 -preset veryfast output.avi – una_dinosauria – 2018-03-19T21:14:59.840

I get [AVFilterGraph @ 0000025e2fb2b480] No such filter: '[0:v]pad=iw*2:ih[int];[int][1:v]overlay=W/2:0[vid]' Error initializing complex filters. – Zurechtweiser – 2018-05-17T12:15:03.793

Let's say I want to do this with three videos, or four. What would I need to change to do so? – Austin Burk – 2020-02-06T17:46:50.587

-3

this can be done with the SOC version of libavfilter and some ingenuity

hoju

Posted 2010-06-16T11:04:48.520

Reputation: 849