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://192.168.0.251:8099/',cv2.CAP_FFMPEG)
ret, frame = cap.read()
while ret:
cv2.imshow('frame', frame)
ret, frame = cap.read()
if (cv2.waitKey(1) & 0xFF == ord('q')):
break
cap.release()
cv2.destroyAllWindows()
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://192.168.0.251:8099/test 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?