Rtsp and gst-launch is not working opencv.VideoCapture in python but working in x86

I am using python 3.6.9 and opencv 4.5.2.

In x86, below code is working. I could see video, but it is not working in xavier nx.


import cv2

cameraCapture = cv2.VideoCapture(“rtsp://192.168.0.201:554/live0”, cv2.CAP_GSTREAMER)

if not cameraCapture.isOpened():
print(‘VideoCapture not opened’)
exit(-1)
cv2.namedWindow(‘RTSP Receiver’)

print(‘VideoCapture is capturing…’)
while True:
success, frame = cameraCapture.read()
cv2.imshow(‘RTSP Receiver’, frame)

if cv2.waitKey(1) & 0xff == ord("q"):
	break

cv2.destroyWindow(‘RTSP Receiver’)

cameraCapture.release()


.

Additionally, gst-launch is working in shell command like below but not working using opencv.

gst-launch-1.0 rtspsrc location=rtsp://192.168.0.201:554/live0 drop_on_latency=true udp_buffer_size=1572864 do_retransmission=false latency=1 ! queue max_size_time=5000000000 max-size-bytes=0 max-size-buffers=0 leaky=1 ! rtph265depay ! h265parse ! omxh265dec ! nvoverlaysink


import cv2

gst_str = ‘rtspsrc location=rtsp://192.168.0.201:554/live0 drop_on_latency=true udp_buffer_size=1572864 do_retransmission=false latency=1 ! queue max_size_time=5000000000 max-size-bytes=0 max-size-buffers=0 leaky=1 ! rtph265depay ! h265parse ! omxh265dec ! nvoverlaysink’

cameraCapture = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

if not cameraCapture.isOpened():
print(‘VideoCapture not opened’)
exit(-1)
cv2.namedWindow(‘RTSP Receiver’)

print(‘VideoCapture is capturing…’)
while True:
success, frame = cameraCapture.read()
cv2.imshow(‘RTSP Receiver’, frame)

if cv2.waitKey(1) & 0xff == ord("q"):
	break

cv2.destroyWindow(‘RTSP Receiver’)

cameraCapture.release()

Thanks,

Hi,
Please try this python code on Xavier NX:
Doesn't work nvv4l2decoder for decoding RTSP in gstreamer + opencv - #3 by DaneLLL

It works well great!. But streaming is delayed about 5~6 sec.
What option needs?

Thank you.

Hi,
Generally delay is from the source and network, but you can run system in max performance mode and check if there is improvment. You can execute sudp nvpmodel -m 2, sudo jetson_clocks, and in nvv4l2decoder, set

  enable-max-performance: Set to enable max performance
                        flags: readable, writable
                        Boolean. Default: false

You may also set

  disable-dpb         : Set to disable DPB buffer for low latency
                        flags: readable, writable
                        Boolean. Default: false

But this works with certain h264 stream. You may try with your source and see if it works.

how to set in nvv4l2decoder?

Hi,
You may try

... ! nvv4l2decoder enable-max-performance-1 ! ...

and

... ! nvv4l2decoder enable-max-performance-1 disable-dpb=1 ! ...

Hi,

this code is working. I think the delay is enough to accept.

import cv2

gst_str = “rtspsrc location=rtsp://192.168.0.201:554/live0 drop_on_latency=true latency=1 ! rtph265depay ! h265parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink”

cameraCapture = cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

if not cameraCapture.isOpened():
print(‘VideoCapture not opened’)
exit(-1)
cv2.namedWindow(‘RTSP Receiver’)

print(‘VideoCapture is capturing…’)
while True:
success, frame = cameraCapture.read()
cv2.imshow(‘RTSP Receiver’, frame)

if cv2.waitKey(1) & 0xff == ord("q"):
    break

cv2.destroyWindow(‘RTSP Receiver’)

cameraCapture.release()

but the video is crumble shortly when fast scene changes and etc.