fix quality parameter for vaapi

Hardware encoders has different expectations about quality input. VAAPI's mjpeg encoder excepts JPEG quality divided by QP2LAMBDA as input.

Signed-off-by: gnattu <gnattuoc@me.com>
pull/11675/head
gnattu 6 months ago
parent 8aee50020b
commit 20a1da1855

@ -871,6 +871,15 @@ namespace MediaBrowser.MediaEncoding.Encoder
throw new InvalidOperationException("Empty or invalid input argument.");
}
float? encoderQuality = qualityScale;
if (vidEncoder.Contains("vaapi", StringComparison.InvariantCultureIgnoreCase))
{
// vaapi's mjpeg encoder uses jpeg quality divided by QP2LAMBDA (118) as input, instead of ffmpeg defined qscale
// ffmpeg qscale is a value from 1-31, with 1 being best quality and 31 being worst
// jpeg quality is a value from 0-100, with 0 being worst quality and 100 being best
encoderQuality = (100 - ((qualityScale - 1) * (100 / 30))) / 118;
}
// Output arguments
var targetDirectory = Path.Combine(_configurationManager.ApplicationPaths.TempDirectory, Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(targetDirectory);
@ -884,7 +893,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
filterParam,
outputThreads.GetValueOrDefault(_threads),
vidEncoder,
qualityScale.HasValue ? "-qscale:v " + qualityScale.Value.ToString(CultureInfo.InvariantCulture) + " " : string.Empty,
qualityScale.HasValue ? "-qscale:v " + encoderQuality.Value.ToString(CultureInfo.InvariantCulture) + " " : string.Empty,
"image2",
outputPath);

Loading…
Cancel
Save