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:
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):
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.