How to combine multiple ffmpeg streams into a single 4x4 collage?

16,893

I think you're looking for the ffmpeg overlay filter, here is the documentation with some examples. A copy of a 2x1 example is below, but you'll have to make adjustments for your stream format, frame sizes and more panels.

ffmpeg -i left.avi -i right.avi -filter_complex " 
nullsrc=size=200x100 [background]; 
[0:v] setpts=PTS-STARTPTS, scale=100x100 [left]; 
[1:v] setpts=PTS-STARTPTS, scale=100x100 [right]; 
[background][left]       overlay=shortest=1       [background+left];
[background+left][right] overlay=shortest=1:x=100 [left+right]
"

Alternately, there's also a way to generate a mosiac with VLC.

Share:
16,893
CoryG
Author by

CoryG

Updated on July 23, 2022

Comments

  • CoryG
    CoryG almost 2 years

    I have a server with 16 video capture card channels coming into it and want to stream them with ffmpeg, is it possible to have another stream going out that is a 4x4 collage of the 16 unique channels?

    Edit: Adding a bounty since no working answer has been submitted yet - will reward it to the first one that can show the code to produce a 4x4 grid of 16 live channels (input device being http:// localhost:8090/x.mpg where x= a number 0-15, 352x288 video in MPEG1VIDEO format, YUV420P color at 24-30FPS) - or code that leads me to that solution - the output will be located at http:// localhost:8090/all.mpg and will be a 1408x1152 mpg live stream.

  • CoryG
    CoryG over 11 years
    Is there a way to use the overlay filter as an output stream?
  • Digikata
    Digikata over 11 years
    Yes, the output of the filter can be plugged into a stream just like any other ffmpeg output. The exact setup of the streaming can be complex answer depending on what your requirements are, but see ffmpeg.org/trac/ffmpeg/wiki/StreamingGuide
  • llogan
    llogan over 11 years
  • CoryG
    CoryG over 11 years
    Thanks for the great references!
  • BenC
    BenC almost 11 years
    There's a also tutorial here: trac.ffmpeg.org/wiki/…