2

我想使用 Media Foundation在内存中执行从 MP3 格式到 WAV (PCM) 格式的媒体转码操作。

我尝试了如下所述的代码:

//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);
}

尝试转码时,出现以下错误:

在执行请求的操作之前,需要初始化此对象。

我还提到了这个有类似问题的链接: https ://social.msdn.microsoft.com/Forums/vstudio/en-US/6156580a-6673-4cf3-b6a9-5853b2a85bf6/what-kind-of-stream-to -feed-into-mediatranscoderpreparestreamtranscodeasync?forum=winappswithnativecode

我正在寻找一个执行内存转码操作而不是将其保存到磁盘的示例。

感谢你的帮助。

4

0 回答 0