none
H.264 Hardware Encoder by SinkWriter

    Question

  •  

    Hi, guys. I just finished an interesting job.

     

    I can somehow get the uncompressed video and audio streams.

     

    Then, I try to use sinkwriter to encode both streams to H.264 and AAC, later muxed to MPEG4 network stream or file.

     

    For pure software version, I already finished. It works nicely.

     

    However, when I try to configure to hardware encode, it failed.

     

     

    Here is my partial code:

     

    //

    //H.264 + MP3 - MP4 Sink Writer

     

    HRESULT hr_SW = S_OK;

     

     

    //1.

    //initialize COM and Media Foundation

    if( SUCCEEDED( hr_SW ) )

    hr_SW = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED );//| COINIT_DISABLE_OLE1DDE);

    if( SUCCEEDED( hr_SW ) )

    hr_SW = MFStartup(MF_VERSION);

     

     

    //2. 

    //create attributes 

    IMFAttributes *pMFAttributes = NULL;

    hr_SW = MFCreateAttributes( &pMFAttributes, 100 );

    hr_SW = pMFAttributes->SetGUID( MF_TRANSCODE_CONTAINERTYPE, MFTranscodeContainerType_MPEG4 );//video

     

    hr_SW = pMFAttributes->SetUINT32( MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, true ); //==> for hardware encode

    hr_SW = pMFAttributes->SetUINT32( MF_READWRITE_DISABLE_CONVERTERS , false );   //==> for hardware encode, msdn says if I would like set MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS true, this parameter should be false.

     

     

     

    //3.

    //create sink writer, and refer to a data stream or file to be output destination:

    if( SUCCEEDED( hr_SW ) )

    {

     

    hr_SW = MFCreateFile( MF_ACCESSMODE_READWRITE, MF_OPENMODE_DELETE_IF_EXIST, MF_FILEFLAGS_NONE, L"c:\\xxx.mp4", &pStream );

    hr_SW = MFCreateSinkWriterFromURL( NULL, pStream, pMFAttributes, &pSinkWriter ); // ==> Here, I got wrong return value.

    } //After I added two sentances above for hardware encode, the return value here is always "E_INVALIDARG," not "S_OK" anymore.

     

    ...

    // There are some other setting in this initialization I should do but I do not yet post out because the problem happens on above.

    // After initialization, start to write sample to sinkwriter.

     

     

    Oh~ and my platform is Intel I5.

    I surveyed online, Microsoft said Intel I3, I5, I7 (i.e., Ironlake chipset) should support H.264 Hardware Encoder with Media Foundation.

     

    Please help me solve this issue. I think if I do not code wrong, Intel must not support Hardware Encoder with Media Foundation yet. However, it is wired. What on earth Intel I5 support Media Foundation SinkWriter, or not?

    Friday, November 19, 2010 10:38 AM

All replies

  • Could you try without setting MF_READWRITE_DISABLE_CONVERTERS (it is assumed to be false when missing)? I am doublechecking with my team but that seems a bug on our side. Apologies for the inconvenience.
    Monday, November 22, 2010 6:24 PM
  • Thanks, Matthieu Maitre, but the problem is still alive.

    Before I posted my quesiton, I ever tried without setting MF_READWRITE_DISABLE_CONVERTERS false.


    The current situation is:

    1)
    if I set MF_READWRITE_DISABLE_CONVERTERS              false
    and
    MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS  true  
    , then MFCreateSinkWriterFromURL would return error.

    2)
    if I set MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS  true  
    without setting MF_READWRITE_DISABLE_CONVERTERS
    , then MFCreateSinkWriterFromURL would return S_OK.
    However, CPU utilization is still the same.
    It seems that Hardware Encode function is not really enabled.

    Hence, I said it seemed that setting MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS true for SinkWriter does not work!



    Furthermore, these two days, I found this blog: http://blogs.msdn.com/b/mf/archive/2009/12/16/mfcopy.aspx
    This blog should be created by Media Foundation team I think.
    The sample application of this webpage provides an argument "-hw" to make us enable Hardware encode function.
    However, I tried it in my Intel I5 and Windows 7, and It does not work, again.
    I input arguments like the following in the command line window: 
        MFCopy.exe -a AAC -v H264 -nc 2 -sr 44100 -fr 20:1  WindowsMedia.wmv output.mp4

    Could you post your platform ID or type to let me experiment my code?
    Tuesday, November 23, 2010 7:21 AM
  • From another post you made on the forum it seems like there is no hardware encoder MFT installed on your machine. Maybe try installing the latest GPU driver if it is not done yet.

    The flag MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS does not guarantee that hardware encoder MFTs will be used: if the SinkWriter cannot find such MFTs it does a fallback on software MFTs.

    To get a better idea of what the SinkWriter is doing you can run your application under MFTrace and grep the log for lines containing 'dll'. That should show you all the DLLs the SinkWriter tried to load.

    http://blogs.msdn.com/b/mf/archive/2010/08/11/using-mftrace-to-trace-media-foundation.aspx
    http://blogs.msdn.com/b/mf/archive/2010/09/09/analyzing-media-foundation-traces.aspx
    http://blogs.msdn.com/b/mf/archive/2010/10/28/automating-trace-analysis.aspx
    http://msdn.microsoft.com/en-us/library/ff685370%28v=VS.85%29.aspx

     

     

     

    Friday, November 26, 2010 6:28 PM
  • Thanks for your suggestion.

    I update to the latest version of driver in my I5 (m520) platform.

    However, I still can not run hardware encode function.

     

     

    Hence, I tried to use MFTrace.exe you mentioned to trace to know whether this software runs hardware MFT or not.

    It always posts the message , Failed with hr=0x80070057 (ERROR_INVALID_PARAMETER) if I use F5 in debug mode in VC++, and post the other message "Listening to ETW events (CTRL+C to end)" if I run the exe file directly.   I input like this: MFTrace.exe -a MyProgram.exe -o trace.txt.

    Therefore, I tried another way: MFTrace.exe MyProgram.exe >> trace.txt

    Then, it works.  I finally can dump traced log into a text file by not attaching existing process to trace, but creating a new process to trace.

     

     

    However,  I still do not know how to use this dumped information to know whether hardware encoder is enabled with sinkwriter.

    Could you give me more hint?  Plus, when I input ParseTopologies.cmd trace.txt,  It always reply me "No Topology found!".

     

     

    PS:
    Could I know whick platform (Notebook, or Pad product, or cell-phone, and CPU/GPU chipset ) really support Hardware Encoder H.264 + AAC with Media Foundation (Sinkwriter)?

     

    • Edited by Hitbook Wednesday, December 01, 2010 2:17 AM
    Tuesday, November 30, 2010 10:48 AM
  • You can use TextAnalysis to read the traces: http://blogs.msdn.com/b/mf/archive/2010/09/09/analyzing-media-foundation-traces.aspx 
    You can add a filter to only display lines containing 'dll' and that should show you which encoder has been loaded.

    The Sink Writer does not use topologies to connect its internal components (encoders/sinks), so it makes sense that there is no topologies in the traces.

    Unfortunately I do not have a list of which platforms support HW encoding. You can either look up whether HW MFTs are present in the registry or use MFTEnumEx() with MFT_ENUM_FLAG_HARDWARE and MFT_CATEGORY_VIDEO_ENCODER.

    Wednesday, December 01, 2010 5:50 PM
  • Thanks. You give me a nice hint to use MFTEnumEx(), a function which I used before, but I forget using it again for this time of coding.

     

    I test three platforms, but there seems to not exist Hardware MFT.

     

    platform 1: Intel Core(TM)2 Duo CPU + p8700 32bits

    platform 2: Intel Core(TM) i5 CPU + M520 32bits

    platform 3: Genuine Intel(R) CPU 0, 64bits (HP notebook) plus AMD Radeon 6470M

     

    My code:

    //testing whether there exists hardware encoder __20101202

    MFT_REGISTER_TYPE_INFO input_MFT_type;

    input_MFT_type.guidMajorType = MFMediaType_Video;

    input_MFT_type.guidSubtype = MFVideoFormat_RGB32;

    MFT_REGISTER_TYPE_INFO output_MFT_type;

    output_MFT_type.guidMajorType = MFMediaType_Video;

    output_MFT_type.guidSubtype = MFVideoFormat_H264;

    IMFActivate **ppMFTActivate = NULL; 

    UINT32 cMFTActivate = 0;

    hr_SW = MFTEnumEx( MFT_CATEGORY_VIDEO_ENCODER, MFT_ENUM_FLAG_HARDWARE, &input_MFT_type, &output_MFT_type, &ppMFTActivate, &cMFTActivate );


    cMFTActivate is always 0, and ppMFTActivate is always NULL, while hr_SW is S_OK.

     

     

    It seems not so easy to find out the platform co-working with Microsoft Media Foundation for hardware encoder function.

    Thursday, December 02, 2010 4:09 AM
  • It is quite possible that none of those systems have a hardware MFT.  However, to make sure you should try MFTEnumEx again with NULL as the input type parameter.  Not all encoders support RGB32 for input; in fact, a lot of them do not.  If you use NULL, you will get encoders regardless of the input format they support.
    Thursday, December 09, 2010 7:09 PM
    Moderator
  • After calling

    hr_SW

     

    = MFTRegisterLocalByCLSID( CLSID_MF_H264EncFilter, MFT_CATEGORY_VIDEO_EFFECT, L"Intel\xae Media SDK H.264 Encoder MFT", MFT_ENUM_FLAG_LOCALMFT, 0, NULL, 0, NULL);

    , cMFTActivate is still 0 by calling hr_SW = MFTEnumEx( MFT_CATEGORY_VIDEO_ENCODER, MFT_ENUM_FLAG_HARDWARE, NULL, &OutputTypes, &ppMFTActivate, &cMFTActivate );

     

     

    Why?

     

    PS:

    MFT_REGISTER_TYPE_INFO output_MFT_type;

    output_MFT_type.guidMajorType = MFMediaType_Video;

     

     

    output_MFT_type.guidSubtype = MFVideoFormat_H264;

    Wednesday, January 05, 2011 11:15 AM
  • To enumerate local decoders, you have to add the MFT_ENUM_FLAG_LOCALMFT to the flags passed to MFTEnumEx.  MFTRegisterLocalByCLSID does not register a hardware MFT, it registers a local MFT (and that local MFT may still be backed by hardware). 
    Wednesday, January 19, 2011 11:05 PM
    Moderator
  • I register MFT locally just like this:


     InputTypes.guidMajorType = MFMediaType_Video;
     InputTypes.guidSubtype = MFVideoFormat_NV12 ;

     OutputTypes.guidMajorType = MFMediaType_Video;
     OutputTypes.guidSubtype = MFVideoFormat_H264;

     hr_SW = MFTRegisterLocalByCLSID( CLSID_MF_H264EncFilter, MFT_CATEGORY_VIDEO_EFFECT, L"Intel\xae Media SDK H.264 Encoder MFT", MFT_ENUM_FLAG_ALL, 1, &InputTypes, 1, &OutputTypes);


    However, when I try to enumerate MFTs, this Intel MFT always can not appear locally.

    hr_SW = MFTEnumEx( MFT_CATEGORY_VIDEO_ENCODER, MFT_ENUM_FLAG_LOCALMFT , &InputTypes, &OutputTypes, &ppMFTActivate, &cMFTActivate );

    CLSID m_clsid;
    hr_SW = ppMFTActivate[0]->GetGUID( MFT_TRANSFORM_CLSID_Attribute, &m_clsid );//get CLSID from this enumerated MFT

    m_clsid is 6CA50344-051A-4DES-9779-A43305165E35, but CLSID_MF_H264EncFilter shoud not be this number.
    I look up the registry, 6CA50344-051A-4DES-9779-A43305165E35 should mean Micorsoft H.264 Encoder MFT.

    and if I call like this : hr_SW = MFTEnumEx( MFT_CATEGORY_VIDEO_ENCODER, MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_LOCALMFT, &InputTypes, &OutputTypes, &ppMFTActivate, &cMFTActivate );

    then CLSID_MF_H264EncFilter would be enumerated.

     

     

    Do you know why this case happen? It seems that  CLSID_MF_H264EncFilter is already registered in the system, but can not be registered locally. In this case, I do not know how to make sinkwriter choose  CLSID_MF_H264EncFilter to do encoding, not default Microsoft H.264 Encoder MFT.

     

     

    Friday, January 28, 2011 8:29 AM
  • Local registrations always override other registrations, even if the MFT is registered somewhere else.  Your MFTRegisterLocalByCLSID call registers under the category MFT_CATEGORY_VIDEO_EFFECT when you want MFT_CATEGORY_VIDEO_ENCODER -- though I think this might be a copy and paste error, since using MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_LOCALMFT works.  If MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_LOCALMFT works, then the sink writer will pick up the MFT as it uses both of those flags when enumerating potential encoders.
    Friday, February 04, 2011 2:00 AM
    Moderator
  • No, you seems wrong.

    MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_LOCALMFT  means "OR", not "AND".

     

    This morning, I finally found the correct way to register MFT locally ==>

    hr_SW = MFTRegisterLocalByCLSID( CLSID_MF_H264EncFilter, MFT_CATEGORY_VIDEO_ENCODER, L"Intel\xae Media SDK H.264 Encoder MFT", NULL, 0, NULL, 0, NULL);

    The flag should be NULL when register.

    hr_SW = MFTEnumEx( MFT_CATEGORY_VIDEO_ENCODER, MFT_ENUM_FLAG_LOCALMFT, NULL, NULL, &ppMFTActivate, &cMFTActivate );

    Now I can enumerate Intel MFT even if I only set flag as MFT_ENUM_FLAG_LOCALMFT when enumeration.

     

     

    ===>

    Anyway, right now I can say I already register Intel MFT locally.

    I have another question:

    Question 1.

    Why the CPU utilization is not different, even if I do not call MFTRegisterLocalByCLSID ??

    If I do not call MFTRegisterLocalByCLSID, the sinkwriter should choose Microsofte MFT as encoder, which should not have Hardware Encoder function on SandyBridge.

    Do you know why?

    Question 2.

    Intel Media Checker can not display any result when I register Intel MFT locally successfully.

    Why?

    Tuesday, February 08, 2011 4:06 AM
  • I am having a problem similar to Hitbook's. 

    I can use MFTRegisterLocalByCLSID and MFTEnumEX to see the Intel(R) Quick Sync Video H.264 Encoder MFT, but the topology is using the H264 Encoder MFT (from mfh264enc.dll). 

    My initial guess was that there wasn't a match between the source reader output and the input to the Intel encoder.  According to the documentation from Intel, their encoder requires the NV12 format at input and my source reader only had RGB24, YUY2, and MJPG.  I added the Color Converter MFT:

            hr = MFTRegisterLocalByCLSID(__uuidof(CColorConvertDMO),MFT_CATEGORY_VIDEO_PROCESSOR,L"",
                MFT_ENUM_FLAG_SYNCMFT, 0,NULL,0,NULL);

    I believe the color converter MFT should be able to convert the format from YUY2 to NV12, but that did not fix the problem.

     From the MFTrace, it looks like it tried to use the Intel encoder, but when it failed it defaulted to the mfh264enc.dll encoder (see trace excerpt below).  There error is REGDB_E_CLASSNOTREG, which is also the error I get when trying to use CoCreateInstance after MFTEnumEX.  What do I need to do to properly use the hardware encoder?

    thanks.

    excerpt from mftrace: <removed> I have a message later explaining the trace

    • Edited by sjbaran Thursday, February 10, 2011 9:09 PM removing a long trace
    Wednesday, February 09, 2011 1:33 AM
  • I've also tried setting the output of the IMFSourceReader to NV12 after registering the color converter DSP:

    GUID subtypes[] = {MFVideoFormat_NV12};

    hr = pType->SetGUID(MF_MT_SUBTYPE, subtypes[0]);

    hr = pReader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,NULL, pType);

    here I get MF_E_INVALIDMEDIATYPE

    I assume that means that the color converter was not used or could not convert from the native media type (YUY2) to NV12.

    If we can't get the media type in the NV12 format, we won't be able to use the Intel® Quick Sync Video H.264 Encoder (mfx_mft_h264ve_32.dll).  Looks like we will need a different transform to converty to NV12 before using the H.264 hardware encoder from Intel.

    Wednesday, February 09, 2011 6:52 PM
  • I've also tried setting the output of the IMFSourceReader to NV12 after registering the color converter DSP:

    GUID subtypes[] = {MFVideoFormat_NV12};

    hr = pType->SetGUID(MF_MT_SUBTYPE, subtypes[0]);

    hr = pReader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,NULL, pType);

    here I get MF_E_INVALIDMEDIATYPE

    I assume that means that the color converter was not used or could not convert from the native media type (YUY2) to NV12.

    If we can't get the media type in the NV12 format, we won't be able to use the Intel® Quick Sync Video H.264 Encoder (mfx_mft_h264ve_32.dll).  Looks like we will need a different transform to converty to NV12 before using the H.264 hardware encoder from Intel.

    Hi, Sjbaran and Microsoft Engineer:

    I use sinkwriter to do encoding. I can set the input stream media type as NV12 or YUY2. However, it is useless.

     

    and when I enumerate by MFT_ENUM_FLAG_LOCALMFT, there are four MFT listed including Intel® Quick Sync Video H.264 Encoder (mfx_mft_h264ve_32.dll), Microsoft H.264 Encoder, WMVideo8 Encoder, WMVideo9 Encoder.

    How does sinkwriter know which one is selected to run?

    Thursday, February 10, 2011 9:52 AM
  • I believe sinkwriter selects the encoders based on a priority, (something like: locally registered first, then other encoders).  The problem, I think, is that the system tries to use the Intel H.264 encoder but is not able to.  If you run MFTrace.exe on your application you probably have something like:

    <snip>
    CoCreateInstance @ Created {08B2F572-51BF-4E93-8B15-33864546DC9A} Intel® Media SDK H.264 Encoder MFT (C:\Program Files (x86)\Common Files\Intel\Media SDK\s1\2.0\mfx_mft_h264ve_32.dll) @06902800
    <snip>

    Here it creates the Intel encoder, next it'll try to use its input with the output of the source reader

    SetInputType @06902800 Failed MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MFVideoFormat_RGB24<snip>
    <snip>

    The output of the source reader is RGB24, but that does not match the expected input of the Intel encoder (NV12).  Next it will attempt to convert the format using the Microsoft color converter

    CoCreateInstance @ Created {98230571-0087-4204-B020-3282538E57D3} Color Converter DMO (C:\Windows\SysWOW64\colorcnv.dll)<snip>
    <snip>
    SetInputType @00566D50 Succeeded MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MFVideoFormat_RGB24<snip>
    SetOutputType @00566D50 Failed MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=MFVideoFormat_NV12<snip>
    <snip>

    It set the input into the color converter as RGB24 successfully, but could not set the output to NV12.  Apparently, the converter does not support that input/output combination.

    It gives up on the Intel encoder and goes on to the next available encoder:

    CoCreateInstance @ Created {6CA50344-051A-4DED-9779-A43305165E35}  (C:\Windows\SysWOW64\mfh264enc.dll)
    <snip>)

    It then goes on to successfully setup and connect the Microsoft software encoder.

    What I plan on doing is finding another media foundation transform that will convert to NV12 successfully or write my own (starting from the MFT_Greyscale project in the Microsoft SDK).

    • Edited by sjbaran Thursday, February 10, 2011 9:07 PM clarity
    Thursday, February 10, 2011 9:06 PM
  • I tried to use MFTRACE.exe, and I found something interesting:

    The log, made by MFTRACE.exe, in the beginning, would show 

    CoCreateInstance @ New MFT @00ABAB48, MF_TRANSFORM_ASYNC=1;MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE=1

    CoCreateInstance @ Created {08B2F572-51BF-4E93-8B15-33864546DC9A} Intel® Media SDK H.264 Encoder MFT (C:\Program Files\Intel\Media SDK\2.0.12.24071\samples\_build\Win32\Debug\mfx_mft_h264ve_32.dll) @00ABAB48 - traced interfaces: IMFTransform @00ABAB48,

    and I tried every stream media input types for H.264 encoder listed in MSDN (http://207.46.16.248/en-us/library/dd797816(VS.85).aspx

    • MFVideoFormat_I420
    • MFVideoFormat_IYUV
    • MFVideoFormat_NV12
    • MFVideoFormat_YUY2
    • MFVideoFormat_YV12
    All failed but MFVideoFormat_NV12.
    The log always show 
    0028 796,638 03:53:18.67152 CMFTransformDetours::SetInputType @00ABAB48 Failed MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE=the media type I set such as the above except MFVideoFormat_NV12;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_SIZE=4398046511872 (1024,768);MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297
    (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1

    Only when I use MFVideoFormat_NV12, the log would show SetInputType @00ABAB48
    Succeeded MT: MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_SUBTYPE= MFVideoFormat_NV12;MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_SIZE=4398046511872 (1024,768);MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297
    (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1


    Microsoft MFT would not be enumerated and used now, but there is nothing written in the output file.
    If you know anything helpful, please propose it to discuss. Thanks.









    Friday, February 11, 2011 5:03 AM
  •  I tried every stream media input types for H.264 encoder listed in MSDN (http://207.46.16.248/en-us/library/dd797816(VS.85).aspx
    • MFVideoFormat_I420
    • MFVideoFormat_IYUV
    • MFVideoFormat_NV12
    • MFVideoFormat_YUY2
    • MFVideoFormat_YV12
    All failed but MFVideoFormat_NV12.


    The link you have there descibes the Microsoft H.264 software encoder.  The Intel Media SDK encoder is a different H.264 encoder.  It is descibed in the guide at:

    http://software.intel.com/en-us/articles/intel-media-developers-guides/ (at the Media Developer's Guide v1.0 link).  The only input supported is NV12.  See section "3.3.3.1 Using the Framework Samples - Tips and Tricks".  

    "The Intel® Media SDK sample filters require the input data to be in NV12 format. NV12 is the native format of the GPU, and thus the filters need this format to pass the data to the hardware for acceleration. Developers may find the need to insert a color conversion filter upstream of the sample decoder filter in order to connect the graph successfully. The Intel® Media SDK does not provide a sample color conversion filter at this time. This is left to the developer to implement"

    I believe the problem you are having is that you can set the input to NV12, but the output from your source is not NV12 so you are not getting any frames from the source to the encoder.  There has to be a converter from the source video format to NV12 in order for the source to connect to the encoder.  The "built in" color converter from Microsoft: http://msdn.microsoft.com/en-us/library/ff819501(v=VS.85).aspx apparently does not support an NV12 output (at least in my experiments - see my MFTrace info above)

    There may be a color converter transform available somewhere, or we have to write our own.  On way is to use an API from Intel: http://software.intel.com/en-us/articles/using-unsupported-color-formats-with-the-intel-media-software-development-kit/

    • Edited by sjbaran Saturday, February 12, 2011 12:50 AM typo
    Saturday, February 12, 2011 12:49 AM
  • Unless you actually do have an NV12 source.  If you do have an NV12 source and aren't seeing video in your output, there might be something wrong with your source.  When I get a chance, here is what I'm going to do:

    1) get FFMpeg and convert a video file to NV12:

    • Windows build of FFMpeg http://ffmpeg.arrozcru.org/autobuilds/ ,
    • and on the command line use something like: ffmpeg -i myVideo.wmv -an -pix_fmt nv12 clip_nv12.yuv
    • (-pix_fmt nv12) so the output is in NV12 format
    • (-an) so that it is video only

    2) test the video (there are free .yuv viewers available online)

    3) Use the video as a media source by using Source Reader and MFCreateSourceReaderFromURL.

    4) convert the video to .mp4 file with the Intel Media SDK H.264 Encoder using Sink Writer

     That way I'll know if the Intel Media SDK H.264 encoder is working or not.  Then I'll have to find some way to convert from my source format to NV12 (I'll probably try using the Intel IPP I mentioned in my previous post).

    Saturday, February 12, 2011 5:20 PM
  • Thanks, Sjbaran, I would try your suggestion tomorrow.

    However, although I did not use NV12 video as source, the sinkwriter should not have ways to know whether this input video stream is NV12 or not. (the output should be wrong, but there should still be wrong output stream to be generated. )  How do you think?

     

     

    And I found another big issue: What I really want to do is to generate output stream to transfer on internet or LAN, but the container supported for sinkwriter are only MP4, MP3, ASF. I want TS/PS container. Does anyone know how to solve this problem?

     

    Sunday, February 13, 2011 6:00 PM
  • MFCreateSourceReaderFromURL is returning 0xC00D36C4 (Unsupported Bytestream) - so it looks like I'm unable to read in a NV12 file using Source Reader.  This result means that without a transform to NV12, I will not be able to test the Intel Media SDK H.264 Encoder with this approach.  I could still write my own transform to get the NV12 output, but now I'm thinking of re-writing the video pipeline using the Intel Media SDK API.
    Monday, February 14, 2011 6:19 PM
  • MFCreateSourceReaderFromURL is returning 0xC00D36C4 (Unsupported Bytestream) - so it looks like I'm unable to read in a NV12 file using Source Reader.  This result means that without a transform to NV12, I will not be able to test the Intel Media SDK H.264 Encoder with this approach.  I could still write my own transform to get the NV12 output, but now I'm thinking of re-writing the video pipeline using the Intel Media SDK API.


    I think we both really got the same situation.

    You can see the Intel Media SDK documents, which propose a method to do color conversion to NV12.  You can use this method to do conversion before sending to Media Foundation sinkwriter to do encoding. (or decoding by sourcereader)

    Of course, purely using Intel Media SDK is the good choice. If I have more time, I will change to use it purely. However, the shortage is its HW acceleration is only enabled on Intel platform.

    Tuesday, February 15, 2011 2:37 AM
  • Hi guys, I want to connect the MP4 sink writer to h264 software encoder.

    The pipeline is

    Source-->Encoder MFT-->Mp4 sink

    Please suggest me the changes in MFT what attributes need to set.

    Thanks for your support.


    Tuesday, February 07, 2012 6:18 AM
  • hi Guys!!

     I want to run the topology like

    videosource->h264Encoder-->sink

    i m unable to set the input media type on encoder  but can set output mediatype on encoder .when i run the topology it send the error-"No suitable transform was found to encode or decode "

    procedure to set media type as follow__

    hr=FindEncoderEx(MFVideoFormat_H264,0,&pEncoder);

        IMFMediaType *pTypeOut=NULL;
        IMFAttributes *pattribute=NULL;
        
        IMFMediaType *pTypein=NULL;    
        hr=MFCreateMediaType(&pTypeOut);//output type
        hr=MFCreateMediaType(&pTypein);//input type
        //Enumrate h.264videoEncoder


        hr = pTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
        hr = pTypeOut->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264);
        hr = MFSetAttributeRatio(pTypeOut, MF_MT_FRAME_RATE, 30000, 1001);
        hr = MFSetAttributeSize(pTypeOut, MF_MT_FRAME_SIZE, 720, 480);
        hr = MFSetAttributeRatio(pTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 10, 11);
        hr = pTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
        hr = pTypeOut->SetUINT32(MF_MT_AVG_BITRATE, (UINT32)(25000));
        hr=pTypeOut->SetUINT32(MF_MT_MPEG2_PROFILE , eAVEncH264VProfile_Base);
        hr=pEncoder->SetOutputType(0,pTypeOut,1);

        //set input type
        hr=pEncoder->GetOutputAvailableType(0,0,&pTypeOut);

        hr = pTypein->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video );
        hr = pTypein->SetGUID(MF_MT_SUBTYPE,MFVideoFormat_YUY2 );
        hr = MFSetAttributeSize(pTypein, MF_MT_FRAME_SIZE, 640, 480);
        hr = pTypein->SetUINT32(MF_MT_DEFAULT_STRIDE, 1280);
        hr = pTypein->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, 1);
        hr = pTypein->SetUINT32(MF_MT_FIXED_SIZE_SAMPLES, 1);
        hr = pTypein->SetUINT32(MF_MT_SAMPLE_SIZE, 614400);
        hr = pTypein->SetUINT32(MF_MT_AVG_BITRATE,    147456000);
        hr = MFSetAttributeRatio(pTypein, MF_MT_FRAME_RATE, (UINT32)30000, 1001);    
        hr = MFSetAttributeRatio(pTypein, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
        hr = pTypein->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);     

          //all hr return ok only this one
        hr=pEncoder->SetInputType(0,pTypein,1);

    Friday, May 11, 2012 12:13 PM