Media Foundation IMFSinkWriter::Finalize() method fails under Windows 7 when muxing H.264 frames into MP4

梦想的初衷 提交于 2019-12-01 11:24:39

Okay, I'm answering this myself.

Having tried unsuccessfully all sorts of attributes with the media type, sink writer, media samples, and media buffers, I finally got to check the media sink object. Long story short: it's the MF_MT_MPEG_SEQUENCE_HEADER attribute that was missing in the media type passed to the sink.

According to the MPEG-4 file sink's documentation, this attribute is resolved automatically in Windows 8, but must be supplied in all other cases. The value should be an SPS/PPS sequence, provided as a byte array, as appearing in the H.264 headers.

To see it work, I extracted a sequence manually (using a hex viewer) from a H.264 sample I have. If I have to parse the headers from my code, I guess I'll have to look for the "3 or 4" byte start codes in the key frames, but I don't know if this will work in all NALU separation formats. Any comments on this are welcome.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!