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.

Encoded file not running on any media player

Mohammad_T_1
Beginner
1,074 Views

Facing problem to run encoded file. I have encoded mp4 video, but don't know why it is not running on any media player. 

Code i have written is below:

int main(int argc, char** argv)
{
    mfxStatus sts = MFX_ERR_NONE;
    bool bEnableInput;  // if true, removes all YUV file reading (which is replaced by pre-initialized surface data). Workload runs for 1000 frames.
    bool bEnableOutput; // if true, removes all output bitsteam file writing and printing the progress
    CmdOptions options;

    // =====================================================================
    // Intel Media SDK encode pipeline setup
    // - In this example we are encoding an AVC (H.264) stream
    // - For simplistic memory management, system memory surfaces are used to store the raw frames
    //   (Note that when using HW acceleration video surfaces are prefered, for better performance)
    //

    // Read options from the command line (if any is given)
    memset(&options, 0, sizeof(CmdOptions));
    options.ctx.options = OPTIONS_ENCODE;
    options.ctx.usage = usage;
    // Set default values:
    options.values.impl = MFX_IMPL_AUTO_ANY;

    // here we parse options
    ParseOptions(argc, argv, &options);

    if (!options.values.Width || !options.values.Height) {
        printf("error: input video geometry not set (mandatory)\n");
        return -1;
    }
    if (!options.values.Bitrate) {
        printf("error: bitrate not set (mandatory)\n");
        return -1;
    }
    if (!options.values.FrameRateN || !options.values.FrameRateD) {
        printf("error: framerate not set (mandatory)\n");
        return -1;
    }

    bEnableInput = (options.values.SourceName[0] != '\0');
    bEnableOutput = (options.values.SinkName[0] != '\0');
    // Open input YV12 YUV file
    FILE* fSource = NULL;
    if (bEnableInput) {
        MSDK_FOPEN(fSource, options.values.SourceName, "rb");
        MSDK_CHECK_POINTER(fSource, MFX_ERR_NULL_PTR);
    }

    // Create output elementary stream (ES) H.264 file
    FILE* fSink = NULL;
    if (bEnableOutput) {
        MSDK_FOPEN(fSink, options.values.SinkName, "wb");
        MSDK_CHECK_POINTER(fSink, MFX_ERR_NULL_PTR);
    }

    // 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 encoder
    MFXVideoENCODE mfxENC(session);

    // Set required video parameters for encode
    // - In this example we are encoding an AVC (H.264) stream
    mfxVideoParam mfxEncParams;
    memset(&mfxEncParams, 0, sizeof(mfxEncParams));

    mfxEncParams.mfx.CodecId = MFX_CODEC_AVC;
    mfxEncParams.mfx.TargetUsage = MFX_TARGETUSAGE_BALANCED;
    mfxEncParams.mfx.TargetKbps = options.values.Bitrate; //15000
    mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_CBR;//MFX_RATECONTROL_VBR;
    mfxEncParams.mfx.FrameInfo.FrameRateExtN = options.values.FrameRateN; //30
    mfxEncParams.mfx.FrameInfo.FrameRateExtD = options.values.FrameRateD; //1
    mfxEncParams.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
    mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
    mfxEncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
    mfxEncParams.mfx.FrameInfo.CropX = 0;
    mfxEncParams.mfx.FrameInfo.CropY = 0;
    mfxEncParams.mfx.FrameInfo.CropW = options.values.Width;
    mfxEncParams.mfx.FrameInfo.CropH = options.values.Height;
    // Width must be a multiple of 16
    // Height must be a multiple of 16 in case of frame picture and a multiple of 32 in case of field picture
    mfxEncParams.mfx.FrameInfo.Width = MSDK_ALIGN16(options.values.Width);
    mfxEncParams.mfx.FrameInfo.Height =
        (MFX_PICSTRUCT_PROGRESSIVE == mfxEncParams.mfx.FrameInfo.PicStruct) ?
        MSDK_ALIGN16(options.values.Height) :
        MSDK_ALIGN32(options.values.Height);

    mfxEncParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
    //mfxEncParams.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;

 

    // Validate video encode parameters (optional)
    // - In this example the validation result is written to same structure
    // - MFX_WRN_INCOMPATIBLE_VIDEO_PARAM is returned if some of the video parameters are not supported,
    //   instead the encoder will select suitable parameters closest matching the requested configuration
    sts = mfxENC.Query(&mfxEncParams, &mfxEncParams);
    MSDK_IGNORE_MFX_STS(sts, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    // Query number of required surfaces for encoder
    mfxFrameAllocRequest EncRequest;
    memset(&EncRequest, 0, sizeof(EncRequest));
    sts = mfxENC.QueryIOSurf(&mfxEncParams, &EncRequest);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    mfxU16 nEncSurfNum = EncRequest.NumFrameSuggested;

    // Allocate surfaces for encoder
    // - Width and height of buffer must be aligned, a multiple of 32
    // - Frame surface array keeps pointers all surface planes and general frame info
    mfxU16 width = (mfxU16) MSDK_ALIGN32(EncRequest.Info.Width);
    mfxU16 height = (mfxU16) MSDK_ALIGN32(EncRequest.Info.Height);
    mfxU8 bitsPerPixel = 12;        // NV12 format is a 12 bits per pixel format
    mfxU32 surfaceSize = width * height * bitsPerPixel / 8;
    mfxU8* surfaceBuffers = (mfxU8*) new mfxU8[surfaceSize * nEncSurfNum];

    // Allocate surface headers (mfxFrameSurface1) for encoder
    mfxFrameSurface1** pEncSurfaces = new mfxFrameSurface1 *[nEncSurfNum];
    MSDK_CHECK_POINTER(pEncSurfaces, MFX_ERR_MEMORY_ALLOC);
    for (int i = 0; i < nEncSurfNum; i++) {
        pEncSurfaces = new mfxFrameSurface1;
        memset(pEncSurfaces, 0, sizeof(mfxFrameSurface1));
        memcpy(&(pEncSurfaces->Info), &(mfxEncParams.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;
        if (!bEnableInput) {
            ClearYUVSurfaceSysMem(pEncSurfaces, width, height);
        }
    }

    // Initialize the Media SDK encoder
    sts = mfxENC.Init(&mfxEncParams);
    MSDK_IGNORE_MFX_STS(sts, MFX_WRN_PARTIAL_ACCELERATION);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

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

    // 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];
    MSDK_CHECK_POINTER(mfxBS.Data, MFX_ERR_MEMORY_ALLOC);

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

    mfxTime tStart, tEnd;
    mfxGetTime(&tStart);

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

    //
    // Stage 1: Main encoding loop
    //
    while (MFX_ERR_NONE <= sts || MFX_ERR_MORE_DATA == sts) {
        nEncSurfIdx = GetFreeSurfaceIndex(pEncSurfaces, nEncSurfNum);   // Find free frame surface
        MSDK_CHECK_ERROR(MFX_ERR_NOT_FOUND, nEncSurfIdx, MFX_ERR_MEMORY_ALLOC);

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

        for (;;) {
            // Encode a frame asychronously (returns immediately)
            sts = mfxENC.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
                break;
            } else if (MFX_ERR_NOT_ENOUGH_BUFFER == sts) {
                // Allocate more bitstream buffer memory here if needed...
                break;
            } else
                break;
        }

        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);
            MSDK_BREAK_ON_ERROR(sts);

            ++nFrame;
            if (bEnableOutput) {
                printf("Frame number: %d\r", nFrame);
                fflush(stdout);
            }
        }
    }

    // MFX_ERR_MORE_DATA means that the input file has ended, need to go to buffering loop, exit in case of other errors
    MSDK_IGNORE_MFX_STS(sts, MFX_ERR_MORE_DATA);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    //
    // Stage 2: Retrieve the buffered encoded frames
    //
    while (MFX_ERR_NONE <= sts) {
        for (;;) {
            // Encode a frame asychronously (returns immediately)
            sts = mfxENC.EncodeFrameAsync(NULL, NULL, &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
                break;
            } else
                break;
        }

        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);
            MSDK_BREAK_ON_ERROR(sts);

            ++nFrame;
            if (bEnableOutput) {
                printf("Frame number: %d\r", nFrame);
                fflush(stdout);
            }
        }
    }

    // MFX_ERR_MORE_DATA indicates that there are no more buffered frames, exit in case of other errors
    MSDK_IGNORE_MFX_STS(sts, MFX_ERR_MORE_DATA);
    MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

    mfxGetTime(&tEnd);
    double elapsed = TimeDiffMsec(tEnd, tStart) / 1000;
    double fps = ((double)nFrame / elapsed);
    printf("\nExecution time: %3.2f s (%3.2f fps)\n", elapsed, fps);

    // ===================================================================
    // Clean up resources
    //  - It is recommended to close Media SDK components first, before releasing allocated surfaces, since
    //    some surfaces may still be locked by internal Media SDK resources.

    mfxENC.Close();
    // session closed automatically on destruction

    for (int i = 0; i < nEncSurfNum; i++)
        delete pEncSurfaces;
    MSDK_SAFE_DELETE_ARRAY(pEncSurfaces);
    MSDK_SAFE_DELETE_ARRAY(mfxBS.Data);

    MSDK_SAFE_DELETE_ARRAY(surfaceBuffers);

    if (fSource) fclose(fSource);
    if (fSink) fclose(fSink);

    Release();

    return 0;
}

How can i check wheather the encoded file is correct or not?

Kindly help me out of this....

 

0 Kudos
1 Solution
Harshdeep_B_Intel
1,074 Views

Hello Mohammad, 

To play h.264 file on VLC you would need to set demux module to "H264 video demuxer" in VLC preferences settings. Please confirm and verify if you have this enabled in player. If not please follow below steps, before playing h.264 file on VLC. 

  • In VLC player, select tools->preferences-> select "All" under show settings -> select Demuxers from Input/Codec menu -> In Demux module set to H.264 video demuxer. Here a link to video showing how to set VLC player to play h.264 streams. 

Let me know if you were able to successfully play the encoded file on VLC, after following above steps. 

Thanks,

View solution in original post

0 Kudos
17 Replies
Harshdeep_B_Intel
1,074 Views

Hi Mohammed, 

You can verify if encoded file is encoded correctly, by decoding the file. Follow below steps to decode the encoded file. 

  • I believe you have already downloaded samples from here: https://software.intel.com/en-us/media-client-solutions-support/code-samples
  • Run commandline: sample_decode h264 -i [Encodedinputfile] -r 
  • This renders (play) the file directly on your screen.
  • You can also use simple_decode to decode the file and play using any players supporting raw YUV formats (http://sourceforge.net/projects/raw-yuvplayer/)

Using any of methods you can verify encoded file. 

Thanks, 

0 Kudos
Matthias_H_Intel
Employee
1,074 Views

what does MediaInfo https://mediaarea.net/de/MediaInfo tell you?

0 Kudos
Mohammad_T_1
Beginner
1,074 Views

How do i pass Screen Capture raw data to encode with Intel Media SDK? Above problem was because i was passing .mp4 file. As mp4 file are already h264 file. So i am stuck at about how to pass Screen Capture raw data to encode ?

 

Kindly help me in doing this...

0 Kudos
Harshdeep_B_Intel
1,074 Views

Hi Mohammad,

Input to encoder cannot be a encoded (.h264) file or the mp4 file. Supported or input file format expected by the encoder is YUV420, NV12 formats and from above code you have intialized correctly (// Open input YV12 YUV file). Glad, you resolved the issue after providing correct input format to encoder. 

Now, in regard to Screen capture raw data to encode via MediaSDK, I am assuming following is pipeline scenario you are building:

Video Capture-> H.264 Encoder <-Please provide more information about the pipeline, if this is not the use case. 

If yes, then you will need DirectShow (Dshow) sample encode filters, these are available here (https://software.intel.com/sites/default/files/MSDK_Samples_Deprecated_Windows.zip). But, I would like to inform you, from INDE MSDK 2015 update, Dshow plugins are deprecated, mean they are no longer supported/tested/validated. We do not encourage their use and they are still up just as a reference. 

Thanks,

0 Kudos
Mohammad_T_1
Beginner
1,073 Views

Hi Harsh

First of all thanks for your reply . Actually i have to Capture Screen continuously and do Encode it in h.264 format. 

Capture Screen -> Encode h264 -> Send on the network -> Other End -> Decode h264. 

I have capture Screen continuously and encode it.

 

Help me in doing this.

0 Kudos
Harshdeep_B_Intel
1,074 Views

Hi Mohammad,

Thanks for provide this information. This helps me understand  your pipeline and provide suggestions. So, you can start with following steps to capture screen continuously to encode.

  • You can use DirectX function GetFrontBufferData to achieve this, https://msdn.microsoft.com/en-us/library/windows/desktop/bb174388, and then use IDirect3DSurface9 with input for h.264 encoder.
  • Also, GetFrontBufferData captures the front buffer in native format which is: D3DFMT_A8R8G8B8 and msdk encoder can only process surface types of type NV12. So, before feeding inputs to encoder, color conversion (RGB32->NV12)  is required which can be done using msdk vpp. Please refer to sample_encode which showcases how to use Vpp ahead of encode.

Also, another best method, I suggest  would be using MediSDK capture screen plugin, where you can screen capture raw frames directly in NV12 format and connect with encoder for encoding. 

  • Screen capture -> MediaSDK encoder. 

Screen capture is implemented as part of decoder plugin. Run the following command line to capture screen in NV12 format directly using samples:

  • sample_decode.exe capture  -p 22d62c07e672408fbb4cc20ed7a053e4 -h (height)  -w (width) -hw 

The above command line shows screen capture operation works. Please take a look at "mediasdkscreencap-man.pdf" in mediasdk/docs folder to know more details about the screen capture plugin. 

Thanks, 

0 Kudos
Mohammad_T_1
Beginner
1,074 Views

Hi Harsh,

I was on leave that's why not able to reply on time. Thanks for your reply, but the problem is VLC is not able to play encoded file , it says: bad header in precompiled chunk. 

What i have done yet : 

1- Initialised pipeline

mfxVideoParam mfxEncParams;
    memset(&mfxEncParams, 0, sizeof(mfxEncParams));

    mfxEncParams.mfx.CodecId =  MFX_CODEC_AVC;
    mfxEncParams.mfx.TargetUsage = MFX_TARGETUSAGE_BALANCED;
    mfxEncParams.mfx.TargetKbps = options.values.Bitrate;
    mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_CBR;//MFX_RATECONTROL_VBR;
    mfxEncParams.mfx.FrameInfo.FrameRateExtN = options.values.FrameRateN;
    mfxEncParams.mfx.FrameInfo.FrameRateExtD = options.values.FrameRateD;
    mfxEncParams.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
    mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
    mfxEncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;//MFX_PICSTRUCT_FIELD_TFF;
    mfxEncParams.mfx.FrameInfo.CropX = 0;
    mfxEncParams.mfx.FrameInfo.CropY = 0;
    mfxEncParams.mfx.FrameInfo.CropW = options.values.Width;
    mfxEncParams.mfx.FrameInfo.CropH = options.values.Height;
    // Width must be a multiple of 16
    // Height must be a multiple of 16 in case of frame picture and a multiple of 32 in case of field picture
    mfxEncParams.mfx.FrameInfo.Width = MSDK_ALIGN16(options.values.Width);
    mfxEncParams.mfx.FrameInfo.Height =
        (MFX_PICSTRUCT_PROGRESSIVE == mfxEncParams.mfx.FrameInfo.PicStruct) ?
        MSDK_ALIGN16(options.values.Height) :
        MSDK_ALIGN32(options.values.Height);

2- Validate video encode parameters.

3-  Query number of required surfaces for encoder.

4- Allocate surface headers for encoder.

5- Initialize the Media SDK encoder.

6- Capture Screen and convert it from Bitmap to Yuv420p. Then write this Yuv420p into fSource file. Then below code: 

while (MFX_ERR_NONE <= sts || MFX_ERR_MORE_DATA == sts) {
            nEncSurfIdx = GetFreeSurfaceIndex(pEncSurfaces, nEncSurfNum);   // Find free frame surface
            MSDK_CHECK_ERROR(MFX_ERR_NOT_FOUND, nEncSurfIdx, MFX_ERR_MEMORY_ALLOC);


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

            for (;;) {
                // Encode a frame asychronously (returns immediately)
                sts = mfxENC.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
                    break;
                }
                else if (MFX_ERR_NOT_ENOUGH_BUFFER == sts) {
                    // Allocate more bitstream buffer memory here if needed...
                    break;
                }
                else
                    break;
            }

            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);
                MSDK_BREAK_ON_ERROR(sts);

                ++nFrame;
                if (bEnableOutput) {
                    printf("Frame number: %d\r", nFrame);
                    fflush(stdout);
                }
            }
        }

7- Retrieve the buffered encoded frames. 

while (MFX_ERR_NONE <= sts) {
            for (;;) {
                // Encode a frame asychronously (returns immediately)
                sts = mfxENC.EncodeFrameAsync(NULL, NULL, &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
                    break;
                }
                else
                    break;
            }

            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);
                MSDK_BREAK_ON_ERROR(sts);

                ++nFrame;
                if (bEnableOutput) {
                    printf("Frame number: %d\r", nFrame);
                    fflush(stdout);
                }
            }
        }

 

I done encode successfully but , the resultant encoded file is not able to run on VLC. When i opened the message log in VLC it shows bad header in precompiled chunk.

I have used GetDIBits(hDC, hBitmap, 0, Bm.bmHeight, pData, &BitInfo, DIB_RGB_COLORS) function to convert HBitmap to pData(bytes). Then i have converted hData(RGB) to Yuv420p. Then i write this to fSource file...

Kindly help me . 

0 Kudos
Harshdeep_B_Intel
1,074 Views

Hi Mohammad,

It's somewhat hard to track down the exact cause of the issue looking at the supplied code. But... I have some concerns.

First, can you confirm if you are able to successfully play Yuv420 captured file with YUV player (http://sourceforge.net/projects/raw-yuvplayer/). If the capture bitstream + color conversion is correct, you should see player successfully play the bitstream. Also, make sure you successfully implemented Step 6 (Capture Screen and convert it from Bitmap to Yuv420p. Then write this Yuv420p into fSource file.) color conversion (RGB->YUV) and the file you write to fSource file is in correct order, header size, width and height alignments. 

Thanks,  

0 Kudos
Mohammad_T_1
Beginner
1,074 Views

Hi Harsh

My pipeline:

mfxEncParams.mfx.CodecId =  MFX_CODEC_AVC;//MFX_CODEC_MPEG2;//MFX_CODEC_MPEG2;
    mfxEncParams.mfx.TargetUsage =  MFX_TARGETUSAGE_BALANCED;
    mfxEncParams.mfx.TargetKbps = options.values.Bitrate;
    mfxEncParams.mfx.RateControlMethod = MFX_RATECONTROL_CBR;//MFX_RATECONTROL_VBR;
    mfxEncParams.mfx.FrameInfo.FrameRateExtN = options.values.FrameRateN;
    mfxEncParams.mfx.FrameInfo.FrameRateExtD = options.values.FrameRateD;
    mfxEncParams.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
    mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
    mfxEncParams.mfx.FrameInfo.PicStruct =  MFX_PICSTRUCT_PROGRESSIVE;//MFX_PICSTRUCT_FIELD_TFF;
    mfxEncParams.mfx.FrameInfo.CropX = 0;
    mfxEncParams.mfx.FrameInfo.CropY = 0;
    mfxEncParams.mfx.FrameInfo.CropW = options.values.Width;
    mfxEncParams.mfx.FrameInfo.CropH = options.values.Height;
    // Width must be a multiple of 16
    // Height must be a multiple of 16 in case of frame picture and a multiple of 32 in case of field picture
    mfxEncParams.mfx.FrameInfo.Width = MSDK_ALIGN16(options.values.Width);
    mfxEncParams.mfx.FrameInfo.Height =
        (MFX_PICSTRUCT_PROGRESSIVE == mfxEncParams.mfx.FrameInfo.PicStruct) ?
        MSDK_ALIGN16(options.values.Height) :
        MSDK_ALIGN32(options.values.Height);

    mfxEncParams.IOPattern =  MFX_IOPATTERN_IN_SYSTEM_MEMORY;

And now i am passing valid YUV file as input, but the encoded file is not running. When i change the CodecId as MFX_CODEC_MPEG2 then it works for MPEG2. But not working with CodecId: MFX_CODEC_AVC.

 

Help me please

 

Thanks

0 Kudos
Matthias_H_Intel
Employee
1,074 Views

And now i am passing valid YUV file as input, but the encoded file is not running. When i change the CodecId as MFX_CODEC_MPEG2 then it works for MPEG2. But not working with CodecId: MFX_CODEC_AVC.

How do you mean? What is "not working"?

0 Kudos
Harshdeep_B_Intel
1,074 Views

Hello Mohammad,

Can you please provide more background and clarify what you meant by, "but the encoded file is not running"? Was there any error message from encoder during encoding? Did media player (VLC) display any error message? You can check and verify YUV file passed to encoder is correct, by using sample_encode to encode the file. If the input file is correct, then encoded h264 file should play successfully on VLC player. Let me know your results.

Thanks, 

0 Kudos
Mohammad_T_1
Beginner
1,074 Views

Hi 

Sorry if i am not able to convey my message properly. My problem is that when i passed CodecId as MFX_CODEC_MPEG2 , then the encoded file is running on VLC but when i passed CodecId: MFX_CODEC_AVC, then the encoded file is not running on VLC.

I checked Message log of VLC :

lua warning: Error loading script C:\Program Files\VideoLAN\VLC\lua\playlist\anevia_streams.luac: C:\Program Files\VideoLAN\VLC\lua\playlist\anevia_streams.luac: bad header in precompiled chunk.

Hope you guys understand now what my problem is.

 

Thanks

0 Kudos
Harshdeep_B_Intel
1,074 Views

Hi Mohammad,

Thank you for clarifying. So, to traige if issue if it is with encoder pipeline in your application or with input file to the encoder. Can you let me know results of below steps.

  1. When you mentioned as "i am passing valid YUV file as input" can you please let me know if you were able to successfully play input file with YUV player (http://sourceforge.net/projects/raw-yuvplayer/)
  2. Using any other valid input YUV file or test_stream_176x96.yuv (available in <samples installed path>/_bin/content) as input to the encoder, are you  able to successfully encode the file and play the encoded file (.h264) with VLC player? 

Thanks,

 

     

    0 Kudos
    Mohammad_T_1
    Beginner
    1,074 Views

    Hi Harsh

    Yes the file i am passing as input for endode is running on YUV player perfectly. Now i am passing YUV file test_stream_176x96.yuv (available in <samples installed path>/_bin/content) as input to the encoder but now also then resultant encode file is not running on VLC player for Codic Id: MFX_CODEC_AVC. But it works will on VLC player for Codic Id: MFX_CODEC_MPEG2. Why this heppens?

    I am using simple_3_encode of https://software.intel.com/sites/default/files/mediasdk-tutorials-0.0.3.zip. 

    Not able to understand why MFX_CODEC_AVC is not working. Help me with this.

     

    Thank you

    0 Kudos
    Harshdeep_B_Intel
    1,075 Views

    Hello Mohammad, 

    To play h.264 file on VLC you would need to set demux module to "H264 video demuxer" in VLC preferences settings. Please confirm and verify if you have this enabled in player. If not please follow below steps, before playing h.264 file on VLC. 

    • In VLC player, select tools->preferences-> select "All" under show settings -> select Demuxers from Input/Codec menu -> In Demux module set to H.264 video demuxer. Here a link to video showing how to set VLC player to play h.264 streams. 

    Let me know if you were able to successfully play the encoded file on VLC, after following above steps. 

    Thanks,

    0 Kudos
    Mohammad_T_1
    Beginner
    1,074 Views

    Hi Harsh 

    Thank you so much, now the file is running on VLC.

    Thank you

    0 Kudos
    Harshdeep_B_Intel
    1,074 Views

    Hi Mohammad,

    Glad, you are able to play file successfully on VLC after above steps. So, we can consider issue resolved and close this thread. Kindly start a new thread for any other questions.

    For quick turnaround on mediasdk related questions, please direct your questions here:  https://software.intel.com/en-us/forums/intel-media-sdk. It will be easier for us to track and respond.

    Thanks,  

    0 Kudos
    Reply