Search code examples
gstreamerrtmp

Multiple RTMP inputs - picture in picture - stream offline handling


I'm using gstreamer to make a picture-in-picture composition of two rtmp inputs into an rtmp output. I've managed to create a pipeline that works very well when both streams are offline However, when one of the rtmp streams is not live when starting the pipeline - the pipeline does not start.

Does anyone know how to overcome this issue, and make sure the pipeline is not blocked if one rtmp source is offline?


Solution

  • You may have to insert identity into compositor input sub-pipelines.

    Simulating 2 sources on localhost with:

    gst-launch-1.0 videotestsrc ! x264enc insert-vui=1 ! h264parse config-interval=1 ! mpegtsmux ! rtpmp2tpay ! udpsink port=5004
    

    (and second source the same to port 5005), the following runs fine for 0, 1 or 2 sources active at launch time:

    gst-launch-1.0 -v \
       udpsrc port=5004 ! application/x-rtp,media=video,encoding-name=MP2T,clock-rate=90000,payload=33 ! rtpjitterbuffer latency=300 ! rtpmp2tdepay ! tsdemux ! h264parse ! avdec_h264 ! videoconvert ! identity ! queue ! comp.sink_0 \
       udpsrc port=5005 ! application/x-rtp,media=video,encoding-name=MP2T,clock-rate=90000,payload=33 ! rtpjitterbuffer latency=300 ! rtpmp2tdepay ! tsdemux ! h264parse ! avdec_h264 ! videoconvert ! identity ! queue ! comp.sink_1 \
       compositor name=comp sink_0::xpos=0 sink_0::ypos=0 sink_0::width=320 sink_0::height=240 sink_1::xpos=0 sink_1::ypos=240 sink_1::width=320 sink_1::height=240 ! video/x-raw,width=320,height=480 ! videoconvert ! xvimagesink
    

    For rtmp, with mpeg audio from first source, it would be something like:

    gst-launch-1.0 -v \
       rtmpsrc <your source1 and options> ! flvdemux name=demux0 ! queue ! h264parse ! avdec_h264 ! videoconvert ! identity ! queue ! comp.sink_0 \
       rtmpsrc <your source2 and options> ! flvdemux name=demux1 ! queue ! h264parse ! avdec_h264 ! videoconvert ! identity ! queue ! comp.sink_1 \
       compositor name=comp sink_0::xpos=0 sink_0::ypos=0 sink_0::width=320 sink_0::height=240 sink_1::xpos=0 sink_1::ypos=240 sink_1::width=320 sink_1::height=240 ! video/x-raw,width=320,height=480 ! videoconvert ! autovideosink \
       demux0. ! queue ! audio/mpeg ! decodebin ! audioconvert ! audioresample ! autoaudiosink