Wednesday 27 February 2013

Merging two videos into a single video with side-by-side view using FFMPEG

I am currently evaluating lots of test videos, recorded at different conditions, and found myself wanting to display them both in a side-by-side view, in a single video. As always when it comes to video, I searched for a solution employing ffmpeg, and found a post on Stack Overflow describing almost exactly what I wanted to do. The post gives a demonstration example with scaling and fading of videos, so I had to simplify it to just

  • Pad the left video with extra space on the right, making space for the right video
  • Overlay the left and right videos, and output them to a single video file

This is the syntax I arrived at after some tweaking (all on a single line in the terminal):

ffmpeg.exe -i LeftInput.VOB -vf "[in] pad=2*iw:ih [left]; movie=RightInput.VOB [right]; 
[left][right] overlay=main_w/2:0 [out]" -b:v 3000k Output.mp4

Since I'm not a ffmpeg wizard, I won't claim to understand all the details of the line above. Hopefully, the syntax is (kind of) self-explanatory. However, note the "-b:v 3000k" parameter, which sets the bitrate of the output video to 3000kbits/second. This has to be adjusted in each individual case.