Currently i am working in a computer vision project. I am using opencv - python… cv2.videoCapture(rtsp_url) is taking 10 sec to read the frame. first frame is read only after the 10th sec. so this is causing latency issue. How to fix this
Before trying to fix this I would see if you get the same latency when reading from the same source with ffmpeg outside of OpenCV.
Thank you for response. How can i check that
when i give this command " ffmpeg -i rtsp://<your_rtsp_stream_url> -vf “fps=25” -f sdl “FFmpeg SDL Output”" (replacing with my rtsp url) i get this
ffmpeg version 2024-03-04-git-e30369bc1c-full_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 58. 40.100 / 58. 40.100
libavcodec 60. 41.100 / 60. 41.100
libavformat 60. 23.100 / 60. 23.100
libavdevice 60. 4.100 / 60. 4.100
libavfilter 9. 17.100 / 9. 17.100
libswscale 7. 6.100 / 7. 6.100
libswresample 4. 14.100 / 4. 14.100
libpostproc 57. 4.100 / 57. 4.100
but i dont see the video anywhere
If you want to see video use ffplay instead, the important thing is to measure the delay which I suspect may be similar to OpenCV.
when i use ffplay instead of ffmpeg. i get this
ffplay version 2024-03-04-git-e30369bc1c-full_build-www.gyan.dev Copyright (c) 2003-2024 the FFmpeg developers
built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 58. 40.100 / 58. 40.100
libavcodec 60. 41.100 / 60. 41.100
libavformat 60. 23.100 / 60. 23.100
libavdevice 60. 4.100 / 60. 4.100
libavfilter 9. 17.100 / 9. 17.100
libswscale 7. 6.100 / 7. 6.100
libswresample 4. 14.100 / 4. 14.100
libpostproc 57. 4.100 / 57. 4.100
[rtsp @ 000001aa3e36f480] max delay reached. need to consume packet
[rtsp @ 000001aa3e36f480] RTP: missed 1 packets
nan : 0.000 fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0
but i dont see video playing anywhere
FFplay should display the video the fact that it isn’t probably has something to do with the errors you are getting
If you can address these then it may help with the OpenCV delay.
Note: OpenCV uses FFmpeg for RTSP streaming by default so you need that to work reliably first.
Are you streaming from an IP camera or rtsp server? Is it on your local network on the same subnet or are you routing accross subnets? Do you have routers/switches in between your computer and the rtsp server which could be causing packet loss?