diff --git a/Wasari.Cli/Commands/DownloadCommand.cs b/Wasari.Cli/Commands/DownloadCommand.cs index 4408871..3207c57 100644 --- a/Wasari.Cli/Commands/DownloadCommand.cs +++ b/Wasari.Cli/Commands/DownloadCommand.cs @@ -112,6 +112,15 @@ public DownloadCommand(EnvironmentService environmentService, ILogger Logger { get; } @@ -166,6 +175,9 @@ public async ValueTask ExecuteAsync(IConsole console) o.Resolution = Resolution; o.Threads = FfmpegThreads; o.FileContainer = FileContainer; + o.HevcProfile = HevcProfile; + o.HevcQualityMin = HevcQualityMin; + o.HevcQualityMax = HevcQualityMax; }); serviceCollection.Configure(o => { diff --git a/Wasari.Daemon/Options/NotificationOptions.cs b/Wasari.Daemon/Options/DaemonOptions.cs similarity index 100% rename from Wasari.Daemon/Options/NotificationOptions.cs rename to Wasari.Daemon/Options/DaemonOptions.cs diff --git a/Wasari.FFmpeg/FFmpegOptions.cs b/Wasari.FFmpeg/FFmpegOptions.cs index 83d914b..0eddcce 100644 --- a/Wasari.FFmpeg/FFmpegOptions.cs +++ b/Wasari.FFmpeg/FFmpegOptions.cs @@ -17,4 +17,10 @@ public record FFmpegOptions public bool UseTemporaryEncodingPath { get; set; } public int? Threads { get; set; } + + public HevcProfile HevcProfile { get; set; } = HevcProfile.Medium; + + public int? HevcQualityMin { get; set; } + + public int? HevcQualityMax { get; set; } } \ No newline at end of file diff --git a/Wasari.FFmpeg/FFmpegService.cs b/Wasari.FFmpeg/FFmpegService.cs index 3c0183c..c1323a5 100644 --- a/Wasari.FFmpeg/FFmpegService.cs +++ b/Wasari.FFmpeg/FFmpegService.cs @@ -30,6 +30,15 @@ public FFmpegService(ILogger logger, IOptions opti private EnvironmentService EnvironmentService { get; } private IServiceProvider Provider { get; } + + private HevcOptions GetHevcOptions() => Options.Value.HevcProfile switch + { + HevcProfile.High => new HevcOptions(18, 18), + HevcProfile.Medium => new HevcOptions(24, 24), + HevcProfile.Low => new HevcOptions(30, 30), + HevcProfile.Custom => new HevcOptions(Options.Value.HevcQualityMin ?? 24, Options.Value.HevcQualityMax ?? 24), + _ => throw new ArgumentOutOfRangeException() + }; private static FileInfo CompileShaders(IEnumerable shaders) { @@ -147,11 +156,13 @@ private async IAsyncEnumerable BuildArgumentsForEpisode(IWasariEpisode e { if(Options.Value is { UseNvidiaAcceleration: true, UseAmdAcceleration: true } && EnvironmentService.IsFeatureAvailable(EnvironmentFeatureType.NvidiaGpu, EnvironmentFeatureType.AmdGpu)) throw new MultipleEncodersException("Cannot use both Nvidia and AMD acceleration at the same time"); + + var hevcOptions = GetHevcOptions(); if (Options.Value.UseNvidiaAcceleration && EnvironmentService.IsFeatureAvailable(EnvironmentFeatureType.NvidiaGpu)) - yield return "-c:v hevc_nvenc -rc vbr -cq 24 -qmin 24 -qmax 24 -profile:v main10 -pix_fmt p010le"; + yield return $"-c:v hevc_nvenc -rc vbr -qmin {hevcOptions.Qmin} -qmax {hevcOptions.Qmax} -profile:v main10 -pix_fmt p010le"; else if(Options.Value.UseAmdAcceleration && EnvironmentService.IsFeatureAvailable(EnvironmentFeatureType.AmdGpu)) - yield return "-c:v hevc_amf -rc cbr -qmin 24 -qmax 24 -pix_fmt p010le"; + yield return $"-c:v hevc_amf -rc cbr -qmin {hevcOptions.Qmin} -qmax {hevcOptions.Qmax} -pix_fmt p010le"; else yield return "-crf 20 -pix_fmt yuv420p10le -c:v libx265 -tune animation -x265-params profile=main10"; } diff --git a/Wasari.FFmpeg/HevcOptions.cs b/Wasari.FFmpeg/HevcOptions.cs new file mode 100644 index 0000000..cd7726e --- /dev/null +++ b/Wasari.FFmpeg/HevcOptions.cs @@ -0,0 +1,3 @@ +namespace Wasari.FFmpeg; + +internal record HevcOptions(int Qmin, int Qmax); \ No newline at end of file diff --git a/Wasari.FFmpeg/HevcProfile.cs b/Wasari.FFmpeg/HevcProfile.cs new file mode 100644 index 0000000..734ecfa --- /dev/null +++ b/Wasari.FFmpeg/HevcProfile.cs @@ -0,0 +1,9 @@ +namespace Wasari.FFmpeg; + +public enum HevcProfile +{ + High, + Medium, + Low, + Custom +} \ No newline at end of file