list file extensions supported by OpenCV
Asked Answered
B

3

6

In OpenCV, I see imread() and VideoCapture() both take a string to a file path of multiple extensions. Is there a way to get a list of extensions that are supported by them? For example, getting a list of "jpg", "png", "mov", "mpg", etc.? I assume this is system dependent and others have needed to query this at runtime.

Furthermore, how is support determined? If have something like the below code and the Mat I get back always seems partially corrupted (I can see a bit of the image). It doesn't seem to change regardless of the frame number I ask for. I can play this video in my video player "totem", but I'm not even sure if totem and OpenCV are even using the same codec for this file.

Mat fromVideo(std::string _videoPath, int frame) {
    VideoCapture capture(_videoPath);

    Mat f;
    for (int i = 0; i < frame; i++) {
        capture >> f;
    }
    return f;
}
Bostow answered 31/12, 2013 at 5:55 Comment(1)
Seems this question never gets answered anywhere.Labret
O
5

For imread() (more info here):

  • Windows bitmaps - *.bmp, *.dib (always supported)
  • JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)
  • JPEG 2000 files - *.jp2 (see the Notes section)
  • Portable Network Graphics - *.png (see the Notes section)
  • Portable image format - *.pbm, *.pgm, *.ppm (always supported)
  • Sun rasters - *.sr, *.ras (always supported)
  • TIFF files - *.tiff, *.tif (see the Notes section)

For VideoCapture():

  • AVI files - *.avi

    It seems that AVI is the only format with decent cross-platform support. See here for more info.

Okra answered 1/1, 2014 at 2:46 Comment(1)
Useful info about AVI being the only supported container. I'd like to add that not all codecs provide accurate frame seeking. For example, on my Windows 7 machine, Lagarith wouldn't allow accurate seeking, but the Ut codec worked fine in either YUV420 format. I didn't try HuffYUV or MS uncompressed i420/yuv.Porous
D
3

Use the method cv::VideoCapture::isOpened() to make sure that the constructor was successful in initializing the VideoCapture object.

Note that even if it was possible to get a list of supported container formats from OpenCV (AVI, MKV for instance) with their typical filename extensions, you would still need to know the exact list of supported codecs (and even then the exact file you want to open might be corrupted, etc...). So a list of filename extensions is not enough to accurately describe what is internally supported by OpenCV, and the simplest solution at the OpenCV API level is this isOpened() method.

Disposal answered 31/12, 2013 at 14:36 Comment(0)
B
0

Just update:

cv::VideoCapture cap("D:\\test.mp4")

works for me.

Benefield answered 14/11, 2017 at 5:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.