diff --git a/VideoNodes/Tests/VideoInfoHelperTests.cs b/VideoNodes/Tests/VideoInfoHelperTests.cs index 7a25ac4c..3651ee5f 100644 --- a/VideoNodes/Tests/VideoInfoHelperTests.cs +++ b/VideoNodes/Tests/VideoInfoHelperTests.cs @@ -20,6 +20,29 @@ namespace VideoNodes.Tests vi.Read(@"D:\videos\unprocessed\Hellboy 2019 Bluray-1080p.mp4"); } + [TestMethod] + public void VideoInfoTest_SubtitleRemover() + { + const string file = @"D:\videos\unprocessed\Bourne.mkv"; + var vi = new VideoInfoHelper(@"C:\utils\ffmpeg\ffmpeg.exe", new TestLogger()); + vi.Read(@"D:\videos\unprocessed\Bourne.mkv"); + + SubtitleRemover remover = new SubtitleRemover(); + remover.SubtitlesToRemove = new List + { + "subrip", "srt" + }; + var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger()); + args.GetToolPath = (string tool) => @"C:\utils\ffmpeg\ffmpeg.exe"; + args.TempPath = @"D:\videos\temp"; + + new VideoFile().Execute(args); + + int output = remover.Execute(args); + + Assert.AreEqual(1, output); + + } } } diff --git a/VideoNodes/VideoInfo.cs b/VideoNodes/VideoInfo.cs index cbe9dea1..ca848c0a 100644 --- a/VideoNodes/VideoInfo.cs +++ b/VideoNodes/VideoInfo.cs @@ -27,6 +27,8 @@ namespace FileFlows.VideoNodes /// The codec of the stream /// public string Codec { get; set; } = ""; + + public string IndexString { get; set; } } public class VideoStream : VideoFileStream diff --git a/VideoNodes/VideoInfoHelper.cs b/VideoNodes/VideoInfoHelper.cs index e51737f6..50526110 100644 --- a/VideoNodes/VideoInfoHelper.cs +++ b/VideoNodes/VideoInfoHelper.cs @@ -71,6 +71,9 @@ namespace FileFlows.VideoNodes if (vs != null) { vs.Index = streamIndex; + var match = Regex.Match(sm.Value, @"(?<=(Stream #))[\d]+:[\d]+"); + if (match.Success) + vs.IndexString = match.Value; vi.VideoStreams.Add(vs); } } @@ -80,6 +83,9 @@ namespace FileFlows.VideoNodes if (audio != null) { audio.Index = streamIndex; + var match = Regex.Match(sm.Value, @"(?<=(Stream #))[\d]+:[\d]+"); + if (match.Success) + audio.IndexString = match.Value; vi.AudioStreams.Add(audio); } } @@ -89,6 +95,9 @@ namespace FileFlows.VideoNodes if (sub != null) { sub.Index = streamIndex; + var match = Regex.Match(sm.Value, @"(?<=(Stream #))[\d]+:[\d]+"); + if (match.Success) + sub.IndexString = match.Value; vi.SubtitleStreams.Add(sub); } } @@ -122,6 +131,7 @@ namespace FileFlows.VideoNodes if (Regex.IsMatch(line, @"([\d]+(\.[\d]+)?)\sfps") && float.TryParse(Regex.Match(line, @"([\d]+(\.[\d]+)?)\sfps").Groups[1].Value, out float fps)) vs.FramesPerSecond = fps; + if (rgxDuration.IsMatch(info) && TimeSpan.TryParse(rgxDuration.Match(info).Value, out TimeSpan duration)) vs.Duration = duration; else if (rgxDuration2.IsMatch(fullOutput) && TimeSpan.TryParse(rgxDuration2.Match(fullOutput).Value, out TimeSpan duration2)) diff --git a/VideoNodes/VideoNodes/EncodingNode.cs b/VideoNodes/VideoNodes/EncodingNode.cs index ba75757b..674c439d 100644 --- a/VideoNodes/VideoNodes/EncodingNode.cs +++ b/VideoNodes/VideoNodes/EncodingNode.cs @@ -30,7 +30,7 @@ namespace FileFlows.VideoNodes if (string.IsNullOrEmpty(outputFile)) outputFile = Path.Combine(args.TempPath, Guid.NewGuid().ToString() + "." + extension); - bool success = Encoder.Encode(args.WorkingFile, outputFile, ffmpegParameters); + bool success = Encoder.Encode(args.WorkingFile, outputFile, ffmpegParameters); args.Logger.ILog("Encoding succesful: " + success); if (success) { diff --git a/VideoNodes/VideoNodes/SubtitleRemover.cs b/VideoNodes/VideoNodes/SubtitleRemover.cs index 7f9eb4f9..aa21bd90 100644 --- a/VideoNodes/VideoNodes/SubtitleRemover.cs +++ b/VideoNodes/VideoNodes/SubtitleRemover.cs @@ -56,8 +56,7 @@ return -1; List ffArgs = new List(); - ffArgs.Add($"-c:v copy"); - ffArgs.Add($"-c:a copy"); + ffArgs.Add($"-map 0:v -map 0:a"); var removeCodecs = SubtitlesToRemove?.Where(x => string.IsNullOrWhiteSpace(x) == false)?.Select(x => x.ToLower())?.ToList() ?? new List(); @@ -68,12 +67,13 @@ foreach (var sub in videoInfo.SubtitleStreams) { + args.Logger?.ILog("Subtitle found: " + sub.Codec + ", " + sub.Title); if (removeCodecs.Contains(sub.Codec.ToLower())) { foundBadSubtitle = true; continue; } - ffArgs.Add("-map 0:s:" + sub.TypeIndex); + ffArgs.Add("-map " + sub.IndexString); } if(foundBadSubtitle == false) @@ -81,6 +81,7 @@ // nothing to remove return 2; } + ffArgs.Add("-c copy"); string ffArgsLine = string.Join(" ", ffArgs); diff --git a/VideoNodes/VideoNodes/VideoNode.cs b/VideoNodes/VideoNodes/VideoNode.cs index 74d9a0a8..3d6d0381 100644 --- a/VideoNodes/VideoNodes/VideoNode.cs +++ b/VideoNodes/VideoNodes/VideoNode.cs @@ -66,6 +66,9 @@ namespace FileFlows.VideoNodes private const string VIDEO_INFO = "VideoInfo"; protected void SetVideoInfo(NodeParameters args, VideoInfo videoInfo, Dictionary variables) { + if (videoInfo.VideoStreams?.Any() == false) + return; + if (args.Parameters.ContainsKey(VIDEO_INFO)) args.Parameters[VIDEO_INFO] = videoInfo; else