Added support for hardware decoding in ffmpeg builder executor

This commit is contained in:
John Andrews
2022-04-25 12:56:41 +12:00
parent 4d7662b861
commit b0fc1ccea4
2 changed files with 48 additions and 1 deletions
@@ -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<string> ffArgs = new List<string>();
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[] { };
}
}
}
+5 -1
View File
@@ -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",