Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Adds hevc profile support
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Cordeiro committed Dec 29, 2023
1 parent 292674c commit 8cd548d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Wasari.Cli/Commands/DownloadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ public DownloadCommand(EnvironmentService environmentService, ILogger<DownloadCo
[CommandOption("file-container", Description = "File container to use for final video file")]
public string FileContainer { get; set; } = "mkv";

[CommandOption("hevc-profile", Description = "HEVC profile to use for encoding")]
public HevcProfile HevcProfile { get; set; } = HevcProfile.Medium;

[CommandOption("hevc-quality-min", Description = "Minimum quality to use for HEVC encoding, only used if HEVC profile is set to Custom")]
public int? HevcQualityMin { get; set; }

[CommandOption("hevc-quality-max", Description = "Maximum quality to use for HEVC encoding, only used if HEVC profile is set to Custom")]
public int? HevcQualityMax { get; set; }

private EnvironmentService EnvironmentService { get; }

private ILogger<DownloadCommand> Logger { get; }
Expand Down Expand Up @@ -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<AuthenticationOptions>(o =>
{
Expand Down
6 changes: 6 additions & 0 deletions Wasari.FFmpeg/FFmpegOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
15 changes: 13 additions & 2 deletions Wasari.FFmpeg/FFmpegService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public FFmpegService(ILogger<FFmpegService> logger, IOptions<FFmpegOptions> 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<IFFmpegShader> shaders)
{
Expand Down Expand Up @@ -147,11 +156,13 @@ private async IAsyncEnumerable<string> 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";
}
Expand Down
3 changes: 3 additions & 0 deletions Wasari.FFmpeg/HevcOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Wasari.FFmpeg;

internal record HevcOptions(int Qmin, int Qmax);
9 changes: 9 additions & 0 deletions Wasari.FFmpeg/HevcProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Wasari.FFmpeg;

public enum HevcProfile
{
High,
Medium,
Low,
Custom
}

0 comments on commit 8cd548d

Please sign in to comment.