Ask Your Question

Revision history [back]

error: (-215:Assertion failed) api != 0 in function 'getBackendName'

I'm trying to choose a different from the default VideoCapture backend in Python. The code is the following:

cap = cv2.VideoCapture("my_video.avi", apiPreference=cv2.CAP_GSTREAMER)

But the capture is not opening:

cap.isOpened()
False

I checked the available backends using the following:

[cv2.videoio_registry.getBackendName(b) for b in cv2.videoio_registry.getBackends()]
['FFMPEG', 'GSTREAMER', 'INTEL_MFX', 'V4L2', 'CV_IMAGES', 'CV_MJPEG']

Querying cap.getBackendName() results in an error:

opencv-4.1.1/modules/videoio/src/cap.cpp:220: error: (-215:Assertion failed) api != 0 in function 'getBackendName'

I also tried to do the same with CAP_V4L2, and got the same result. The only option works is CAP_FFMPEG.

Why cannot I use a different backend?

OpenCV version: 4.1.1, Python 3.7. The backends were found during the build:

Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   YES (57.107.100)
--       avformat:                  YES (57.83.100)
--       avutil:                    YES (55.78.100)
--       swscale:                   YES (4.8.100)
--       avresample:                YES (3.7.0)
--     GStreamer:                   YES (1.14.5)
--     v4l/v4l2:                    YES (linux/videodev2.h)