From fa0a52c85e735a9ef971efba3085e37ecbb98f2a Mon Sep 17 00:00:00 2001 From: John Andrews Date: Mon, 9 May 2022 10:39:35 +1200 Subject: [PATCH] added two new ffmpeg builder nodes --- .../FfmpegBuilderAddInputFile.cs | 41 ++++++++++++ .../FfmpegBuilderSubtitleTrackMerge.cs | 65 +++++++++++++++++++ VideoNodes/VideoNodes.en.json | 26 ++++++++ VideoNodes/VideoNodes/SubtitleRemover.cs | 1 + 4 files changed, 133 insertions(+) create mode 100644 VideoNodes/FfmpegBuilderNodes/FfmpegBuilderAddInputFile.cs create mode 100644 VideoNodes/FfmpegBuilderNodes/Subtitle/FfmpegBuilderSubtitleTrackMerge.cs diff --git a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderAddInputFile.cs b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderAddInputFile.cs new file mode 100644 index 00000000..e48e6a91 --- /dev/null +++ b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderAddInputFile.cs @@ -0,0 +1,41 @@ +using FileFlows.VideoNodes.FfmpegBuilderNodes.Models; + +namespace FileFlows.VideoNodes.FfmpegBuilderNodes; + +public class FfmpegBuilderAddInputFile : FfmpegBuilderNode +{ + public override string HelpUrl => "https://github.com/revenz/FileFlows/wiki/FFMPEG-Builder:-Add-Input-File"; + + public override string Icon => "fas fa-file-plus"; + + public override int Outputs => 2; + + + [TextVariable(1)] + [Required] + public string Pattern { get; set; } + + [Boolean(2)] + public bool UseSourceDirectory { get; set; } + + public override int Execute(NodeParameters args) + { + this.Init(args); + var dir = new FileInfo(UseSourceDirectory ? args.FileName : args.WorkingFile).Directory; + if (dir.Exists == false) + { + args.Logger?.ILog("Directory does not exist: " + dir.FullName); + return 2; + } + var regex = new Regex(this.Pattern, RegexOptions.IgnoreCase); + bool added = false; + foreach (var file in dir.GetFiles()) + { + if (regex.IsMatch(file.Name) == false) + continue; + this.Model.InputFiles.Add(file.FullName); + added = true; + } + return added ? 1 : 2; + } +} diff --git a/VideoNodes/FfmpegBuilderNodes/Subtitle/FfmpegBuilderSubtitleTrackMerge.cs b/VideoNodes/FfmpegBuilderNodes/Subtitle/FfmpegBuilderSubtitleTrackMerge.cs new file mode 100644 index 00000000..e17c16a7 --- /dev/null +++ b/VideoNodes/FfmpegBuilderNodes/Subtitle/FfmpegBuilderSubtitleTrackMerge.cs @@ -0,0 +1,65 @@ +using FileFlows.VideoNodes.FfmpegBuilderNodes.Models; + +namespace FileFlows.VideoNodes.FfmpegBuilderNodes; + +public class FfmpegBuilderSubtitleTrackMerge : FfmpegBuilderNode +{ + public override string HelpUrl => "https://github.com/revenz/FileFlows/wiki/FFMPEG-Builder:-Subtitle-Track-Merge"; + + public override string Icon => "fas fa-comment-medical"; + + public override int Outputs => 2; + + [Checklist(nameof(Options), 1)] + [Required] + public List Subtitles { get; set; } + + private static List _Options; + public static List Options + { + get + { + if (_Options == null) + { + _Options = new List + { + new ListOption { Value = "ass", Label = "ass: Advanced SubStation Alpha"}, + new ListOption { Value = "srt", Label = "srt: SubRip subtitle"}, + new ListOption { Value = "ssa", Label = "ssa: SubStation Alpha"}, + new ListOption { Value = "sub", Label = "sub: SubStation Alpha"}, + new ListOption { Value = "text", Label = "txt: Raw text subtitle"} + }; + } + return _Options; + } + } + + [Boolean(2)] + [DefaultValue(true)] + public bool UseSourceDirectory { get; set; } = true; + + public override int Execute(NodeParameters args) + { + this.Init(args); + var dir = new FileInfo(UseSourceDirectory ? args.FileName : args.WorkingFile).Directory; + if (dir.Exists == false) + { + args.Logger?.ILog("Directory does not exist: " + dir.FullName); + return 2; + } + bool added = false; + foreach (var file in dir.GetFiles()) + { + string ext = file.Extension; + if (string.IsNullOrEmpty(ext) || ext.Length < 2) + continue; + ext = ext.Substring(1).ToLower();// remove . + if (Subtitles.Contains(ext)) + continue; + + this.Model.InputFiles.Add(file.FullName); + added = true; + } + return added ? 1 : 2; + } +} diff --git a/VideoNodes/VideoNodes.en.json b/VideoNodes/VideoNodes.en.json index b806fb9e..56b0a6ea 100644 --- a/VideoNodes/VideoNodes.en.json +++ b/VideoNodes/VideoNodes.en.json @@ -168,6 +168,19 @@ "HardwareDecoding-Help": "If the executor should attempt to use hardware decoding. If not available the execution will proceed just without hardware decoding enabled." } }, + "FfmpegBuilderAddInputFile": { + "Label": "FFMPEG Builder: Add Input File", + "Outputs": { + "1": "File found and added", + "2": "No file found" + }, + "Fields": { + "Pattern": "Pattern", + "Pattern-Help": "A regular expression used to search for input files", + "UseSourceDirectory": "Use Source Directory", + "UseSourceDirectory-Help": "If checked the original source directory will be searched, otherwise the working directory will be used." + } + }, "FfmpegBuilderAudioAddTrack": { "Label": "FFMPEG Builder: Audio Add Track", "Outputs": { @@ -332,6 +345,19 @@ "UseLanguageCode-Help": "If the language code of the audio track should be used instead of the title" } }, + "FfmpegBuilderSubtitleTrackMerge": { + "Label": "FFMPEG Builder: Subtitle Track Merge", + "Outputs": { + "1": "Subtitles found and added", + "2": "No subtitles found" + }, + "Fields": { + "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." + } + }, "FfmpegBuilderCropBlackBars": { "Label": "FFMPEG Builder: Crop Black Bars", "Description": "Updated FFMPEG Builder to crop black bars if detected", diff --git a/VideoNodes/VideoNodes/SubtitleRemover.cs b/VideoNodes/VideoNodes/SubtitleRemover.cs index 0954d065..4b5fadc0 100644 --- a/VideoNodes/VideoNodes/SubtitleRemover.cs +++ b/VideoNodes/VideoNodes/SubtitleRemover.cs @@ -19,6 +19,7 @@ public bool RemoveAll { get; set; } [Checklist(nameof(Options), 2)] + [ConditionEquals(nameof(RemoveAll), false)] public List SubtitlesToRemove { get; set; } private static List _Options;