I ran into this exact error when I first started using the MP4 container (upon finalizing the sink).
Error 0xC00D4A45: Sink could not create valid output file because
required headers were not provided to the sink.
You didn't mention what sub-type of audio samples you are feeding the sink, nor what sub-type of audio stream that was added (for output), however I am confident that your issue is with the latter.
Developing with media foundation, the MP4 container is easiest to configure using MFAudioFormat_AAC
or MFAudioFormat_MP3
. If you look at the details for the MP4 File Sink at this link, you will see that the sink can generate the sample description box (stsd) for the following formats:
- H.264/AVC video
- AAC audio
- MP3 audio
It is possible to use a few other formats, however you will have to manually supply the sample description box (stsd) description using MF_MT_MPEG4_SAMPLE_DESCRIPTION
GUID when configuring the attributes before creating the sink. This is accomplished using the following function:
// IMFAttributes::SetBlob
attributes->SetBlob(MF_MT_MPEG4_SAMPLE_DESCRIPTION, buffer, buffer_size);
However, there are few other types which can be used, as described by the MP4 File Source here. Under Media Types, there is a table of various allowed types. Other than AAC/MP3 previously mentioned, there are few remaining audio types, and none are very attractive choices. You will find that sticking to MFAudioFormat_AAC
or MFAudioFormat_MP3
will serve you well.
Hope this helps.
EDIT:
If you choose to use an audio sub-type other than AAC
or MP3
, and provide a MF_MT_MPEG4_SAMPLE_DESCRIPTION
configuration using IMFAttributes::SetBlob
, the sample description box (stsd) is described in this answer. As that answer states, the boxes are nested.
Pertaining to Audio, take for instance, if you to select MFAudioFormat_PCM
, MP4 File Source lists 5 entries in the Media Types section. As a result, use the appropriate sample entry code ('raw ', 'sowt', 'twos', 'NONE', 0x00) when building the sample description box. Note the space in 'raw '. The high level summary is as follows:
// 'raw ' Audio MFAudioFormat_PCM 8-bit PCM audio
// 'sowt' Audio MFAudioFormat_PCM 16-bit little-endian PCM audio
// 'twos' Audio MFAudioFormat_PCM 16-bit big-endian PCM audio
// 'NONE' Audio MFAudioFormat_PCM 8-bit or 16-bit big-endian PCM audio
// 0x00 Audio MFAudioFormat_PCM 8-bit or 16-bit big-endian PCM audio
You may also find these registered codecs interesting.