diff --git a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs index c8b0ea1d..2bddae00 100644 --- a/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs +++ b/VideoNodes/FfmpegBuilderNodes/FfmpegBuilderExecutor.cs @@ -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); diff --git a/VideoNodes/LogicalNodes/VideoHasErrors.cs b/VideoNodes/LogicalNodes/VideoHasErrors.cs index c826c5c8..7e1def85 100644 --- a/VideoNodes/LogicalNodes/VideoHasErrors.cs +++ b/VideoNodes/LogicalNodes/VideoHasErrors.cs @@ -28,6 +28,13 @@ public class VideoHasErrors: VideoNode /// public override string Icon => "fas fa-exclamation-circle"; + /// + /// Gets or sets if hardware decoding should be used + /// + [DefaultValue(true)] + [Boolean(1)] + public bool HardwareDecoding { get; set; } + /// /// Executes the flow element /// @@ -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 /// /// Validates a video file for errors using FFmpeg. /// + /// the arguments /// The path to the FFmpeg executable. /// The path to the video file to be validated. + /// The video information for the current file + /// If hardware decoding should be attempted /// /// A tuple containing a boolean indicating whether there are no errors (NoErrors) /// and a log message (Log) from FFmpeg. /// - 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 { diff --git a/VideoNodes/VideoNodes.en.json b/VideoNodes/VideoNodes.en.json index b0cb8ec6..4fd38a00 100644 --- a/VideoNodes/VideoNodes.en.json +++ b/VideoNodes/VideoNodes.en.json @@ -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": {