Why is it still TCP when I using opencv python rtsp capture option "udp"?

I am using python 3.10.12 and opencv-python 4.10.0.84.
I’ve written a code which plays a IP Camera RTSP Video using python and opencv.
Like this:

import cv2
cap = cv2.VideoCapture("rtsp://videoIP")

And I added a line for using UDP packets. (I want to connect with camera through rtsp using UDP. And it really supports it.)

os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"

After wrote this, wireshark says it is still TCP packet from camera IP.

I’ve erased my IPs, just camera source and my PC.
Why is it happend? I’ve already found some docs for opencv, ffmpeg but still I have no idea.

I already ask this question on stackoverflow (Why is it still TCP when I using python opencv rtsp capture option "udp"? - Stack Overflow). but I couldn’t get a clear answer.

see also:

This option always used to work for me. What happens if you set the environmental variable before importing OpenCV or better still in the terminal before starting python?

Does your camera support UDP and have you confirmed this by steaming via udp using another client?

Linear Regression. I like it

Thank you for your advice. I deleted that line and set the environment variable outside the python, session. And I reboot VSCode, Now it captures UDP correctly.

And my camera supports UDP. Actually I already check it up with VLC Media Player Network Streaming via RTSP udp.

Here is the result of setting the environment variable.

1 Like