Added SW encoding strategies

This commit is contained in:
Samuele Lorefice
2025-12-18 02:11:52 +01:00
parent 6464268253
commit 2ddcfd2edb
2 changed files with 148 additions and 8 deletions

View File

@@ -89,7 +89,7 @@ public class EncoderService : BackgroundService, IEncoderService {
FileName = Path.Combine(options.FfmpegPath, "ffmpeg.exe"),
Arguments = @"-hide_banner -init_hw_device ""list""",
CreateNoWindow = true,
UseShellExecute = true,
UseShellExecute = false,
RedirectStandardOutput = true
};
using Process ffmpeg = Process.Start(psi)!;
@@ -97,12 +97,21 @@ public class EncoderService : BackgroundService, IEncoderService {
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),
EncoderType.AV1 => new AV1EncodingStrategy(file, outputPath, job),
IEncodingStrategy strategy;
if(nvenc) strategy= job.RequestedEncoding switch {
EncoderType.H264 => new H264NvencEncodingStrategy(file, outputPath, job),
EncoderType.HEVC => new HevcNvencEncodingStrategy(file, outputPath, job),
EncoderType.AV1 => new AV1NvencEncodingStrategy(file, outputPath, job),
_ => throw new ArgumentOutOfRangeException(nameof(job), job, null)
};
else strategy = job.RequestedEncoding switch {
EncoderType.H264 => new H264SwEncodingStrategy(file, outputPath, job),
EncoderType.HEVC => new HevcSwEncodingStrategy(file, outputPath, job),
EncoderType.AV1 => new AV1SwEncodingStrategy(file, outputPath, job),
_ => throw new ArgumentOutOfRangeException(nameof(job), job, null)
};
bool result = await strategy.ExecuteAsync(cancellationToken, Progress);
if(result) {