mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-31 07:39:29 -06:00
confirmed subtitle remover working
This commit is contained in:
@@ -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<string>
|
||||
{
|
||||
"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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace FileFlows.VideoNodes
|
||||
/// The codec of the stream
|
||||
/// </summary>
|
||||
public string Codec { get; set; } = "";
|
||||
|
||||
public string IndexString { get; set; }
|
||||
}
|
||||
|
||||
public class VideoStream : VideoFileStream
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -56,8 +56,7 @@
|
||||
return -1;
|
||||
|
||||
List<string> ffArgs = new List<string>();
|
||||
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<string>();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ namespace FileFlows.VideoNodes
|
||||
private const string VIDEO_INFO = "VideoInfo";
|
||||
protected void SetVideoInfo(NodeParameters args, VideoInfo videoInfo, Dictionary<string, object> variables)
|
||||
{
|
||||
if (videoInfo.VideoStreams?.Any() == false)
|
||||
return;
|
||||
|
||||
if (args.Parameters.ContainsKey(VIDEO_INFO))
|
||||
args.Parameters[VIDEO_INFO] = videoInfo;
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user