I try to stream via rtsp using opencv but i always get 'can't connect to rstp', but i've tryto acces my rtsp url through VLC and It's work. Why?

Hi everyone, I’m trying to acces my cctv frame using rtsp but it always return ‘empty frame’. I am using HIkvision cctv camera. Here’s the code:

import cv2

rtsp_url = 'rtsp://<username>:<password>@<IP address of device>:<RTSP port>/Streaming/channels/<channel number><stream number>'

cap = cv2.VideoCapture(rtsp_url)

if not cap.isOpened():

    print("can't connect to rstp")


while True:

    ret, frame = cap.read()

    if not ret:

        print("can't read the frame")

    cv2.imshow('RTSP Streaming', frame)

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


The default distribution of VLC includes many free decoding and encoding libraries, avoiding the need for finding/calibrating proprietary plugins. The libavcodec library from the FFmpeg project provides many of VLC’s codecs, but the player mainly[15] uses its own muxers and demuxers. It also has its own protocol implementations.

may be you should try with gstreamer

Usually hik requires a username and password unless you explicitly disabled it. Did you enter a username and password in vlc the first time you connect?

ok, thanks. I’ll read the doc first

yes i did, but some how it didnt work on my code

Whats the exact url you are using?