Deepstream_test_3.py can't handle rtp video stream, any modification

Hi

I have tried to use deepstream_test_3.py to handle rtp streaming.

Here is a segfault, any idea and how to use it for rtp real time video stream?

PS: python code is from DeepStream v1.1.8

daniel@daniel-nvidia:~/Work/deepstream/sources/deepstream_python_apps/apps/deepstream-test3$ python3 deepstream_test_3.py -i rtp://@:5000
{'input': ['rtp://@:5000'], 'configfile': None, 'pgie': None, 'no_display': False, 'file_loop': False, 'disable_probe': False, 'silent': False}
Creating Pipeline 
 
Creating streamux 
 
Creating source_bin  0  
 
Creating source bin
source-bin-00
Creating Pgie 
 
Creating tiler 
 
Creating nvvidconv 
 
Creating nvosd 
 
Creating nv3dsink 

Adding elements to Pipeline 

Linking elements in the Pipeline 

Now playing...
0 :  rtp://@:5000
Starting pipeline 

WARNING: Deserialize engine failed because file path: /opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-test3/../../../../samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine open error
0:00:03.970644706  9497 0xffff440022f0 WARN                 nvinfer gstnvinfer.cpp:679:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::deserializeEngineAndBackend() <nvdsinfer_context_impl.cpp:1976> [UID = 1]: deserialize engine from file :/opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-test3/../../../../samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine failed
0:00:04.185221884  9497 0xffff440022f0 WARN                 nvinfer gstnvinfer.cpp:679:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::generateBackendContext() <nvdsinfer_context_impl.cpp:2081> [UID = 1]: deserialize backend context from engine from file :/opt/nvidia/deepstream/deepstream-6.3/sources/deepstream_python_apps/apps/deepstream-test3/../../../../samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine failed, try rebuild
0:00:04.185301116  9497 0xffff440022f0 INFO                 nvinfer gstnvinfer.cpp:682:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Info from NvDsInferContextImpl::buildModel() <nvdsinfer_context_impl.cpp:2002> [UID = 1]: Trying to create engine from model files
WARNING: [TRT]: The implicit batch dimension mode has been deprecated. Please create the network with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag whenever possible.
WARNING: Serialize engine failed because of file path: /opt/nvidia/deepstream/deepstream-6.3/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine opened error
0:01:14.081567276  9497 0xffff440022f0 WARN                 nvinfer gstnvinfer.cpp:679:gst_nvinfer_logger:<primary-inference> NvDsInferContext[UID 1]: Warning from NvDsInferContextImpl::buildModel() <nvdsinfer_context_impl.cpp:2029> [UID = 1]: failed to serialize cude engine to file: /opt/nvidia/deepstream/deepstream-6.3/samples/models/Primary_Detector/resnet10.caffemodel_b1_gpu0_int8.engine
INFO: [Implicit Engine Info]: layers num: 3
0   INPUT  kFLOAT input_1         3x368x640       
1   OUTPUT kFLOAT conv2d_bbox     16x23x40        
2   OUTPUT kFLOAT conv2d_cov/Sigmoid 4x23x40         

0:01:14.350950432  9497 0xffff440022f0 INFO                 nvinfer gstnvinfer_impl.cpp:328:notifyLoadModelStatus:<primary-inference> [UID 1]: Load new model:dstest3_pgie_config.txt sucessfully
Decodebin child added: source 

Segmentation fault (core dumped)

Test Environment:

Software part of jetson-stats 4.2.12 - (c) 2024, Raffaello Bonghi
Model: NVIDIA Orin Nano Developer Kit - Jetpack 5.1.4 [L4T 35.6.0]
NV Power Mode[0]: 15W
Serial Number: [XXX Show with: jetson_release -s XXX]
Hardware:
 - P-Number: p3767-0005
 - Module: NVIDIA Jetson Orin Nano (Developer kit)
Platform:
 - Distribution: Ubuntu 20.04 focal
 - Release: 5.10.216-tegra
jtop:
 - Version: 4.2.12
 - Service: Active
Libraries:
 - CUDA: 11.4.315
 - cuDNN: 8.6.0.166
 - TensorRT: 8.5.2.2
 - VPI: 2.4.8
 - OpenCV: 4.9.0 - with CUDA: YES
DeepStream C/C++ SDK version: 6.3

Python Environment:
Python 3.8.10
    GStreamer:                   YES (1.16.3)
  NVIDIA CUDA:                   YES (ver 11.4, CUFFT CUBLAS FAST_MATH)
        OpenCV version: 4.9.0  CUDA True
          YOLO version: 8.3.33
         Torch version: 2.1.0a0+41361538.nv23.06
   Torchvision version: 0.16.1+fdea156
DeepStream SDK version: 1.1.8

I have replied the correct answer. If you want to use test3 to process rtp multicast, you need to modify the code yourself.

diff --git a/apps/deepstream-test3/deepstream_test_3.py b/apps/deepstream-test3/deepstream_test_3.py
index 1d04ebc..4ba889f 100755
--- a/apps/deepstream-test3/deepstream_test_3.py
+++ b/apps/deepstream-test3/deepstream_test_3.py
@@ -34,6 +34,8 @@ import platform
 from common.platform_info import PlatformInfo
 from common.bus_call import bus_call
 from common.FPS import PERF_DATA
+import re
+from urllib.parse import urlparse

 import pyds

@@ -169,6 +171,70 @@ def decodebin_child_added(child_proxy,Object,name,user_data):



+# def create_source_bin(index,uri):
+#     print("Creating source bin")
+
+#     # Create a source GstBin to abstract this bin's content from the rest of the
+#     # pipeline
+#     bin_name="source-bin-%02d" %index
+#     print(bin_name)
+#     nbin=Gst.Bin.new(bin_name)
+#     if not nbin:
+#         sys.stderr.write(" Unable to create source bin \n")
+
+#     # Source element for reading from the uri.
+#     # We will use decodebin and let it figure out the container format of the
+#     # stream and the codec and plug the appropriate demux and decode plugins.
+#     if file_loop:
+#         # use nvurisrcbin to enable file-loop
+#         uri_decode_bin=Gst.ElementFactory.make("nvurisrcbin", "uri-decode-bin")
+#         uri_decode_bin.set_property("file-loop", 1)
+#         uri_decode_bin.set_property("cudadec-memtype", 0)
+#     else:
+#         uri_decode_bin=Gst.ElementFactory.make("uridecodebin", "uri-decode-bin")
+#     if not uri_decode_bin:
+#         sys.stderr.write(" Unable to create uri decode bin \n")
+#     # We set the input uri to the source element
+#     uri_decode_bin.set_property("uri",uri)
+#     # Connect to the "pad-added" signal of the decodebin which generates a
+#     # callback once a new pad for raw data has beed created by the decodebin
+#     uri_decode_bin.connect("pad-added",cb_newpad,nbin)
+#     uri_decode_bin.connect("child-added",decodebin_child_added,nbin)
+
+#     # We need to create a ghost pad for the source bin which will act as a proxy
+#     # for the video decoder src pad. The ghost pad will not have a target right
+#     # now. Once the decode bin creates the video decoder and generates the
+#     # cb_newpad callback, we will set the ghost pad target to the video decoder
+#     # src pad.
+#     Gst.Bin.add(nbin,uri_decode_bin)
+#     bin_pad=nbin.add_pad(Gst.GhostPad.new_no_target("src",Gst.PadDirection.SRC))
+#     if not bin_pad:
+#         sys.stderr.write(" Failed to add ghost pad in source bin \n")
+#         return None
+#     return nbin
+
+def parse_rtp_url(rtp_url):
+    parsed_url = urlparse(rtp_url)
+    if parsed_url.scheme != "rtp":
+        raise ValueError("URL scheme is not RTP")
+
+    # Extract IP and port
+    netloc = parsed_url.netloc
+
+    # Handle the case where the URL is in the format rtp://@port
+    if netloc.startswith('@'):
+        port = int(netloc[1:])  # Extract port after '@'
+        ip = "224.224.255.255"  # No IP provided
+    else:
+        match = re.match(r"(.+):(\d+)", netloc)
+        if match:
+            ip = match.group(1)
+            port = int(match.group(2))
+        else:
+            raise ValueError("Invalid RTP URL format")
+
+    return ip, port
+
 def create_source_bin(index,uri):
     print("Creating source bin")

@@ -180,35 +246,40 @@ def create_source_bin(index,uri):
     if not nbin:
         sys.stderr.write(" Unable to create source bin \n")

-    # Source element for reading from the uri.
-    # We will use decodebin and let it figure out the container format of the
-    # stream and the codec and plug the appropriate demux and decode plugins.
-    if file_loop:
-        # use nvurisrcbin to enable file-loop
-        uri_decode_bin=Gst.ElementFactory.make("nvurisrcbin", "uri-decode-bin")
-        uri_decode_bin.set_property("file-loop", 1)
-        uri_decode_bin.set_property("cudadec-memtype", 0)
-    else:
-        uri_decode_bin=Gst.ElementFactory.make("uridecodebin", "uri-decode-bin")
-    if not uri_decode_bin:
-        sys.stderr.write(" Unable to create uri decode bin \n")
-    # We set the input uri to the source element
-    uri_decode_bin.set_property("uri",uri)
-    # Connect to the "pad-added" signal of the decodebin which generates a
-    # callback once a new pad for raw data has beed created by the decodebin
-    uri_decode_bin.connect("pad-added",cb_newpad,nbin)
-    uri_decode_bin.connect("child-added",decodebin_child_added,nbin)
+    ip, port = parse_rtp_url(uri)
+    udpsrc = Gst.ElementFactory.make("udpsrc", "udpsrc")
+    print(f"{ip} {port}")
+    udpsrc.set_property('address', ip)
+    udpsrc.set_property('port', port)
+    caps = Gst.Caps.from_string("application/x-rtp,encoding-name=H265,payload=96")
+    capsfilter = Gst.ElementFactory.make("capsfilter", "capsfilter")
+    capsfilter.set_property("caps", caps)
+    rtph265depay = Gst.ElementFactory.make("rtph265depay", "rtph265depay")
+    h265parse = Gst.ElementFactory.make("h265parse", "h265parse")
+    nvv4l2decoder = Gst.ElementFactory.make("nvv4l2decoder", "nvv4l2decoder")

     # We need to create a ghost pad for the source bin which will act as a proxy
     # for the video decoder src pad. The ghost pad will not have a target right
     # now. Once the decode bin creates the video decoder and generates the
     # cb_newpad callback, we will set the ghost pad target to the video decoder
     # src pad.
-    Gst.Bin.add(nbin,uri_decode_bin)
-    bin_pad=nbin.add_pad(Gst.GhostPad.new_no_target("src",Gst.PadDirection.SRC))
+    #Gst.Bin.add(nbin, udpsrc, capsfilter, rtph265depay,h265parse,nvv4l2decoder)
+    nbin.add(udpsrc)
+    nbin.add(capsfilter)
+    nbin.add(rtph265depay)
+    nbin.add(h265parse)
+    nbin.add(nvv4l2decoder)
+    udpsrc.link(capsfilter)
+    capsfilter.link(rtph265depay)
+    rtph265depay.link(h265parse)
+    h265parse.link(nvv4l2decoder)
+    bin_ghost_pad = Gst.GhostPad.new_no_target("src",Gst.PadDirection.SRC)
+    bin_pad=nbin.add_pad(bin_ghost_pad)
     if not bin_pad:
         sys.stderr.write(" Failed to add ghost pad in source bin \n")
         return None
+    decoder_src_pad=nvv4l2decoder.get_static_pad("src")
+    bin_ghost_pad.set_target(decoder_src_pad)
     return nbin

 def main(args, requested_pgie=None, config=None, disable_probe=False):
gst-launch-1.0 uridecodebin uri=file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264 ! nvvideoconvert ! "video/x-raw(memory:NVMM),format=NV12" ! nvv4l2h265enc bitrate=2000000 insert-sps-pps=true ! h265parse ! rtph265pay ! udpsink host=224.224.255.255 port=5600
python3 deepstream_test_3.py -i rtp://@5600

That’s very kind of you to help with the demo code. It works here very well!

And two more simple quick questions:

  1. how to get hands on those element/property/parameters, is there any link or guide?
  2. It’s NOT fullscreen (my RTP source is 1920x1080, display is 1920x1080, but the window only displayed roughly a quarter of the screen.). As I’m new to this, just googled some method below, but not working, maybe question 1 can help me. Any idea about this ?
Traceback (most recent call last):
  File "./utils/deepstream/deepstream.py", line 574, in <module>
    sys.exit(main(stream_paths, pgie, config, disable_probe))
  File "./utils/deepstream/deepstream.py", line 377, in main
    sink.set_property('fullscreen', True)
TypeError: object of type `GstNv3dSink' does not have property `fullscreen'

EDIT: I have found top1 search result from Google: GSTreamer nv3dsink without window decorations , but I didn’t get any idea from it. I though it has been set1920x1080 by streammux.

Set the window-width and window-height properties to the width and height of the display resolution.

Use this command line to view the properties that can be set

gst-inspect-1.0 nv3dsink
1 Like

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