fixed issue in subtitle extractor

This commit is contained in:
reven
2022-01-12 11:35:23 +13:00
parent ac5ca8dcd7
commit 221ad25438
3 changed files with 54 additions and 5 deletions

View File

@@ -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);
}
}
}

View File

@@ -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();

View File

@@ -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);