5

It's been a week since I'm trying to make my encoder works...

So the things is:

  1. I create a file using the Sink Writer from MF.

  2. I write all my video sample.

    --> (If I stop there and call the Finish methods, I'm able to read the file using VLC but if I do the bellow stuff, the file will be "corrupted")

  3. I write all my audio sample.

  4. I call the finish function and I get a HRESULT code saying: "Sink could not create valid output file because required headers were not provided to the sink". I totally understand the error, just I don't get how to solve it...

If you guys need any code , I'll be glad to put it here.

Nox
  • 932
  • 1
  • 9
  • 27

1 Answers1

3

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.

Community
  • 1
  • 1
Jeff
  • 2,495
  • 18
  • 38
  • Thank you for that, I don't have my project with me at the moment but I will definitely try that later. Just a enquiry tho, could you please explain how do you init and set that "buffer" please? `attributes->SetBlob(MF_MT_MPEG4_SAMPLE_DESCRIPTION, buffer, buffer_size);` – Nox Mar 31 '15 at 20:54
  • Certainly. What type of audio do you intend to use? I will format the example with your audio sub-type. – Jeff Apr 01 '15 at 12:36
  • I will go for MFAudioFormat_AAC which I found to have better quality in general. I've got my audio in PCM right now, but it will be pretty easy to convert I reckon – Nox Apr 01 '15 at 20:07
  • If you use MFAudioFormat_AAC, then IMFAttributes::SetBlob is not necessary, since the sink can auto-generate the description (as described above). For a basic config, select a sub-type with a sample rate of 44100, 16 bps, and 2 channels. But any AAC selection will finalize smoothly without the need for IMFAttributes::SetBlob. – Jeff Apr 01 '15 at 20:46
  • Hum, ok, and what if I want to use WAV PCM straight? Is that possible? – Nox Apr 01 '15 at 20:51
  • Yes, and a few others (which are listed on the MP4 File Source link above). It will be a bit more coding, and more config. That is where MF_MT_MPEG4_SAMPLE_DESCRIPTION comes in. You will have to manually provide the headers to the sink. And I am not sure why you would do that. AAC and MP3 work quite well with MP4. They are easy to use, and compress nicely. – Jeff Apr 01 '15 at 21:37
  • Because, in my app I do not modify the audio stream(s) and I want to put them back untouch, so for example if I have a Wav inside my input video I want a Wav onto my output ones. – Nox Apr 01 '15 at 21:39
  • Sorry, I didn't want to seem rude or so. Just trying to figure out if my idea is event doable or not... Thanks anyway for those useful input! Pretty hard to find some MediaFoudation enthusiast! – Nox Apr 01 '15 at 21:45
  • I will edit the above answer to include a bit more information with respect to the Sample Description Box. – Jeff Apr 01 '15 at 22:21