[FFmpeg-user] Merge two videos into one with side-by-side composition

Lou lou at lrcd.com
Mon Jun 10 21:57:51 CEST 2013


On Mon, 10 Jun 2013 09:27:22 -0700
John Crossman <johncrossman at berkeley.edu> wrote:

> Is there ffmpeg documentation on how to merge two videos into one with
> side-by-side composition?
> 
> The following is an example of what I'm after. Jump to 0:30:
> http://www.youtube.com/watch?v=0AJWmt5A62Y

You can use the pad [1] and overlay [2] video filters to place your
videos:

ffmpeg -i input1 -i input2 -filter_complex \
"[0:v:0]pad=iw*2:ih[bg]; [bg][1:v:0]overlay=w" output

The overlay docs states:

  Be aware that frames are taken from each input video in timestamp
  order, hence, if their initial timestamps differ, it is a a good
  idea to pass the two inputs through a setpts=PTS-STARTPTS filter to
  have them begin in the same zero timestamp, as it does the example
  for the movie filter. 

Resulting in:

ffmpeg -i input1 -i input2 -filter_complex \
"[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; \
[1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w" output

By default only one audio stream will be used, so if you want to combine
both input audio streams into one output audio stream you can use the
amerge [3] and pan [4] audio filters. My example has one stereo audio
stream per input and the output will have one combined stereo audio
stream:

ffmpeg -i input1 -i input2 -filter_complex \
"[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; \
[1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w; \
amerge,pan=stereo:c0<c0+c2:c1<c1+c3" output

This combination of filters is not the only method to do this, and I
may have forgotten something, so feel free to experiment.

[1] http://ffmpeg.org/ffmpeg-filters.html#pad
[2] http://ffmpeg.org/ffmpeg-filters.html#overlay-1
[3] http://ffmpeg.org/ffmpeg-filters.html#amerge
[4] http://ffmpeg.org/ffmpeg-filters.html#pan


More information about the ffmpeg-user mailing list