-215 opencv runtime_error ai_generated partial

cv2.error: OpenCV(4.8.0) /modules/videoio/src/cap_gstreamer.cpp:1058: error: (-215:Assertion failed) gst_pipeline is NULL in function 'CvCapture_GStreamer::open'

ID: opencv/video-capture-gstreamer-pipeline-failed

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2024-08-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.5 active — — —
4.8.0 active — — —
4.9.0 active — — —

Root Cause

The GStreamer pipeline string passed to VideoCapture is invalid or GStreamer is not properly initialized.

generic

中文

传递给 VideoCapture 的 GStreamer 管道字符串无效,或 GStreamer 未正确初始化。

Official Documentation

https://docs.opencv.org/4.x/dd/d43/tutorial_gstreamer.html

Workarounds

  1. 85% success gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink # If this works, adapt the same pipeline string for OpenCV: cap = cv2.VideoCapture('videotestsrc ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
    gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink
    # If this works, adapt the same pipeline string for OpenCV:
    cap = cv2.VideoCapture('videotestsrc ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
  2. 80% success cap = cv2.VideoCapture('rtspsrc location=rtsp://example.com/stream ! decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
    cap = cv2.VideoCapture('rtspsrc location=rtsp://example.com/stream ! decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)

中文步骤

  1. gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink
    # If this works, adapt the same pipeline string for OpenCV:
    cap = cv2.VideoCapture('videotestsrc ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
  2. cap = cv2.VideoCapture('rtspsrc location=rtsp://example.com/stream ! decodebin ! videoconvert ! appsink', cv2.CAP_GSTREAMER)

Dead Ends

Common approaches that don't work:

  1. 40% fail

    If OpenCV is built without GStreamer backend, the error changes; this error specifically occurs when GStreamer is present but pipeline fails.

  2. 60% fail

    For RTSP or network streams, a file path won't work; the pipeline must be correctly formatted.

  3. 50% fail

    Missing plugins (e.g., 'videotestsrc') cause pipeline construction to fail silently; the error is not just about syntax.