Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can OpenCV 3.1.0 be set to capture an RTSP stream over UDP?

Using OpenCV for Java, I've been trying to connect to an RTSP server that will transport video over UDP. The code looks like:

VideoCapture cam = new VideoCapture("rtsp://localhost:8554");

OpenCV sends a setup request to the RTSP server that looks like:

SETUP 127.0.0.1:8554/trackID=1
RTSP/1.0 Transport: RTP/AVP/TCP;unicast;interleaved=0-1
CSeq: 3

The server has to send data over UDP not TCP. I've tried passing in "rtsp://localhost:8554?udp" but that doesn't change the request sent. If I use OpenCV 3.0.0 the setup request that's sent looks like:

SETUP 127.0.0.1:8554/trackID=1
RTSP/1.0 Transport: RTP/AVP/UDP;unicast;client_port=744-7445
CSeq: 3

However, OpenCV 3.0.0 doesn't seem to have VideoWriter while OpenCV 3.1.0 does.

The discussion for a bug report, RTSP over TCP with cvCreateFileCapture not working (Bug #2235), mentions that there was a modification introduced in OpenCV 2.4.11 and 3.1.0, that forces VideoCapture to default to using TCP to transport media. Is data transport over TCP hard coded, or can VideoCapture be somehow set to use UDP?

Also, I tried having the RTSP server send "400 Bad Request" as a response to the TCP transport request, and OpenCV didn't send a follow up request for UDP. It just reported an error:

warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:578)