24

I have 2 videos: HEADSHOT.MOV and SCREEN.MOV. They are both large files and I am looking to both shrink (size, bitrate, etc) and place these two side by side in the same, very wide, video frame. The end result would be that when you play the output_video.mp4, you would have a very wide frame with both videos in sync and playing at the same rate.

Here is the syntatically incorrect version of what I am trying to do:

ffmpeg -i HEADSHOT.MOV -t 00:02:00 -acodec libfaac -ab 64k -vcodec libx264 -r 30 -pass 1 -s 374x210 -vf "movie=SCREEN.MOV [small]; [in][small] -an -r 30 -pass 1 -s 374x210 overlay=10:10 -t 00:02:00 [out]" -threads 0 output_movie.mp4

In the above example, I also tried to set a test movie duration for 2 minutes which raises another question, What is the best way to handle 2 movies of varying length (if they are close)?

The resources I have found helpful so far are:

Multiple video sources combined into one and

http://ffmpeg.org/ffmpeg.html#overlay-1

Any help/advice is greatly appreciated. I am having trouble with the FFMPEG syntax! Thank you!

34

The result can be achieved with the combination of scale, pad and overlay filters as the following:

ffmpeg.exe -i LeftInput.mp4 -vf "[in] scale=iw/2:ih/2, pad=2*iw:ih [left]; 
    movie=RightInput.mp4, scale=iw/3:ih/3, fade=out:300:30:alpha=1 [right]; 
    [left][right] overlay=main_w/2:0 [out]" -b:v 768k Output.mp4

Here the first video is shrunk by half, and padded to its original size. The second video is shrunk by two thirds and overlayed on the right half (padding area) of the first one.

The shorter video can be faded out; otherwise, it last frame will be display till the end of the combined video.

The result bit rate can be set with -b:v option. Also, video sizes and positions can be specified in pixels for pad, scale and overlay filters.

6
  • Thank you Dmitry, this is great. Do you have any suggestions for seeking both videos to a common timecode? I know that for the [left] I can use -ss but the only filter I can find for [right] is seek_point but this is only a number of seconds, not a reference to the timecode. Is it possible to use something like setpts=[specific timecode point]? Any other advice for syncing the two? – dcoffey3296 Feb 26 '12 at 14:10
  • 7
    In order to pass input parameters other than movie filter allows, use -filter_complex instead. It is more flexible than -vf. For example the same output could be achieved with following command: ffmpeg.exe -i LeftInput.mp4 -i RightInput.mp4 -filter_complex "[0:v] scale=iw/2:ih/2, pad=2*iw:ih [left]; [1:v] scale=iw/3:ih/3, fade=out:300:30:alpha=1 [right]; [left][right] overlay=main_w/2:0 [out]" -b:v 768k Output.mp4 – Can Bal Mar 30 '13 at 8:10
  • 5
    And is it possible to sync times somehow if one movie start few seconds later? – Flash Thunder Jun 18 '14 at 13:14
  • How to get both audios to line up? – Joshua F. Rountree Jun 12 '15 at 22:54
  • 1
    @CanBal, I get a Filter overlay has a unconnected output error when I try your version with -filter_complex, but after some experimenting I resolved id by removing the final [out] in the args to -filter_complex. – zrajm Dec 11 '18 at 15:53
0

In order to have one video take up the full left half of the output video and the other video take up the full right half of the output video AND to have the correct audio, I will expand upon @Dmitry Shkuropatsky's answer. This took me like 5 or more minutes to figure out, and I used ffmpeg version 3.4 (Copyright (c) 2000-2017):

>ffmpeg -i left.webm -vf "[in] scale=iw/2:ih/2, pad=2*iw:ih [left]; movie=right.mp4, scale=iw/2:ih/2, fade=alpha=1 [right]; [left][right] overlay=main_w/2:0 [out]" -c:a aac -b:v 3800k output.mp4

>ffmpeg -i output.mp4 -i right.mp4 -c copy -map 0:0 -map 1:1 -shortest output_with_audio.mp4

Changes:

  • No fadeout
    I successfully removed the fade out option/argument because it was causing me problems. If you want to use fade out then maybe change the numbers in fade=out:300:30:alpha=1 for your specific case.
  • Left video filling the whole left half and right video filling the whole right half
    Instead of the right half only being two thirds full with the right video I changed it to be fully full with the video for the right half.
  • Fixed audio problems
    I ran the second FFmpeg command because the first one (with all the -vf stuff) seems to only use the audio from the contents of -i and not the contents of movie=. This is a problem if -i is a video with no audio and you want to use the audio from movie=. The second ffmpeg command copies the video stream from output.mp4 and the audio stream from right.mp4 into output_with_audio.mp4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.