Creating mosaic of videos using ffmpeg command line

Hi all,

I’ve been looking for a simple solution to create a mosaic of videos more time that I would like to admit. One can do it using OpenCV, or special video editing tools, like Adobe Premier, but I wanted something really specific and simple.

Somebody told me “Maybe ffmpeg can do the job”. Of course!, and it is really straightforward. Here you are an example I just tried, creating a mosaic of two videos of the same size, putting them side by side.

So we have left and right videos:

left  right

And we want to have a single video like this (which can be really useful in Power Point presentations or alike when you want to compare the output of two methods or two videos simultaneously):

mosaic

So the code I used is:

C:\ffmpeg\bin\ffmpeg -i left.avi -i right.avi -filter_complex "nullsrc=size=720x288 [base]; [0:v] setpts=PTS-STARTPTS, scale=360x288 [left]; [1:v] setpts=PTS-STARTPTS, scale=360x288 [right]; [base][left] overlay=shortest=1 [tmp1]; [tmp1][right] overlay=shortest=1:x=360:y=0" -c:v libx264 mosaic.avi

You can download the latest binaries of ffmpeg here.

And you can find more details on this topic in the wiki page.

Cheers!

This entry was posted in Computer vision and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s