Added NVDIA gpu check

This commit is contained in:
Samuele Lorefice
2025-12-17 21:14:45 +01:00
parent fc915be3aa
commit 6464268253
3 changed files with 31 additions and 0 deletions

2
.gitignore vendored
View File

@@ -330,3 +330,5 @@ fabric.properties
# Android studio 3.1+ serialized cache file # Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser .idea/caches/build_file_checksums.ser
#FFMPEG binaries
/Encoder/ffmpeg/*

View File

@@ -18,4 +18,17 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="ffmpeg\" />
</ItemGroup>
<ItemGroup>
<None Update="ffmpeg\ffmpeg.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ffmpeg\ffprobe.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@@ -1,4 +1,6 @@
using System.Diagnostics;
using FFMpegCore; using FFMpegCore;
using FFMpegCore.Helpers;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace Encoder; namespace Encoder;
@@ -81,6 +83,20 @@ public class EncoderService : BackgroundService, IEncoderService {
job.Status = JobStatus.InProgress; job.Status = JobStatus.InProgress;
var file = job.FilePath; var file = job.FilePath;
string outputPath = Path.Combine(options.TemporaryFilesPath, Path.GetFileName(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 { IEncodingStrategy strategy = job.RequestedEncoding switch {
EncoderType.H264 => new H264EncodingStrategy(file, outputPath, job), EncoderType.H264 => new H264EncodingStrategy(file, outputPath, job),
EncoderType.HEVC => new HEVCEncodingStrategy(file, outputPath, job), EncoderType.HEVC => new HEVCEncodingStrategy(file, outputPath, job),