6

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

Eyal Hadida
  • 81
  • 1
  • 4

1 Answers1

5

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).

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • 1
    Hi Roman and thank you very much for your answer. It made things very clear, and I can't thank you enough for your time. I will go with the AAC Encoder from WMF to get raw AAC and see what I can do from there. If I may ask you 2 other minutes of your knowledge, as I am pretty much a beginner in audio encoding... I can't seem to find any code example to help me out on which steps should I follow to transform pcm to aac. As I understand it now thanks to you, I need to create an IMFTransform interface, set input raw and output aac, set sample duration and call ProcessOutput. Is it that simple? – Eyal Hadida Sep 16 '12 at 12:00
  • 1
    Unfortunately I am not aware of good reference sample code. However I used to have it working some time in past, so I know it works well. Yes what you basically need is to follow [AAC Encoder](http://msdn.microsoft.com/library/dd742785%28v=vs.85%29.aspx) and instantiate the MFT class, set input media type, set output media type (carefully!), then push PCM data with `ProcessInput` and pull AAC data with `ProcessOutput`. – Roman R. Sep 16 '12 at 12:29