Beispiel #1
0
        private void btnPre_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtVideoUrl.Text))
                {
                    MessageBox.Show("You Must Set a Video!", "Warning", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                container.Clear();
                var ran = new Random();
                a = DateTime.Now.ToString("MM-dd-hh-mm");
                File.WriteAllText(Path.GetTempPath() + "Script" + a + ".avs", Builder.Build(false));

                SaveFileDialog s = new SaveFileDialog
                {
                    Filter     = "Video Files(*.mp4/*.mkv)|*.mp4;*.mkv",
                    DefaultExt = '.' + cbFormat.Text.ToLower()
                };
                if (s.ShowDialog() == false)
                {
                    MessageBox.Show("You must choose a path.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                // encoder.ExtractAudio(new VideoInfo(new FileInfo(Builder.GetMainVideo())),new FileInfo(Path.GetTempPath() + "Sound" + a + ".mp3"))

                container.Add(new InputArgument(new string[] { Builder.GetMainVideo(), Path.GetTempPath() + "Script" + a + ".avs" }));
                container.Add(new ThreadsArgument(true));
                container.Add(new LogArgument(Path.GetTempPath() + @"log" + a + ".txt"));

                string u = cbEncoder.Text.ToLower();
                switch (u)
                {
                case "libx264":
                {
                    container.Add(new VideoCodecArgument(VideoCodec.LibX264));
                    break;
                }

                case "libx265":
                {
                    container.Add(new BestCodecArgument(true));
                    break;
                }

                case "vp9":
                {
                    container.Add(new BestCodecArgument(false));
                    break;
                }
                }
                u = cbSpeed.Text.Replace(" ", "");

                SpeedArgument sa = new SpeedArgument(Speed.Medium);
                switch (u)
                {
                case "VerySlow":
                {
                    sa = new SpeedArgument(Speed.VerySlow);
                    break;
                }

                case "Slower":
                {
                    sa = new SpeedArgument(Speed.Slower);
                    break;
                }

                case "Slow":
                {
                    sa = new SpeedArgument(Speed.Slow);
                    break;
                }

                case "Medium":
                {
                    sa = new SpeedArgument(Speed.Medium);
                    break;
                }

                case "Fast":
                {
                    sa = new SpeedArgument(Speed.Fast);
                    break;
                }

                case "Faster":
                {
                    sa = new SpeedArgument(Speed.Faster);
                    break;
                }

                case "VeryFast":
                {
                    sa = new SpeedArgument(Speed.VeryFast);
                    break;
                }

                case "SuperFast":
                {
                    sa = new SpeedArgument(Speed.SuperFast);
                    break;
                }

                case "UltraFast":
                {
                    sa = new SpeedArgument(Speed.UltraFast);
                    break;
                }
                }
                container.Add(sa);
                AudioCodecArgument ac = new AudioCodecArgument(AudioCodec.Aac);
                switch (cbAudioCodec.Text.Replace(" ", "").ToLower())
                {
                case "aac":
                {
                    ac = new AudioCodecArgument(AudioCodec.Aac);
                    break;
                }

                default:
                {
                    ac = new AudioCodecArgument(AudioCodec.LibVorbis);
                    break;
                }
                }
                container.Add(ac);
                container.Add(new MapArgument(new string[] { "1:v:0", "0:a:0" }));
                //  if (!string.IsNullOrEmpty(NumberTextBox.Text))
                //  {
                //     container.Add(new QualityArgument(double.Parse(NumberTextBox.Text)));
                // }
                container.Add(new OutputArgument(s.FileName.Trim()));
                container.Add(new OverrideArgument());
                V = s.FileName;
                Task t = Task.Run(() =>
                {
                    try
                    {
                        encoder.Convert(container);
                    }
                    catch (FFMpegCore.FFMPEG.Exceptions.FFMpegException er)
                    {
                        MessageBox.Show(er.Message + "\n" + er.Source + "\n" + er.Type, er.InnerException?.Message, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                    }
                });

                tt.Interval = TimeSpan.FromMilliseconds(400);
                tt.Tick    += Tt_Tick;
                tt.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }