mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-05-06 08:49:25 -05:00
renamed audio track remover to track remover and added support for video, audio and subtitles
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,39 +1,76 @@
|
||||
namespace FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes.Models;
|
||||
|
||||
namespace FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
|
||||
public class FfmpegBuilderAudioTrackRemover: FfmpegBuilderNode
|
||||
{
|
||||
public override string HelpUrl => "https://docs.fileflows.com/plugins/video-nodes/ffmpeg-builder/audio-track-remover";
|
||||
public override string HelpUrl => "https://docs.fileflows.com/plugins/video-nodes/ffmpeg-builder/track-remover";
|
||||
|
||||
public override string Icon => "fas fa-volume-off";
|
||||
public override string Icon => "fas fa-eraser";
|
||||
|
||||
public override int Outputs => 2;
|
||||
public override int Outputs => 2;
|
||||
|
||||
[Boolean(1)]
|
||||
|
||||
[Select(nameof(StreamTypeOptions), 1)]
|
||||
public string StreamType { get; set; }
|
||||
|
||||
[Boolean(2)]
|
||||
[ConditionEquals(nameof(StreamType), "Video", inverse: true)]
|
||||
public bool RemoveAll { get; set; }
|
||||
[NumberInt(2)]
|
||||
|
||||
[NumberInt(3)]
|
||||
public int RemoveIndex { get; set; }
|
||||
|
||||
|
||||
[TextVariable(3)]
|
||||
[TextVariable(4)]
|
||||
[ConditionEquals(nameof(RemoveAll), false)]
|
||||
public string Pattern { get; set; }
|
||||
|
||||
[Boolean(4)]
|
||||
[Boolean(5)]
|
||||
[ConditionEquals(nameof(RemoveAll), false)]
|
||||
public bool NotMatching { get; set; }
|
||||
|
||||
[Boolean(5)]
|
||||
[Boolean(6)]
|
||||
[ConditionEquals(nameof(RemoveAll), false)]
|
||||
public bool UseLanguageCode { get; set; }
|
||||
|
||||
private static List<ListOption> _StreamTypeOptions;
|
||||
public static List<ListOption> StreamTypeOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StreamTypeOptions == null)
|
||||
{
|
||||
_StreamTypeOptions = new List<ListOption>
|
||||
{
|
||||
new ListOption { Label = "Audio", Value = "Audio" },
|
||||
new ListOption { Label = "Video", Value = "Video" },
|
||||
new ListOption { Label = "Subtitle", Value = "Subtitle" }
|
||||
};
|
||||
}
|
||||
return _StreamTypeOptions;
|
||||
}
|
||||
}
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
if(string.IsNullOrEmpty(StreamType) || StreamType.ToLower() == "audio")
|
||||
return RemoveTracks(Model.AudioStreams) ? 1 : 2;
|
||||
if (StreamType.ToLower() == "subtitle")
|
||||
return RemoveTracks(Model.SubtitleStreams) ? 1 : 2;
|
||||
if (StreamType.ToLower() == "video")
|
||||
return RemoveTracks(Model.VideoStreams) ? 1 : 2;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
private bool RemoveTracks<T>(List<T> tracks) where T: FfmpegStream
|
||||
{
|
||||
bool removing = false;
|
||||
Regex? regex = null;
|
||||
int index = -1;
|
||||
foreach(var audio in Model.AudioStreams)
|
||||
foreach (var track in tracks)
|
||||
{
|
||||
if (audio.Deleted == false)
|
||||
if (track.Deleted == false)
|
||||
{
|
||||
// only record indexes of tracks that have not been deleted
|
||||
++index;
|
||||
@@ -41,15 +78,22 @@ public class FfmpegBuilderAudioTrackRemover: FfmpegBuilderNode
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RemoveAll)
|
||||
if (RemoveAll || string.IsNullOrEmpty(this.Pattern))
|
||||
{
|
||||
audio.Deleted = true;
|
||||
track.Deleted = true;
|
||||
removing = true;
|
||||
continue;
|
||||
}
|
||||
if(regex == null)
|
||||
|
||||
if (regex == null)
|
||||
regex = new Regex(this.Pattern, RegexOptions.IgnoreCase);
|
||||
string str = UseLanguageCode ? audio.Stream.Language : audio.Stream.Title;
|
||||
string str = "";
|
||||
if(track is FfmpegAudioStream audio)
|
||||
str = UseLanguageCode ? audio.Stream.Language : audio.Stream.Title;
|
||||
else if (track is FfmpegSubtitleStream subtitle)
|
||||
str = UseLanguageCode ? subtitle.Stream.Language : subtitle.Stream.Title;
|
||||
else if (track is FfmpegVideoStream video)
|
||||
str = video.Stream.Title;
|
||||
if (string.IsNullOrEmpty(str) == false) // if empty we always use this since we have no info to go on
|
||||
{
|
||||
bool matches = regex.IsMatch(str);
|
||||
@@ -57,11 +101,11 @@ public class FfmpegBuilderAudioTrackRemover: FfmpegBuilderNode
|
||||
matches = !matches;
|
||||
if (matches)
|
||||
{
|
||||
audio.Deleted = true;
|
||||
track.Deleted = true;
|
||||
removing = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return removing ? 1 : 2;
|
||||
return removing;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1089,6 +1089,49 @@ public class FfmpegBuilder_BasicTests
|
||||
string log = logger.ToString();
|
||||
Assert.IsTrue(log.Contains("this is a \"testing bobby drake\" blah"));
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_ImageStream()
|
||||
{
|
||||
const string file = @"D:\videos\testfiles\img_stream.mp4";
|
||||
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));
|
||||
|
||||
FfmpegBuilderRemuxToMkv ffMkv = new();
|
||||
ffMkv.PreExecute(args);
|
||||
Assert.AreEqual(1, ffMkv.Execute(args));
|
||||
|
||||
FfmpegBuilderAudioTrackRemover ffRemover = new();
|
||||
ffRemover.StreamType = "Video";
|
||||
ffRemover.RemoveIndex = 1;
|
||||
ffRemover.PreExecute(args);
|
||||
Assert.AreEqual(1, ffRemover.Execute(args));
|
||||
|
||||
|
||||
FfmpegBuilderAudioTrackRemover ffRemoverSubtitles = new();
|
||||
ffRemoverSubtitles.StreamType = "Subtitle";
|
||||
ffRemoverSubtitles.RemoveAll = true;
|
||||
ffRemoverSubtitles.PreExecute(args);
|
||||
Assert.AreEqual(1, ffRemoverSubtitles.Execute(args));
|
||||
|
||||
FfmpegBuilderExecutor ffExecutor = new();
|
||||
ffExecutor.PreExecute(args);
|
||||
int result = ffExecutor.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
Assert.AreEqual(1, result);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Binary file not shown.
@@ -254,23 +254,25 @@
|
||||
}
|
||||
},
|
||||
"FfmpegBuilderAudioTrackRemover": {
|
||||
"Label": "FFMPEG Builder: Audio Track Remover",
|
||||
"Label": "FFMPEG Builder: Track Remover",
|
||||
"Outputs": {
|
||||
"1": "Audio tracks set to remove",
|
||||
"2": "Audio tracks NOT set to removed"
|
||||
"1": "Tracks set to remove",
|
||||
"2": "Tracks NOT set to removed"
|
||||
},
|
||||
"Description": "Allows you to remove audio tracks based on either their title or their language codes.\n\nAny title (or language code if set to \"Use Language Code\") that is blank will NOT be removed regardless of the pattern.",
|
||||
"Description": "Allows you to remove tracks based on either their title or their language codes.\n\nAny title (or language code if set to \"Use Language Code\") that is blank will NOT be removed regardless of the pattern.",
|
||||
"Fields": {
|
||||
"StreamType": "Type",
|
||||
"StreamType-Help": "The type of tracks to reorder in the FFMPEG Builder",
|
||||
"RemoveAll": "Remove All",
|
||||
"RemoveAll-Help": "Remove all current tracks from the output file. You can use Add Audio Track afterwards to add tracks of specific codecs",
|
||||
"RemoveAll-Help": "Remove all current tracks from the output file. You can use Add Track afterwards to add tracks of specific codecs",
|
||||
"Pattern": "Pattern",
|
||||
"Pattern-Help": "A regular expression to match against, eg \"commentary\" to remove commentary tracks",
|
||||
"NotMatching": "Not Matching",
|
||||
"NotMatching-Help": "If audio tracks NOT matching the pattern should be removed",
|
||||
"UseLanguageCode": "Use Language Code",
|
||||
"UseLanguageCode-Help": "If the language code of the audio track should be used instead of the title",
|
||||
"UseLanguageCode-Help": "If the language code of the track should be used instead of the title",
|
||||
"RemoveIndex": "Remove Index",
|
||||
"RemoveIndex-Help": "The start index where to remove the audio tracks from. This allows you to remove all, or all matching, audio streams after the starting index.\nSet to zero to remove all matching the parameters.\nSet to 1 to keep the first audio track and remove any after the first matching the parameters"
|
||||
"RemoveIndex-Help": "The start index where to remove the tracks from. This allows you to remove all, or all matching, tracks after the starting index.\nSet to zero to remove all matching the parameters.\nSet to 1 to keep the first track and remove any after the first matching the parameters"
|
||||
}
|
||||
},
|
||||
"FfmpegBuilderAudioTrackReorder": {
|
||||
|
||||
Reference in New Issue
Block a user