# Latency in rtsp link

**URL:** <https://forum.opencv.org/t/latency-in-rtsp-link/18201>\
**Category:** Python\
**Tags:** ffmpeg, rtsp, videoio\
**Created:** [July 9, 2024, 8:57am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201 "2024-07-09T08:57:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![s\_p](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/s_p/32/10770_2.png) [@s\_p](https://forum.opencv.org/u/s_p)\
**Post date:** [July 9, 2024, 8:57am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201/1 "2024-07-09T08:57:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [July 9, 2024, 9:22am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201/2 "2024-07-09T09:22:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![s\_p](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/s_p/32/10770_2.png) [@s\_p](https://forum.opencv.org/u/s_p)\
**Post date:** [July 9, 2024, 9:28am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201/3 "2024-07-09T09:28:52Z")

</div>

Thank you for response. How can i check that

---

<div class="post-metadata">

**Author:** ![s\_p](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/s_p/32/10770_2.png) [@s\_p](https://forum.opencv.org/u/s_p)\
**Post date:** [July 9, 2024, 9:36am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201/4 "2024-07-09T09:36:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [July 9, 2024, 10:26am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201/5 "2024-07-09T10:26:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![s\_p](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/s_p/32/10770_2.png) [@s\_p](https://forum.opencv.org/u/s_p)\
**Post date:** [July 9, 2024, 10:57am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201/6 "2024-07-09T10:57:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [July 9, 2024, 11:55am UTC](https://forum.opencv.org/t/latency-in-rtsp-link/18201/7 "2024-07-09T11:55:28Z")

</div>

FFplay should display the video the fact that it isn’t probably has something to do with the errors you are getting

> [@s\_p](#):
>
> [rtsp @ 000001aa3e36f480] max delay reached. need to consume packet  
> [rtsp @ 000001aa3e36f480] RTP: missed 1 packets

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?
