From f8da69f8e5a9e88d1829f174354d4c5841e03da9 Mon Sep 17 00:00:00 2001 From: gnattu Date: Thu, 23 May 2024 23:02:57 +0800 Subject: [PATCH] Allow decimal aspect ratio Signed-off-by: gnattu --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 387571cdb5..e478fb97fe 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -828,15 +828,15 @@ namespace MediaBrowser.MediaEncoding.Encoder { // 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)); + var (wa, ha) = (double.Parse(darParts[0], CultureInfo.InvariantCulture), double.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; + var shouldResetHeight = Math.Abs((imageStream.Width.Value * ha) - (imageStream.Height.Value * wa)) > .05; 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); + imageStream.Height = Convert.ToInt32(imageStream.Width.Value * ha / wa); } }