private async void ButtonCreatePreview_Click(object sender, RoutedEventArgs e)
        {
            if (buttonCreatePreview.Content.ToString() == "Create preview")
            {
                await mediaElementOriginal.Pause();

                blurEffect.Radius             = 10;
                buttonPlayPause.IsEnabled     = false;
                sliderPreview.Visibility      = Visibility.Hidden;
                buttonCreatePreview.Content   = "Cancel";
                textBlockPreviewTimespan.Text = "Cutting original...";
                Storyboard storyboard = FindResource("ProgressAnimationIn") as Storyboard;
                storyboard.Begin();
                Directory.CreateDirectory(Environment.CurrentDirectory + "\\temp");

                double keyFrameBefore = (await mediaFile.GetNearestBeforeAndAfterKeyFrames(start.TotalSeconds)).before;
                start             = TimeSpan.FromSeconds(keyFrameBefore);
                end               = start.Add(TimeSpan.FromSeconds(4));
                conversionOptions = new ConversionOptions(encoder, 6, 16)
                {
                    Start = start,
                    End   = end
                };
                ffmpegEngine.FastCut(mediaFile.Source, Environment.CurrentDirectory + "\\temp\\source.mkv", start.Add(TimeSpan.FromSeconds(0.1)).ToString(@"hh\:mm\:ss\.ff"), end.ToString(@"hh\:mm\:ss\.ff"));
            }
            else
            {
                ButtonClose_Click(null, null);
            }
        }
Exemplo n.º 2
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;
        }