The delay of Gstreamer pipeline in Opencv videoCapture()

Hi everyone,

I have encountered a confusing problem on my jetson TX2. When I use gst command line:

gst-launch-1.0 rtspsrc location=rtsp://192.168.1.168/main latency=30 ! decodebin ! autovideosink

I got the real-time video from my IP camera. But when I tested it by using opencv VideoCapture(), the video is not in real-time, and the delay is accumulating over time.

cap = cv2.VideoCapture("rtspsrc location=rtsp://192.168.1.168/main  latency=30 ! decodebin ! videoconvert ! appsink")

Could someone help me? Best wishes to you all!

Please refer to [url]https://devtalk.nvidia.com/default/topic/1024245/jetson-tx2/opencv-3-3-and-integrated-camera-problems-/post/5210735/#5210735[/url]

Hi DaneLLL,

Thank you very much for you reply. My IP camera is connected with the TX2 by using an Internet cable, not the onboard camera. I built the OpenCV with Gstreamer support and I was able to open the camera, the only problem is that the video is not in real time, the delay is accumulating over time.

Best wishes

Hi,
One performance bottleneck is to do RGBA to BGR conversion via ‘videoconvert’. You shall see improvement by giving I420/NV12 to appsink. In this case you can avoid the SW conversion.

We do see improvement in running the sample and share the information. Also other users can share their experience/suggestion.

Hi DaneLLL,
Thank you very much for your reply! You are right, it seems the bottleneck is ‘videoconvert’. I setup the same environment and code on a server, It runs in real-time.
After I change the code to the following on TX2:

cap = cv2.VideoCapture("rtspsrc location=rtsp://192.168.1.168/main  latency=30 ! decodebin ! nvvidconv ! appsink")

The video can run in real-time without delay. But the video is grey. How can I set it to rgb?

Best wishes

Hi DaneLLL,
I recompiled opencv by the clue in above link. It works fine. Thank you very much for your help.

I have the same problem. How can I fix this in windows?
I have a camera that works with RTPS. When I try with opencv in windows, there is a delay of 4-5 seconds. But when I try the same code with opencv on Ubuntu 20, there is a 300ms delay. How can I fix this?

Hi yusuf-5896,

This is an old thread, plesae help to open a new one for your issue. Thanks