mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-05-06 15:09:07 -05:00
added metadata remover node
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.
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.
Binary file not shown.
Binary file not shown.
@@ -95,6 +95,11 @@ public class FfmpegBuilderAudioAddTrack : FfmpegBuilderNode
|
||||
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Codec) || Codec == "ORIGINAL")
|
||||
{
|
||||
// this is a special case we use in the templates, to not add an audio track and use original
|
||||
return 1;
|
||||
}
|
||||
var audio = new FfmpegAudioStream();
|
||||
|
||||
var bestAudio = GetBestAudioTrack(args, Model.AudioStreams.Select(x => x.Stream));
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes.Models;
|
||||
|
||||
namespace FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
|
||||
/// <summary>
|
||||
/// Node that removes metadata from a file
|
||||
/// </summary>
|
||||
public class FfmpegBuilderMetadataRemover : FfmpegBuilderNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Help URL for this node
|
||||
/// </summary>
|
||||
public override string HelpUrl => "https://docs.fileflows.com/plugins/video-nodes/ffmpeg-builder/metadata-remover";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon for this node
|
||||
/// </summary>
|
||||
public override string Icon => "fas fa-remove-format";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of outputs for this node
|
||||
/// </summary>
|
||||
public override int Outputs => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if should run against video tracks
|
||||
/// </summary>
|
||||
[Boolean(1)]
|
||||
public bool Video { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if should run against audio tracks
|
||||
/// </summary>
|
||||
[Boolean(2)]
|
||||
public bool Audio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if should run against subtitle tracks
|
||||
/// </summary>
|
||||
[Boolean(3)]
|
||||
public bool Subtitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if images should be removed
|
||||
/// </summary>
|
||||
[Boolean(4)]
|
||||
public bool RemoveImages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if title should be removed
|
||||
/// </summary>
|
||||
[Boolean(5)]
|
||||
public bool RemoveTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if language should be removed
|
||||
/// </summary>
|
||||
[Boolean(6)]
|
||||
public bool RemoveLanguage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if additional metadata should be removed
|
||||
/// </summary>
|
||||
[Boolean(6)]
|
||||
public bool RemoveAdditionalMetadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Executes the node
|
||||
/// </summary>
|
||||
/// <param name="args">the node parameters</param>
|
||||
/// <returns>the output number to execute next</returns>
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
if (Video)
|
||||
Process(Model.VideoStreams);
|
||||
|
||||
if (Audio)
|
||||
Process(Model.AudioStreams);
|
||||
|
||||
if (Subtitle)
|
||||
Process(Model.SubtitleStreams);
|
||||
|
||||
if (RemoveAdditionalMetadata)
|
||||
{
|
||||
Model.CustomParameters.AddRange(new[] { "-map_metadata", "-1" });
|
||||
Model.ForceEncode = true;
|
||||
}
|
||||
|
||||
|
||||
if (RemoveImages)
|
||||
{
|
||||
foreach (var video in Model.VideoStreams)
|
||||
{
|
||||
if (video.Stream.IsImage)
|
||||
video.Deleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void Process<T>(List<T> streams) where T : FfmpegStream
|
||||
{
|
||||
if (streams == null)
|
||||
return;
|
||||
foreach (var stream in streams)
|
||||
Process(stream);
|
||||
}
|
||||
|
||||
private void Process(FfmpegStream stream)
|
||||
{
|
||||
if (RemoveTitle)
|
||||
{
|
||||
stream.Title = string.Empty;
|
||||
}
|
||||
|
||||
if (stream is FfmpegAudioStream audio)
|
||||
{
|
||||
if (RemoveLanguage)
|
||||
audio.Language = string.Empty;
|
||||
}
|
||||
else if (stream is FfmpegSubtitleStream sub)
|
||||
{
|
||||
if (RemoveLanguage)
|
||||
sub.Language = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,44 +1,88 @@
|
||||
//#if(DEBUG)
|
||||
#if(DEBUG)
|
||||
|
||||
//using FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
//using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
//using VideoNodes.Tests;
|
||||
using FileFlows.VideoNodes.FfmpegBuilderNodes;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using VideoNodes.Tests;
|
||||
|
||||
//namespace FileFlows.VideoNodes.Tests.FfmpegBuilderTests
|
||||
//{
|
||||
// [TestClass]
|
||||
// public class FfmpegBuilder_MetadataTests
|
||||
// {
|
||||
// [TestMethod]
|
||||
// public void FfmpegBuilder_MetadataJson()
|
||||
// {
|
||||
// const string file = @"D:\videos\unprocessed\basic.mkv";
|
||||
// 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);
|
||||
// VideoMetadata md = System.Text.Json.JsonSerializer.Deserialize<VideoMetadata>(File.ReadAllText(@"D:\videos\metadata.json"));
|
||||
// args.Variables.Add("VideoMetadata", md);
|
||||
// args.GetToolPathActual = (string tool) => ffmpeg;
|
||||
// args.TempPath = @"D:\videos\temp";
|
||||
// args.Parameters.Add("VideoInfo", vii);
|
||||
namespace FileFlows.VideoNodes.Tests.FfmpegBuilderTests;
|
||||
|
||||
[TestClass]
|
||||
public class FfmpegBuilder_MetadataTests: TestBase
|
||||
{
|
||||
//[TestMethod]
|
||||
//public void FfmpegBuilder_MetadataJson()
|
||||
//{
|
||||
// const string file = @"D:\videos\unprocessed\basic.mkv";
|
||||
// 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);
|
||||
// VideoMetadata md = System.Text.Json.JsonSerializer.Deserialize<VideoMetadata>(File.ReadAllText(@"D:\videos\metadata.json"));
|
||||
// args.Variables.Add("VideoMetadata", md);
|
||||
// args.GetToolPathActual = (string tool) => ffmpeg;
|
||||
// args.TempPath = @"D:\videos\temp";
|
||||
// args.Parameters.Add("VideoInfo", vii);
|
||||
|
||||
|
||||
// FfmpegBuilderStart ffStart = new ();
|
||||
// Assert.AreEqual(1, ffStart.Execute(args));
|
||||
// FfmpegBuilderStart ffStart = new ();
|
||||
// Assert.AreEqual(1, ffStart.Execute(args));
|
||||
|
||||
|
||||
// FfmpegBuilderVideoMetadata ffMetadata = new();
|
||||
// Assert.AreEqual(1, ffMetadata.Execute(args));
|
||||
// FfmpegBuilderVideoMetadata ffMetadata = new();
|
||||
// Assert.AreEqual(1, ffMetadata.Execute(args));
|
||||
|
||||
// FfmpegBuilderExecutor ffExecutor = new();
|
||||
// int result = ffExecutor.Execute(args);
|
||||
// FfmpegBuilderExecutor ffExecutor = new();
|
||||
// int result = ffExecutor.Execute(args);
|
||||
|
||||
// string log = logger.ToString();
|
||||
// Assert.AreEqual(1, result);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
// string log = logger.ToString();
|
||||
// Assert.AreEqual(1, result);
|
||||
//}
|
||||
|
||||
//#endif
|
||||
|
||||
[TestMethod]
|
||||
public void FfmpegBuilder_Metadata_Remover()
|
||||
{
|
||||
string file = TestFile_MovText_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));
|
||||
|
||||
FfmpegBuilderAudioTrackRemover ffRemover = new();
|
||||
ffRemover.StreamType = "subtitle";
|
||||
ffRemover.RemoveAll = true;
|
||||
ffRemover.PreExecute(args);
|
||||
Assert.AreEqual(1, ffRemover.Execute(args));
|
||||
|
||||
|
||||
FfmpegBuilderMetadataRemover ffMetadata = new();
|
||||
ffMetadata.RemoveImages = true;
|
||||
ffMetadata.RemoveTitle = true;
|
||||
ffMetadata.RemoveLanguage = true;
|
||||
ffMetadata.Video = true;
|
||||
ffMetadata.Audio= true;
|
||||
ffMetadata.Subtitle = true;
|
||||
ffMetadata.RemoveAdditionalMetadata = true;
|
||||
ffMetadata.PreExecute(args);
|
||||
Assert.AreEqual(1, ffMetadata.Execute(args));
|
||||
|
||||
FfmpegBuilderExecutor ffExecutor = new();
|
||||
ffExecutor.PreExecute(args);
|
||||
int result = ffExecutor.Execute(args);
|
||||
|
||||
string log = logger.ToString();
|
||||
Assert.AreEqual(1, result);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -39,6 +39,14 @@ namespace FileFlows.VideoNodes
|
||||
/// </summary>
|
||||
public string Codec { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// If this stream is an image
|
||||
/// </summary>
|
||||
public bool IsImage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the index string of this track
|
||||
/// </summary>
|
||||
public string IndexString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -220,6 +220,8 @@ namespace FileFlows.VideoNodes
|
||||
// Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709/unknown/unknown, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn (default)
|
||||
string line = info.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries).First();
|
||||
VideoStream vs = new VideoStream();
|
||||
vs.IsImage = info.Contains("(attached pic)");
|
||||
|
||||
vs.Codec = line.Substring(line.IndexOf("Video: ") + "Video: ".Length).Replace(",", "").Trim().Split(' ').First().ToLower();
|
||||
var dimensions = Regex.Match(line, @"([\d]{3,})x([\d]{3,})");
|
||||
if (int.TryParse(dimensions.Groups[1].Value, out int width))
|
||||
|
||||
Binary file not shown.
@@ -222,6 +222,29 @@
|
||||
"2": "No HDR stream found"
|
||||
}
|
||||
},
|
||||
"FfmpegBuilderMetadataRemover": {
|
||||
"Label": "FFMPEG Builder: Metadata Remover",
|
||||
"Description": "Removes metadata from the FFMPEG Builder so when the file is processed the selected metadata will be removed.\n\nNote: Only the metadata when this node is effected, if metadata is added after this node runs, that will not be effected.",
|
||||
"Outputs": {
|
||||
"1": "Metadata removed from FFMPEG Builder"
|
||||
},
|
||||
"Fields": {
|
||||
"Video": "Video",
|
||||
"Video-Help": "If video tracks should have this metadata removed",
|
||||
"Audio": "Audio",
|
||||
"Audio-Help": "If audio tracks should have this metadata removed",
|
||||
"Subtitle": "Subtitle",
|
||||
"Subtitle-Help": "If subtitle tracks should have this metadata removed",
|
||||
"RemoveImages": "Remove Images",
|
||||
"RemoveImages-Help": "If any images found in the metadata should be removed",
|
||||
"RemoveTitle": "Remove Title",
|
||||
"RemoveTitle-Help": "If the title should be removed from the tracks",
|
||||
"RemoveLanguage": "Remove Language",
|
||||
"RemoveLanguage-Help": "If the language should be removed from the tracks",
|
||||
"RemoveAdditionalMetadata": "Remove Additional Metadata",
|
||||
"RemoveAdditionalMetadata-Help": "If additional metadata should be removed. Additional metadata is non-standard metadata that may have been added to a video file, eg by iTunes."
|
||||
}
|
||||
},
|
||||
"FfmpegBuilderSubtitleFormatRemover": {
|
||||
"Label": "FFMPEG Builder: Subtitle Format Remover",
|
||||
"Description": "Removes subtitles from a video file if found.",
|
||||
|
||||
Reference in New Issue
Block a user