# RTSP is slow when using Opencv

**URL:** <https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731>\
**Category:** Python\
**Tags:** rtsp, highgui, videoio\
**Created:** [February 23, 2021, 12:54pm UTC](https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731 "2021-02-23T12:54:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego\_Foca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/diego_foca/32/1034_2.png) [@Diego\_Foca](https://forum.opencv.org/u/Diego_Foca)\
**Post date:** [February 23, 2021, 12:54pm UTC](https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731/1 "2021-02-23T12:54:24Z")

</div>

Hello. I’m trying to create a program that when a motion is detected, it takes a picture of a car and storage it, but, I’m using cv2.VideoCapture(“rtsp://admin:a10b20c30d40@192.168.0.116:554/cam/realmonitor?channel=1&subtype=0”) to get that RTSP stream, but, it is really slow and lost some frames compared with the camera stream when access it via http, what could causing this slowly stream ? When I use VLC to show rtsp stream it works normally. Thanks all

import cv2  
import imutils

cap = cv2.VideoCapture(“rtsp://admin:a10b20c30d40@192.168.0.116:554/cam/realmonitor?channel=1&subtype=0”)

while cap.isOpened():

```
ret, frame1 = cap.read()
resized = imutils.resize(frame1, width=600)
cv2.imshow('feed', resized)
# frame1 = frame2

if cv2.waitKey(20) & 0xFF == ord('q'):
    break

```

cap.release()  
cv2.destroyWindow(‘rwr’)

---

<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:** [February 23, 2021, 1:17pm UTC](https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731/2 "2021-02-23T13:17:33Z")

</div>

It depends what you mean by slow?

If you are loosing frames then I would reduce your wait from 20ms to 1ms `waitKey(1)`. This may also be causing rtsp to be “slow”. When you have a long wait in between calls to read(), the bitstream that you are reading from and decoding from under the hood, can get overwritten before you read from it.

---

<div class="post-metadata">

**Author:** ![Diego\_Foca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/diego_foca/32/1034_2.png) [@Diego\_Foca](https://forum.opencv.org/u/Diego_Foca)\
**Post date:** [February 23, 2021, 1:49pm UTC](https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731/3 "2021-02-23T13:49:34Z")

</div>

Tried to change waitKey(1) nothing changed cudawarped. What I mean is when I access camera stream from http and run that project, the difference between a car that appears in a http camera stream image and the applications is about 4 seconds between then, and when my application show that car on a screen, it goes slowly and lost some frames of that image.

---

<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:** [February 23, 2021, 2:15pm UTC](https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731/4 "2021-02-23T14:15:33Z")

</div>

That’s odd. I find VLC has round the same delay (between what’s happening live and what is displayed) as opencv, that’s using opencv with the ffmpeg backend on windows.

Is there still a delay if you remove the resize operation and/or use opencv for the resize operation?

---

<div class="post-metadata">

**Author:** ![Diego\_Foca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/diego_foca/32/1034_2.png) [@Diego\_Foca](https://forum.opencv.org/u/Diego_Foca)\
**Post date:** [February 24, 2021, 1:38pm UTC](https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731/5 "2021-02-24T13:38:32Z")

</div>

Worked cudawarped, tried cv2.resize instead of imutils.resize as you said is working well. Thanks a lot…

---

<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:** [February 24, 2021, 1:40pm UTC](https://forum.opencv.org/t/rtsp-is-slow-when-using-opencv/1731/6 "2021-02-24T13:40:13Z")

</div>

That’s great glad I could help.
