2

Can anyone please help understand how to make correct -filter_complex expression in ffmpeg to join 4 RTSP streams in a row collage 1x4? The complexity is that there is ONE input with 4 video streams inside. ffprobe output:

Input #0, rtsp, from 'rtsp://MyStream':
  Metadata:
    title           : h264.sdp
  Duration: N/A, start: 0.024944, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), yuv420p, 640x480, 27.92 tbr, 90k tbn, 180k tbc
Stream #0:1: Video: h264 (Baseline), yuv420p, 640x480, 27.92 tbr, 90k tbn, 180k tbc
Stream #0:2: Video: h264 (Baseline), yuv420p, 640x480, 27.92 tbr, 90k tbn, 180k tbc
Stream #0:3: Video: h264 (Baseline), yuv420p, 640x480, 27.92 tbr, 90k tbn, 180k tbc
llogan
  • 121,796
  • 28
  • 232
  • 243
vyazikov
  • 35
  • 1
  • 8

1 Answers1

8

A row of videos

You can use the hstack (or vstack) video filter:

overlay example
In this example each color represents a separate video input or stream.

One input with four video streams (as in the question)

ffmpeg -i input \
-filter_complex "[0:v:0][0:v:1][0:v:2][0:v:3]hstack=inputs=4[v]" \
-map "[v]" output.mp4

Four inputs with one video stream each

ffmpeg -i input0 -i input1 -i input2 -i input3 \
-filter_complex "[0:v][1:v][2:v][3:v]hstack=inputs=4[v]" \
-map "[v]" output.mp4

Same as above but with combined audio

Using the amerge filter:

ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex \
"[0:v][1:v][2:v][3:v]hstack=inputs=4:shortest=1[v]; \
 [0:a][1:a][2:a][3:a]amerge=inputs=4[a]" \
-map "[v]" -map "[a]" -shortest output.mp4

With padding or borders

You can add a border between each video with the pad filter. This example will add 10 pixel padding between each video:

overlay with padding

ffmpeg -i input0 -i input1 -i input2 -i input3 -filter_complex \
"[0:v]pad=iw+10[v0]; \
 [1:v]pad=iw+10[v1]; \
 [2:v]pad=iw+10[v2]; \
 [0v][1v][2v][3:v]hstack=inputs=4[v]" \
-map "[v]" output.mp4
llogan
  • 121,796
  • 28
  • 232
  • 243