OpenCV VideoCapture failed in capture RTSP video stream

Hi all,

I met a problem while using OpenCV’s VideoCapture function to read the RTSP video stream from a web cam. Here is the result from gdb:

Thread 1 “python” received signal SIGSEGV, Segmentation fault.
0x0000007fb17a3c38 in av_buffer_unref ()
from /usr/lib/aarch64-linux-gnu/libavutil-ffmpeg.so.54

And my OpenCV version is 3.3 with CUDA support, Python version is 2.7.

Thanks a lot for any advices.

Tianpei

Could you share your sample code?

Sure,here is my code:

import cv2

source = “rtsp://admin:pwd@ipaddress”
cap = cv2.VideoCapture(source)
ret, frame = cap.read()

while True:
cv2.imshow(“Frame”, frame)
key = cv2.waitkey(1) & 0xFF

if key == ord("q"):
    break

The video source is a webcam video stream, and I tried these lines in terminal, I got segmentation fault after typing the cv2.VideoCapture line. And I used gbd to run these lines again to get the error info in my first post. Thanks a lot for your help.

Sure,here is my code:

import cv2

source = “rtsp://admin:pwd@ipaddress”
cap = cv2.VideoCapture(source)
ret, frame = cap.read()

while True:
cv2.imshow(“Frame”, frame)
key = cv2.waitkey(1) & 0xFF

if key == ord(“q”):
break

The video source is a webcam video stream, and I tried these lines in terminal, I got segmentation fault after typing the cv2.VideoCapture line. And I used gbd to run these lines again to get the error info in my first post. Thanks a lot for your help.

My code can work, but I don’t have account/pwd setting.

import cv2

source = "rtsp://10.19.106.192:8554/test"
cap = cv2.VideoCapture(source)


if cap.isOpened():
        cv2.namedWindow("demo", cv2.WINDOW_AUTOSIZE)
        while True:
                ret_val, img = cap.read();
                cv2.imshow('demo',img)
                cv2.waitKey(10)
else:
        print "camera open failed"

cv2.destroyAllWindows()

Thank you for your reply. I tried your code in my terminal, but it failed again at the cv2.VideoCapture line, it showed segmentation fault as I mentioned in my first post. I tested to use local video as source video for OpenCV and it worked. Have no idea if I need to re-install the ffmpeg module and OpenCV. BTW which version of OpenCV are you using?

Hi 516920502,

My opencv is installed through Jetapck3.2 which should be v3.3.1. Please select mmapi sample in jetapck and it will install opencv. That is my environment setup.

OK, I will try this way to setup OpenCV again. Thanks.