locked
Setting H264 ICodec properties in Metro (Modern) interface through an IMFMediaSink/IMFStreamSink pair.

    Question

  • Hello,

    I'm trying to set some properties (CODECAPI_AVEncCommonRateControlMode and CODECAPI_AVEncCommonQuality), but I'm not sure how to do it. I tried to set them through the media type, but they seem to get ignored by the system (I tried with 1 and 100 of quality, but the quality didn't change at ALL) :

    12120,2B54 18:22:32.20885 CMFTransformDetours::SetOutputType @0000001F7B346958 Succeeded MT: MF_MT_FRAME_SIZE=8246337209400 (1920,1080);{1C0608E9-370C-4710-8A58-CB6181C42423}=3;MF_MT_AVG_BITRATE=2048000;MF_MT_MPEG_SEQUENCE_HEADER=00 00 00 01 67 64 00 28 ac 2b 40 3c 01 13 f2 e0 22 00 00 03 00 02 00 00 03 00 78 1b 41 10 8d 40 00 00 00 01 68 ce 3c 30 ;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_MPEG2_PROFILE=100;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_INTERLACE_MODE=2;MF_MT_SUBTYPE=MEDIASUBTYPE_H264;{FCBF57A3-7EA5-4B0C-9644-69B40C39C391}=1 
    12120,2B54 18:22:32.20886 CMFTransformDetours::SetOutputType @0000001F7B346958 - exit 
    12120,2B54 18:22:32.20887 CMFTransformDetours::SetInputType @0000001F7B346958 - enter 
    12120,2B54 18:22:32.20891 CMFTransformDetours::SetInputType @0000001F7B346958 Succeeded MT: MF_MT_FRAME_SIZE=8246337209400 (1920,1080);MF_MT_COMPRESSED=0;MF_MT_MAJOR_TYPE=MEDIATYPE_Video;MF_MT_AM_FORMAT_TYPE=FORMAT_VideoInfo;MF_MT_FIXED_SIZE_SAMPLES=1;MF_MT_FRAME_RATE=128849018881 (30,1);MF_MT_PIXEL_ASPECT_RATIO=4294967297 (1,1);MF_MT_ALL_SAMPLES_INDEPENDENT=1;MF_MT_FRAME_RATE_RANGE_MIN=128849018881 (30,1);MF_MT_INTERLACE_MODE=2;MF_MT_FRAME_RATE_RANGE_MAX=128849018881 (30,1);MF_MT_SUBTYPE=MFVideoFormat_YUY2 
    12120,2B54 18:22:32.20891 CMFTransformDetours::SetInputType @0000001F7B346958 - exit 

    This is the output captured by mftrace. What am I doing wrong? What is the correct way to set these properties (that are marked as compatible with the Metro interface)

    Thank you!

    Saturday, January 31, 2015 7:09 PM

All replies

  • Hello,

    Why and how are you getting access to the code interface?

    Typically you would not set these properties directly on the codec but set them via the MediaEncodingProfile before passing them to the MediaCapture API.

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Monday, February 02, 2015 6:55 PM
    Moderator
  • I want to be able to set the parameters of the ICodecAPI (for the Microsoft h264 encoder) because I want to be able to optimize the encoding process (more speed or more quality depending on user settings) and there are a couple of interesting options in there.

    The MediaEncodingProfile is far too limiting (the version for Windows 8.1 at least) as it doesn't allow you to modify pretty much anything aside from bitrate and resolution (the rest of the fields are read-only). Being stuck with an unconstrained VBR and no way to choose isn't that good. What's the point of allowing to set High profile on the h264 encoder if you can't enable CABAC in the first place?

    https://msdn.microsoft.com/en-us/library/windows/desktop/dd797816(v=vs.85).aspx

    How? At the moment I'm just trying through the IMFMediaType (which isn't working). 

    I implemented the IMFMediaSink, IMFStreamSink and IMFMediaTypeHandler interfaces (It's a TCP network + archive sink) and on the SetCurrentMediaType of the IMFMediaTypeHandler I modify the IMFMediaType programmatically. That isn't working (even if the parameters are passed as I gathered from mftrace) so I was asking if there was any other way to reach the encoder settings and set the options I want.

    Thank you,
    C13

    Monday, February 02, 2015 9:18 PM
  • The MediaEncodingProfile is far too limiting (the version for Windows 8.1 at least) as it doesn't allow you to modify pretty much anything aside from bitrate and resolution (the rest of the fields are read-only).

    Hello,

    Your interpretation of the documentation is incorrect. You can add any Media Foundation property to the MediaEncodingProfile by using "VideoEncodingProperties.Properties" and adding or setting the additional properties via the read / write MediaPropertySet that is returned. You should never have to access and then manipulate the codec directly.

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Monday, February 02, 2015 11:22 PM
    Moderator
  • Hello James,

    Let's go with an example. 

    https://msdn.microsoft.com/en-us/library/windows/desktop/dd317841(v=vs.85).aspx
    https://msdn.microsoft.com/en-us/library/windows/desktop/dd317842(v=vs.85).aspx

    I want to be able to set these two properties in my MediaEncodingProfile in order to switch from a bitrate based encoding to a quality based encoding. Both properties are marked in the documentation as compatible with Windows Store Apps so they should work right?

    Following your example I set them in the video MediaPropertySet as 

    MediaPropertySet^ set = mediaEncodingProperties->Properties;
    set->Insert(CODECAPI_AVEncCommonRateControlMode, (int)eAVEncCommonRateControlMode_Quality);
    set->Insert(CODECAPI_AVEncCommonQuality, 1);

    Quality 1 because I want to be sure that they're working. The default is 70 so the quality should be really low and visible.

    Then I call (as usual)

    mediaCapture.StartRecordToCustomSinkAsync(encodingProfile, mfExtension);

    But I still get a bitrate based encoding. What am I doing wrong?

    Thank you,

    C13


    • Edited by C13 Tuesday, February 03, 2015 7:36 AM
    Tuesday, February 03, 2015 7:36 AM
  • Try clearing the property set and add everything you need from scratch.

    MediaPropertySet.Clear

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Tuesday, February 03, 2015 10:48 PM
    Moderator