diff --git a/BasicNodes/BasicNodes.csproj b/BasicNodes/BasicNodes.csproj index 1cfd3366..f333d63a 100644 Binary files a/BasicNodes/BasicNodes.csproj and b/BasicNodes/BasicNodes.csproj differ diff --git a/Builds/BasicNodes.zip b/Builds/BasicNodes.zip deleted file mode 100644 index b66d5892..00000000 Binary files a/Builds/BasicNodes.zip and /dev/null differ diff --git a/Builds/MetaNodes.zip b/Builds/MetaNodes.zip deleted file mode 100644 index 753dc169..00000000 Binary files a/Builds/MetaNodes.zip and /dev/null differ diff --git a/Builds/VideoNodes.zip b/Builds/VideoNodes.zip deleted file mode 100644 index ffb0f205..00000000 Binary files a/Builds/VideoNodes.zip and /dev/null differ diff --git a/FileFlows.Plugin.dll b/FileFlows.Plugin.dll index 7130055c..0917a19d 100644 Binary files a/FileFlows.Plugin.dll and b/FileFlows.Plugin.dll differ diff --git a/FileFlows.Plugin.pdb b/FileFlows.Plugin.pdb index 8e93f588..28e2ff63 100644 Binary files a/FileFlows.Plugin.pdb and b/FileFlows.Plugin.pdb differ diff --git a/MetaNodes/MetaNodes.csproj b/MetaNodes/MetaNodes.csproj index 43d22413..28117d51 100644 Binary files a/MetaNodes/MetaNodes.csproj and b/MetaNodes/MetaNodes.csproj differ diff --git a/VideoNodes/LogicalNodes/DetectBlackBars.cs b/VideoNodes/LogicalNodes/DetectBlackBars.cs index 4088925a..7a0c03bb 100644 --- a/VideoNodes/LogicalNodes/DetectBlackBars.cs +++ b/VideoNodes/LogicalNodes/DetectBlackBars.cs @@ -29,7 +29,7 @@ namespace FileFlows.VideoNodes if (crop == string.Empty) return 2; - args.Logger.ILog("Black bars detected, crop: " + crop); + args.Logger?.ILog("Black bars detected, crop: " + crop); args.Parameters.Add(CROP_KEY, crop); return 1; diff --git a/VideoNodes/Tests/VideoInfoHelperTests.cs b/VideoNodes/Tests/VideoInfoHelperTests.cs index 3651ee5f..763d38d1 100644 --- a/VideoNodes/Tests/VideoInfoHelperTests.cs +++ b/VideoNodes/Tests/VideoInfoHelperTests.cs @@ -20,6 +20,7 @@ namespace VideoNodes.Tests vi.Read(@"D:\videos\unprocessed\Hellboy 2019 Bluray-1080p.mp4"); } + [TestMethod] public void VideoInfoTest_SubtitleRemover() { @@ -43,6 +44,37 @@ namespace VideoNodes.Tests Assert.AreEqual(1, output); } + + [TestMethod] + public void VideoInfoTest_DetectBlackBars() + { + 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"); + + var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger()); + args.GetToolPath = (string tool) => @"C:\utils\ffmpeg\ffmpeg.exe"; + args.TempPath = @"D:\videos\temp"; + + int result = new DetectBlackBars().Execute(args); + + Assert.IsTrue(result > 0); + + } + [TestMethod] + public void VideoInfoTest_NvidiaCard() + { + const string file = @"D:\videos\unprocessed\Bourne.mkv"; + const string ffmpeg = @"C:\utils\ffmpeg\ffmpeg.exe"; + var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger()); + //args.Process = new FileFlows.Plugin.ProcessHelper(args.Logger); + + var node = new VideoEncode(); + node.SetArgs(args); + bool result = node.HasNvidiaCard(ffmpeg); + + Assert.IsTrue(result); + } } } diff --git a/VideoNodes/VideoNodes.csproj b/VideoNodes/VideoNodes.csproj index 9c54a1f0..6c3c502f 100644 Binary files a/VideoNodes/VideoNodes.csproj and b/VideoNodes/VideoNodes.csproj differ diff --git a/VideoNodes/VideoNodes/VideoEncode.cs b/VideoNodes/VideoNodes/VideoEncode.cs index 0dd022b1..744f0f7f 100644 --- a/VideoNodes/VideoNodes/VideoEncode.cs +++ b/VideoNodes/VideoNodes/VideoEncode.cs @@ -1,6 +1,7 @@ namespace FileFlows.VideoNodes { using System.ComponentModel; + using System.Diagnostics; using System.Text.RegularExpressions; using FileFlows.Plugin; using FileFlows.Plugin.Attributes; @@ -116,7 +117,10 @@ namespace FileFlows.VideoNodes List ffArgs = new List(); if (videoIsRightCodec == null || crop != string.Empty) + { + string codecParameters = CheckVideoCodec(ffmpegExe, VideoCodecParameters); ffArgs.Add($"-map 0:v:0 -c:v {VideoCodecParameters} {crop}"); + } else ffArgs.Add($"-map 0:v:0 -c:v copy"); @@ -156,6 +160,93 @@ namespace FileFlows.VideoNodes } } +#if(DEBUG) + /// + /// Used for unit tests + /// + /// the args + public void SetArgs(NodeParameters args) + { + this.args = args; + } +#endif + + public string CheckVideoCodec(string ffmpeg, string vidparams) + { + if (string.IsNullOrEmpty(vidparams)) + return string.Empty; + if (vidparams.ToLower().Contains("hevc_nvenc")) + { + // nvidia h265 encoding, check can + bool nvidia = HasNvidiaCard(ffmpeg); + if(nvidia == false) + { + // change to cpu encoding + args.Logger?.ILog("No NVIDIA card detected, falling back to CPU encoding H265 (libx265)"); + return "libx265"; + } + return vidparams; + } + else if (vidparams.ToLower().Contains("h264_nvenc")) + { + // nvidia h265 encoding, check can + bool nvidia = HasNvidiaCard(ffmpeg); + if (nvidia == false) + { + // change to cpu encoding + args.Logger?.ILog("No NVIDIA card detected, falling back to CPU encoding H264 (libx264)"); + return "libx264"; + } + return vidparams; + } + return vidparams; + } + + public bool HasNvidiaCard(string ffmpeg) + { + try + { + if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) + { + var cmd = args.Process.ExecuteShellCommand(new ExecuteArgs + { + Command = "wmic", + Arguments = "path win32_VideoController get name" + }).Result; + if(cmd.ExitCode == 0) + { + // it worked + if (cmd.Output?.ToLower()?.Contains("nvidia") == false) + return false; + } + } + else + { + // linux, crude method, look for nvidia in the /dev dir + var dir = new DirectoryInfo("/dev"); + if (dir.Exists == false) + return false; + + bool dev = dir.GetDirectories().Any(x => x.Name.ToLower().Contains("nvidia")); + if (dev == false) + return false; + } + + // check cuda in ffmpeg itself + var result = args.Process.ExecuteShellCommand(new ExecuteArgs + { + Command = ffmpeg, + Arguments = "-hide_banner -init_hw_device list" + }).Result; + return result.Output?.Contains("cuda") == true; + } + catch (Exception ex) + { + args.Logger?.ELog("Failed to detect NVIDIA card: " + ex.Message + Environment.NewLine + ex.StackTrace); + return false; + } + } + protected bool IsSameVideoCodec(string current, string wanted) { wanted = ReplaceCommon(wanted); diff --git a/plugins.json b/plugins.json index eab92be6..6fb22ad8 100644 --- a/plugins.json +++ b/plugins.json @@ -1,17 +1,17 @@ [ { "Name": "BasicNodes", - "Version": "0.0.1.33", + "Version": "0.0.1.34", "Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/BasicNodes.zip?raw=true" }, { "Name": "MetaNodes", - "Version": "0.0.1.33", + "Version": "0.0.1.34", "Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/MetaNodes.zip?raw=true" }, { "Name": "VideoNodes", - "Version": "0.0.1.33", + "Version": "0.0.1.34", "Package": "https://github.com/revenz/FileFlowsPlugins/blob/master/Builds/VideoNodes.zip?raw=true" } ]