I have Logitech C920 USB webcam connected to my rPi 4 4GB model. I want to stream the video feed through rtsp. The following command runs on the pi:

cvlc -v v4l2:///dev/video0:chroma=mp2v --v4l2-width 1280 --v4l2-height 720 --sout '#transcode{vcodec=mp2v,acodec=mpga,fps=30}:rtp{mux=ts,sdp=rtsp://:8099/}'

When opening the feed using VLC media player on Windows, I am able to see the feed. However, with the following Python code, I am unable to receive the feed in OpenCV:

import cv2
import os

os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"

cap = cv2.VideoCapture('rtsp://',cv2.CAP_FFMPEG)
ret, frame = cap.read()

while ret:
    cv2.imshow('frame', frame)

    ret, frame = cap.read()
    if (cv2.waitKey(1) & 0xFF == ord('q')):


With this code, I get the following error output:

[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (116) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): rtsp:// in function 'cv::icvExtractPattern'

[rtsp @ 000001db6d7528c0] method SETUP failed: 459 Client error

Even by removing the line os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp" or removing the parameter cv2.CAP_FFMPEG it is not working and then I get the same error except the 459 Client error is not showing.

What am I doing wrong or am I missing to get it to work via Python OpenCV?

  • I think this might be more of a general programming question rather than a Raspberry Pi question. Did you try asking on Stack Overflow?
    – David
    Nov 12, 2020 at 21:13
  • Have you already tried the same Python code but from a different streaming source? If that's the case and it worked, is the problem that this is not working because the source is now a Raspberry Pi?
    – David
    Nov 12, 2020 at 21:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.