Video-viewer stops working after some time

I initially used the video-viewer to stream cameras to rtsp, however the video-viewer stops working after X hours.
The way I use video viewer is to loop through my /dev/videoX cameras, and just call video-viewer /dev/videoX rtsp://@:855{i}/camera and send this to background.

The logs I get when it stops working are not very detailed, so I tried to create my own pipeline with Gstreamer python bindings, however the Stream is choppy and always stops after 2 seconds.

import gi
import os
import signal
import sys

gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GLib


def signal_handler(sig, frame):
    print("Caught signal, cleaning up and stopping the main loop.")

def on_new_sample(appsink, appsrc):
    sample = appsink.emit("pull-sample")
    if sample:
        appsrc.emit("push-sample", sample)
    return Gst.FlowReturn.OK

BITRATE = 2000000

main_pipeline_str = f"""
v4l2src device=/dev/video7 do-timestamp=true ! video/x-raw, format=YUY2, width=1920, height=1080, framerate=30/1 ! nvvidconv ! video/x-raw(memory:NVMM) ! nvv4l2h264enc bitrate={BITRATE} preset-level=4 insert-sps-pps=true ! tee name=t
t. ! h264parse ! splitmuxsink location=/external/video_%05d.mkv max-size-time=100000000000 max-files=10
t. ! h264parse ! appsink name=appsink emit-signals=true sync=false

main_pipeline = Gst.parse_launch(main_pipeline_str)
appsink = main_pipeline.get_by_name("appsink")

def error_cb(bus, msg):
    err, debug_info = msg.parse_error()
    print(f"Error: {err.message}")

bus = main_pipeline.get_bus()
bus.connect("message::error", error_cb)

class TestRtspMediaFactory(GstRtspServer.RTSPMediaFactory):
    def __init__(self, appsink):
        self.appsink = appsink

    def do_create_element(self, url):
        print("New client has entered!")
        pipeline_str = "appsrc name=appsrc is-live=true do-timestamp=true ! h264parse ! rtph264pay config-interval=1 pt=96 name=pay0"
        pipeline = Gst.parse_launch(pipeline_str)
        appsrc = pipeline.get_by_name("appsrc")
        self.appsink.connect("new-sample", on_new_sample, appsrc)
        return pipeline

rtsp_server = GstRtspServer.RTSPServer()
factory = TestRtspMediaFactory(appsink)
mount_points = rtsp_server.get_mount_points()
mount_points.add_factory("/camera", factory)

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

mainloop = GLib.MainLoop()

Am I setting up the pipeline wrong ?

@snejati86 I can’t speak to your GstPython code, but regarding video-viewer - I have not comprehensively stress-tested it, as it’s primarily meant for quickly building demos and examples (usually single-stream).

For network streams that are timing out, what you can do is modify video-viewer/ so that if the Capture() call times out or stops working for N frames in a row (or N frames in a time period), then re-created the videoSource/videoOutput interfaces to re-establish connection with the camera devices.

1 Like


Thanks for your response.
My use case is to store the footage on rolling files, and also support rtsp (and in future inference)
Do you have any recommendations on what to use from NVIDIA Tool set for production environment?

I would recommend looking into DeepStream which supports RTSP output as well.

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