From 3b4f8871ccfc7e95b5687d7db2de76006a8b1651 Mon Sep 17 00:00:00 2001 From: John Andrews Date: Tue, 14 Jun 2022 09:56:47 +1200 Subject: [PATCH] added ffmpeg builder custom parameters node --- Apprise/Apprise.csproj | Bin 2760 -> 2760 bytes Apprise/Plugin.cs | Bin 586 -> 592 bytes BasicNodes/BasicNodes.csproj | Bin 3566 -> 3566 bytes BasicNodes/Plugin.cs | Bin 734 -> 740 bytes ChecksumNodes/ChecksumNodes.csproj | Bin 2872 -> 2872 bytes ChecksumNodes/Plugin.cs | Bin 546 -> 552 bytes CollectionNodes/CollectionNodes.csproj | Bin 3256 -> 3256 bytes CollectionNodes/Plugin.cs | Bin 886 -> 892 bytes DiscordNodes/DiscordNodes.csproj | Bin 2870 -> 2870 bytes DiscordNodes/Plugin.cs | Bin 584 -> 590 bytes EmailNodes/EmailNodes.csproj | Bin 3386 -> 3386 bytes EmailNodes/Plugin.cs | Bin 542 -> 548 bytes Emby/Emby.csproj | Bin 2844 -> 2844 bytes Emby/Plugin.cs | Bin 562 -> 568 bytes Gotify/Gotify.csproj | Bin 2752 -> 2752 bytes Gotify/Plugin.cs | Bin 582 -> 588 bytes ImageNodes/ImageNodes.csproj | Bin 3232 -> 3232 bytes ImageNodes/Plugin.cs | Bin 588 -> 594 bytes MetaNodes/MetaNodes.csproj | Bin 4504 -> 4504 bytes MetaNodes/Plugin.cs | Bin 640 -> 646 bytes MusicNodes/MusicNodes.csproj | Bin 4228 -> 4228 bytes MusicNodes/Plugin.cs | Bin 756 -> 762 bytes Plex/Plex.csproj | Bin 2844 -> 2844 bytes Plex/Plugin.cs | Bin 562 -> 568 bytes .../FfmpegBuilderCustomParameters.cs | 68 ++++++++++++++++++ .../FfmpegBuilderExecutor.cs | 6 +- .../FfmpegBuilderNodes/Models/FfmpegModel.cs | 16 +++++ VideoNodes/Plugin.cs | Bin 756 -> 762 bytes .../FfmpegBuilder_BasicTests.cs | 33 +++++++++ VideoNodes/VideoNodes.csproj | Bin 4098 -> 4098 bytes VideoNodes/VideoNodes.en.json | 13 ++++ 31 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 VideoNodes/FfmpegBuilderNodes/FfmpegBuilderCustomParameters.cs diff --git a/Apprise/Apprise.csproj b/Apprise/Apprise.csproj index 7503db9dc5f4b7b6a69f8816e27791ec37d5ebdf..5abb4ad4cef1ed966673d252bed8d1baa70e503a 100644 GIT binary patch delta 56 ycmX>hdO~!A1(To!gC2tc5F0U=1F;Q*{$yz;$;o?|I3{N?DehdO~!A1(TpTgC2t+5F0U=GZ-+~Fz8Q~W|Ew|hlyiy7LyV$itOf@O!^!EME?q~ diff --git a/Apprise/Plugin.cs b/Apprise/Plugin.cs index bdd5705f3163a596b4334edda39c2853a4cebc4d..ef22b601dd2350e74c4f8472cdbc29a0971af569 100644 GIT binary patch delta 27 hcmX@ba)D*TBSwA;20aD?AU0$$W-w>4nEaYC9sp-Y2D$(M delta 21 acmcb>a*AccBSubh20aD?5T5*zF&+R(KL!>6 diff --git a/BasicNodes/BasicNodes.csproj b/BasicNodes/BasicNodes.csproj index e5867bad9a4e6b48ee35317e2938cb31153a53d3..b94382d440fa23493d5d6c5a16efb35474270514 100644 GIT binary patch delta 44 mcmaDS{Z4wr14dp820aD?AU0w!XE2)lmeChgWV1Wda&7gJ|;m620aD?AU0w!2Vxrr{mBcNBq!hF;+m|+!Z(Rogcn7@W<_Rk4gic^ B3z7f; delta 59 zcmdlXwnJ>gJ|;nP20aEtAU0w!XE0!}VbGtvkV$g#Jua@vYAk${m_>L|6l_*x7Uuu} Di~I|Y diff --git a/ChecksumNodes/Plugin.cs b/ChecksumNodes/Plugin.cs index e8664e32ca94e4d67309733bda158a3b474488fd..570092ae27e10a2ea7b57f34ae458d86164f588f 100644 GIT binary patch delta 39 tcmZ3)vVvv9E=F++20aD?AU0$$W-w>4U{GSPX5eMun#{{6J^2}<4FH^*2T}k4 delta 21 acmZ3%vWR8FE=Eps20aD?5T1OJF&+Rw2L*Nj diff --git a/CollectionNodes/CollectionNodes.csproj b/CollectionNodes/CollectionNodes.csproj index 3d7f1d2a08efc8d76d37e66542e867e4dfd021b3..71dc3d424a2bb010195d79f65af1801d60ac4f5b 100644 GIT binary patch delta 60 zcmdlXxkGZpIYvPX20aD?AU0w!2Vxrr{mB~{B`3%6a82IB%r{wpNrV?g#b!gMb}j&( C>I_~0 delta 60 zcmdlXxkGZpIYvQq20aEtAU0w!XE0!}VbGtvkx_DT91qvzJ4nEaA49sp*o2C@JE delta 21 acmX@da)M>U14d4B20aD?5T5*=F&+R&$p#Jp diff --git a/EmailNodes/EmailNodes.csproj b/EmailNodes/EmailNodes.csproj index 672cd6114679e0bf6a4e88c9fb6dd6b5caa2ef14..918cbb7973a54bb31cfd325f76f1fbfbeed88f84 100644 GIT binary patch delta 56 ycmdlbwM%M)1&g2sgC2tc5F0U=1F;Q*{$yzu$;o?IxF+YYDDa}lZl1}qkOKfiiwhtC delta 56 zcmdlbwM%M)1&g3LgC2t+5F0U=GZ-+~Fz8Q~W|5q{hlOi$4vPXWitOf@EDJdRLoW*) diff --git a/EmailNodes/Plugin.cs b/EmailNodes/Plugin.cs index 26fae782f601e5fb2074b1dda4ded6cc41fecec4..7f400544d5e956402055d6f0133ceb0721f4567f 100644 GIT binary patch delta 27 hcmbQovV>*BHb#C620aD?AU0$$W-w>4n7p4c9spVk1_}TG delta 21 acmZ3&GLL1$Hbzc!20aD?5T1OLF&+Rv8wF+n diff --git a/Emby/Emby.csproj b/Emby/Emby.csproj index ddb2d71008df2bf43b749a67ad225dab74ba34d3..ee308ac7f6a97c9ea88ba91f5a679ce1d5ff52b5 100644 GIT binary patch delta 44 mcmbOuHb-nj8xyYugC2tc5F0U=GZ;;t%;b(LviUiaDF*=0hzPv^ delta 44 mcmbOuHb-nj8xyZNgC2t+5F0U=GZ;*s%;b(LviUiaDF*=0L4U{GSPX5eMunrz4@J^34>4FII42etqJ delta 21 acmdnNvWaEGDMn6n20aD?5T1OKF&+Rzw*|HU diff --git a/Gotify/Gotify.csproj b/Gotify/Gotify.csproj index a5e437fb23a75f58c350d9e88e3ad67d6ab801b3..25c2ef224bdc4c5e1bff66211569b202d8f13107 100644 GIT binary patch delta 56 ycmX>gdO&o81(To!gC2tc5F0U=1F;Q*{$yz;$;o?|I3{N?DegdO&o81(TpTgC2t+5F0U=GZ-+~Fz8Q~W|Ew|hlyiy7LyV$itOf@OzIo}L4OLE diff --git a/Gotify/Plugin.cs b/Gotify/Plugin.cs index f46455e452ec55d088b6c98291f289783e7e21e7..6e547a5ff4b1f5a66dc9b99dd674411ba7a0ce22 100644 GIT binary patch delta 38 scmX@ca)xEYJw|a020aD?AU0$$W-w>4U{GSPX5eMunz&GUG8dB#0H*l|bN~PV delta 21 acmX@Za*SoeJw{G*20aD?5T5*&F&+R&Qw9bA diff --git a/ImageNodes/ImageNodes.csproj b/ImageNodes/ImageNodes.csproj index d5ff868eaa3281f805377bddcc5cc009786c4f38..786a21cf261fe40527c3ac58b42a3fef89e1d56c 100644 GIT binary patch delta 52 ucmZ1=xj=G550jt;gC2tc5F0U=1F;Q*{^Wcn$;sQ840uswHh*SX%LxD=MGEc! delta 52 vcmZ1=xj=G550judgC2t+5F0U=GZ-+~Fz8RtXOf(}jmdx)MP~D7rnQ^^AMpz6 diff --git a/ImageNodes/Plugin.cs b/ImageNodes/Plugin.cs index d9516c4cade2a9e65ffcc3783531a42f78f096db..f0dc2da3c5e06f390c01d271246f839df4ff4b0b 100644 GIT binary patch delta 27 hcmX@Za*1Wb6Gnau20aD?AU0$$W-w>4nEaM89spj>xo diff --git a/MetaNodes/Plugin.cs b/MetaNodes/Plugin.cs index 13dbe9ca21aa1d7f4629b275254dd303c9478b71..855b8c842a92abe764b68514353d068e37681358 100644 GIT binary patch delta 27 gcmZo*ZDZY_!^CgFpvPbU#D)yU4CV|LlTDet0YaM`8H^@BX7WW9*=)<~&IaM`84M;rX7WW9*=)<~&I@2jTz# delta 21 acmeyx`h|5v4-=<3gC2tc2v45P6b}GNqy@qN diff --git a/Plex/Plex.csproj b/Plex/Plex.csproj index 7bdcdff93251540ca5782abe18ae52268bbfe63c..0f0e55489411d626d9e0bc8d6ec8cdb92ba7016f 100644 GIT binary patch delta 44 mcmbOuHb-nj8xyYugC2tc5F0U=GZ;;t%;b(LviUiaDF*=0hzPv^ delta 44 mcmbOuHb-nj8xyZNgC2t+5F0U=GZ;*s%;b(LviUiaDF*=0L4U{GSPX5eMunrz4@J^34>4FII42etqJ delta 21 acmdnNvWaEGDMn6n20aD?5T1OKF&+Rzw*|HU diff --git a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderCustomParameters.cs b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderCustomParameters.cs new file mode 100644 index 00000000..e8ce1d3d --- /dev/null +++ b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderCustomParameters.cs @@ -0,0 +1,68 @@ +using FileFlows.VideoNodes.FfmpegBuilderNodes.Models; + +namespace FileFlows.VideoNodes.FfmpegBuilderNodes; + +/// +/// Node that adds custom parameters to the FFMPEG Builder +/// +public class FfmpegBuilderCustomParameters : FfmpegBuilderNode +{ + /// + /// Gets the Help URL for this node + /// + public override string HelpUrl => "https://docs.fileflows.com/plugins/video-nodes/ffmpeg-builder/custom-parameters"; + + /// + /// Gets the icon for this node + /// + public override string Icon => "fas fa-plus-square"; + + /// + /// Gets the number of outputs for this node + /// + public override int Outputs => 1; + + + /// + /// Gets or sets the parameters to add + /// + [TextVariable(1)] + [Required] + public string Parameters { get; set; } + + /// + /// Gets or sets if the video should be forcable encoded when these parameters are added + /// + [Boolean(2)] + [DefaultValue(true)] + public bool ForceEncode { get; set; } + + + /// + /// Executes the node + /// + /// the node parameters + /// the output number to execute next + public override int Execute(NodeParameters args) + { + string parameters = args.ReplaceVariables(Parameters); + if (string.IsNullOrWhiteSpace(parameters)) + return 1; + + string[] split = Regex.Split(parameters, "(\"[^\"]+\"|[^\\s\"]+)"); + foreach(var parameter in split) + { + if (string.IsNullOrWhiteSpace(parameter)) + continue; + + string actual = parameter; + if (parameter.StartsWith("\"") && parameter.EndsWith("\"")) + actual = parameter[1..^1]; + this.Model.CustomParameters.Add(actual); + } + + this.Model.ForceEncode = ForceEncode; + + return 1; + } +} diff --git a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs index 00132b28..a6eceefe 100644 --- a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs +++ b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs @@ -24,6 +24,10 @@ namespace FileFlows.VideoNodes.FfmpegBuilderNodes List ffArgs = new List(); ffArgs.AddRange(new[] { "-strict", "-2" }); // allow experimental stuff ffArgs.AddRange(new[] { "-fflags", "+genpts" }); //Generate missing PTS if DTS is present. + + if(model.CustomParameters?.Any() == true) + ffArgs.AddRange(model.CustomParameters); + bool hasChange = false; int actualIndex = 0; int currentType = 0; @@ -53,7 +57,7 @@ namespace FileFlows.VideoNodes.FfmpegBuilderNodes ffArgs.AddRange(model.MetadataParameters); } - if (hasChange == false && (string.IsNullOrWhiteSpace(model.Extension) || args.WorkingFile.ToLower().EndsWith("." + model.Extension.ToLower()))) + if (model.ForceEncode == false && hasChange == false && (string.IsNullOrWhiteSpace(model.Extension) || args.WorkingFile.ToLower().EndsWith("." + model.Extension.ToLower()))) return 2; // nothing to do string extension = model.Extension?.EmptyAsNull() ?? "mkv"; diff --git a/VideoNodes/FfmpegBuilderNodes/Models/FfmpegModel.cs b/VideoNodes/FfmpegBuilderNodes/Models/FfmpegModel.cs index b52aecd1..0776c511 100644 --- a/VideoNodes/FfmpegBuilderNodes/Models/FfmpegModel.cs +++ b/VideoNodes/FfmpegBuilderNodes/Models/FfmpegModel.cs @@ -37,6 +37,22 @@ set => _InputFiles = value ?? new List(); } + private List _CustomParameters = new List(); + + /// + /// Gets or sets custom parameters to use in the FFMPEG Builder + /// + public List CustomParameters + { + get => _CustomParameters; + set => _CustomParameters = value ?? new List(); + } + + /// + /// Gets or sets if the builder should forcable execute even if nothing appears to have changed + /// + public bool ForceEncode { get; set; } + /// /// Gets or sets the video information for this video file /// diff --git a/VideoNodes/Plugin.cs b/VideoNodes/Plugin.cs index f8a6d4ba2f49009784b53bd84e85728fd047e404..82aa1b3bf9d71b623624a1d174f129ad49c95a55 100644 GIT binary patch delta 39 tcmeyu`ipf#50khBgC2tc5F0WWGng}2FeoutGw?ESO%7y~p1gy}1^}>@2jTz# delta 21 acmeyx`h|5v4-=<3gC2tc2v45P6b}GNqy@qN diff --git a/VideoNodes/Tests/FfmpegBuilderTests/FfmpegBuilder_BasicTests.cs b/VideoNodes/Tests/FfmpegBuilderTests/FfmpegBuilder_BasicTests.cs index 68a94657..87197c8d 100644 --- a/VideoNodes/Tests/FfmpegBuilderTests/FfmpegBuilder_BasicTests.cs +++ b/VideoNodes/Tests/FfmpegBuilderTests/FfmpegBuilder_BasicTests.cs @@ -1056,6 +1056,39 @@ public class FfmpegBuilder_BasicTests string log = logger.ToString(); Assert.AreEqual(1, result); } + + + + [TestMethod] + public void FfmpegBuilder_CustomParameters() + { + const string file = @"D:\videos\testfiles\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); + 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)); + + FfmpegBuilderCustomParameters ffCustom = new(); + ffCustom.Parameters = "this is a \"testing bobby drake\" blah"; + ffCustom.ForceEncode = true; + ffCustom.PreExecute(args); + ffCustom.Execute(args); + + FfmpegBuilderExecutor ffExecutor = new(); + ffExecutor.PreExecute(args); + int result = ffExecutor.Execute(args); + + string log = logger.ToString(); + Assert.IsTrue(log.Contains("this is a \"testing bobby drake\" blah")); + } } #endif \ No newline at end of file diff --git a/VideoNodes/VideoNodes.csproj b/VideoNodes/VideoNodes.csproj index 6562e48167c7b78ddce0cf6ca46a21d805a3e0b0..94d1ee318d52f907bcc257d93c22b2a577afd04c 100644 GIT binary patch delta 44 mcmZotXj0g4jfvNSL65-zh>aM`8H^@BX7WW9*=);vlm`IZ8woA| delta 44 mcmZotXj0g4jfvNsL65-@h>aM`84M;rX7WW9*=);vlm`IY*9j^B diff --git a/VideoNodes/VideoNodes.en.json b/VideoNodes/VideoNodes.en.json index 03558d94..da936194 100644 --- a/VideoNodes/VideoNodes.en.json +++ b/VideoNodes/VideoNodes.en.json @@ -329,6 +329,19 @@ "2": "No commercials detected" } }, + "FfmpegBuilderCustomParameters": { + "Label": "FFMPEG Builder: Custom Parameters", + "Description": "Lets you add custom parameters to the FFMPEG Builder for execution", + "Outputs": { + "1": "Parameters added" + }, + "Fields": { + "Parameters": "Parameters", + "Parameters-Help": "The parameters to add to the FFMPEG Builder for execution", + "ForceEncode": "Force Encode", + "ForceEncode-Help": "If this should force the FFMPEG Builder Executor to always execute even if no changes are detected that would usually require the executor to run." + } + }, "FfmpegBuilderHdrToSdr": { "Label": "FFMPEG Builder: HDR to SDR", "Description": "Checks if a video stream is HDR and if it is updates the FFMPEG Builder to convert it to SDR",