예제 #1
0
        public static async Task ExecuteSoftRemoval(String sourceVideoFileName, String outputFileName)
        {
            using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath,
                                                                     $"-i \"{sourceVideoFileName}\" -map 0 -map -0:s -codec copy \"{outputFileName}\""))
            {
                App.LogViewModel.RedirectedProcess = process;

                await process.StartAsync();
            }
        }
예제 #2
0
        public static async Task ExecuteFormatConversion(String sourceFileName, String outputFileName, Boolean noReEncode)
        {
            String commonParameters = $"-y ";

            if (noReEncode)
            {
                commonParameters += "-c copy ";
            }

            // Pass 1
            StringBuilder sb = new StringBuilder();

            sb.Append($"-i \"{sourceFileName}\" ");
            sb.Append(commonParameters);
            sb.Append($"\"{outputFileName}\"");

            using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath, sb.ToString()))
            {
                App.LogViewModel.RedirectedProcess = process;

                await process.StartAsync();
            }
        }
        public static async Task ExecuteConversion(String sourceVideoFileName, String sourceSubtitleFileName, String outputFileName, Boolean is60FPS)
        {
            String outputDirectory     = Path.GetDirectoryName(outputFileName);
            String tempFileName        = Path.Combine(outputDirectory, Path.GetRandomFileName());
            String outputFileExtension = Path.GetExtension(outputFileName);
            String commonParameters    = $"-vcodec libx264 -preset veryslow -profile:v high -level:v 4.1 -pix_fmt yuv420p -b:v 2000k -acodec aac -strict -2 -ac 2 -ab 192k -ar 44100 -f {outputFileExtension.Remove(0, 1)} -y ";

            // Pass 1
            StringBuilder sb = new StringBuilder();

            sb.Append($"-i \"{sourceVideoFileName}\" ");

            if (!String.IsNullOrEmpty(sourceSubtitleFileName))
            {
                // Subtitle filename must be escaped twice
                sb.Append($"-vf subtitles=\"{sourceSubtitleFileName.Replace(@"\", @"\\\\").Replace(":", @"\\:")}\" ");
            }

            sb.Append(commonParameters);

            if (is60FPS)
            {
                sb.Append("-r 60 ");
            }

            sb.Append("-pass 1 ");
            sb.Append($"\"{tempFileName}\"");

            using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath, sb.ToString()))
            {
                App.LogViewModel.RedirectedProcess = process;

                await process.StartAsync();
            }

            // Pass 2
            sb = new StringBuilder();

            sb.Append($"-i \"{tempFileName}\" ");
            sb.Append(commonParameters);

            if (is60FPS)
            {
                sb.Append("-r 60 ");
            }

            sb.Append("-pass 2 ");
            sb.Append($"\"{outputFileName}\"");

            using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath, sb.ToString()))
            {
                App.LogViewModel.RedirectedProcess = process;

                await process.StartAsync();
            }

            File.Delete(tempFileName);

            foreach (String item in Directory.GetFiles(outputDirectory, "ffmpeg2pass-0.*"))
            {
                File.Delete(item);
            }
        }
예제 #4
0
        public static async Task ExecuteHardRemoval
            (String sourceVideoFileName, String outputFileName,
            IEnumerable <SubtitleParameters> subtitleParameters)
        {
            // AviSynth for x26x - Process source file using hard-coded subtitle removal algorithm
            String avsFileName = Path.Combine(Path.GetTempPath(), "HardCodedSubtitleRemoval.avs");
            // For some reason avs4x26x program cannot accept input file name with # character
            String x264OutputFileName = Path.Combine(Path.GetTempPath(),
                                                     Path.GetFileNameWithoutExtension(outputFileName).Replace("#", String.Empty) + ".264");

            File.WriteAllText(avsFileName, SubtitleRemovalHelper.WriteHardCodedSubtitleRemovalAVS
                                  (sourceVideoFileName, ToolPaths.ToolsPath, subtitleParameters));

            String arguments = $"-o \"{x264OutputFileName}\" \"{avsFileName}\"";

            using (RedirectedProcess process = new RedirectedProcess(ToolPaths.AVS4x26xPath, arguments))
            {
                App.LogViewModel.RedirectedProcess = process;

                await process.StartAsync();
            }

            File.Delete(avsFileName);

            // FFVideoSource produces .ffindex files in the same folder of the source file
            if (File.Exists(sourceVideoFileName + ".ffindex"))
            {
                File.Delete(sourceVideoFileName + ".ffindex");
            }

            // MP4Box - Pack AviSynth output into video stream
            String videoOutputFileName = Path.Combine(Path.GetTempPath(),
                                                      Path.GetFileNameWithoutExtension(outputFileName) + ".v");

            arguments = $"-add \"{x264OutputFileName}\" \"{videoOutputFileName}\"";

            using (RedirectedProcess process = new RedirectedProcess(ToolPaths.MP4BoxPath, arguments))
            {
                App.LogViewModel.RedirectedProcess = process;

                await process.StartAsync();
            }

            File.Delete(x264OutputFileName);

            // FFProbe - Detect audio format of the source
            arguments = $"-v error -select_streams a:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1" +
                        $" \"{sourceVideoFileName}\"";

            String audioFormat = null;

            using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFProbePath, arguments))
            {
                await Task.Run(() =>
                {
                    process.Start();

                    audioFormat = process.StandardOutput.ReadToEnd().Trim();

                    process.WaitForExit();
                });
            }

            if (!String.IsNullOrEmpty(audioFormat))
            {
                // FFMPEG - Extract audio stream
                String audioOutputFileName = Path.Combine(Path.GetTempPath(),
                                                          Path.GetFileNameWithoutExtension(outputFileName) + $".{audioFormat}");

                arguments = $"-i \"{sourceVideoFileName}\" -vn -acodec copy \"{audioOutputFileName}\"";

                using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath, arguments))
                {
                    App.LogViewModel.RedirectedProcess = process;

                    await process.StartAsync();
                }

                // FFMPEG - Remux audio stream with packed video stream
                arguments = $"-i \"{videoOutputFileName}\" -i \"{audioOutputFileName}\" -map 0:v -map 1:a -c copy -y" +
                            $" \"{outputFileName}\"";

                using (RedirectedProcess process = new RedirectedProcess(ToolPaths.FFMPEGPath, arguments))
                {
                    App.LogViewModel.RedirectedProcess = process;

                    await process.StartAsync();
                }

                File.Delete(videoOutputFileName);
                File.Delete(audioOutputFileName);
            }
            else
            {
                throw new InvalidDataException("Unexpected audio format detection error occurred.");
            }
        }