From 6464268253fd8c52b3f32904ac458a583c73f7a0 Mon Sep 17 00:00:00 2001 From: Samuele Lorefice Date: Wed, 17 Dec 2025 21:14:45 +0100 Subject: [PATCH] Added NVDIA gpu check --- .gitignore | 2 ++ Encoder/Encoder.csproj | 13 +++++++++++++ Encoder/EncoderService.cs | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/.gitignore b/.gitignore index 0e4c305..4162bab 100644 --- a/.gitignore +++ b/.gitignore @@ -330,3 +330,5 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser +#FFMPEG binaries +/Encoder/ffmpeg/* \ No newline at end of file diff --git a/Encoder/Encoder.csproj b/Encoder/Encoder.csproj index 59f3754..74bad04 100644 --- a/Encoder/Encoder.csproj +++ b/Encoder/Encoder.csproj @@ -18,4 +18,17 @@ + + + + + + + Always + + + Always + + + diff --git a/Encoder/EncoderService.cs b/Encoder/EncoderService.cs index e7414ec..2d8abbf 100644 --- a/Encoder/EncoderService.cs +++ b/Encoder/EncoderService.cs @@ -1,4 +1,6 @@ +using System.Diagnostics; using FFMpegCore; +using FFMpegCore.Helpers; using Microsoft.Extensions.Options; namespace Encoder; @@ -81,6 +83,20 @@ public class EncoderService : BackgroundService, IEncoderService { job.Status = JobStatus.InProgress; var file = job.FilePath; string outputPath = Path.Combine(options.TemporaryFilesPath, Path.GetFileName(job.FilePath)); + + // Determine if an NVDA graphics card is available for hardware acceleration + ProcessStartInfo psi = new ProcessStartInfo { + FileName = Path.Combine(options.FfmpegPath, "ffmpeg.exe"), + Arguments = @"-hide_banner -init_hw_device ""list""", + CreateNoWindow = true, + UseShellExecute = true, + RedirectStandardOutput = true + }; + using Process ffmpeg = Process.Start(psi)!; + string output = await ffmpeg.StandardOutput.ReadToEndAsync(cancellationToken); + await ffmpeg.WaitForExitAsync(cancellationToken); + bool nvenc = output.Contains("cuda"); + IEncodingStrategy strategy = job.RequestedEncoding switch { EncoderType.H264 => new H264EncodingStrategy(file, outputPath, job), EncoderType.HEVC => new HEVCEncodingStrategy(file, outputPath, job),