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)
Hi. Did you ever find a solution to this? I'm in the same boat.
I haven't found a solution yet. Instead, I've been using a workaround which is just using OpenCV 3.0.0. (OpenCV 3.2.0 seems to have the same problem.) Another workaround would be to modify the code by undoing the changes mentioned in the bug report and doing a full recompile of opencv_java310.dll, open-cv-310.jar, and (most importantly) opencv_ffmpeg310_64.dll. I haven't tried this yet.
Using a modified version of opencv_ffmpeg320_64.dll, I was able to connect to the RTSP server and transmit video over UDP. The modification to opencv_ffmpeg320_64.dll just replaces:
with
in the file cap_ffmpeg_impl.hpp. After making this change, only opencv_ffmpeg320_64.dll has to be recompiled. This workaround will most likely work with a modified opencv_ffmpeg310_64.dll, too.
Hi victorft, I had still the same issue. I tried the following steps:
1 - change cap_ffmpeg_impl.hpp:
2 - recompile opencv (http://www.learnopencv.com/install-op...).
What did I do wrong?
Someone help me,please... :(
Dear @victorft, can you help me again please ?
@victorft i need your help
@victorft i need your help
Just if someone drops here, you can set the environment variable to solve this problem as shown on this PR
setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp");