FF-1227 - added hw decoding to has errors

This commit is contained in:
John Andrews
2024-01-28 09:41:18 +13:00
parent d188dd0305
commit 1d443e8629
3 changed files with 54 additions and 13 deletions
@@ -189,7 +189,10 @@ public class FfmpegBuilderExecutor: FfmpegBuilderNode
// else
{
args.Logger?.ILog("Auto-detecting hardware decoder to use");
startArgs.AddRange(GetHardwareDecodingArgs(args, localFile));
var video = this.Model.VideoStreams.FirstOrDefault(x => x.Stream.IsImage == false);
startArgs.AddRange(GetHardwareDecodingArgs(args, localFile, FFMPEG, video?.Stream?.Codec));
}
}
@@ -254,14 +257,13 @@ public class FfmpegBuilderExecutor: FfmpegBuilderNode
return 1;
}
internal string[] GetHardwareDecodingArgs(NodeParameters args, string localFile)
internal static string[] GetHardwareDecodingArgs(NodeParameters args, string localFile, string ffmpeg, string codec)
{
string testFile = FileHelper.Combine(args.TempPath, Guid.NewGuid() + ".hwtest.mkv");
var video = this.Model.VideoStreams.FirstOrDefault(x => x.Stream.IsImage == false);
if (string.IsNullOrWhiteSpace(video?.Stream?.Codec))
if (string.IsNullOrWhiteSpace(codec))
return new string[] { };
bool isH264 = video.Stream.Codec.Contains("264");
bool isHevc = video.Stream.Codec.Contains("265") || video.Stream.Codec.ToLower().Contains("hevc");
bool isH264 = codec.Contains("264");
bool isHevc = codec.Contains("265") || codec.ToLowerInvariant().Contains("hevc");
var decoders = isH264 ? Decoders_h264(args) :
isHevc ? Decoders_hevc(args) :
@@ -294,7 +296,7 @@ public class FfmpegBuilderExecutor: FfmpegBuilderNode
var result = args.Execute(new ExecuteArgs
{
Command = FFMPEG,
Command = ffmpeg,
ArgumentList = arguments.ToArray()
});
if (result.ExitCode == 0)
@@ -328,7 +330,7 @@ public class FfmpegBuilderExecutor: FfmpegBuilderNode
private static readonly bool IsMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
private string[][] Decoders_h264(NodeParameters args)
private static string[][] Decoders_h264(NodeParameters args)
{
bool noNvidia =
args.Variables.Any(x => x.Key?.ToLowerInvariant() == "nonvidia" && x.Value as bool? == true);
@@ -367,7 +369,7 @@ public class FfmpegBuilderExecutor: FfmpegBuilderNode
};
}
private string[][] Decoders_hevc(NodeParameters args)
private static string[][] Decoders_hevc(NodeParameters args)
{
bool noNvidia =
args.Variables.Any(x => x.Key?.ToLowerInvariant() == "nonvidia" && x.Value as bool? == true);
@@ -406,7 +408,7 @@ public class FfmpegBuilderExecutor: FfmpegBuilderNode
};
}
private string[][] Decoders_Default(NodeParameters args)
private static string[][] Decoders_Default(NodeParameters args)
{
bool noNvidia =
args.Variables.Any(x => x.Key?.ToLowerInvariant() == "nonvidia" && x.Value as bool? == true);
+38 -3
View File
@@ -28,6 +28,13 @@ public class VideoHasErrors: VideoNode
/// </summary>
public override string Icon => "fas fa-exclamation-circle";
/// <summary>
/// Gets or sets if hardware decoding should be used
/// </summary>
[DefaultValue(true)]
[Boolean(1)]
public bool HardwareDecoding { get; set; }
/// <summary>
/// Executes the flow element
/// </summary>
@@ -41,7 +48,10 @@ public class VideoHasErrors: VideoNode
args.Logger?.ILog("Failed to get file: " + file.Error);
return -1;
}
var result = ValidateFile(FFMPEG, file);
var videoInfo = GetVideoInfo(args);
var result = ValidateFile(args, FFMPEG, file, videoInfo, useHardwareDecoding: HardwareDecoding);
if (result.NoErrors)
return 2;
@@ -52,28 +62,53 @@ public class VideoHasErrors: VideoNode
/// <summary>
/// Validates a video file for errors using FFmpeg.
/// </summary>
/// <param name="args">the arguments</param>
/// <param name="ffmpegPath">The path to the FFmpeg executable.</param>
/// <param name="filename">The path to the video file to be validated.</param>
/// <param name="info">The video information for the current file</param>
/// <param name="useHardwareDecoding">If hardware decoding should be attempted</param>
/// <returns>
/// A tuple containing a boolean indicating whether there are no errors (NoErrors)
/// and a log message (Log) from FFmpeg.
/// </returns>
public static (bool NoErrors, string Log) ValidateFile(string ffmpegPath, string filename)
public static (bool NoErrors, string Log) ValidateFile(NodeParameters args, string ffmpegPath, string filename, VideoInfo info, bool useHardwareDecoding)
{
if (System.IO.File.Exists(ffmpegPath) == false)
return (false, "FFmpeg does not exist at the specified path.");
if (System.IO.File.Exists(filename) == false)
return (false, "The input file does not exist.");
var video = info.VideoStreams.FirstOrDefault(x => x.IsImage == false);
var processStartInfo = new ProcessStartInfo
{
FileName = ffmpegPath,
ArgumentList = { "-v", "error", "-i", filename, "-f", "null", "-" },
//ArgumentList = { "-v", "error", "-i", filename, "-f", "null", "-" },
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
processStartInfo.ArgumentList.Add("-v");
processStartInfo.ArgumentList.Add("error");
if (useHardwareDecoding)
{
var hardwareDecodingArgs =
FfmpegBuilderNodes.FfmpegBuilderExecutor.GetHardwareDecodingArgs(args, filename, ffmpegPath,
video?.Codec);
if (hardwareDecodingArgs?.Any() == true)
{
foreach (var hwArg in hardwareDecodingArgs)
processStartInfo.ArgumentList.Add(hwArg);
}
}
processStartInfo.ArgumentList.Add("-i");
processStartInfo.ArgumentList.Add(filename);
processStartInfo.ArgumentList.Add("-f");
processStartInfo.ArgumentList.Add("null");
processStartInfo.ArgumentList.Add("-");
Process process = new Process
{
+4
View File
@@ -656,6 +656,10 @@
"Outputs": {
"1": "Contains an error",
"2": "Did not detect any errors"
},
"Fields": {
"HardwareDecoding": "Hardware Decoding",
"HardwareDecoding-Help": "If the an attempt to use hardware decoding should be made. If not available the execution will proceed just without hardware decoding enabled."
}
},
"VideoHasStream": {