Writing custom audio format to MP4
Asked Answered
S

0

2

I'm trying to encode audio to an MP4 file with a custom compression codec and my IMFTransform works correctly until SinkWriter's Finalize:

0xc00d4a45 : Sink could not create valid output file because required headers were not provided to the sink.

I'm trying to provide a dummy sample descriptor to no result:

struct SADB
{
    unsigned int len = 28;
    unsigned int stsd = 0xBBBB;
    unsigned int verflag = 0;
    unsigned int nume = 1;
    unsigned int len1 = 12;
    unsigned int cod1 = 0xAAAA;
    unsigned int data1 = 0;
};
SADB sadb;
attributes->SetBlob(MF_MT_MPEG4_SAMPLE_DESCRIPTION, (UINT8*)&sadb, sizeof(sadb));

MFCreateSinkWriterFromURL(L"1.mp4", 0, attributes, &wr);
...
audiooutmt->SetBlob(MF_MT_MPEG4_SAMPLE_DESCRIPTION, (UINT8*)&sadb, sizeof(sadb));
wr->AddStream(audiooutmt, &sidx);

I even tried to provide a sample description got from a known mp4 file with AAC compression, still same error.

How can I make the Sink Writer accept my custom audio compression?

Best,

Edit: as I found out, the media type of the stream had erased the mpeg info. Why?

By getting the MF_SOURCE_READER_MEDIASOURCE media source, then the stream, then the media type handler I was able to reinject the mpeg2 type.

Why this weird behaviour occurs?

Stanstance answered 7/8 at 4:41 Comment(3)
Maybe it's just for this sample code, but are you really using 0xBBBB for stsd? should be 'stsd'Kerbstone
Yes it's 'stsd'. For some reason it erases it from the media type until I write it again.Stanstance
Does the answer stackoverflow.com/a/29375021 work for you?Souvenir

© 2022 - 2024 — McMap. All rights reserved.