public PrepareFileTranscodeAsync ( [ source, [ destination, [ profile ) : IAsyncOperation |
||
source | [ | |
destination | [ | |
profile | [ | |
리턴 | IAsyncOperation |
async void TranscodeTrim(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { StopPlayers(); DisableButtons(); GetPresetProfile(ProfileSelect); // Clear messages StatusMessage.Text = ""; _Transcoder.TrimStartTime = _Start; _Transcoder.TrimStopTime = _Stop; try { if (_InputFile != null) { _OutputFile = await KnownFolders.VideosLibrary.CreateFileAsync(_OutputFileName, CreationCollisionOption.GenerateUniqueName); var preparedTranscodeResult = await _Transcoder.PrepareFileTranscodeAsync(_InputFile, _OutputFile, _Profile); if (EnableMrfCrf444.IsChecked.HasValue && (bool)EnableMrfCrf444.IsChecked) { _Transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.MrfCrf444; } else { _Transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default; } if (preparedTranscodeResult.CanTranscode) { SetCancelButton(true); var progress = new Progress <double>(TranscodeProgress); await preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, progress); TranscodeComplete(); } else { TranscodeFailure(preparedTranscodeResult.FailureReason); } } } catch (TaskCanceledException) { OutputText(""); TranscodeError("Transcode Canceled"); } catch (Exception exception) { TranscodeError(exception.Message); } }
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(); }
async void TranscodeCustom(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { StopPlayers(); DisableButtons(); GetCustomProfile(); // Clear messages StatusMessage.Text = ""; try { if (_InputFile != null && _Profile != null && _OutputFile != null) { var preparedTranscodeResult = await _Transcoder.PrepareFileTranscodeAsync(_InputFile, _OutputFile, _Profile); if (EnableMrfCrf444.IsChecked.HasValue && (bool)EnableMrfCrf444.IsChecked) { _Transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.MrfCrf444; } else { _Transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default; } if (preparedTranscodeResult.CanTranscode) { SetCancelButton(true); var progress = new Progress <double>(TranscodeProgress); await preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, progress); TranscodeComplete(); } else { TranscodeFailure(preparedTranscodeResult.FailureReason); } } } catch (TaskCanceledException) { OutputText(""); TranscodeError("Transcode Canceled"); } catch (Exception exception) { TranscodeError(exception.Message); } }
private async void Run() { try { var files = await Windows.Storage.KnownFolders.VideosLibrary.GetFilesAsync( Windows.Storage.Search.CommonFileQuery.OrderBySearchRank, 0, 10); var pics = files.Where(f => { return(f.Name.EndsWith("wmv")); }); foreach (var pic in pics) { _OutputFile = await KnownFolders.VideosLibrary.CreateFileAsync("out.mp4", CreationCollisionOption.GenerateUniqueName); _Profile = MediaEncodingProfile.CreateAvi(VideoEncodingQuality.Vga); var preparedTranscodeResult = await _Transcoder.PrepareFileTranscodeAsync(pic, _OutputFile, _Profile); _Transcoder.VideoProcessingAlgorithm = MediaVideoProcessingAlgorithm.Default; if (preparedTranscodeResult.CanTranscode) { var progress = new Progress <double>(TranscodeProgress); _cts = new CancellationTokenSource(); await preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, progress); TranscodeComplete(); } else { TranscodeFailure(preparedTranscodeResult.FailureReason); } } } catch (TaskCanceledException) { TranscodeError("Transcode Canceled"); } catch (Exception exception) { Console.WriteLine("error"); Console.WriteLine(exception); TranscodeError(exception.Message); } }
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); } }
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 <ExtractionResult> ExtractAudio(StorageFile videoFile, StorageFolder outputFolder) { var outputFile = await outputFolder.CreateFileAsync(videoFile.DisplayName + Mp3Extension, CreationCollisionOption.GenerateUniqueName); var prepareOp = await _transcoder.PrepareFileTranscodeAsync(videoFile, outputFile, _mediaEncodingProfile); if (prepareOp.CanTranscode) { await prepareOp.TranscodeAsync(); return(ExtractionResult.Success); } if (prepareOp.FailureReason == TranscodeFailureReason.CodecNotFound) { return(ExtractionResult.CodecNotFound); } return(ExtractionResult.Failed); }
async void TranscodeCustom(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { StopPlayers(); DisableButtons(); GetCustomProfile(); // Clear messages StatusMessage.Text = ""; try { if (_InputFile != null && _Profile != null) { _OutputFile = await KnownFolders.VideosLibrary.CreateFileAsync(_OutputFileName, CreationCollisionOption.GenerateUniqueName); var preparedTranscodeResult = await _Transcoder.PrepareFileTranscodeAsync(_InputFile, _OutputFile, _Profile); if (preparedTranscodeResult.CanTranscode) { SetCancelButton(true); var progress = new Progress <double>(TranscodeProgress); await preparedTranscodeResult.TranscodeAsync().AsTask(_cts.Token, progress); TranscodeComplete(); } else { TranscodeFailure(preparedTranscodeResult.FailureReason); } } } catch (TaskCanceledException) { OutputText(""); TranscodeError("Transcode Canceled"); } catch (Exception exception) { TranscodeError(exception.Message); } }
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(); }
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; } }
/// <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"; }
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; }
static void Main(string[] args) { GetProfile(); Task <IAsyncOperation <StorageFile> > task2 = new Task <IAsyncOperation <StorageFile> >(() => { return(StorageFile.GetFileFromPathAsync(args[0])); }); task2.RunSynchronously(); StorageFile _InputFile = task2.Result.GetResults(); // This is going to be nasty. // Output can only be to known directories. var openPicker = new Windows.Storage.Pickers.FolderPicker(); //var task = Task.Factory.StartNew<IAsyncOperation<StorageFolder>>(() => openPicker.PickSingleFolderAsync()); //task.Wait(); //var res = task.Result.GetResults(); var res = KnownFolders.MusicLibrary; // var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(res); var task3 = Task.Factory.StartNew <IAsyncOperation <StorageFile> >(() => res.CreateFileAsync(args[1], CreationCollisionOption.GenerateUniqueName)); task3.Wait(); _OutputFile = task3.Result.GetResults(); var task4 = Task.Factory.StartNew <IAsyncOperation <PrepareTranscodeResult> >(() => _Transcoder.PrepareFileTranscodeAsync(_InputFile, _OutputFile, _Profile)); task4.Wait(); var r4 = task4.Result.GetResults(); if (r4.CanTranscode) { var task5 = Task.Factory.StartNew(() => r4.TranscodeAsync()); task5.Wait(); } }