private void FFmpegEngine_CutCompleted(ProgressData progressData)
        {
            conversionOptions.Encoder         = encoder;
            conversionOptions.Encoder.Quality = (Quality)currentPreview++;
            ffmpegEngine.Convert(mediaFile, $"temp\\preview_{currentPreview}.mkv", conversionOptions);
            textBlockPreviewBuildProgress.Text = $"Creating preview ({currentPreview}/{PREVIEW_COUNT})";

            ffmpegEngine.ConversionCompleted -= FFmpegEngine_CutCompleted;
            ffmpegEngine.ConversionCompleted += FFmpegEngine_ConversionCompleted;
            ffmpegEngine.ProgressChanged     += FFmpegEngine_ProgressChanged;
        }
 private void FFmpegEngine_ConversionCompleted()
 {
     if (currentPreview < PREVIEW_COUNT)
     {
         conversionOptions.Encoder.Quality = (Quality)currentPreview++;
         ffmpegEngine.Convert(mediaFile, $"temp\\preview_{currentPreview - 1}.mkv", conversionOptions);
         textBlockPreviewBuildProgress.Text = $"Creating preview ({currentPreview}/{PREVIEW_COUNT})";
     }
     else
     {
         DoubleAnimation progressAnimation = new DoubleAnimation(100, TimeSpan.FromSeconds(0.5));
         progressAnimation.Completed += ProgressAnimation_Completed;
         progressBarPreview.BeginAnimation(ProgressBar.ValueProperty, progressAnimation);
     }
 }
 private void FFmpegEngine_ConversionCompleted(ProgressData progressData)
 {
     if (currentPreview < PREVIEW_COUNT)
     {
         string quality = comboBoxQuality.Items[currentPreview].ToString();
         conversionOptions.Crf       = MainWindow.GetCRFFromQuality(quality, encoder);
         conversionOptions.SkipAudio = true;
         ffmpegEngine.Convert(mediaFile, $"temp\\preview_{currentPreview}.mkv", conversionOptions);
         currentPreview++;
         textBlockPreviewTimespan.Text = $"Creating preview ({currentPreview}/{PREVIEW_COUNT})";
     }
     else
     {
         DoubleAnimation progressAnimation = new DoubleAnimation(100, TimeSpan.FromSeconds(0.5));
         progressAnimation.Completed += ProgressAnimation_Completed;
         progressBarPreview.BeginAnimation(ProgressBar.ValueProperty, progressAnimation);
     }
 }
Exemplo n.º 4
0
        private async void ButtonConvert_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxDestination.Text.EndsWith("mp4") && mediaInfo.AudioCodec.ToLower() == "opus")
            {
                MessageBox.Show("Opus audio in mp4 container is currently unsupported.\nEither use aac audio or mkv container.", "FF Video Converter");
                return;
            }

            textBlockProgress.Text = "Starting conversion process...";

            ffmpegEngine = new FFmpegEngine();
            ffmpegEngine.ProgressChanged     += UpdateProgress;
            ffmpegEngine.ConversionCompleted += ConversionCompleted;
            Encoder           selectedEncoder   = comboBoxEncoder.SelectedIndex == 0 ? Encoder.H264 : Encoder.H265;
            ConversionOptions conversionOptions = new ConversionOptions(selectedEncoder, (byte)comboBoxPreset.SelectedIndex, GetCRFFromQuality(comboBoxQuality.Text, selectedEncoder));

            if (checkBoxCrop.IsChecked == true)
            {
                conversionOptions.CropData = new CropData((short)integerTextBoxCropLeft.Value, (short)integerTextBoxCropTop.Value, (short)integerTextBoxCropRight.Value, (short)integerTextBoxCropBottom.Value);
            }
            else if (comboBoxResolution.SelectedIndex != 0)
            {
                conversionOptions.Resolution = GetResolutionFromString(comboBoxResolution.Text);
            }
            if (comboBoxFramerate.SelectedIndex != 0)
            {
                conversionOptions.Framerate = Convert.ToByte(comboBoxFramerate.SelectedItem);
            }
            outputFps = comboBoxFramerate.SelectedIndex == 0 ? Convert.ToSingle(mediaInfo.Framerate) : Convert.ToSingle(comboBoxFramerate.SelectedItem);

            if (checkBoxCut.IsChecked == true)
            {
                if (!TimeSpan.TryParse(textBoxStart.Text, out TimeSpan start))
                {
                    MessageBox.Show("Enter a valid start time", "FF Video Converter");
                    return;
                }
                if (!TimeSpan.TryParse(textBoxEnd.Text, out TimeSpan end))
                {
                    MessageBox.Show("Enter a valid end time", "FF Video Converter");
                    return;
                }
                if (checkBoxFastCut.IsChecked == true)
                {
                    start = start.Add(TimeSpan.FromSeconds(0.2));
                    ffmpegEngine.FastCut(mediaInfo.Source, textBoxDestination.Text, start.ToString(@"hh\:mm\:ss\.ff"), textBoxEnd.Text);
                    currentOutputPath = textBoxDestination.Text;
                    return;
                }
                else
                {
                    conversionOptions.Start = start;
                    conversionOptions.End   = end;
                }
            }

            ffmpegEngine.Convert(mediaInfo, textBoxDestination.Text, conversionOptions);

            currentOutputPath           = textBoxDestination.Text;
            buttonPauseResume.IsEnabled = true;
            buttonCancel.IsEnabled      = true;
            buttonConvert.IsEnabled     = false;
            buttonPreview.IsEnabled     = false;
            buttonOpenFile.IsEnabled    = false;
            buttonOpenStream.IsEnabled  = false;
            checkBoxCrop.IsEnabled      = false;
            checkBoxCut.IsEnabled       = false;
            await mediaElementInput.Pause();

            buttonPlayPause.Content     = " ▶️";
            gridSourceMedia.IsEnabled   = false;
            buttonOpenOutput.Visibility = Visibility.Hidden;
            Storyboard storyboard = FindResource("ProgressAnimationIn") as Storyboard;

            storyboard.Begin();
            TaskbarItemInfo.ProgressState = TaskbarItemProgressState.Normal;
        }