CV capturing rtsp error

Hello, i have been stuck the last couple of days trying to solve this error. I am currently trying to capture a rtsp stream using opencv. I am using the following command to try and capture it. cv::VideoCapture capture(“rtsp://192.168.1.220:10101/stream/1”); W

When I run this line i run into the following error [ WARN:0@30.091] global cap_ffmpeg_impl.hpp:453 _opencv_ffmpeg_interrupt_callback Stream timeout triggered after 30072.553324 ms.

I have also verfied the stream can be captured running the following command ffmpeg -i rtsp://192.168.1.220:10101/stream/1 -c copy output.mp4.

Does anyone have any suggestion on how to fix?

Are you successfully reading any frames by calling capture.read() directly after creating it?

yea I am getting a 0 outputted when i run this.

Which version of OpenCV are you using? If its not the latest version or its before the below commit

you may be facing the issue identified in

If that’s the case either upgrade your version of OpenCV or set the environmental OPENCV_FFMPEG_CAPTURE_OPTIONS variable before launching your program

Windows: set OPENCV_FFMPEG_CAPTURE_OPTIONS="rtsp_flags;tcp"

or
Linux: export OPENCV_FFMPEG_CAPTURE_OPTIONS="rtsp_flags;tcp"

I am using 4.12. After exporting the variable I am now getting this output.

[RTSP demuxer @ 0x5ed1fb95ee00] [Eval @ 0x7ffff543d260] Undefined constant or missing ‘(’ in ‘tcp’
[RTSP demuxer @ 0x5ed1fb95ee00] Unable to parse option value “tcp”
[RTSP demuxer @ 0x5ed1fb95ee00] Error setting option rtsp_flags to value tcp.
[ WARN:0@0.048] global cap.cpp:215 open VIDEOIO(FFMPEG): backend is generally available but can’t be used to capture by name

This shouldn’t be your issue then. Just out of interest how are you setting this environmental variable because the errors don’t make sense?

Can you also add the following to get additional logging

export OPENCV_VIDEOIO_DEBUG=1
export OPENCV_LOG_LEVEL=DEBUG

I’m confused by your error if you are able to stream using ffmpeg from the command line with the exact same string (no username/password) and it is an rtsp stream it should work in OpenCV hopefully the additional logging will shed some light on the situation.

yea i am using a container to run it. so i am just setting it when i make the container using ENV.

adding the debug logs gives me the following errors.

[ WARN:0@0.045] global cap.cpp:141 open VIDEOIO(FFMPEG): trying capture filename=‘rtsp://192.168.1.220:10101/stream/1’ …
[DEBUG:0@0.045] global cap_ffmpeg_impl.hpp:1150 open VIDEOIO/FFMPEG: using capture options from environment: rtsp_flags;tcp
[RTSP demuxer @ 0x5cbc8c8f6f40]
[Eval @ 0x7ffe8af5f9b0] Undefined constant or missing ‘(’ in ‘tcp’
[RTSP demuxer @ 0x5cbc8c8f6f40] Unable to parse option value “tcp”
[RTSP demuxer @ 0x5cbc8c8f6f40] Error setting option rtsp_flags to value tcp.
[ WARN:0@0.045] global cap.cpp:164 open VIDEOIO(FFMPEG): can’t create capture
[ WARN:0@0.045] global cap.cpp:215 open VIDEOIO(FFMPEG): backend is generally available but can’t be used to capture by name
[DEBUG:0@0.045] global cap.cpp:234 open VIDEOIO: choosen backend does not work or wrong. Please make sure that your computer support chosen backend and OpenCV built with right flags.

Also here is how i am installing open cv for my container

RUN apt-get update

RUN apt-get install -y
openssh-server
vim
net-tools
iputils-ping
iproute2
sudo
ffmpeg \
libgstreamer1.0-dev
libavcodec-dev
libavformat-dev
libswscale-dev
libv4l-dev
libx264-dev
gstreamer1.0-plugins-base
gstreamer1.0-plugins-good
gstreamer1.0-plugins-bad
gstreamer1.0-plugins-ugly
gstreamer1.0-libav
libgstreamer-plugins-base1.0-dev
libgstreamer1.0-0

RUN apt-get install -y
wget
git
unzip

RUN apt-get update &&
apt-get install -y build-essential gdb cmake libboost-all-dev &&
apt-get clean

RUN mkdir -p ~/opencv cd ~/opencv &&
wget https://github.com/opencv/opencv/archive/4.12.0.zip &&
unzip 4.12.0.zip &&
rm 4.12.0.zip &&
mv opencv-4.12.0 OpenCV &&
cd OpenCV &&
mkdir build &&
cd build &&
cmake
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=/usr/local
-DWITH_FFMPEG=ON
-DWITH_QT=ON
-DWITH_GSTREAMER=ON
-DWITH_OPENGL=ON
-DFORCE_VTK=ON
-DWITH_TBB=ON
-DWITH_GDAL=ON
-DWITH_XINE=ON
-DBUILD_EXAMPLES=ON .. &&
make -j4 &&
make install &&
ldconfig

ok i forget the quotes on the the inital export. after adding quotes i get this out

[DEBUG:0@0.042] global videoio_registry.cpp:225 VideoBackendRegistry VIDEOIO: Builtin backends(9): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@0.042] global videoio_registry.cpp:249 VideoBackendRegistry VIDEOIO: Available backends(9): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.042] global videoio_registry.cpp:251 VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ WARN:0@0.042] global cap.cpp:141 open VIDEOIO(FFMPEG): trying capture filename=‘rtsp://192.168.1.220:10101/stream/1’ …
[DEBUG:0@0.042] global cap_ffmpeg_impl.hpp:1150 open VIDEOIO/FFMPEG: using capture options from environment: rtsp_transport;tcp
[ WARN:0@30.099] global cap_ffmpeg_impl.hpp:453 _opencv_ffmpeg_interrupt_callback Stream timeout triggered after 30057.021014 ms
[DEBUG:0@30.099] global cap_ffmpeg_impl.hpp:1268 open FFMPEG: stream[0] is video stream with codecID=27 width=0 height=0
[DEBUG:0@30.099] global cap_ffmpeg_hw.hpp:934 HWAccelIterator FFMPEG: allowed acceleration types (none): ‘’
[ WARN:0@30.102] global cap.cpp:153 open VIDEOIO(FFMPEG): created, isOpened=1
[ WARN:0@60.162] global cap_ffmpeg_impl.hpp:453 _opencv_ffmpeg_interrupt_callback Stream timeout triggered after 30059.990509 ms

got it working had to switch to udp instead of using tcp thanks for help

1 Like

Great news. So it opens with tcp but doesn’t send any frames so the prefer_tcp option doesn’t fall back to udp. Maybe a bug in the the way OpenCV is using the ffmpeg lib but will be impossible to re-create without the camera you are using.

Is it easy for you to check what the output is without the addition of the OPENCV_FFMPEG_CAPTURE_OPTIONS flag but with the additonal debug flags so I can see if there is anything obviously wrong?

i had the camera stream set wrong. but yea i can send the output

[DEBUG:0@0.019] global videoio_registry.cpp:225 VideoBackendRegistry VIDEOIO: Builtin backends(9): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@0.019] global videoio_registry.cpp:249 VideoBackendRegistry VIDEOIO: Available backends(9): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.019] global videoio_registry.cpp:251 VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ WARN:0@0.019] global cap.cpp:141 open VIDEOIO(FFMPEG): trying capture filename=‘rtsp://192.168.1.220:10101/stream/1’ …
[DEBUG:0@0.019] global cap_ffmpeg_impl.hpp:1150 open VIDEOIO/FFMPEG: using capture options from environment: rtsp_transport;udp
[rtsp @ 0x639a06dce600] Empty H.264 RTP packet
[rtsp @ 0x639a06dce600] Empty H.264 RTP packet
[h264 @ 0x639a06dd2700] non-existing PPS 0 referenced
[h264 @ 0x639a06dd2700] non-existing PPS 0 referenced
[h264 @ 0x639a06dd2700] decode_slice_header error
[rtsp @ 0x639a06dce600] Empty H.264 RTP packet
[rtsp @ 0x639a06dce600] Empty H.264 RTP packet
[DEBUG:0@15.993] global cap_ffmpeg_impl.hpp:1268 open FFMPEG: stream[0] is video stream with codecID=27 width=1280 height=720
[DEBUG:0@15.993] global cap_ffmpeg_hw.hpp:934 HWAccelIterator FFMPEG: allowed acceleration types (none): ‘’
[ WARN:0@15.995] global cap.cpp:153 open VIDEOIO(FFMPEG): created, isOpened=1

Thank you but I wanted to see the output if you don’t force udp to see what the errors are.

sorry about that. so i disabled that udp capture option in docker file and rebuilt i am now getting this.

[DEBUG:0@0.019] global videoio_registry.cpp:225 VideoBackendRegistry VIDEOIO: Builtin backends(9): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@0.019] global videoio_registry.cpp:249 VideoBackendRegistry VIDEOIO: Available backends(9): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.019] global videoio_registry.cpp:251 VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); FFMPEG(990); GSTREAMER(980); INTEL_MFX(970); V4L2(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ WARN:0@0.019] global cap.cpp:141 open VIDEOIO(FFMPEG): trying capture filename=‘rtsp://192.168.1.220:10101/stream/1’ …
[ WARN:0@30.069] global cap_ffmpeg_impl.hpp:453 _opencv_ffmpeg_interrupt_callback Stream timeout triggered after 30049.319030 ms
[DEBUG:0@30.069] global cap_ffmpeg_impl.hpp:1268 open FFMPEG: stream[0] is video stream with codecID=27 width=0 height=0
[DEBUG:0@30.069] global cap_ffmpeg_hw.hpp:934 HWAccelIterator FFMPEG: allowed acceleration types (none): ‘’
[ WARN:0@30.071] global cap.cpp:153 open VIDEOIO(FFMPEG): created, isOpened=1
ROS finish

1 Like

It looks like there may be an issue with the stream.