Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raw Audio File to AAC using Windows Media Foundation on Windows 7

Thanks for taking some time to read my question.

I'm developping a C++ application using Qt and windows API.

I'm recording the microphone output in small 10s audio files in raw format, and I want to convert them to aac format.

I have tried to read as many things as I could, and thought it would be a great idea to start from windows media foundation transcode API.

Problem is, I can't seem to use a .raw or .pcm file in the "CreateObjectFromUrl" function, and so I'm pretty much stuck here for the moment. It keeps on failing. The hr return code equals 3222091460. I have tried to pass an .mp3 file to the function and of course it works, so no url-human-failure involved.

MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;

IMFSourceResolver* pSourceResolver = NULL;
IUnknown* pUnkSource = NULL;

// Create the source resolver.
hr = MFCreateSourceResolver(&pSourceResolver);
if (FAILED(hr))
{
    qDebug() << "Failed !";
}


// Use the source resolver to create the media source.


 hr = pSourceResolver->CreateObjectFromURL(
        sURL,                       // URL of the source.
        MF_RESOLUTION_MEDIASOURCE,  // Create a source object.
        NULL,                       // Optional property store.
        &ObjectType,                // Receives the created object type.
        &pUnkSource                 // Receives a pointer to the media source.
        );

The MFCreateSourceResolver works fine, but CreateObjectFromURL does not succeed :(

So I have two questions for you folks :

  1. Is it possible to encode raw audio files to aac files using windows media foundation ?
  2. If yes, what should I read to accomplish what I want ?

I want to point out that I can't just use ffmpeg or libav because I can't afford any license for my software, and don't want it to be under the GPL license. But if there are alternatives to windows media foundations to encode raw audio files to aac, I would be glad to hear them.

And finally, sorry for my bad english, this is obviously not my native language and I'm sorry if I made your eyes bleed. (and happy if I made you laugh)

Have a nice day

like image 764
Eyal Hadida Avatar asked Sep 16 '12 10:09

Eyal Hadida


1 Answers

The hr return code equals 3222091460

Those are HRESULT codes. Use this "ShowHresult" tool to have them conveniently decoded for you. The code means 0xC00D36C4 MF_E_UNSUPPORTED_BYTESTREAM_TYPE "The byte stream type of the given URL is unsupported."

The problem is basically that there is no support for these raw files, .WAV is a good source for raw audio - the file holds both format descriptor and the payload.

You can obviously read data from the raw audio file yourself and compress into AAC using Media Foundation's AAC Encoder via its IMFTransform interface. This is reasonably easy and you have AAC data on the output to e.g. write into raw .AAC.

Alternate options to Media Foundation is DirectShow (there are suitable codecs, though I thought it might be not so easy to start), libfaac, FFmpeg's libavcodec (available under LGPL, not GPL).

like image 69
Roman R. Avatar answered Oct 13 '22 12:10

Roman R.