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.