Hi, i am running a ubuntu VM and trying to get my RTSP from IP camera using open CV but without any success.

import cv2
import os

RTSP_URL = 'rtsp://xxxxx:xxxxxxxxx@178.199.xxx.xx:554/stream1'

cap = cv2.VideoCapture(RTSP_URL)

if not cap.isOpened():
print('Cannot open RTSP stream')
exit(-1)

while True:
print(cap.read())
ret, frame = cap.read()
cv2.imshow('RTSP stream', frame)

if cv2.waitKey(1) == 27:
    break

cap.release()
cv2.destroyAllWindows()

The error i am getting is:

(False, None)
Traceback (most recent call last):
File "b.txt", line 17, in <module>
cv2.imshow('RTSP stream', frame)
cv2.error: OpenCV(4.5.5) /io/opencv/modules/highgui/src/window.cpp:1000: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

This RTSP is working fine in VLC and on local computer but not working when i am trying to run from a Azure VM. Please help asap

@Ashwin Kumar Samal , I did stream with the following code in my environment where I see there is no issue with the code. Also, there should not be any barriers from the OS side. I suggest you check these two,

  • You should use the Public IP of your router while connecting to RSTP URL.
  • Make sure you open the 554 ports on your VM NSG rules. (NSG's are Firewall rules that will by default restrict I/B and O/B traffic to a VM).
  • This should solve your issue.

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.