mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-30 21:30:05 -06:00
FF-191 - fixed subtitles not actually merging
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
if (Deleted)
|
||||
return new string[] { };
|
||||
|
||||
var results = new List<string> { "-map", "0:s:{sourceTypeIndex}", "-c:s:{index}" };
|
||||
List<string> results= new List<string> { "-map", Stream.InputFileIndex + ":s:{sourceTypeIndex}", "-c:s:{index}" };
|
||||
|
||||
if(args.DestinationExtension == "mkv" && Stream.Codec == "mov_text")
|
||||
{
|
||||
|
||||
@@ -39,6 +39,9 @@ public class FfmpegBuilderSubtitleTrackMerge : FfmpegBuilderNode
|
||||
[Boolean(2)]
|
||||
[DefaultValue(true)]
|
||||
public bool UseSourceDirectory { get; set; } = true;
|
||||
|
||||
[Boolean(3)]
|
||||
public bool MatchFilename { get; set; }
|
||||
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
@@ -64,11 +67,39 @@ public class FfmpegBuilderSubtitleTrackMerge : FfmpegBuilderNode
|
||||
if (Subtitles.Contains(ext) == false)
|
||||
continue;
|
||||
|
||||
if (MatchFilename)
|
||||
{
|
||||
var origFile = new FileInfo(args.FileName);
|
||||
string origFilename = origFile.Name.Replace(origFile.Extension, "");
|
||||
bool matchesOriginal = file.Name.Replace(file.Extension, string.Empty).ToLowerInvariant().Equals(origFilename.ToLowerInvariant());
|
||||
|
||||
var workingFile = new FileInfo(args.WorkingFile);
|
||||
string workingFilename = workingFile.Name.Replace(workingFile.Extension, "");
|
||||
bool matchesWorking = file.Name.Replace(file.Extension, string.Empty).ToLowerInvariant().Equals(workingFilename.ToLowerInvariant());
|
||||
|
||||
if (matchesOriginal == false && matchesWorking == false)
|
||||
continue;
|
||||
}
|
||||
|
||||
args.Logger.ILog("Adding file: " + file.FullName + " [" + ext + "]");
|
||||
this.Model.InputFiles.Add(file.FullName);
|
||||
this.Model.SubtitleStreams.Add(new FfmpegSubtitleStream
|
||||
{
|
||||
Stream = new SubtitleStream()
|
||||
{
|
||||
InputFileIndex = this.Model.InputFiles.Count - 1,
|
||||
TypeIndex = 0,
|
||||
Title = file.Name.Replace(file.Extension, ""),
|
||||
Codec = file.Extension[1..],
|
||||
IndexString = (this.Model.InputFiles.Count - 1) + ":s:0"
|
||||
},
|
||||
|
||||
});
|
||||
++count;
|
||||
}
|
||||
args.Logger.ILog("Subtitles added: " + count);
|
||||
if (count > 0)
|
||||
this.Model.ForceEncode = true;
|
||||
return count > 0 ? 1 : 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1183,6 +1183,42 @@ public class FfmpegBuilder_BasicTests
|
||||
string log = logger.ToString();
|
||||
Assert.AreEqual(1, result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_SubtitleTrackMerge()
|
||||
{
|
||||
const string file = @"D:\videos\testfiles\dummy.mkv";
|
||||
var logger = new TestLogger();
|
||||
const string ffmpeg = @"C:\utils\ffmpeg\ffmpeg.exe";
|
||||
var vi = new VideoInfoHelper(ffmpeg, logger);
|
||||
var vii = vi.Read(file);
|
||||
var args = new NodeParameters(file, logger, false, string.Empty);
|
||||
args.GetToolPathActual = (string tool) => ffmpeg;
|
||||
args.TempPath = @"D:\videos\temp";
|
||||
args.Parameters.Add("VideoInfo", vii);
|
||||
|
||||
|
||||
FfmpegBuilderStart ffStart = new();
|
||||
ffStart.PreExecute(args);
|
||||
Assert.AreEqual(1, ffStart.Execute(args));
|
||||
|
||||
|
||||
FfmpegBuilderSubtitleTrackMerge ffSubMerge = new();
|
||||
ffSubMerge.Subtitles = new List<string> { "srt" };
|
||||
ffSubMerge.MatchFilename = true;
|
||||
ffSubMerge.PreExecute(args);
|
||||
Assert.AreEqual(1, ffSubMerge.Execute(args));
|
||||
|
||||
FfmpegBuilderExecutor ffExecutor = new();
|
||||
ffExecutor.HardwareDecoding = true;
|
||||
ffExecutor.PreExecute(args);
|
||||
int result = ffExecutor.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
Assert.AreEqual(1, result);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -53,6 +53,11 @@ namespace FileFlows.VideoNodes
|
||||
/// Gets or sets if the stream is HDR
|
||||
/// </summary>
|
||||
public bool HDR { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the input file index
|
||||
/// </summary>
|
||||
public int InputFileIndex { get; set; } = 0;
|
||||
}
|
||||
|
||||
public class VideoStream : VideoFileStream
|
||||
|
||||
@@ -306,7 +306,9 @@
|
||||
"Subtitles": "Subtitles",
|
||||
"Subtitles-Help": "Select which subtitles to search for to add",
|
||||
"UseSourceDirectory": "Use Source Directory",
|
||||
"UseSourceDirectory-Help": "If checked the original source directory will be searched, otherwise the working directory will be used."
|
||||
"UseSourceDirectory-Help": "If checked the original source directory will be searched, otherwise the working directory will be used.",
|
||||
"MatchFilename": "Match Filename",
|
||||
"MatchFilename-Help": "When checked only subtitles with the same filename as the input file or the working file will be merged"
|
||||
}
|
||||
},
|
||||
"FfmpegBuilderCropBlackBars": {
|
||||
|
||||
Reference in New Issue
Block a user