From 770b7a08af4aaaeb535ce4849291e0dd6c0353b7 Mon Sep 17 00:00:00 2001 From: John Andrews Date: Sat, 29 Jul 2023 07:58:26 +1200 Subject: [PATCH] FF-1042 - added options to subtitle extractor --- VideoNodes/Helpers/SubtitleHelper.cs | 2 +- VideoNodes/VideoNodes.en.json | 4 +++- VideoNodes/VideoNodes/SubtitleExtractor.cs | 12 ++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/VideoNodes/Helpers/SubtitleHelper.cs b/VideoNodes/Helpers/SubtitleHelper.cs index c3f6699e..63f693ea 100644 --- a/VideoNodes/Helpers/SubtitleHelper.cs +++ b/VideoNodes/Helpers/SubtitleHelper.cs @@ -29,7 +29,7 @@ internal class SubtitleHelper /// the subtitle codec /// true if the subtitle is an image based subtitle internal static bool IsImageSubtitle(string codec) - => Regex.IsMatch(codec.Replace("_", ""), "dvbsub|pgs|xsub|vobsub", RegexOptions.IgnoreCase); + => Regex.IsMatch((codec ?? string.Empty).Replace("_", ""), "dvbsub|pgs|xsub|vobsub", RegexOptions.IgnoreCase); /// /// Determines the appropriate subtitle codec for conversion based on the container type and current subtitle codec. diff --git a/VideoNodes/VideoNodes.en.json b/VideoNodes/VideoNodes.en.json index 66b1e4ad..db510c88 100644 --- a/VideoNodes/VideoNodes.en.json +++ b/VideoNodes/VideoNodes.en.json @@ -521,7 +521,9 @@ "SetWorkingFile": "Set as Working File", "SetWorkingFile-Help": "When this is checked, if a subtitle is extracted, the working file will be changed to this extracted subtitle. The original working file will NOT be deleted.", "ForcedOnly": "Forced Only", - "ForcedOnly-Help": "If only forced subtitles should be extracted." + "ForcedOnly-Help": "If only forced subtitles should be extracted.", + "OnlyTextSubtitles": "Only Text Subtitles", + "OnlyTextSubtitles-Help": "If only text subtitles should be extracted, all image based subtitles will be skipped." } }, "VideoHasStream": { diff --git a/VideoNodes/VideoNodes/SubtitleExtractor.cs b/VideoNodes/VideoNodes/SubtitleExtractor.cs index f59977f6..0e0ba4b3 100644 --- a/VideoNodes/VideoNodes/SubtitleExtractor.cs +++ b/VideoNodes/VideoNodes/SubtitleExtractor.cs @@ -1,4 +1,5 @@ using System.Net; +using FileFlows.VideoNodes.Helpers; namespace FileFlows.VideoNodes; @@ -40,7 +41,11 @@ public class SubtitleExtractor : EncodingNode /// [Boolean(4)] public bool ForcedOnly { get; set; } - + /// + /// Gets or sets if only text subtitles should be extracted + /// + [Boolean(5)] + public bool OnlyTextSubtitles { get; set; } private Dictionary _Variables; /// @@ -75,6 +80,9 @@ public class SubtitleExtractor : EncodingNode // ffmpeg -i input.mkv -map "0:m:language:eng" -map "-0:v" -map "-0:a" output.srt var subTrack = videoInfo.SubtitleStreams?.Where(x => { + if (OnlyTextSubtitles && SubtitleHelper.IsImageSubtitle(x.Codec)) + return false; + if (ForcedOnly && x.Forced == false) return false; if(string.IsNullOrEmpty(Language)) @@ -103,7 +111,7 @@ public class SubtitleExtractor : EncodingNode OutputFile = args.MapPath(OutputFile); string extension = "srt"; - if (subTrack.Codec?.ToLower()?.Contains("pgs") == true) + if (SubtitleHelper.IsImageSubtitle(subTrack.Codec)) extension = "sup"; if (OutputFile.ToLower().EndsWith(".srt") || OutputFile.ToLower().EndsWith(".sup")) OutputFile = OutputFile[0..^4];