Media (Intel® Video Processing Library, Intel Media SDK)
Access community support with transcoding, decoding, and encoding in applications using media tools like Intel® oneAPI Video Processing Library and Intel® Media SDK
Announcements
The Intel Media SDK project is no longer active. For continued support and access to new features, Intel Media SDK users are encouraged to read the transition guide on upgrading from Intel® Media SDK to Intel® Video Processing Library (VPL), and to move to VPL as soon as possible.
For more information, see the VPL website.

MFX_ERR_INVALID_HANDLE during DecodeHeader

spencer_f_
Beginner
1,198 Views

If I compile and run the simple_decode project from the Intel Media SDK tutorials project, it properly decodes my h264 (NVENC) encoded file.  For reference, the piece of code in the tutorial I'm stepping through is this:

    // Initialize Intel Media SDK session
    // - MFX_IMPL_AUTO_ANY selects HW acceleration if available (on any adapter)
    // - Version 1.0 is selected for greatest backwards compatibility.
    // OS specific notes
    // - On Windows both SW and HW libraries may present
    // - On Linux only HW library only is available
    //   If more recent API features are needed, change the version accordingly
    mfxIMPL impl = options.values.impl;
    mfxVersion ver = { {0, 1} };
    MFXVideoSession session;

    sts = Initialize(impl, ver, &session, NULL);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    // Create Media SDK decoder
    MFXVideoDECODE mfxDEC(session);

    // Set required video parameters for decode
    mfxVideoParam mfxVideoParams;
    memset(&mfxVideoParams, 0, sizeof(mfxVideoParams));
    mfxVideoParams.mfx.CodecId = MFX_CODEC_AVC;
    mfxVideoParams.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;

    // Prepare Media SDK bit stream buffer
    // - Arbitrary buffer size for this example
    mfxBitstream mfxBS;
    memset(&mfxBS, 0, sizeof(mfxBS));
    mfxBS.MaxLength = 1024 * 1024;
    mfxBS.Data = new mfxU8[mfxBS.MaxLength];
    MSDK_CHECK_POINTER(mfxBS.Data, MFX_ERR_MEMORY_ALLOC);

    // Read a chunk of data from stream file into bit stream buffer
    // - Parse bit stream, searching for header and fill video parameters structure
    // - Abort if bit stream header is not found in the first bit stream buffer chunk
    sts = ReadBitStreamData(&mfxBS, fSource);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    sts = mfxDEC.DecodeHeader(&mfxBS, &mfxVideoParams);
    MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

I copied this code almost verbatim into another project of mine:

	// H264 decoding for color images
	// START INTEL MEDIA SERVER STUDIO CODE
	mfxStatus sts = MFX_ERR_NONE;
	mfxIMPL impl = MFX_IMPL_AUTO_ANY;	// - MFX_IMPL_AUTO_ANY selects HW acceleration if available (on any adapter)
	mfxVersion ver = { { 0, 1 } };		// - Version 1.0 is selected for greatest backwards compatibility.
	MFXVideoSession session;
	// Create the decoder
	MFXVideoDECODE mfxDecoder(session);
	mfxVideoParam videoParameters;
	mfxBitstream mfxBS;
	mfxFrameAllocRequest FrameAllocRequest;	

	sts = session.Init(impl, &ver);
	MFX_CHECK_RESULT(sts);

	// Set video params
	memset(&videoParameters, 0, sizeof(videoParameters));
	videoParameters.mfx.CodecId = MFX_CODEC_AVC; // h264
	videoParameters.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;

	// Prepare a bitstream buffer
	memset(&mfxBS, 0, sizeof(mfxBS));
	mfxBS.MaxLength = 1024*1024;
	mfxBS.Data = new mfxU8[mfxBS.MaxLength]; // (mfxU8*)pColorData; // put our data into the bitstream buffer

	// Read in the h264 from a file to test that my code actually works for decoding
	// Read a chunk of data from stream file into bit stream buffer
	// - Parse bit stream, searching for header and fill video parameters structure
	// - Abort if bit stream header is not found in the first bit stream buffer chunk
	FILE* fSource;
	fopen_s(&fSource, "D:\\PeabodyData\\encodeOutput.h264", "rb");
	MSDK_CHECK_POINTER(fSource, MFX_ERR_NULL_PTR);
	sts = ReadBitStreamData(&mfxBS, fSource);
	MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

	// Decode the header from the buffer
	sts = mfxDecoder.DecodeHeader(&mfxBS, &videoParameters);
	MFX_CHECK_RESULT(sts);

and it fails with MFX_ERR_INVALID_HANDLE as the return value from mfxDecoder.DecodeHeader.  I've stepped through both programs and mfxBS.Data are identical in both pieces of code, as are videoParameters (aside from memory locations).

What am I missing that would be causing this error in one project but not in the original?

System:

Windows 10 Enterprise 64-bit
Xeon E5-2680v2
256GB RAM
Visual Studio 2013
Tutorials version 0.0.3
Software decode/encode.  API version 1.20
 

0 Kudos
2 Replies
Dmitry_E_Intel
Employee
1,198 Views

In your code you create a decoder with an uninitialized session and then initialize the session. The right order is to create/initialize a session and then to create decoder.

0 Kudos
ViCue_S_
New Contributor I
1,198 Views

I am curious how could you make it work at all on CPU with NO graphics accelerators on board?

Xeon E5-2680v2  CPU basically is not supposed to be supported by Media SDK. 

0 Kudos
Reply