GOOGLE ADS

Montag, 11. April 2022

GStreamer-Pipeline + OpenCV VideoCapture.read() gibt None zurück

Ich versuche, eine GStreamer + OpenCV RTSP-Videoaufnahme mit dem folgenden zu erhalten:

vcap = cv2.VideoCapture("""rtspsrc location=rtsp://192.168.100.60:554/stream1 latency=0! queue! rtph264depay
! h264parse! avdec_h264! videoconvert! appsink""", cv2.CAP_GSTREAMER)
while True:
ret, frame = vcap.read()
print(frame)
cv2.imshow('VIDEO', frame)
cv2.waitKey(1)

Der Frame, der von gelesen wird, vcapist jedoch None:

(<unknown>:79564): GLib-GObject-WARNING **: 00:27:54.660: invalid cast from 'GstQueue' to 'GstBin'
(<unknown>:79564): GStreamer-CRITICAL **: 00:27:54.660: gst_bin_iterate_elements: assertion 'GST_IS_BIN (bin)' failed
(<unknown>:79564): GStreamer-CRITICAL **: 00:27:54.660: gst_iterator_next: assertion 'it!= NULL' failed
(<unknown>:79564): GStreamer-CRITICAL **: 00:27:54.660: gst_iterator_free: assertion 'it!= NULL' failed
[ WARN:0@0.020] global /tmp/opencv-20220409-60041-xvxfur/opencv-4.5.5/modules/videoio/src/cap_gstreamer.cpp (1226) open OpenCV | GStreamer warning: cannot find appsink in manual pipeline
[ WARN:0@0.020] global /tmp/opencv-20220409-60041-xvxfur/opencv-4.5.5/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
None
Traceback (most recent call last):
File "/Volumes/Data/Projects/rtmp_test/src/test.py", line 21, in <module>
read(1)
File "/Volumes/Data/Projects/rtmp_test/src/test.py", line 18, in read
cv2.imshow('VIDEO', frame)
cv2.error: OpenCV(4.5.5) /tmp/opencv-20220409-60041-xvxfur/opencv-4.5.5/modules/highgui/src/window.cpp:1000: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

Der Stream kann in VLC einwandfrei abgespielt werden und gst-launch-1.0 rtspsrc location=rtsp://192.168.100.60:554/stream1 latency=0! queue! rtph264depay! h264parse! avdec_h264! videoconvert! appsinkliefert eine reguläre Ausgabe. Weiß jemand, was falsch sein könnte?


Lösung des Problems

Sie können versuchen, Großbuchstaben als Videoformat BGR (oder GRAY8 für Monochrom) vor Appsink anzugeben, da dies das Standardformat wäre, das in den meisten Fällen von OpenCV erwartet wird:

gst_pipeline='rtspsrc location=rtsp://192.168.100.60:554/stream1 latency=0! queue! rtph264depay! h264parse! avdec_h264! videoconvert! video/x-raw,format=BGR! appsink drop=1'
cap = cv2.VideoCapture(gst_pipeline, cv2.CAP_GSTREAMER)

Keine Kommentare:

Kommentar veröffentlichen

Warum werden SCHED_FIFO-Threads derselben physischen CPU zugewiesen, obwohl CPUs im Leerlauf verfügbar sind?

Lösung des Problems Wenn ich das richtig verstehe, versuchen Sie, SCHED_FIFO mit aktiviertem Hyperthreading ("HT") zu verwenden, ...