Esempio n. 1
0
        private async void AcceptButton_Click(object sender, RoutedEventArgs e)
        {
            Pause();

            progressText.Text        = "0";
            progressText.Visibility  = Visibility.Visible;
            completedText.Visibility = Visibility.Collapsed;

            overlayGrid.Visibility = Visibility.Visible;
            OpenProcessingOverlay.Begin();

            var props   = await(_model.StorageFile as StorageFile).Properties.GetVideoPropertiesAsync();
            var profile = MediaTranscoding.CreateVideoEncodingProfileFromProps(true, props);

            if (_tempFile == null)
            {
                _tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(Path.ChangeExtension(_model.StorageFile.Name, ".mp4"), CreationCollisionOption.GenerateUniqueName);
            }

            await SaveComposition();

            _renderTask           = _model.Composition.RenderToFileAsync(_tempFile, MediaTrimmingPreference.Precise, profile);
            _renderTask.Progress  = OnProgress;
            _renderTask.Completed = OnCompleted;
        }
Esempio n. 2
0
        private async Task <IStorageFile> TryTranscodeMediaAsync(IStorageFile file, MediaType type, IProgress <double?> progress, CancellationToken token)
        {
            var         success          = false;
            StorageFile tempFile         = null;
            var         channelViewModel = (ChannelViewModel)DataContext;

            try
            {
                switch (type)
                {
                case MediaType.Audio:
                    tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(Path.ChangeExtension(file.Name, ".mp3"), CreationCollisionOption.GenerateUniqueName);

                    success = await MediaTranscoding.TryTranscodeAudioAsync(file, tempFile, channelViewModel.HasNitro, progress, token);

                    break;

                case MediaType.Video:
                    tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(Path.ChangeExtension(file.Name, ".mp4"), CreationCollisionOption.GenerateUniqueName);

                    success = await MediaTranscoding.TryTranscodeVideoAsync(file, tempFile, progress, token);

                    break;

                case MediaType.Photo:
                    tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(file.Name, CreationCollisionOption.GenerateUniqueName);

                    success = await MediaTranscoding.TryTranscodePhotoAsync(file, tempFile, progress, token);

                    break;

                default:
                    return(file);
                }
            }
            catch (Exception ex)
            {
                if (!(ex is TaskCanceledException))
                {
                    // TODO: port
                    // HockeyClient.Current.TrackException(ex, new Dictionary<string, string> { ["type"] = "UploadFailure" });
                }
            }

            if (success)
            {
                return(tempFile);
            }

            if (tempFile != null)
            {
                await tempFile.DeleteAsync();
            }
            return(null);
        }
Esempio n. 3
0
        private async void AcceptButton_Click(object sender, RoutedEventArgs e)
        {
            Pause();

            progressText.Text        = "0";
            progressText.Visibility  = Visibility.Visible;
            completedText.Visibility = Visibility.Collapsed;

            overlayGrid.Visibility = Visibility.Visible;
            OpenProcessingOverlay.Begin();

            Analytics.TrackEvent("VideoEditor_ExportStarted");

            await SaveComposition();

            var transcoder = new MediaTranscoder()
            {
                VideoProcessingAlgorithm = App.RoamingSettings.Read(Constants.VIDEO_PROCESSING, MediaVideoProcessingAlgorithm.Default)
            };
            var props   = await(_model.StorageFile as StorageFile).Properties.GetVideoPropertiesAsync();
            var profile = MediaTranscoding.CreateVideoEncodingProfileFromProps(props);
            var source  = _model.Composition.GenerateMediaStreamSource();

            if (_tempFile == null)
            {
                _tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(Path.ChangeExtension(_model.StorageFile.Name, ".mp4"), CreationCollisionOption.GenerateUniqueName);
            }

            if (_tempStream != null)
            {
                _tempStream.Dispose();
            }

            _tempStream = await _tempFile.OpenAsync(FileAccessMode.ReadWrite);

            var result = await transcoder.PrepareMediaStreamSourceTranscodeAsync(source, _tempStream, profile);

            if (!result.CanTranscode)
            {
                await UIUtilities.ShowErrorDialogAsync("Unable to Transcode!", $"Returned {result.FailureReason}");

                return;
            }

            _renderTask            = result.TranscodeAsync();
            _renderTask.Progress   = OnProgress;
            _renderTask.Completed += OnCompleted;
        }