# OpenCV: GStreamer: cannot link elements: source -> decodebin

- **ID:** `opencv/videocapture-gstreamer-pipeline-failed`
- **Domain:** opencv
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The GStreamer pipeline string passed to VideoCapture contains incompatible elements or missing plugins, preventing the source element from linking to decodebin.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| opencv-4.5.5 | active | — | — |
| opencv-4.8.0 | active | — | — |
| opencv-4.9.0 | active | — | — |

## Workarounds

1. **Test the pipeline outside OpenCV first: run 'gst-launch-1.0 filesrc location=video.mp4 ! decodebin ! fakesink'. If it fails, install missing plugins: 'sudo apt-get install gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly'. Then adjust the pipeline string: cv::VideoCapture cap('filesrc location=video.mp4 ! decodebin ! videoconvert ! appsink', cv::CAP_GSTREAMER);** (85% success)
   ```
   Test the pipeline outside OpenCV first: run 'gst-launch-1.0 filesrc location=video.mp4 ! decodebin ! fakesink'. If it fails, install missing plugins: 'sudo apt-get install gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly'. Then adjust the pipeline string: cv::VideoCapture cap('filesrc location=video.mp4 ! decodebin ! videoconvert ! appsink', cv::CAP_GSTREAMER);
   ```
2. **Simplify the pipeline to use autovideosrc for live cameras: cv::VideoCapture cap('autovideosrc ! videoconvert ! appsink', cv::CAP_GSTREAMER);** (75% success)
   ```
   Simplify the pipeline to use autovideosrc for live cameras: cv::VideoCapture cap('autovideosrc ! videoconvert ! appsink', cv::CAP_GSTREAMER);
   ```
3. **Provide a full GStreamer pipeline with explicit caps: cv::VideoCapture cap('filesrc location=video.mp4 ! qtdemux ! h264parse ! avdec_h264 ! videoconvert ! appsink', cv::CAP_GSTREAMER);** (80% success)
   ```
   Provide a full GStreamer pipeline with explicit caps: cv::VideoCapture cap('filesrc location=video.mp4 ! qtdemux ! h264parse ! avdec_h264 ! videoconvert ! appsink', cv::CAP_GSTREAMER);
   ```

## Dead Ends

- **Change the video file path to an absolute path** — The error is about GStreamer element linking, not file path resolution. Absolute paths don't fix element compatibility. (90% fail)
- **Reinstall OpenCV with gstreamer support using cmake -DWITH_GSTREAMER=ON** — If OpenCV already has GStreamer support (the error message shows GStreamer is running), recompiling won't fix the pipeline syntax. (80% fail)
- **Use CAP_FFMPEG backend instead by setting cv::CAP_FFMPEG** — This workaround avoids GStreamer but may not be available if FFMPEG is not compiled in, or the source requires GStreamer-specific features. (60% fail)
