我正在尝试使用媒体组合和Windows.Media.Transcoding API自动将一些.mp4文件中的音频轨道转换为16 the的单PCM音频,以便使用Microsoft语音认知服务(语音到文本)。
我有一个带有正确MEdiaEncodingProfile的示例音频文件,我使用MediaEncodingProfile.CreateFromFileAsync(sampleAudio)
。
之后,我设置了一个转码器,然后使用
PrepareTranscodeResult prepareOp = await transcoder.PrepareFileTranscodeAsync(SourceVideo.VideoFile, tempFile, profile);
..。但这会导致prepareOp.CanTranscode = false
,因为我认为我不能直接将.mp4转换成音频文件。
有什么方法可以让我在.mp4文件中获取对左音频轨道的引用,然后将其转换成wav文件?
发布于 2018-05-14 07:22:43
但这会导致prepareOp.CanTranscode = false,因为我认为不能将.mp4直接转换为音频文件。
实际上,你可以直接用MediaTranscoder
把视频转换成音频。您可以参考以下内容,它在我的测试中有效。
MediaEncodingProfile profile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Low);
MediaTranscoder transcoder = new MediaTranscoder();
PrepareTranscodeResult prepareOp = await
transcoder.PrepareFileTranscodeAsync(source, destination, profile);
if (prepareOp.CanTranscode)
{
var transcodeOp = prepareOp.TranscodeAsync();
transcodeOp.Progress +=
new AsyncActionProgressHandler<double>(TranscodeProgress);
transcodeOp.Completed +=
new AsyncActionWithProgressCompletedHandler<double>(TranscodeComplete);
}
else
{
switch (prepareOp.FailureReason)
{
case TranscodeFailureReason.CodecNotFound:
System.Diagnostics.Debug.WriteLine("Codec not found.");
break;
case TranscodeFailureReason.InvalidProfile:
System.Diagnostics.Debug.WriteLine("Invalid profile.");
break;
default:
System.Diagnostics.Debug.WriteLine("Unknown failure.");
break;
}
}
唯一的区别是MediaEncodingProfile
是用MediaEncodingProfile.CreateWav(AudioEncodingQuality.Low)
创建的,而不是从sampleAudio
创建的。我也尝试过定制的PCM
AudioEncodingProperties
,但是它不起作用。我建议你使用内部侧写。
https://stackoverflow.com/questions/50314125
复制相似问题