Exemplo n.º 1
0
        public static void ConfirmQuality(QualityOption qualityOption)
        {
            int index = 1;

            switch (qualityOption)
            {
            case QualityOption.High:
                index = 5;
                break;

            case QualityOption.Medium:
                index = 3;
                break;

            case QualityOption.Low:
                index = 1;
                break;
            }
            QualitySettings.SetQualityLevel(index);
        }
Exemplo n.º 2
0
            public void run(bool to1dir, bool allFiles, List <OutputFileObj> videos, List <OutputFileObj> others, MainWindow window,
                            CodecOption codec, AudioOption audioOp, ResolutionOption res, QualityOption quality, VideoTypeOption typeOp)
            {
                Console.WriteLine(
                    "Running Configurartion:" +
                    "\n  Codec: " + Enum.GetName(typeof(CodecOption), codec) +
                    "\n  Audio Codec: " + Enum.GetName(typeof(AudioOption), audioOp) +
                    "\n  Video Resolution: " + Enum.GetName(typeof(ResolutionOption), res) +
                    "\n Video Type: " + Enum.GetName(typeof(VideoTypeOption), typeOp));

                int totalVideos = videos.Count * 100;

                window.Dispatcher.Invoke(() => window.allVideoFilesProgressBar.Maximum = 100);

                Converter = new FFMpegConverter();
                int        index   = 0;
                MainWindow _window = window;
                Thread     _t      = Thread.CurrentThread;

                Converter.ConvertProgress += (sender, e) =>
                {
                    try
                    {
                        _window.Dispatcher.Invoke(() =>
                        {
                            Console.WriteLine("Processed: " + e.Processed);
                            _window.currFileProgressBar.Value = (float)e.Processed.TotalSeconds / (float)e.TotalDuration.TotalSeconds * 100;
                            Console.WriteLine((float)e.Processed.TotalSeconds / (float)e.TotalDuration.TotalSeconds * 100);
                            Console.WriteLine(_window.currFileProgressBar.Value);
                            _window.allVideoFilesProgressBar.Value = 100 / (float)videos.Count * index +
                                                                     (float)e.Processed.TotalSeconds / (float)e.TotalDuration.TotalSeconds * 100 / (float)videos.Count;
                        });
                    }
                    catch (TaskCanceledException tce)
                    {
                        _t.Abort();
                    }
                };
                foreach (OutputFileObj video in videos)
                {
                    var videoMedia = new NReco.VideoInfo.FFProbe().GetMediaInfo(video.Path);
                    window.Dispatcher.Invoke(() =>
                    {
                        window.currFileProgressBar.Maximum = 100;
                    });

                    if (typeOp != VideoTypeOption.copy)
                    {
                        video.OutPath = System.IO.Path.ChangeExtension(video.OutPath, "." + Enum.GetName(typeof(VideoTypeOption), typeOp));
                    }

                    if (audioOp == AudioOption.flac &&
                        System.IO.Path.GetExtension(video.Path).ToLower() ==
                        "." + Enum.GetName(typeof(VideoTypeOption), VideoTypeOption.mp4).ToLower())
                    {
                        audioOp = AudioOption.copy;
                    }

                    string scaleString =
                        res == ResolutionOption.copy ? "" :
                        res == ResolutionOption._1080 ? "-vf scale=-2:1080" :
                        res == ResolutionOption._720 ? "-vf scale=-2:720" :
                        res == ResolutionOption._480 ? "-vf scale=-2:480" :
                        res == ResolutionOption._240 ? "-vf scale=-2:240" : "";

                    Func <string> getCopyCodec = () =>
                    {
                        string videoCodec = videoMedia.Streams.ToList().Find(
                            (item) => item.CodecType.ToLower() == "video").CodecName;
                        if (videoCodec.Contains("h264"))
                        {
                            return("libx264");
                        }
                        if (videoCodec.Contains("hevc"))
                        {
                            return("libx265");
                        }
                        return("libx264");
                    };

                    string codecString =
                        codec == CodecOption.copy ? getCopyCodec() :
                        codec == CodecOption.h264 ? "libx264" :
                        codec == CodecOption.HEVC ? "libx265" : getCopyCodec();

                    string Command = string.Format(
                        "-c:v {3} {0} -crf {1} -c:a {2} -stats -y",
                        scaleString, (int)quality,
                        Enum.GetName(typeof(AudioOption), (int)audioOp), codecString);

                    Console.WriteLine("Input Path: '" + video.Path + "'");
                    Console.WriteLine("Output Path: '" + video.OutPath + "'");

                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(video.OutPath));
                    Console.WriteLine("Created direcotory: '" + System.IO.Path.GetDirectoryName(video.OutPath) + "'");
                    Console.WriteLine("Running Command: '" + Command + "'");
                    Converter.ConvertMedia(video.Path, null, video.OutPath, null, new ConvertSettings()
                    {
                        CustomOutputArgs = Command
                    });
                    Console.WriteLine("Video converted");

                    index++;
                }
            }
Exemplo n.º 3
0
        private void RunRenderButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(inputDirTextBox.Text))
            {
                inputDirTextBox.Background = new SolidColorBrush(Colors.Red);
                return;
            }
            else
            {
                inputDirTextBox.Background = new SolidColorBrush(Colors.White);
            }

            if (string.IsNullOrWhiteSpace(outputDirTextBox.Text))
            {
                outputDirTextBox.Background = new SolidColorBrush(Colors.Red);
                return;
            }
            else
            {
                outputDirTextBox.Background = new SolidColorBrush(Colors.White);
            }

            DirObj dir = new DirObj
            {
                Path = inputDirTextBox.Text
            };

            bool dirError = !dir.renderFolder();

            if (dirError)
            {
                Console.WriteLine("We wasn't able to render folder");
                return;
            }

            dir.allFiles.ForEach(file => Console.WriteLine("Path: \"" + file.Path + "\""));
            List <OutputFileObj> videoFiles = new List <OutputFileObj>();
            List <OutputFileObj> otherFiles = new List <OutputFileObj>();

            Func <FileObj, ObservableCollection <CheckableItem>, CheckableItem> findCorrespondingItem = null;

            findCorrespondingItem = (file, items) => {
                foreach (CheckableItem item in items)
                {
                    if (item.Path == file.Path)
                    {
                        return(item);
                    }
                    var foundItem = findCorrespondingItem(file, item.Children);
                    if (foundItem != null)
                    {
                        return(foundItem);
                    }
                }
                return(null);
            };

            foreach (FileObj file in dir.allFiles)
            {
                if (findCorrespondingItem(file, items).IsChecked)
                {
                    string relPath = new Uri(inputDirTextBox.Text).MakeRelativeUri(new Uri(file.Path)).ToString();
                    string outPath = System.IO.Path.Combine(outputDirTextBox.Text, relPath);
                    outPath = Uri.UnescapeDataString(outPath);

                    if (videoExtensions.Contains(System.IO.Path.GetExtension(file.Name)))
                    {
                        videoFiles.Add(new OutputFileObj(file)
                        {
                            OutPath = outPath
                        });
                    }
                    else
                    {
                        otherFiles.Add(new OutputFileObj(file)
                        {
                            OutPath = outPath
                        });
                    }
                }
            }

            bool to1Dir       = videoTo1Dir.IsChecked == true;
            bool CopyAllFiles = copyAllFiles.IsChecked == true;

            CodecOption      codec      = (CodecOption)videoCodecCombo.SelectedItem;
            AudioOption      audioCodec = (AudioOption)audioCodecCombo.SelectedItem;
            ResolutionOption res        = Enum.GetValues(typeof(ResolutionOption)).Cast <ResolutionOption>().ToArray()[videoResolutionCombo.SelectedIndex];
            QualityOption    quality    = (QualityOption)videoQualityCombo.SelectedItem;
            VideoTypeOption  type       = (VideoTypeOption)videoTypeCombo.SelectedItem;

            runner = new runnerThread();

            Thread t = new Thread(() => { runner.run(
                                              to1Dir,
                                              CopyAllFiles,
                                              videoFiles,
                                              otherFiles,
                                              this,
                                              codec,
                                              audioCodec,
                                              res,
                                              quality,
                                              type); });

            t.Start();
        }