mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-01-10 10:29:30 -06:00
fixed issue in subtitle extractor
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user