If the ntp time is received correctly, there will be no problem
Since I don’t have a DS-6.0 xavier, the following example is based on the DS-6.0 x86 docker image
Save the following script as pyds.sh
#!/usr/bin/env bash
set -e
apt update
apt install -y git python-dev python3 python3-pip python3.8-dev cmake g++ build-essential \
libglib2.0-dev libglib2.0-dev-bin python-gi-dev libtool m4 autoconf automake
rm -rf /usr/bin/python3
ln -s /usr/bin/python3.6 /usr/bin/python3
cd /opt/nvidia/deepstream/deepstream/sources
git clone https://github.com/NVIDIA-AI-IOT/deepstream_python_apps.git -b v1.1.0
cd deepstream_python_apps
cp /opt/nvidia/deepstream/deepstream/out.patch .
git apply out.patch
git clone https://github.com/GStreamer/gst-python.git 3rdparty/gst-python
cd 3rdparty/gst-python
git checkout 1a8f48a
./autogen.sh PYTHON=python3
./configure PYTHON=python3
make
make install
cd -
git clone https://github.com/pybind/pybind11.git 3rdparty/pybind11 -b v2.3.0
mkdir bindings/build
cd bindings/build
cmake ../
make -j
pip3 uninstall pyds
pip3 install ./pyds-1.1.0-*.whl
cd -
Save the following patch as out.patch
diff --git a/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py b/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py
index a7de46d..4e036dc 100644
--- a/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py
+++ b/apps/deepstream-rtsp-in-rtsp-out/deepstream_test1_rtsp_in_rtsp_out.py
@@ -31,6 +31,7 @@ gi.require_version("GstRtspServer", "1.0")
from gi.repository import GObject, Gst, GstRtspServer, GLib
import configparser
+import datetime
import argparse
from common.FPS import GETFPS
@@ -56,7 +57,7 @@ pgie_classes_str = ["Vehicle", "TwoWheeler", "Person", "RoadSign"]
# and update params for drawing rectangle, object information etc.
-def tiler_src_pad_buffer_probe(pad, info, u_data):
+def pgie_src_pad_buffer_probe(pad, info, u_data):
frame_number = 0
num_rects = 0
gst_buffer = info.get_buffer()
@@ -112,6 +113,10 @@ def tiler_src_pad_buffer_probe(pad, info, u_data):
obj_counter[PGIE_CLASS_ID_PERSON],
)
+ if ts_from_rtsp:
+ ts = frame_meta.ntp_timestamp/1000000000 # Retrieve timestamp, put decimal in proper position for Unix format
+ print("RTSP Timestamp:",datetime.datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')) # Convert timestamp to UTC
+
# Get frame rate through this probe
fps_streams["stream{0}".format(frame_meta.pad_index)].get_fps()
try:
@@ -155,6 +160,10 @@ def decodebin_child_added(child_proxy, Object, name, user_data):
if name.find("decodebin") != -1:
Object.connect("child-added", decodebin_child_added, user_data)
+ if ts_from_rtsp:
+ if name.find("source") != -1:
+ pyds.configure_source_for_ntp_sync(hash(Object))
+
def create_source_bin(index, uri):
print("Creating source bin")
@@ -310,6 +319,9 @@ def main(args):
streammux.set_property("batch-size", 1)
streammux.set_property("batched-push-timeout", 4000000)
+ if ts_from_rtsp:
+ streammux.set_property("attach-sys-ts", 0)
+
if gie=="nvinfer":
pgie.set_property("config-file-path", "dstest1_pgie_config.txt")
else:
@@ -362,6 +374,12 @@ def main(args):
bus.add_signal_watch()
bus.connect("message", bus_call, loop)
+ pgie_src_pad=pgie.get_static_pad("src")
+ if not pgie_src_pad:
+ sys.stderr.write(" Unable to get src pad \n")
+ else:
+ pgie_src_pad.add_probe(Gst.PadProbeType.BUFFER, pgie_src_pad_buffer_probe, 0)
+
# Start streaming
rtsp_port_num = 8554
@@ -403,6 +421,8 @@ def parse_args():
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("--rtsp-ts", action="store_true", default=False, dest='rtsp_ts', help="Attach NTP timestamp from RTSP source",
+ )
# Check input arguments
if len(sys.argv)==1:
parser.print_help(sys.stderr)
@@ -412,10 +432,12 @@ def parse_args():
global bitrate
global stream_path
global gie
+ global ts_from_rtsp
gie = args.gie
codec = args.codec
bitrate = args.bitrate
stream_path = args.input
+ ts_from_rtsp = args.rtsp_ts
return stream_path
if __name__ == '__main__':
diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt
index 5bf88e4..0c0232c 100644
--- a/bindings/CMakeLists.txt
+++ b/bindings/CMakeLists.txt
@@ -99,7 +99,7 @@ function(add_ds_lib libname)
target_link_libraries(pyds ${libname})
endfunction()
-foreach(nvds_lib nvds_osd nvds_meta nvds_infer nvdsgst_meta nvbufsurface nvbufsurftransform)
+foreach(nvds_lib nvds_osd nvds_meta nvds_infer nvdsgst_meta nvbufsurface nvbufsurftransform nvdsgst_helper)
add_ds_lib(${nvds_lib})
endforeach()
diff --git a/bindings/src/bindfunctions.cpp b/bindings/src/bindfunctions.cpp
index 1397f2b..747d609 100644
--- a/bindings/src/bindfunctions.cpp
+++ b/bindings/src/bindfunctions.cpp
@@ -17,6 +17,7 @@
#include "bind_string_property_definitions.h"
#include "bindfunctions.hpp"
+#include "nvdsgstutils.h"
namespace py = pybind11;
using namespace std;
@@ -741,5 +742,12 @@ namespace pydeepstream {
},
"data"_a,
pydsdoc::methodsDoc::get_segmentation_masks);
+ m.def("configure_source_for_ntp_sync",
+ [](size_t src_elem) {
+ auto *element = reinterpret_cast<GstElement *>(src_elem);
+ configure_source_for_ntp_sync(element);
+ return;
+ },
+ "src_elem"_a);
}
}
\ No newline at end of file
Put them at /opt/nvidia/deepstream/deepstream
, then run ./pyds.sh
pyds-1.1.0 will be installed correctly. If there are permission issues, please add sudo.
Then run the deepstream_test1_rtsp_in_rtsp_out.py
pip3 install datetime
cd /opt/nvidia/deepstream/deepstream-6.0/sources/deepstream_python_apps/apps/deepstream-rtsp-in-rtsp-out
python3 deepstream_test1_rtsp_in_rtsp_out.py -i rtsp://xxxxx:8554/mystream --rtsp-ts
After receiving ntp time, I got the correct log
Frame Number= 672 Number of Objects= 21 Vehicle_count= 19 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53
Frame Number= 673 Number of Objects= 23 Vehicle_count= 20 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53
Frame Number= 674 Number of Objects= 22 Vehicle_count= 20 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53
Frame Number= 675 Number of Objects= 20 Vehicle_count= 18 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53
Frame Number= 676 Number of Objects= 18 Vehicle_count= 16 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53
^CFrame Number= 677 Number of Objects= 16 Vehicle_count= 14 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53
Frame Number= 678 Number of Objects= 14 Vehicle_count= 12 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53
Frame Number= 679 Number of Objects= 16 Vehicle_count= 14 Person_count= 2
RTSP Timestamp: 2024-12-13 09:07:53