How to run RTSP Program?

Please provide complete information as applicable to your setup.
• Hardware Platform (Jetson / GPU) nano
• DeepStream Version 7.0
• JetPack Version (valid for Jetson only) 6.0
• TensorRT Version 8.6.2.3-1+cuda12.2
• NVIDIA GPU Driver Version (valid for GPU only) NVIDIA-SMI 540.2.0
• Issue Type( questions, new requirements, bugs) I have implemented python binding,

  1. how to execute code for RTSP Camera : ? https://github.com/NVIDIA-AI- OT/deepstream_python_apps/tree/master/apps/deepstream-test1-rtsp-out

  2. For executation it mentioned to used : $ python3 deepstream_test1_rtsp_out.py -i <h264_elementary_stream> -e 1 with Default RTSP streaming location:
    rtsp://:8554/ds-test

When I execute : sudo python3 test.py -i …/…/video/busan_video.h264 -e 1 it execute only busan_video.h26 frames not rtsp frames

  1. RTSP camera details : when I run sudo python peoplenet_test1_rtsp_out.py -i rtsp://admin:paymentinapp82@192.168.10.138 -c H264 -b 4000000 -e 0 it give error : Unable to create Encoder for H264

Code :

#!/usr/bin/env python3
import argparse
import sys
sys.path.append(‘…/’)

import gi
gi.require_version(‘Gst’, ‘1.0’)
gi.require_version(‘GstRtspServer’, ‘1.0’)
from gi.repository import GLib, Gst, GstRtspServer
from common.is_aarch_64 import is_aarch64
from common.bus_call import bus_call

import pyds

import os

PGIE_CLASS_ID_PERSON = 0
MUXER_BATCH_TIMEOUT_USEC = 33000
global h264parser

def osd_sink_pad_buffer_probe(pad,info,u_data):
frame_number=0
#Intiallizing object counter with 0.
obj_counter = {
PGIE_CLASS_ID_PERSON:0
}
num_rects=0

gst_buffer = info.get_buffer()
if not gst_buffer:
    print("Unable to get GstBuffer ")
    return

# Retrieve batch metadata from the gst_buffer
# Note that pyds.gst_buffer_get_nvds_batch_meta() expects the
# C address of gst_buffer as input, which is obtained with hash(gst_buffer)
batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
l_frame = batch_meta.frame_meta_list
while l_frame is not None:
    try:
        # Note that l_frame.data needs a cast to pyds.NvDsFrameMeta
        # The casting is done by pyds.NvDsFrameMeta.cast()
        # The casting also keeps ownership of the underlying memory
        # in the C code, so the Python garbage collector will leave
        # it alone.
        frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
    except StopIteration:
        break

    frame_number=frame_meta.frame_num
    num_rects = frame_meta.num_obj_meta
    l_obj=frame_meta.obj_meta_list
    while l_obj is not None:
        try:
            # Casting l_obj.data to pyds.NvDsObjectMeta
            obj_meta=pyds.NvDsObjectMeta.cast(l_obj.data)
        except StopIteration:
            break
        obj_counter[obj_meta.class_id] += 1

        # add ssuni------------
        obj_meta.rect_params.border_color.set(0.0, 0.0, 1.0, 0.8) 
        # ---------------------
        
        try: 
            l_obj=l_obj.next
        except StopIteration:
            break

    # Acquiring a display meta object. The memory ownership remains in
    # the C code so downstream plugins can still access it. Otherwise
    # the garbage collector will claim it when this probe function exits.
    display_meta=pyds.nvds_acquire_display_meta_from_pool(batch_meta)
    display_meta.num_labels = 1
    py_nvosd_text_params = display_meta.text_params[0]
    # Setting display text to be shown on screen
    # Note that the pyds module allocates a buffer for the string, and the
    # memory will not be claimed by the garbage collector.
    # Reading the display_text field here will return the C address of the
    # allocated string. Use pyds.get_string() to get the string content.
    py_nvosd_text_params.display_text = "Frame Number={} Number of Objects={} Person_count={}".format(frame_number, num_rects, obj_counter[PGIE_CLASS_ID_PERSON])

    # Now set the offsets where the string should appear
    py_nvosd_text_params.x_offset = 10
    py_nvosd_text_params.y_offset = 12

    # Font , font-color and font-size
    py_nvosd_text_params.font_params.font_name = "Serif"
    py_nvosd_text_params.font_params.font_size = 10
    # set(red, green, blue, alpha); set to White
    py_nvosd_text_params.font_params.font_color.set(1.0, 1.0, 1.0, 1.0)

    # Text background color
    py_nvosd_text_params.set_bg_clr = 1
    # set(red, green, blue, alpha); set to Black
    py_nvosd_text_params.text_bg_clr.set(0.0, 0.0, 0.0, 1.0)
    # Using pyds.get_string() to get display_text as string
    print(pyds.get_string(py_nvosd_text_params.display_text))
    pyds.nvds_add_display_meta_to_frame(frame_meta, display_meta)
    try:
        l_frame=l_frame.next
    except StopIteration:
        break
		
return Gst.PadProbeReturn.OK	

def main(args):
global h264parser
Gst.init(None)

# Create GStreamer elements
print("Creating Pipeline \n ")
pipeline = Gst.Pipeline()
if not pipeline:
    sys.stderr.write("Unable to create Pipeline \n")
    sys.exit(1)

print("Creating RTSP Source \n ")
source = Gst.ElementFactory.make("rtspsrc", "rtsp-source")
if not source:
    sys.stderr.write("Unable to create RTSP Source \n")
    sys.exit(1)

# Connect to the RTSP stream
source.set_property('location', stream_path)
source.set_property('latency', 200)

print("Creating H264Parser \n")
h264parser = Gst.ElementFactory.make("h264parse", "h264-parser")
if not h264parser:
    sys.stderr.write("Unable to create H264 Parser \n")
    sys.exit(1)

print("Creating Decoder \n")
decoder = Gst.ElementFactory.make("nvv4l2decoder", "nvv4l2-decoder")
if not decoder:
    sys.stderr.write("Unable to create Decoder \n")
    sys.exit(1)

print("Creating Stream Muxer \n")
streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
if not streammux:
    sys.stderr.write("Unable to create Stream Muxer \n")
    sys.exit(1)

print("Creating Primary Inference \n")
pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
if not pgie:
    sys.stderr.write("Unable to create Primary Inference \n")
    sys.exit(1)

print("Creating Video Converter \n")
nvvidconv = Gst.ElementFactory.make("nvvidconv", "convertor")
if not nvvidconv:
    sys.stderr.write("Unable to create Video Converter \n")
    sys.exit(1)

print("Creating OSD \n")
nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")
if not nvosd:
    sys.stderr.write("Unable to create OSD \n")
    sys.exit(1)

print("Creating Post OSD Video Converter \n")
nvvidconv_postosd = Gst.ElementFactory.make("nvvidconv", "convertor_postosd")
if not nvvidconv_postosd:
    sys.stderr.write("Unable to create Post OSD Video Converter \n")
    sys.exit(1)

print("Creating Caps Filter \n")
caps = Gst.ElementFactory.make("capsfilter", "filter")
if enc_type == 0:
    caps.set_property("caps", Gst.Caps.from_string("video/x-raw(memory:NVMM), format=I420"))
else:
    caps.set_property("caps", Gst.Caps.from_string("video/x-raw, format=I420"))

# print(f"Creating {codec} Encoder \n")
# if codec == "H264":
#     if enc_type == 0:
#         encoder = Gst.ElementFactory.make("nvv4l2h264enc", "encoder")
#     else:
#         encoder = Gst.ElementFactory.make("x264enc", "encoder")
# elif codec == "H265":
#     if enc_type == 0:
#         encoder = Gst.ElementFactory.make("nvv4l2h265enc", "encoder")
#     else:
#         encoder = Gst.ElementFactory.make("x265enc", "encoder")
# print("Creating Encoder")

# encoder.set_property('bitrate', bitrate)

print(f"Creating {codec} Encoder \n")
if codec == "H264":
    if enc_type == 0:
        encoder = Gst.ElementFactory.make("nvv4l2h264enc", "encoder")
    else:
        encoder = Gst.ElementFactory.make("x264enc", "encoder")
elif codec == "H265":
    if enc_type == 0:
        encoder = Gst.ElementFactory.make("nvv4l2h265enc", "encoder")
    else:
        encoder = Gst.ElementFactory.make("x265enc", "encoder")
else:
    sys.stderr.write(f"Unsupported codec: {codec} \n")
    sys.exit(1)

if not encoder:
    sys.stderr.write(f"Unable to create Encoder for {codec} \n")
    sys.exit(1)

encoder.set_property('bitrate', bitrate)

if is_aarch64() and enc_type == 0:
    encoder.set_property('preset-level', 1)
    encoder.set_property('insert-sps-pps', 1)

print(f"Creating RTP Payloader for {codec} \n")
rtppay = Gst.ElementFactory.make(f"rtp{codec.lower()}pay", "rtppay")
if not rtppay:
    sys.stderr.write(f"Unable to create RTP Payload for {codec} \n")
    sys.exit(1)

print("Creating UDP Sink \n")
updsink_port_num = 5400
sink = Gst.ElementFactory.make("udpsink", "udpsink")
if not sink:
    sys.stderr.write("Unable to create UDP Sink \n")
    sys.exit(1)

sink.set_property('host', '224.224.255.255')
sink.set_property('port', updsink_port_num)
sink.set_property('async', False)
sink.set_property('sync', 1)

print(f"RTSP Camera streaming from {stream_path} \n")

if os.environ.get('USE_NEW_NVSTREAMMUX') != 'yes':
    streammux.set_property('width', 1920)
    streammux.set_property('height', 1080)
    streammux.set_property('batched-push-timeout', MUXER_BATCH_TIMEOUT_USEC)

streammux.set_property('batch-size', 1)
pgie.set_property('config-file-path', "peoplenet_test1_pgie_config.txt")

print("Adding elements to Pipeline \n")
pipeline.add(source)
pipeline.add(h264parser)
pipeline.add(decoder)
pipeline.add(streammux)
pipeline.add(pgie)
pipeline.add(nvvidconv)
pipeline.add(nvosd)
pipeline.add(nvvidconv_postosd)
pipeline.add(caps)
pipeline.add(encoder)
pipeline.add(rtppay)
pipeline.add(sink)

print("Linking elements in the Pipeline \n")
source.connect("pad-added", on_pad_added)
h264parser.link(decoder)

sinkpad = streammux.get_request_pad("sink_0")
srcpad = decoder.get_static_pad("src")
srcpad.link(sinkpad)

streammux.link(pgie)
pgie.link(nvvidconv)
nvvidconv.link(nvosd)
nvosd.link(nvvidconv_postosd)
nvvidconv_postosd.link(caps)
caps.link(encoder)
encoder.link(rtppay)
rtppay.link(sink)

# Create an event loop and feed GStreamer bus messages to it
loop = GLib.MainLoop()
bus = pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message", bus_call, loop)

# Start streaming
rtsp_port_num = 554
server = GstRtspServer.RTSPServer.new()
server.props.service = "%d" % rtsp_port_num
server.set_address("92.168.10.138")
server.attach(None)

factory = GstRtspServer.RTSPMediaFactory.new()
factory.set_launch(f"( udpsrc name=pay0 port={updsink_port_num} buffer-size=524288 caps=\"application/x-rtp, media=video, clock-rate=90000, encoding-name=(string){codec}, payload=96 \" )")
factory.set_shared(True)
server.get_mount_points().add_factory("/ds-test", factory)

print(f"\n *** DeepStream: Launched RTSP Streaming at rtsp://92.168.10.138:{rtsp_port_num}/ds-test ***\n\n")

osdsinkpad = nvosd.get_static_pad("sink")
if not osdsinkpad:
    sys.stderr.write("Unable to get sink pad of nvosd \n")
    sys.exit(1)

osdsinkpad.add_probe(Gst.PadProbeType.BUFFER, osd_sink_pad_buffer_probe, 0)

print("Starting pipeline \n")
pipeline.set_state(Gst.State.PLAYING)
try:
    loop.run()
except KeyboardInterrupt:
    pass
finally:
    pipeline.set_state(Gst.State.NULL)

def on_pad_added(src, new_pad):
sink_pad = h264parser.get_static_pad(“sink”)
if not sink_pad.is_linked():
new_pad.link(sink_pad)

def parse_args():
parser = argparse.ArgumentParser(description='RTSP Output Sample Application Help ')
parser.add_argument(“-i”, “–input”,
help=“RTSP URL for input stream”, required=True)
parser.add_argument(“-c”, “–codec”, default=“H264”,
help=“RTSP Streaming Codec H264/H265 , default=H264”, choices=[‘H264’,‘H265’])
parser.add_argument(“-b”, “–bitrate”, default=4000000,
help=“Set the encoding bitrate “, type=int)
parser.add_argument(”-e”, “–enc_type”, default=0,
help=“0:Hardware encoder , 1:Software encoder , default=0”, choices=[0, 1], type=int)
# Check input arguments
if len(sys.argv)==1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
global stream_path
global codec
global bitrate
global enc_type
stream_path = args.input
codec = args.codec
bitrate = args.bitrate
enc_type = args.enc_type

return args

if name == ‘main’:
args = parse_args()
main(args)

• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
• Requirement details( This is for new requirement. Including the module name-for which plugin or for which sample application, the function description)

Do you using orin nano? This device does not support hardware encoding.

This program input is *.h264 file and forward it to rtsp stream

python3 deepstream_test1_rtsp_out.py -i /opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264 -e 1

Then use ffplay/vlc open rtsp://localhost:8554/ds-test

When I run this code :

sudo python3 sample.py -i …/…/video/busan_video.h264 -e 1

Linking elements in the Pipeline

/home/paymentinapp/Desktop/nus-2024-vision-main/peoplenet_code/rtsp/sample.py:457: DeprecationWarning: Gst.Element.get_request_pad is deprecated
sinkpad = streammux.get_request_pad(“sink_0”)

*** DeepStream: Launched RTSP Streaming at rtsp://192.168.10.138:554/ds-test ***

output :
Frame Number=0 Number of Objects=1 Person_count=1
Frame Number=1 Number of Objects=3 Person_count=3
Frame Number=2 Number of Objects=3 Person_count=3

What is meaning of it ? is it that frame from rtsp://192.168.10.138:554/ds-test is stored into busan_video.h264 ? then program run ?

The purpose of this program is to stream busan_video.h264 to rtsp://192.168.10.138:554/ds-test

But I want to give rtsp://192.168.10.138:554 camera frame input to program, then how to do that ?

Refer to deepstream-test3 or deepstream-rtsp-in-rtsp-out

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

Issue unsolved.