locked
Difficulty Definitively Configuring MediaFoundation's H264 Encoder Bit Rate RRS feed

  • Question

  • Hello All,

    I am developing an MP4 (H264/AAC) export pipe using a SinkWriter object from MediaFoundation. I have the pipe fully implemented, and it is largely successfully operational. However, one thing sticks out as not behaving properly. When configuring the H264 encoder of the SinkWriter, via creating an output media type and adding this media type to the SinkWriter via AddStream(), the bit rate I set via MF_MT_AVG_BITRATE gets clipped at some seemingly arbitrary upper bound (at least as reported via pulling up 'Properties' in Windows Explorer on the exported .mp4 file, though from reported file size this reported bit rate seems to fit). This upper bound seems to vary for different samples of video media. However, for example, lets say I have VideoMediaA, which is 20 seconds of 1080p30 video of someone walking down a street. Also for the purpose of this example lets say when I export this video using my SinkWriter, the bit rate cap experienced on this video, when setting the bit rate directly via MF_MT_AVG_BITRATE, is 18Mbps, resulting in a file of about 45MB. No matter what value I set on the media type for MF_MT_AVG_BIT_RATE that is in excess of 18Mbps I cannot increase the bit rate of the exported file. The immediate visual results of this are that the image quality of this exported file is very low, with macro blocks abound in areas of subtle vignette. Note that I have tried setting different H264 levels, different H264 profiles, and different encoder control modes, and none seems to allow me to get past this apparent upper bound.

    Seeking a way around this, I found that when 'properly' configuring the encoder to use a control mode of 'quality' (via: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/6da521e9-7bb3-4b79-a2b6-b31509224638/win7-h264-encoder-imfsinkwriter-cant-use-quality-vbr-encoding?forum=mediafoundationdevelopment), and when setting the quality to its maximum value, that being 100, and exporting my self-same example file, VideoMediaA, I am able to get a bit rate dramatically higher than that which is the apparent cap when setting the bit rate directly on the media type via MF_MT_AVG_BIT_RATE. When I say dramatically higher, I mean in the neighborhood of 70Mbps, as opposed to the aforementioned 18Mpbs. Adjusting this quality setting down from 100 allows me to export all over the bit rate spectrum underneath the bit rate that results from a quality of 100. When configuring the encoder via this 'quality' setting I am actually able to create an export that is of the quality I want - with one major caveat.

    The export pipe I am creating is fitting into an existent application which has always, and will always by specification, give the user a control that allows the user to set the bit rate directly in terms of Mpbs (and not via an abstracted 'quality' setting). I cannot expose to the user this 'quality' setting, I must expose to the user a bit rate control. Thus I get to the question portion of this post:

    1) Via MF_MT_AVG_BITRATE  on the output media type, is there a way to definitively set the bit rate in excess of this seemingly mysterious and undocumented upper bound? I mean, I know that bit rates in excess of this upper bound are possible via configuring the encoder for quality…

    Failing that…

    2) Is there some known mapping I can use that can map a desired bit rate to a quality setting? From my plotting of the results of exporting different frame-sized examples at different quality settings it seems to be some type of power curve, which is also dependent upon frame size, frame rate, and (unfortunately...) image contents.

    Any help would be much appreciated!

    Thanks in advance,
    Josh

    ==================

    Edit: I am performing my development and testing on a Win7 machine.






    • Edited by jbodinet Wednesday, November 6, 2013 9:18 PM added information
    Wednesday, November 6, 2013 5:18 PM