Пример #1
0
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            Video.Stop();
            Video.Source = null;
            Video.RemoveAllEffects();

            if (CurrentVideo == null || CurrentEffect == null || SecondVideo == null || ThirdVideo == null)
            {
                return;
            }

            MediaComposition comp = new MediaComposition();

            StorageFile VideoFile1 = await StorageFile.GetFileFromApplicationUriAsync(new Uri(CurrentVideo));

            StorageFile VideoFile2 = await StorageFile.GetFileFromApplicationUriAsync(new Uri(SecondVideo));

            StorageFile VideoFile3 = await StorageFile.GetFileFromApplicationUriAsync(new Uri(ThirdVideo));

            MediaClip mediaClip1 = await MediaClip.CreateFromFileAsync(VideoFile1);

            MediaClip mediaClip2 = await MediaClip.CreateFromFileAsync(VideoFile2);

            MediaClip mediaClip3 = await MediaClip.CreateFromFileAsync(VideoFile3);

            TransitionEffectParameter transitionEffectParameter1 = new TransitionEffectParameter();
            TransitionEffectParameter transitionEffectParameter2 = new TransitionEffectParameter();
            TransitionEffectParameter transitionEffectParameter3 = new TransitionEffectParameter();

            transitionEffectParameter1.SetStartEffect(TransitionEffectType.TRANSITION_NONE, 0);
            transitionEffectParameter1.SetEndEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter1.SetVideoDuration((float)mediaClip1.OriginalDuration.TotalSeconds);

            transitionEffectParameter2.SetStartEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter2.SetEndEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter2.SetVideoDuration((float)mediaClip2.OriginalDuration.TotalSeconds);

            transitionEffectParameter3.SetStartEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter3.SetEndEffect(TransitionEffectType.TRANSITION_NONE, 0);
            transitionEffectParameter3.SetVideoDuration((float)mediaClip3.OriginalDuration.TotalSeconds);

            PropertySet configuration1 = new PropertySet();

            configuration1.Add("TransitionEffectParameter", transitionEffectParameter1);
            mediaClip1.VideoEffectDefinitions.Add(new VideoEffectDefinition("TransitionEffectTransform.TransitionEffect", configuration1));  //change it to EffectTransform

            PropertySet configuration2 = new PropertySet();

            configuration2.Add("TransitionEffectParameter", transitionEffectParameter2);
            mediaClip2.VideoEffectDefinitions.Add(new VideoEffectDefinition("TransitionEffectTransform.TransitionEffect", configuration2));  //change it to EffectTransform

            PropertySet configuration3 = new PropertySet();

            configuration3.Add("TransitionEffectParameter", transitionEffectParameter3);
            mediaClip3.VideoEffectDefinitions.Add(new VideoEffectDefinition("TransitionEffectTransform.TransitionEffect", configuration3));  //change it to EffectTransform

            comp.Clips.Add(mediaClip1);
            comp.Clips.Add(mediaClip2);
            comp.Clips.Add(mediaClip3);

            StorageFile destination = await ApplicationData.Current.LocalFolder.CreateFileAsync("transition_result.mp4", CreationCollisionOption.ReplaceExisting);

            Save.IsEnabled = false;

            var a = comp.RenderToFileAsync(destination);

            a.Progress  = new AsyncOperationProgressHandler <Windows.Media.Transcoding.TranscodeFailureReason, double>(tempProgress);
            a.Completed = new AsyncOperationWithProgressCompletedHandler <Windows.Media.Transcoding.TranscodeFailureReason, double>(tempCOmpleted);
        }
Пример #2
0
        private async void Apply_Effect(object sender, RoutedEventArgs e)
        {
            if (CurrentVideo == null || CurrentEffect == null)
            {
                return;
            }

            SecondVideo = VideoList.IndexOf(CurrentVideo) == VideoList.Count - 1 ? VideoList[0] : VideoList[VideoList.IndexOf(CurrentVideo) + 1];
            ThirdVideo  = VideoList.IndexOf(SecondVideo) == VideoList.Count - 1 ? VideoList[0] : VideoList[VideoList.IndexOf(SecondVideo) + 1];

            MediaComposition comp = new MediaComposition();

            StorageFile VideoFile1 = await StorageFile.GetFileFromApplicationUriAsync(new Uri(CurrentVideo));

            StorageFile VideoFile2 = await StorageFile.GetFileFromApplicationUriAsync(new Uri(SecondVideo));

            StorageFile VideoFile3 = await StorageFile.GetFileFromApplicationUriAsync(new Uri(ThirdVideo));

            MediaClip mediaClip1 = await MediaClip.CreateFromFileAsync(VideoFile1);

            MediaClip mediaClip2 = await MediaClip.CreateFromFileAsync(VideoFile2);

            MediaClip mediaClip3 = await MediaClip.CreateFromFileAsync(VideoFile3);

            TransitionEffectParameter transitionEffectParameter1 = new TransitionEffectParameter();
            TransitionEffectParameter transitionEffectParameter2 = new TransitionEffectParameter();
            TransitionEffectParameter transitionEffectParameter3 = new TransitionEffectParameter();

            transitionEffectParameter1.SetStartEffect(TransitionEffectType.TRANSITION_NONE, 0);
            transitionEffectParameter1.SetEndEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter1.SetVideoDuration((float)mediaClip1.OriginalDuration.TotalSeconds);

            transitionEffectParameter2.SetStartEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter2.SetEndEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter2.SetVideoDuration((float)mediaClip2.OriginalDuration.TotalSeconds);

            transitionEffectParameter3.SetStartEffect(CurrentEffect.EffectType, 1);
            transitionEffectParameter3.SetEndEffect(TransitionEffectType.TRANSITION_NONE, 0);
            transitionEffectParameter3.SetVideoDuration((float)mediaClip3.OriginalDuration.TotalSeconds);

            PropertySet configuration1 = new PropertySet();

            configuration1.Add("TransitionEffectParameter", transitionEffectParameter1);
            mediaClip1.VideoEffectDefinitions.Add(new VideoEffectDefinition("TransitionEffectTransform.TransitionEffect", configuration1));

            PropertySet configuration2 = new PropertySet();

            configuration2.Add("TransitionEffectParameter", transitionEffectParameter2);
            mediaClip2.VideoEffectDefinitions.Add(new VideoEffectDefinition("TransitionEffectTransform.TransitionEffect", configuration2));

            PropertySet configuration3 = new PropertySet();

            configuration3.Add("TransitionEffectParameter", transitionEffectParameter3);
            mediaClip3.VideoEffectDefinitions.Add(new VideoEffectDefinition("TransitionEffectTransform.TransitionEffect", configuration3));

            comp.Clips.Add(mediaClip1);
            comp.Clips.Add(mediaClip2);
            comp.Clips.Add(mediaClip3);

            Video.SetMediaStreamSource(comp.GeneratePreviewMediaStreamSource(320, 240));
        }