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

asked 2019-09-05 05:02:06 -0600

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)
edit retag flag offensive close merge delete

Comments

  • you can only query the backend name IF it is opened, see note
berak gravatar imageberak ( 2019-09-05 08:17:52 -0600 )edit

Thank you for the note. Anyway the capture isn't being opened but I have the GSTREAMER and V4L2 backends available.

vladvin gravatar imagevladvin ( 2019-09-05 08:50:07 -0600 )edit