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

1

12

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.

Hills answered 13/3, 2013 at 16:43 Comment(2)
possible duplicate of Best way to combine 16 live streams into a live 4x4 collage within LinuxWorkbook
It's not a duplicate, I've been leaning toward ffmpeg but I asked if there was a better way in another thread to see if there is one. This thread is specifically how to accomplish a live streaming collage in ffmpeg.Hills
D
11

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.

Dixon answered 13/3, 2013 at 17:19 Comment(4)
Is there a way to use the overlay filter as an output stream?Hills
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/StreamingGuideDixon
Also see the multiple input overlay in 2x2 grid example on the FFmpeg Community Contributed Documentation Wiki.Audiogenic
There's a also tutorial here: trac.ffmpeg.org/wiki/…Ingrid

© 2022 - 2024 — McMap. All rights reserved.