Media (Intel® oneAPI 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
3027 Discussions

Simple Example of how to use Intel Media SDK to Encode/Decode streams with VC++ for starter person.


I am reading about Intel Media SDK from last 5 days but not able to start working with it, to stream frames for Encode/Decode in VC++, please help me with starter example. I have already linked it's lib to VC++ project and included Media SDK headers to it. Guide me please/

0 Kudos
16 Replies

Hello Mohammad, 

Yes, we do have MediaSDK encode/decode samples that can help you get started, steps below

  1. Download and install sample ver 6.0.068 from here:
  2. Sample_decode.exe/Sample_encode.exe  available at (installed path/_bin/x64/) and content at same path (_bin/content)
  3. Example - decode command line : “sample_decode.exe h264 –i inputfile –o outputfile –hw -w -h

Let us know if any further questions:


0 Kudos

Hi Harsh,

Error comes when i install Intel@MediaSamples6.0.0.48/49 Setup. Error message is:

The installer has encounter an unexpected error installing this package. This may indicate a problem with this package. The error code is 2503.

Now what is supposed to do.

0 Kudos

Hi Harsh

I got samples by installing Intel@MediaSamples6.0.0.49 Setup on other system. But in Project: sample_encode not able to understand how it is filling sInputParams structure from command line.?  What parameters it is getting from command line to fill it's structure?


0 Kudos

HI Mohammad,

Can you send me you system information? Check and verify if you have latest driver installed on your system from here: Share a log for analyzer tool at (Installed folder/media_sdk/tools/media_sdk_analyzer.exe). It will be interesting to investigate cause of error during samples installation. 

Now, the version of samples you are downloaded MediaSamples6.0.0.49 is the old version. As I suggested in previous comment, install samples version ver 6.0.068 which are the latest. In sample_encode sInputParams structure accepts many parameters from the command line like target usage, codec, width, height and many more and the parameters accepted from command line by the structure is defined is pipeline_user.cpp file. 

Also, samples are bit complex and we have a simplified samples (tutorials) using which you can understand the various parameters calls in mediasdk. Take a look at simple_3_encode tutorial to get started. 


0 Kudos

Hi Harsh,

Log for analyzer tool at (Installed folder/media_sdk/tools/media_sdk_analyzer.exe) is below:

Intel Media SDK System Analyzer (64 bit)

The following versions of Media SDK API are supported by platform/driver:

        Version Target  Supported       Dec     Enc
        1.0     HW      Yes             X       X
        1.0     SW      Yes             X       X
        1.1     HW      Yes             X       X
        1.1     SW      Yes             X       X
        1.3     HW      Yes             X       X
        1.3     SW      Yes             X       X
        1.4     HW      Yes             X       X
        1.4     SW      Yes             X       X
        1.5     HW      No              X       X
        1.5     SW      Yes             X       X
        1.6     HW      No              X       X
        1.6     SW      Yes             X       X
        1.7     HW      No              X       X
        1.7     SW      No              X       X

Graphics Devices:
        Name                         Version             State
        Intel(R) HD Graphics 4400       Active

System info:
        CPU:    Intel(R) Core(TM) i3-4150 CPU @3.50GHz
        OS:     Microsoft Windows 8.1 Pro
        Arch:   64-bit

Installed Media SDK packages (be patient...processing takes some time):
        Intel« INDE Media SDK  for Windows

Installed Media SDK DirectShow filters:
Installed Intel Media Foundation transforms:
    Intel<<Hardware M-JPEG Decoder MFT:<Some Hexa-decimal values>

    Intel<<Hardware VP9 Sync Decoder MFT:<>

    Intel<<Hardware VP9 Decoder MFT:<>

     Intel<<Hardware VP8 Sync Decoder MFT:<>

    Intel<<Hardware VP8 Decoder MFT:<>

   Intel<< Quick Sync Video H.264 Encoder MFT:<>


Hope you will find the cause...

And thanks for the simple example , i am going to understand it. 

Thank you so much for helping me.

0 Kudos

Hi Mohammad,

Thank you for logs. I tried on one of our system and was not able to see the installer issue. Can you try again installing latest samples version after updating your system to latest drivers ( from here. Let me know how it goes.


0 Kudos

It was earlier suggested to use the sample_encode or sample_decode samples to understand how to create an application that makes use of the Intel Media SDK for encoding/decoding purposes.  But, both of these samples are fairly complicated and not necessarily a good starting point for figuring this stuff out.

Instead, the tutorials, available at , are generally a much better way to learn how to develop software that uses the Media SDK, and then the sample_encode and sample_decode samples can be used for reference purposes but not as a starting point.

0 Kudos

Hi Aaron,

Thank you for your feedback. Agree, samples are bit complicated to understand as a starting point and we are working on making them simpler. Hence as part of the effort, as you pointed out and as suggested before "Also, samples are bit complex and we have a simplified samples (tutorials) using which you can understand the various parameters calls in mediasdk. Take a look at simple_3_encode tutorial to get started. "  tutorials are good starting point for mediaSDK.


0 Kudos

Hi Harsh ,

I updated Intel driver but samples code unable to run. But i have created my program from new sample_3_encode which you have provided. Till now i have done these things: 1- Initialize Session, 2- Set Parameters, 3- Done Query, 4- Allocate Surfaces. All this 4 steps successfully done but, now GetFreeSurfaceIndex( , ) function is not supported  , i don't know why.

Few functions which are not working are: GetFreeSurfaceIndex( , ), MSDK_CHECK_ERROR( , , ), LoadRawFrame( , ), MSDK_BREAK_ON_ERROR(), MSDK_SLEEP(), MSDK_CHECK_RESULT( , , ).

Help me out about this issue, which Header or Library is required. I have already install INDE Media SDK. and included :  #include"mfxaudio++.h"
#include "mfxjpeg.h"
#include <iostream>
#include <memory>
#include "mfxastructures.h"

and linked libmfx.lib.


Help me 

0 Kudos

Hi Harsh 

First of  all thanks for your valueable reply, help me out with above mentioned problem and why MSDK_......() related function is not supported in my program?



0 Kudos

This is all my code , may be you will find something from here:

#include "stdafx.h"
#include "mfxjpeg.h"
#include <iostream>
#include "mfxplugin++.h"
#include "mfxplugin.h"

int _tmain(int argc, _TCHAR* argv[])
    MFXVideoSession session;

    mfxStatus sts;
    mfxVersion version;

    if (MFX_ERR_NONE != sts)
           sts = session.Init((impl & (!MFX_IMPL_HARDWARE_ANY)) | MFX_IMPL_HARDWARE, &version);

    mfxVideoParam Params_in;
    int size=sizeof(Params_in);

    Params_in.mfx.TargetUsage = MFX_TARGETUSAGE_BALANCED;
    Params_in.mfx.TargetKbps = 8000;
    Params_in.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
     Params_in.mfx.FrameInfo.FrameRateExtN = 30;
    Params_in.mfx.FrameInfo.FrameRateExtD = 1;
    Params_in.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
    Params_in.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
    Params_in.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
    Params_in.mfx.FrameInfo.CropX = 0;
    Params_in.mfx.FrameInfo.CropY = 0;
    Params_in.mfx.FrameInfo.CropW = 352;
    Params_in.mfx.FrameInfo.CropH = 288;
    Params_in.mfx.FrameInfo.Width = 352;
    Params_in.mfx.FrameInfo.Height = 288;

    sts = MFXQueryIMPL(session,&impl);
    sts = MFXQueryVersion((mfxSession)session, &version);

   MFXVideoENCODE enc(session);
    sts = enc.Query(&Params_in,&Params_in);

   mfxFrameAllocRequest Request;
    memset(&Request, 0, sizeof(Request));
    sts = enc.QueryIOSurf(&Params_in,&Request); 
    mfxU16 numSurfaces = Request.NumFrameSuggested;

    mfxU16 width = (mfxU16) Request.Info.Width;
    mfxU16 height = (mfxU16) Request.Info.Height;
    mfxU8 bitsPerPixel = (mfxU8)12;        // NV12 format is a 12 bits per pixel format
    mfxU32 surfaceSize = width * height * bitsPerPixel / 8;
    mfxU8* surfaceBuffers = (mfxU8*) new mfxU8[surfaceSize * numSurfaces];

    mfxFrameSurface1** pEncSurfaces = new mfxFrameSurface1 *[numSurfaces];
    for (int i = 0; i < numSurfaces; i++) {
        pEncSurfaces = new mfxFrameSurface1;
        memset(pEncSurfaces, 0, sizeof(mfxFrameSurface1));
        memcpy(&(pEncSurfaces->Info), &(Params_in.mfx.FrameInfo), sizeof(mfxFrameInfo));
        pEncSurfaces->Data.Y = &surfaceBuffers[surfaceSize * i];
        pEncSurfaces->Data.U = pEncSurfaces->Data.Y + width * height;
        pEncSurfaces->Data.V = pEncSurfaces->Data.U + 1;
        pEncSurfaces->Data.Pitch = width;


// Initialize the Media SDK encoder
    sts = enc.Init(&Params_in);

    // Retrieve video parameters selected by encoder.
    // - BufferSizeInKB parameter is required to set bit stream buffer size
    mfxVideoParam par;
    memset(&par, 0, sizeof(par));
    sts = enc.GetVideoParam(&par);

    // Prepare Media SDK bit stream buffer
    mfxBitstream mfxBS;
    memset(&mfxBS, 0, sizeof(mfxBS));
    mfxBS.MaxLength = par.mfx.BufferSizeInKB * 1000;
    mfxBS.Data = new mfxU8[mfxBS.MaxLength];

    // ===================================
    // Start encoding the frames

    int nEncSurfIdx = 0;
    mfxSyncPoint syncp;
    mfxU32 nFrame = 0;


Till here code is working fine...*************************************************************************************************/

    /********** CONFUSION IN BELOW CODE****** How to find video path? &  Why MSDK...() related functions are not working? ***************/

FILE* fSource = NULL;
    fSource=fopen("E:\\'Main Hoon Hero Tera' VIDEO Song - Salman Khan _ Hero _ T-Series_HD.mp4","r");
        while (MFX_ERR_NONE <= sts || MFX_ERR_MORE_DATA == sts) {
        nEncSurfIdx = GetFreeSurfaceIndex(pEncSurfaces, numSurfaces);   // Find free frame surface

        sts = LoadRawFrame(pEncSurfaces[nEncSurfIdx], fSource);

        for (;;) {
            // Encode a frame asychronously (returns immediately)
            sts = enc.EncodeFrameAsync(NULL, pEncSurfaces[nEncSurfIdx], &mfxBS, &syncp);

            if (MFX_ERR_NONE < sts && !syncp) {     // Repeat the call if warning and no output
                if (MFX_WRN_DEVICE_BUSY == sts)
                    MSDK_SLEEP(1);  // Wait if device is busy, then repeat the same call
            } else if (MFX_ERR_NONE < sts && syncp) {
                sts = MFX_ERR_NONE;     // Ignore warnings if output is available
            } else if (MFX_ERR_NOT_ENOUGH_BUFFER == sts) {
                // Allocate more bitstream buffer memory here if needed...
            } else

        if (MFX_ERR_NONE == sts) {
            sts = session.SyncOperation(syncp, 60000);      // Synchronize. Wait until encoded frame is ready
            MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

            sts = WriteBitStreamFrame(&mfxBS, fSink);



Sir all function in mentioned in BOLD are showing undefined.


Help me out please

0 Kudos

Hi Mohammad,

Please consider making following changes to code:

  1. Include "mfxstructures.h" and "mfxdefs.h" header files.
  2. The input file extension is (mp4) which is a container. As input codec ID is set to AVC, using a splitter tool,get the H264 bitstream and provide it as input. Please go through the media-sdk manual for input supported formats for mediasdk.
  3. MSDK_CHECK_ERROR, MSDK_BREAK_ON_ERROR are defined macros, Please define them before there usage or attach "common_utils.h" header file. 
  4. I do not see MSDK_SLEEP defined in the code, these are OS- specific type definitions and has to be defined before used. 

Please go through the tutorial code simple_3_encode carefully again, and define all the parameters before calling them and attach all required files as shown in tutorial.



0 Kudos

Hi Harsh

Thanks for all your reply, now the thinks are working. It's basically i was working on VS2010 now i have installed VS2013 . 


0 Kudos

Glad, you got the issues resolved. Please open a new thread, if any further questions.


0 Kudos

How long did it take to learn the Media SDK? I am in a bit of rush for developing a code for Screen Capture using this library.

0 Kudos

I am new to this SDK. I am getting the following error when I run simple_decode on VS 2012 provided under tutorial(

The thread 0x9bc8 has exited with code -1 (0xffffffff).
The thread 0x89e8 has exited with code -1 (0xffffffff).
The thread 0x9ff0 has exited with code -1 (0xffffffff).
The program '[22640] simple_decode.exe' has exited with code -1 (0xffffffff).

I have also run the 'mediasdk_system_analyzer_64.exe' whose results are provided below.

The following versions of Media SDK API are supported by platform/driver
[opportunistic detection of MSDK API > 1.19]:

        Version Target  Supported       Dec     Enc
        1.0     HW      Yes             X       X
        1.0     SW      Yes             X       X
        1.1     HW      Yes             X       X
        1.1     SW      Yes             X       X
        1.2     HW      Yes             X       X
        1.2     SW      Yes             X       X
        1.3     HW      Yes             X       X
        1.3     SW      Yes             X       X
        1.4     HW      Yes             X       X
        1.4     SW      Yes             X       X
        1.5     HW      Yes             X       X
        1.5     SW      Yes             X       X
        1.6     HW      Yes             X       X
        1.6     SW      Yes             X       X
        1.7     HW      Yes             X       X
        1.7     SW      Yes             X       X
        1.8     HW      Yes             X       X
        1.8     SW      Yes             X       X
        1.9     HW      Yes             X       X
        1.9     SW      Yes             X       X
        1.10    HW      Yes             X       X
        1.10    SW      Yes             X       X
        1.11    HW      Yes             X       X
        1.11    SW      Yes             X       X
        1.12    HW      Yes             X       X
        1.12    SW      Yes             X       X
        1.13    HW      Yes             X       X
        1.13    SW      Yes             X       X
        1.14    HW      Yes             X       X
        1.14    SW      Yes             X       X
        1.15    HW      Yes             X       X
        1.15    SW      Yes             X       X
        1.16    HW      Yes             X       X
        1.16    SW      Yes             X       X
        1.17    HW      No
        1.17    SW      Yes             X       X
        1.18    HW      No
        1.18    SW      Yes             X       X
        1.19    HW      No
        1.19    SW      Yes             X       X

Graphics Devices:
        Name                                         Version             State
        Intel(R) HD Graphics 4600                 Active
        NVIDIA GeForce GT 740M                    08

System info:
        CPU:    Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
        OS:     Microsoft Windows 10 Home Single Language
        Arch:   64-bit

Installed Media SDK packages (be patient...processing takes some time):
        Intel(R) Media Samples
        Intel(R) Media SDK 2016 R2

Installed Media SDK DirectShow filters:

Installed Intel Media Foundation Transforms:
        Intel(R) Hardware M-JPEG Decoder MFT : {00C69F81-0524-48C0-A353-4DD9D54F9A6E}
        Intel(R) Hardware VP9 Sync Decoder MFT : {07AB4BD2-1979-4FCD-A697-DF9AD15B34FE}
        Intel(R) Hardware VP9 Decoder MFT : {0C69E30B-A112-4A86-B496-35120CD745D5}
        Intel(R) Hardware VP8 Sync Decoder MFT : {451E3CB7-2622-4BA5-8E1D-44B3C41D0924}
        Intel(R) Hardware VP8 Decoder MFT : {6D856398-834E-4A89-8EE5-071BB3F58BE4}
        Intel(R) Quick Sync Video H.264 Encoder MFT : {4BE8D3C0-0515-4A37-AD55-E4BAE19AF471}
        Intel(R) Hardware H265 Encoder MFT : {BC10864D-2B34-408F-912A-102B1B867B6C}


Analysis complete... [press ENTER]


Any help is appreciated.

0 Kudos