Inheritance: IMediaTranscoder
        async Task CS_WP_MT_Basic(EffectType effectType)
        {
            StorageFile source = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Input/Car.mp4"));
            StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("CS_WP_MT_Basic" + effectType + ".mp4", CreationCollisionOption.ReplaceExisting);

            var definition = await Utils.CreateEffectDefinitionAsync(effectType);

            var transcoder = new MediaTranscoder();
            transcoder.AddVideoEffect(definition.ActivatableClassId, true, definition.Properties);

            PrepareTranscodeResult transcode = await transcoder.PrepareFileTranscodeAsync(source, destination, MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga));
            await transcode.TranscodeAsync();
        }
Esempio n. 2
0
        public static async void VideoConvert(StorageFile file,MediaEncodingProfile mediaProfile,VideoItem caller)
        {
            try
            {
                var outFolder = await Settings.GetOutputFolder();
                StorageFile audioFile;
                if (Settings.GetBoolSettingValueForKey(Settings.PossibleSettingsBool.SETTING_AUTO_RENAME) && caller.tagTitle != "")
                    audioFile = await outFolder.CreateFileAsync(caller.tagTitle+"."+mediaProfile.Container.Subtype.ToLower(), CreationCollisionOption.ReplaceExisting);
                else
                    audioFile = await outFolder.CreateFileAsync(file.Name.Replace("mp4", mediaProfile.Container.Subtype.ToLower()), CreationCollisionOption.ReplaceExisting);

                MediaTranscoder transcoder = new MediaTranscoder();

                if (caller.trimEnd != null)
                    transcoder.TrimStartTime = new TimeSpan(0, 0, 0, (int)caller.trimStart, 0);
                if (caller.trimEnd != null)
                    transcoder.TrimStopTime = new TimeSpan(0, 0, 0, (int)caller.trimEnd, 0);

                var result = await transcoder.PrepareFileTranscodeAsync(file, audioFile, mediaProfile);
               
                if(result.CanTranscode)
                {
                    var transcodeOp = result.TranscodeAsync();
                    transcodeOp.Progress +=
                        async (IAsyncActionWithProgress<double> asyncInfo, double percent) =>
                        {
                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                caller.SetConvProgress((int)percent);
                            });
                        };
                    transcodeOp.Completed +=
                        (IAsyncActionWithProgress<double> asyncInfo, AsyncStatus status) =>
                        {
                            QueueManager.Instance.ConvCompleted(caller.id);                     
                            Utils.TryToRemoveFile(5, file);
                            TagProcessing.SetTagsSharp(new TagsPackage(caller.tagArtist, caller.tagAlbum, caller.tagTitle,caller.AlbumCoverPath), audioFile);
                        };
                }            
            }
            catch (Exception exc)
            {
                Debug.WriteLine("Conversion : " + exc.Message);
            }
        }
Esempio n. 3
0
        private async void Transcode_Click(object sender, RoutedEventArgs e)
        {
            StartMediaTranscoder.IsEnabled = false;

            StorageFile source = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Car.mp4"));
            StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("VideoEffectsTestApp.MediaTranscoder.mp4", CreationCollisionOption.ReplaceExisting);

            var encodingProfile = await MediaEncodingProfile.CreateFromFileAsync(source);

            var definition = await CreateEffectDefinitionAsync(encodingProfile.Video);

            var transcoder = new MediaTranscoder();
            transcoder.AddVideoEffect(definition.ActivatableClassId, true, definition.Properties);

            PrepareTranscodeResult transcode = await transcoder.PrepareFileTranscodeAsync(source, destination, MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga));
            await transcode.TranscodeAsync();

            StartMediaTranscoder.IsEnabled = true;
        }
        public async Task CS_WP_MC_PreviewTranscode(EffectType effectType)
        {
            StorageFile source = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Input/Car.mp4"));
            StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("CS_WP_MC_PreviewTranscode_" + effectType + ".mp4", CreationCollisionOption.ReplaceExisting);

            var definition = await Utils.CreateEffectDefinitionAsync(effectType);

            var clip = await MediaClip.CreateFromFileAsync(source);
            clip.VideoEffectDefinitions.Add(definition);

            var composition = new MediaComposition();
            composition.Clips.Add(clip);

            MediaStreamSource sourceStreamSource = composition.GenerateMediaStreamSource();
            using (IRandomAccessStream destinationStream = await destination.OpenAsync(FileAccessMode.ReadWrite))
            {
                var transcoder = new MediaTranscoder();
                var transcode = await transcoder.PrepareMediaStreamSourceTranscodeAsync(sourceStreamSource, destinationStream, MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga));
                await transcode.TranscodeAsync();
            }
        }
        public async Task CS_WP_MT_LumiaCropSquare()
        {
            StorageFile source = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Input/Car.mp4"));
            StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("CS_W_MT_CropSquare.mp4", CreationCollisionOption.ReplaceExisting);

            // Select the largest centered square area in the input video
            var encodingProfile = await MediaEncodingProfile.CreateFromFileAsync(source);
            uint inputWidth = encodingProfile.Video.Width;
            uint inputHeight = encodingProfile.Video.Height;
            uint outputLength = Math.Min(inputWidth, inputHeight);
            Rect cropArea = new Rect(
                (float)((inputWidth - outputLength) / 2),
                (float)((inputHeight - outputLength) / 2),
                (float)outputLength,
                (float)outputLength
                );
            encodingProfile.Video.Width = outputLength;
            encodingProfile.Video.Height = outputLength;

            var definition = new LumiaEffectDefinition(new FilterChainFactory(() =>
            {
                var filters = new List<IFilter>();
                filters.Add(new CropFilter(cropArea));
                return filters;
            }));
            definition.InputWidth = inputWidth;
            definition.InputHeight = inputHeight;
            definition.OutputWidth = outputLength;
            definition.OutputHeight = outputLength;

            var transcoder = new MediaTranscoder();
            transcoder.AddVideoEffect(definition.ActivatableClassId, true, definition.Properties);

            PrepareTranscodeResult transcode = await transcoder.PrepareFileTranscodeAsync(source, destination, encodingProfile);
            await transcode.TranscodeAsync();
        }
Esempio n. 6
0
        public async Task TranscodeAsync(string sourceFileName, string destinationFileName, uint bitrate, CancellationToken cancellationToken, IProgress<double> progress)
        {
            var transcoder = new MediaTranscoder();
            var sourceFile = await StorageFile.GetFileFromPathAsync(sourceFileName);
            var destinationFolder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(destinationFileName));
            var destinationFile = await destinationFolder.CreateFileAsync(Path.GetFileName(destinationFileName));

            var profile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High);
            profile.Audio.Bitrate = bitrate;

            var preparedTranscodeResult = await transcoder.PrepareFileTranscodeAsync(sourceFile, destinationFile, profile);

            Exception error = null;
            try
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (preparedTranscodeResult.CanTranscode)
                {
                    await preparedTranscodeResult.TranscodeAsync().AsTask(cancellationToken, progress);
                }
                else
                {
                    throw new InvalidOperationException("Reason: " + preparedTranscodeResult.FailureReason);
                }
            }
            catch (Exception ex)
            {
                error = ex;
            }

            if (error != null)
            {
                await destinationFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
                throw error;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            StorageFile source = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Input/Car.mp4"));

            // Select the largest centered square area in the input video
            var inputProfile = await MediaEncodingProfile.CreateFromFileAsync(source);
            uint inputWidth = inputProfile.Video.Width;
            uint inputHeight = inputProfile.Video.Height;
            uint outputLength = Math.Min(inputWidth, inputHeight);
            Rect cropArea = new Rect(
                (float)((inputWidth - outputLength) / 2),
                (float)((inputHeight - outputLength) / 2),
                (float)outputLength,
                (float)outputLength
                );

            // Create the output encoding profile
            var outputProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p);
            outputProfile.Video.Bitrate = inputProfile.Video.Bitrate;
            outputProfile.Video.FrameRate.Numerator = inputProfile.Video.FrameRate.Numerator;
            outputProfile.Video.FrameRate.Denominator = inputProfile.Video.FrameRate.Denominator;
            outputProfile.Video.Width = outputLength;
            outputProfile.Video.Height = outputLength;

            var definition = new LumiaEffectDefinition(new FilterChainFactory(() =>
            {
                var filters = new List<IFilter>();
                filters.Add(new CropFilter(cropArea));
                return filters;
            }));
            definition.InputWidth = inputWidth;
            definition.InputHeight = inputHeight;
            definition.OutputWidth = outputLength;
            definition.OutputHeight = outputLength;

            var clip = await MediaClip.CreateFromFileAsync(source);
            clip.VideoEffectDefinitions.Add(definition);

            var composition = new MediaComposition();
            composition.Clips.Add(clip);

            TextLog.Text = "Encoding using MediaComposition";

            StorageFile destination1 = await KnownFolders.VideosLibrary.CreateFileAsync("Square_MC.mp4", CreationCollisionOption.ReplaceExisting);

            await composition.RenderToFileAsync(destination1, MediaTrimmingPreference.Fast, outputProfile);

            TextLog.Text = "Encoding using MediaTranscoder";

            StorageFile destination2 = await KnownFolders.VideosLibrary.CreateFileAsync("Square_MT.mp4", CreationCollisionOption.ReplaceExisting);

            var transcoder = new MediaTranscoder();
            transcoder.AddVideoEffect(definition.ActivatableClassId, true, definition.Properties);
            var transcode = await transcoder.PrepareFileTranscodeAsync(source, destination2, outputProfile);
            await transcode.TranscodeAsync();

            TextLog.Text = "Starting MediaComposition preview";

            PreviewMC.SetMediaStreamSource(
                composition.GeneratePreviewMediaStreamSource((int)outputLength, (int)outputLength)
                );

            TextLog.Text = "Starting MediaElement preview";

            PreviewME.AddVideoEffect(definition.ActivatableClassId, false, definition.Properties);
            PreviewME.Source = new Uri("ms-appx:///Input/Car.mp4");
            PreviewME.Play();

            TextLog.Text = "Done";
        }
Esempio n. 8
0
        public async void ExtractAudio(string artist, string title, StorageFile videoFile, StorageFile audioFile)
        {
            if (this.transcoder == null)
            {
                this.transcoder = new MediaTranscoder();
                this.encodingProfile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High);
            }

            var preparedTranscodeResult = await this.transcoder.PrepareFileTranscodeAsync(videoFile, audioFile, this.encodingProfile);
            await preparedTranscodeResult.TranscodeAsync();
            await TagStorageFile(artist, title, audioFile);
        }
 private static async void TranscodeFile(StorageFile srcFile, StorageFile destFile, AsyncActionWithProgressCompletedHandler<double> action, AsyncActionProgressHandler<double> progress )
 {
     var profile = MediaEncodingProfile.CreateMp3(AudioEncodingQuality.High);
     var transcoder = new MediaTranscoder();
     var prepareOp = await transcoder.PrepareFileTranscodeAsync(srcFile, destFile, profile);
     if (!prepareOp.CanTranscode) return;
     var transcodeOp = prepareOp.TranscodeAsync();
     transcodeOp.Progress += progress;
     transcodeOp.Completed += action;
 }
        public async Task CS_WP_MC_LumiaCropSquare()
        {
            StorageFile source = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Input/Car.mp4"));
            StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("CS_W_MT_CropSquare.mp4", CreationCollisionOption.ReplaceExisting);

            // Select the largest centered square area in the input video
            var encodingProfile = await MediaEncodingProfile.CreateFromFileAsync(source);
            uint inputWidth = encodingProfile.Video.Width;
            uint inputHeight = encodingProfile.Video.Height;
            uint outputLength = Math.Min(inputWidth, inputHeight);
            Rect cropArea = new Rect(
                (float)((inputWidth - outputLength) / 2),
                (float)((inputHeight - outputLength) / 2),
                (float)outputLength,
                (float)outputLength
                );
            encodingProfile.Video.Width = outputLength;
            encodingProfile.Video.Height = outputLength;

            var definition = new LumiaEffectDefinition(new FilterChainFactory(() =>
            {
                var filters = new List<IFilter>();
                filters.Add(new CropFilter(cropArea));
                return filters;
            }));
            definition.InputWidth = inputWidth;
            definition.InputHeight = inputHeight;
            definition.OutputWidth = outputLength;
            definition.OutputHeight = outputLength;

            var clip = await MediaClip.CreateFromFileAsync(source);
            clip.VideoEffectDefinitions.Add(definition);

            var composition = new MediaComposition();
            composition.Clips.Add(clip);

            MediaStreamSource sourceStreamSource = composition.GenerateMediaStreamSource();
            using (IRandomAccessStream destinationStream = await destination.OpenAsync(FileAccessMode.ReadWrite))
            {
                var transcoder = new MediaTranscoder();
                var transcode = await transcoder.PrepareMediaStreamSourceTranscodeAsync(sourceStreamSource, destinationStream, MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga));
                await transcode.TranscodeAsync();
            }
        }