Problem with saving concatenated rtsp stream

Hi,
I’m currently using this command to record the video stream from 4 rtsp cameras and to concatenate the 4 stream to create one video file:

gst-launch-1.0 nvcompositor name=mix \
    sink_0::xpos=0 sink_0::ypos=0 sink_0::width=$3 sink_0::height=$4  \
    sink_1::xpos=$3 sink_1::ypos=0 sink_1::width=$3 sink_1::height=$4 \
    sink_2::xpos=0 sink_2::ypos=$4 sink_2::width=$3 sink_2::height=$4 \
    sink_3::xpos=$3 sink_3::ypos=$4 sink_3::width=$3 sink_3::height=$4 \
    ! "video/x-raw(memory:NVMM),format=RGBA,width=$(($3*2)),height=$(($4*2))" ! nvvidconv ! "video/x-raw(memory:NVMM),format=NV12" ! nvv4l2h264enc insert-vui=1 profile=2 \
    ! h264parse ! video/x-h264,width=$(($3*2)),height=$(($4*2)),framerate=$5/1 ! matroskamux ! filesink location=$6$1.mp4 sync=false  \
    rtspsrc location=rtsp://192.168.2.18:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! "video/x-raw(memory:NVMM),format=NV12,width=$3,height=$4,pixel-aspect-ratio=1/1" ! queue ! mix.sink_0      \
    rtspsrc location=rtsp://192.168.2.19:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! "video/x-raw(memory:NVMM),format=NV12,width=$3,height=$4,pixel-aspect-ratio=1/1" ! queue ! mix.sink_1      \
    rtspsrc location=rtsp://192.168.2.20:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! "video/x-raw(memory:NVMM),format=NV12,width=$3,height=$4,pixel-aspect-ratio=1/1" ! queue ! mix.sink_2      \
    rtspsrc location=rtsp://192.168.2.21:554/1/h264major ! application/x-rtp,media=video,encoding-name=H264 ! rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! "video/x-raw(memory:NVMM),format=NV12,width=$3,height=$4,pixel-aspect-ratio=1/1" ! queue ! mix.sink_3      

This command run perfectly but I have 2 issues :

  • When I play my video file there is a problem in the ending of the video, it likes the video never finished. There is no fix duration of the video.

  • Second issue is if a camera is not connected or broken my command stops and doesn’t record. Is it possible to find a way to record only on 3 cameras and ignore the one which doesn’t work ? Like a parameter to add in the command ?

The error for the second issue :

ERROR: from element /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc2: Could not open resource for reading and writing.
Additional debug info:
gstrtspsrc.c(7469): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline0/GstRTSPSrc:rtspsrc2:
Failed to connect. (Generic error)

Hi,

It may help to send EoS while terminating the pipeline. Please try to run in a sample like this:
Nvv4l2decoder sometimes fails to negotiate with downstream after several pipeline re-launches - #16 by DaneLLL
Or set -e in gst-launch-1.0 command.

This condition is not handled. By default we verify the functionality of nvcompositor with local video file so the condition does not happen. A possilbe solution is to run in C or python sample to launch the string and receive the error messages. Once either source is broken, re-initialize the string with 3 sources.

For receiving multiple RTSP sources, we would suggest to apply this and set background width and height:
Jetson/L4T/r32.6.x patches - eLinux.org
[gstreamer] patch for running v4l2src + nvcompositor

Thanks for your answer !
It works with the -e option for the first issue
For the second issue, I have to try like you say. How do you run this command on python ?
I don’t understand what changes do the option background-w=2560 background-h=1440 ?

Hi,
There is a potential issue about launching multiple RTSP sources, so we suggest try the patch. Here’s a related topic:
RTSP Server fails when using a second camera with nvcompositor

In python, you can call Gst.parse_launch() to launch a pipeline.

Hi,
I run the command in a subprocess python. It works great !

command_gstreamer="gst-launch-1.0 nvcompositor -e background-w=2560 background-h=1440 name=mix \
    "+camera["18"]+" "+camera["19"]+" "+camera["20"]+" "+camera["21"]+"   \
    ! 'video/x-raw(memory:NVMM),format=RGBA,width="+resolution_w_double+",height="+resolution_h_double+"' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nvv4l2h264enc insert-vui=1 profile=2 \
    ! h264parse ! video/x-h264,width="+resolution_w_double+",height="+resolution_h_double+",framerate="+fps+"/1 ! matroskamux ! filesink location="+folder_to_save+date+".mp4 sync=false  \
    "+camera["18_bis"]+" "+camera["19_bis"]+" "+camera["20_bis"]+" "+camera["21_bis"]+" \
    & PID=$!  ; sleep "+time+" ; kill -INT $PID"

process = subprocess.call(command_gstreamer, shell=True)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.