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

后端 未结 1 1082
再見小時候
再見小時候 2021-01-15 06:08

I\'m writing a tool in C# that muxes H.264 frames into MP4 files, and I\'m using Media Foundation\'s media sink with sink writer to do this.

Things work pretty well

相关标签:
1条回答
  • 2021-01-15 06:44

    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.

    0 讨论(0)
提交回复
热议问题