Failing to open rtsp stream in ubuntu 18.04 and python

asked 2019-06-19 05:42:50 -0500

Henrik_ gravatar image

Hi!

I am trying to receive a rtsp video stream from my drone camera in python. After searching for solutions online, I ended up trying to use open cv's VideoCapture(...) function. The problem is that it does not open the video capture object, but returns false. It gives no error message. VLC manage to open the stream, so I know it is transmitted correctly.

The code i use for reception:


import cv2 as cv
vcap = cv.VideoCapture("rtsp:// ...")
if vcap.isOpened():
    while(1):
        ret, frame = vcap.read()
        print(ret)
        cv.namedWindow('VIDEO', cv.WINDOW_AUTOSIZE)
        cv.imshow('VIDEO', frame)
        cv.waitKey(1)
else:
    print("Camera failed to open. :(")
 

It prints "Camera failed to open. :(" every time.

I have FFMPEG installed, and cv2. getBuildInformation() returns (among other things):


Video I/O:
    DC1394:                      YES (2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (57.107.100)
      avformat:                  YES (57.83.100)
      avutil:                    YES (55.78.100)
      swscale:                   YES (4.8.100)
      avresample:                YES (3.7.0)
    GStreamer:                   NO
    v4l/v4l2:                    YES (linux/videodev2.h)
 

My system:


OS: Ubuntu 18.04
Python version: 3
OpenCV version: 4.1.0
 

The video stream:


rtps
.h264
 

Any help would be appreciated. :)

edit retag flag offensive close merge delete

Comments

afaik, it only supports tcp over rstp, not udp.

berak gravatar imageberak ( 2019-06-19 05:45:46 -0500 )edit

Thanks for the quick comment!

That makes sense, but is unfortunate. I have tried to use ffmpeg to convert the video stream to a UDP based stream, but that increases the latency. Would you happen to know an other trick to be able to prosess the stream in opencv?

Henrik_ gravatar imageHenrik_ ( 2019-06-19 13:41:35 -0500 )edit