diff --git a/VideoNodes/Tests/VideoInfoHelperTests.cs b/VideoNodes/Tests/VideoInfoHelperTests.cs index f72b31f3..81183f50 100644 --- a/VideoNodes/Tests/VideoInfoHelperTests.cs +++ b/VideoNodes/Tests/VideoInfoHelperTests.cs @@ -341,6 +341,29 @@ namespace VideoNodes.Tests int output = node.Execute(args); Assert.AreEqual(1, output); } + + + + [TestMethod] + public void VideoInfoTest_Subtitle_Extractor() + { + const string file = @"D:\videos\Injustice.mkv"; + var vi = new VideoInfoHelper(@"C:\utils\ffmpeg\ffmpeg.exe", new TestLogger()); + var vii = vi.Read(file); + + SubtitleExtractor node = new (); + //node.OutputFile = file + ".sup"; + var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty); + args.GetToolPath = (string tool) => @"C:\utils\ffmpeg\ffmpeg.exe"; + args.TempPath = @"D:\videos\temp"; + + new VideoFile().Execute(args); + + int output = node.Execute(args); + + Assert.AreEqual(1, output); + + } } } diff --git a/VideoNodes/VideoInfoHelper.cs b/VideoNodes/VideoInfoHelper.cs index 612db978..7a88bf5d 100644 --- a/VideoNodes/VideoInfoHelper.cs +++ b/VideoNodes/VideoInfoHelper.cs @@ -46,9 +46,12 @@ namespace FileFlows.VideoNodes process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; - process.StartInfo.Arguments = $"-i \"{filename}\""; + process.StartInfo.ArgumentList.Add("-hide_banner"); + process.StartInfo.ArgumentList.Add("-i"); + process.StartInfo.ArgumentList.Add(filename); process.Start(); string output = process.StandardError.ReadToEnd(); + output = output.Replace("At least one output file must be specified", string.Empty).Trim(); string error = process.StandardError.ReadToEnd(); process.WaitForExit(); diff --git a/VideoNodes/VideoNodes/SubtitleExtractor.cs b/VideoNodes/VideoNodes/SubtitleExtractor.cs index 0bb5d8e2..ad3c8424 100644 --- a/VideoNodes/VideoNodes/SubtitleExtractor.cs +++ b/VideoNodes/VideoNodes/SubtitleExtractor.cs @@ -48,9 +48,15 @@ else { var file = new FileInfo(args.FileName); - OutputFile = file.FullName.Substring(0, file.FullName.LastIndexOf(file.Extension)) + ".srt"; + + string extension = "srt"; + if(subTrack.Codec?.ToLower()?.Contains("pgs") == true) + extension = "sup"; + + OutputFile = file.FullName.Substring(0, file.FullName.LastIndexOf(file.Extension)) + "." + extension; } OutputFile = args.MapPath(OutputFile); + bool textSubtitles = System.Text.RegularExpressions.Regex.IsMatch(OutputFile, @"\.(sup)$") == false; if (File.Exists(OutputFile)) @@ -63,14 +69,21 @@ var result = args.Process.ExecuteShellCommand(new ExecuteArgs { Command = ffmpegExe, - ArgumentList = new [] - { + ArgumentList = textSubtitles ? new[] { + "-i", args.WorkingFile, - "-map", $"0:s:{subTrack.TypeIndex}", + "-map", $"{subTrack.IndexString}", "-map", "-0:v", "-map", "-0:a", OutputFile } + : new [] + { + "-i", args.WorkingFile, + "-c", "copy", + "-map", $"{subTrack.IndexString}", + OutputFile + } }).Result; if (result.ExitCode == 0) @@ -78,6 +91,16 @@ return 1; } + var of = new FileInfo(OutputFile); + if (of.Exists && of.Length == 0) + { + // delete the output file if it created an empty file + try + { + of.Delete(); + } + catch (Exception) { } + } args.Logger?.ELog("FFMPEG process failed to extract subtitles"); args.Logger?.ILog("Unexpected exit code: " + result.ExitCode); args.Logger?.ILog(result.StandardOutput ?? String.Empty);