0

我正在尝试使用VideoTransformEffectDefinition

        var clip = await MediaClip.CreateFromFileAsync(pickedFile);//creating clip from storage file
        MediaComposition composition = new MediaComposition();
        composition.Clips.Add(clip);
        VideoTransformEffectDefinition videoEffect1 = new VideoTransformEffectDefinition();
        videoEffect1.PaddingColor = Colors.Blue;//this line is not necessary, does not matter how videoEffect is changed 
        clip.VideoEffectDefinitions.Add(videoEffect1);//adding videoEffect
        this.mediaElement.SetMediaStreamSource(composition.GenerateMediaStreamSource());//setting source to MediaElement

这不会抛出异常,但它告诉我

“错误:视频无法解码”

关于媒体元素。

这很奇怪,因为代码与VideoStabilizationEffectDefinition配合得很好:

        var clip = await MediaClip.CreateFromFileAsync(pickedFile);//creating clip from storage file
        MediaComposition composition = new MediaComposition();
        composition.Clips.Add(clip);
        VideoStabilizationEffectDefinition videoEffect = new VideoStabilizationEffectDefinition();
        clip.VideoEffectDefinitions.Add(videoEffect);//adding videoEffect
        this.mediaElement.SetMediaStreamSource(composition.GenerateMediaStreamSource());//setting source to MediaElement

我究竟做错了什么?

4

1 回答 1

1

VideoTransformEffectDefinition唯一适用于MediaTranscoder. 它没有任何效果MediaCompositionMediaElement当您设置by时,它会抛出 NullReferenceException MediaElement.SetMediaStreamSource(MediaComposition .GenerateMediaStreamSource())

GitHub提供了一个使用MediaTranscoder. 在 Scenario1 中,它创建了MediaTranscoderbyprivate MediaTranscoder _Transcoder = new MediaTranscoder();您可以将 by添加VideoTransformEffectDefinition到。MediaTranscoderAddAudioEffect(System.String activatableClassId, System.Boolean effectRequired, IPropertySet configuration)

您可以将以下代码添加到TranscodePresetScenario1_Default.xaml.cs 中的事件。

例如:

VideoTransformEffectDefinition videoEffect = new VideoTransformEffectDefinition();
_Transcoder.ClearEffects();
var activatableClassId = videoEffect.ActivatableClassId;
_Transcoder.AddVideoEffect(activatableClassId, true, videoEffect.Properties);
videoEffect.PaddingColor = Colors.Blue;
videoEffect.Rotation = MediaRotation.Clockwise90Degrees;
于 2016-04-12T09:49:53.067 回答