diff --git a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs index 6d748cc3..0e9f1411 100644 --- a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs +++ b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs @@ -10,12 +10,22 @@ namespace FileFlows.VideoNodes.FfmpegBuilderNodes public override int Outputs => 2; public override FlowElementType Type => FlowElementType.BuildEnd; + public override bool NoEditorOnAdd => true; + + [DefaultValue(true)] + [Boolean(1)] + public bool HardwareDecoding { get; set; } + public override int Execute(NodeParameters args) { this.Init(args); var model = this.Model; List ffArgs = new List(); ffArgs.AddRange(new[] { "-strict", "-2" }); // allow experimental stuff + if (HardwareDecoding) + { + ffArgs.AddRange(GetHardwareDecodingArgs()); + } bool hasChange = false; int actualIndex = 0; int currentType = 0; @@ -70,5 +80,38 @@ namespace FileFlows.VideoNodes.FfmpegBuilderNodes return 1; } + + internal string[] GetHardwareDecodingArgs() + { + string testFile = Path.Combine(args.TempPath, Guid.NewGuid() + ".hwtest.mkv"); + foreach(var hw in new [] { "cuda", "dxva2","qsv","d3d11va","opencl" }) + { + // ffmpeg -y -hwaccel qsvf -f lavfi -i color=color=red -frames:v 10 test.mkv + try + { + var result = args.Execute(new ExecuteArgs + { + ArgumentList = new[] + { + "-y", + "-hwaccel", hw, + "-f", "lavfi", + "-i", "color=color=red", + "-frames:v", "10", + testFile + } + }); + if (result.ExitCode == 0) + { + args.Logger?.ILog("Supported hardware decoding detected: " + hw); + return new[] { "-hwaccel", hw }; + } + } + catch (Exception) { } + } + + args.Logger?.ILog("No hardware decoding availble"); + return new string[] { }; + } } } diff --git a/VideoNodes/VideoNodes.en.json b/VideoNodes/VideoNodes.en.json index 901e82d7..8d968fee 100644 --- a/VideoNodes/VideoNodes.en.json +++ b/VideoNodes/VideoNodes.en.json @@ -157,7 +157,11 @@ "1": "FFMPEG Builder ran successfully and created new temporary file", "2": "No changes detected in FFMPEG Builder, file not created" }, - "Description": "Executes a FFMPEG Builder command created by other FFMPEG Builder nodes." + "Description": "Executes a FFMPEG Builder command created by other FFMPEG Builder nodes.", + "Fields": { + "HardwareDecoding": "Hardware Decoding", + "HardwareDecoding-Help": "If the executor should attempt to use hardware decoding. If not available the execution will proceed just without hardware decoding enabled." + } }, "FfmpegBuilderAudioAddTrack": { "Label": "FFMPEG Builder: Audio Add Track",