Recalculate trickplay image height for anamorphic videos

Signed-off-by: gnattu <gnattuoc@me.com>
This commit is contained in:
gnattu
2024-05-08 08:33:23 +08:00
parent 06a5ddda5e
commit c6e29647fc
2 changed files with 33 additions and 10 deletions

View File

@@ -824,6 +824,22 @@ namespace MediaBrowser.MediaEncoding.Encoder
options.EnableTonemapping = false;
}
if (imageStream.Width is not null && imageStream.Height is not null)
{
// For hardware trickplay encoders, we need to re-calculate the size because they used fixed scale dimensions
var darParts = imageStream.AspectRatio.Split(":");
var (wa, ha) = (int.Parse(darParts[0], CultureInfo.InvariantCulture), int.Parse(darParts[1], CultureInfo.InvariantCulture));
// When dimension / DAR does not equal to 1:1, then the frames are most likely stored stretched.
// Note: this might be incorrect for 3D videos as the SAR stored might be per eye instead of per video, but we really can do little about it.
var shouldResetHeight = imageStream.Width * ha != imageStream.Height * wa;
if (shouldResetHeight)
{
// SAR = DAR * Height / Width
// RealHeight = Height / SAR = Height / (DAR * Height / Width) = Width / DAR
imageStream.Height = Convert.ToInt32(imageStream.Width.Value * (double)ha / wa);
}
}
var baseRequest = new BaseEncodingJobOptions { MaxWidth = maxWidth, MaxFramerate = (float)(1.0 / interval.TotalSeconds) };
var jobState = new EncodingJobInfo(TranscodingJobType.Progressive)
{