Search code examples
videorgbms-media-foundation

How does one find out whether a Windows Media Foundation sink writer needs bottom-up or top-down images?


I'm using Windows Media Foundation to create a video file. I've got some code working based on the Using the Sink Writer to Encode Video tutorial.

When the input type in MFVideoFormat_RGB32, and the output type is MFVideoFormat_WMV3, and the sink writer is writing to a WMV file, and I provide the sink writer with top-down RGB32 data, I get the video that I'd expect.

When the output type is MFVideoFormat_H264, on the other hand - everything else the same - the bitmaps come out upside-down.

How can I find out at runtime what sort of bitmap data is needed?


Solution

  • RGB video media types might be given an optional MF_MT_DEFAULT_STRIDE attribute to specify row order:

    Default surface stride, for an uncompressed video media type. Stride is the number of bytes needed to go from one row of pixels to the next. [...]

    Stride is positive for top-down images, and negative for bottom-up images.

    The attribute is optional and when omitted might lead to confusion as data consumer might apply different defaults. In general it is typical for RGB data to come in reversed row order for historical reasons, however most recent APIs tend to fix it and have data in normal row order.