I’m trying to play a UDP video stream coming from a camera with ethernet interface through OpenCV-Gstreamer backend on Windows. For this I’ve already built OpenCV-4.9.0 from source with GStreamer 1.24.3 in Visual Studio 22. After adding necessary paths, I’ve verified its working with the following test program:
import os
os.add_dll_directory("D:\opencv-4.9.0\opencv-4.9.0\build\install\x64\vc17\bin")
os.add_dll_directory("D:\opencv-4.9.0\opencv-4.9.0\build\install\x64\vc17\lib")
os.add_dll_directory("D:\gstreamer\1.0\msvc_x86_64\bin")
import cv2
cap = cv2.VideoCapture('videotestsrc ! videoconvert ! appsink')
while True:
ret,frame = cap.read()
cv2.imshow('',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
cap.release()
This works perfectly and yields me an output window with gstreamer testsrc video:
Now, the problem is when I run gst-launch tool:
gst-launch-1.0 udpsrc buffer-size=600000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)640, height=(string)480, colorimetry=(string)BT709-2, payload=(int)100" port=50001 ! rtpvrawdepay ! glimagesink
I’m able to see the video from the camera without any problem but when I convert the same into Python code below, it fails to create the video pipeline:
import os
os.add_dll_directory("D:\opencv-4.9.0\opencv-4.9.0\build\install\x64\vc17\bin")
os.add_dll_directory("D:\opencv-4.9.0\opencv-4.9.0\build\install\x64\vc17\lib")
os.add_dll_directory("D:\gstreamer\1.0\msvc_x86_64\bin")
import cv2
cap = cv2.VideoCapture('udpsrc buffer-size=600000 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:2, depth=(string)8, width=(string)640, height=(string)480, colorimetry=(string)BT709-2, payload=(int)100" port=50001 ! rtpvrawdepay ! appsink', cv2.CAP_GSTREAMER)
while True:
ret,frame = cap.read()
if ret:
cv2.imshow('',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
cap.release()
and nothing gets displayed:
[ WARN:[email protected]] global cap_gstreamer.cpp:2839 cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module udpsrc0 reported: Internal data stream error.
[ WARN:[email protected]] global cap_gstreamer.cpp:1698 cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:[email protected]] global cap_gstreamer.cpp:1173 cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:[email protected]] global cap.cpp:206 cv::VideoCapture::open VIDEOIO(GSTREAMER): backend is generally available but can't be used to capture by name