Search code examples
c++winapims-media-foundationheifheic

WIC HEIF HEIC image decoding C++


Windows Imaging Component is used for decoding heif images. However extra apps from the microsoft store (heif image extension, hevc video extensions) are required for a successful decoding of the images.

Without them the WIC api returns blank image. Now I want to be able to programatically determine whether the heif file can be correctly decoded.

I have tried to locate the existence of required decoder type using DXVA Checker which is supposed to be WIC_HEIF_Decoder. But I can't find it registered anywhere.

enter image description here

There is a GUID key however CLSID_WICHeifDecoder documented here which I think can be registered in the system even if the decoder is missing.

Does anyone have any idea how to do this?


Solution

  • Since the HEIF decoders are still recognized on Windows that can't decode them this is the best hack imo:

    In order to decode HEIF images HEVC video extension should be installed on the machine. So the right check is to see if there is any decoding type matching the HEVC input

    MFStartup(MF_VERSION);
    IMFActivate** activate {};
    unsigned int count {};
    // Set the HEVC GUID
    MFT_REGISTER_TYPE_INFO input;
    input.guidMajorType = MFMediaType_Video;
    input.guidSubtype = MFVideoFormat_HEVC;
    // Get all available output types for HEVC input
    MFTEnumEx(MFT_CATEGORY_VIDEO_DECODER, MFT_ENUM_FLAG_SORTANDFILTER | MFT_ENUM_FLAG_SYNCMFT, &input, nullptr, &activate, &count);
    // Release interface pointers
    for (size_t i = 0; i < count; i++) {
        activate[i]->Release();
    }
    CoTaskMemFree(activate);
    MFShutdown();
    return (count > 0);