I am trying to use 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
This is not going to throw exception but it show me
"Error: Video could not be decoded"
on media element.
It is strange, because code is working well with 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
What am I doing wrong?
The
VideoTransformEffectDefinition
only works withMediaTranscoder
. It has no effect overMediaComposition
. And it throw an NullReferenceException when you set theMediaElement
byMediaElement.SetMediaStreamSource(MediaComposition .GenerateMediaStreamSource())
.There is an official sample from GitHub that uses the
MediaTranscoder
. And in Scenario1, it creates theMediaTranscoder
byprivate MediaTranscoder _Transcoder = new MediaTranscoder();
You can add theVideoTransformEffectDefinition
toMediaTranscoder
byAddAudioEffect(System.String activatableClassId, System.Boolean effectRequired, IPropertySet configuration)
.You can add the following code to
TranscodePreset
event in Scenario1_Default.xaml.cs.For example: