ubuntu vm - ip camera RTSP is not not getting the frame

Ashwin Kumar Samal 1 Reputation point
2022-01-06T00:43:16.197+00:00

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

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,038 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. suvasara-MSFT 10,046 Reputation points
    2022-01-06T12:43:37.957+00:00

    @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,

    1. You should use the Public IP of your router while connecting to RSTP URL.
    2. 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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.