2

I want to perform media transcoding operation in-memory using Media Foundation from a MP3 format to a WAV (PCM) format.

I tried the code as mentioned below:

//Initialize MediaStreamSource with location of MP3 file
var mediaStream = new MediaStreamSource(mp3File);

//Create a "dummy" wav file to attach to IRandomAccessStream
StorageFile _OutputFile2 = await  
KnownFolders.VideosLibrary.CreateFileAsync("Test.wav", 
CreationCollisionOption.GenerateUniqueName);

IRandomAccessStream iras = 
_OutputFile2.OpenAsync(FileAccessMode.ReadWrite).AsTask().Result;

//Setup the transcode operation to convert from MP3 to WAV
_Profile = MediaEncodingProfile.CreateWav(audioEncodingProfile);
var preparedTranscodeResult = await 
_Transcoder.PrepareMediaStreamSourceTranscodeAsync(mediaStream, iras, 
_Profile);

try
{
    if (preparedTranscodeResult.CanTranscode)
    {
        var progress = new Progress<double>(TranscodeProgress);

        await 
        preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, 
        progress);
    }
    else
    {
        TranscodeFailure(preparedTranscodeResult.FailureReason);
    }
}
catch (Exception ex)
{
    TranscodeError(ex.Message);
}

When trying to transcode, I get the following error:

This object needs to be initialized before the requested operation can be carried out.

I also referred this link which has a similar issue: https://social.msdn.microsoft.com/Forums/vstudio/en-US/6156580a-6673-4cf3-b6a9-5853b2a85bf6/what-kind-of-stream-to-feed-into-mediatranscoderpreparestreamtranscodeasync?forum=winappswithnativecode

I am looking for a sample which performs in-memory transcode operation instead of saving it to disk.

Appreciate your help.

user3261909
  • 145
  • 1
  • 2
  • 11
  • Media Foundation is a perfect solution for this. I intend to provide a detailed answer (may take a bit to reserve some time). What do intend to do with the PCM stream? IEEE float or 16bit unsigned? – Jeff Feb 02 '15 at 20:37
  • Did you solved this issue? If yes, can you post an answer? – tomab Aug 06 '15 at 07:41

0 Answers0