diff options
| author | Bond-009 <bond.009@outlook.com> | 2026-03-03 20:34:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 20:34:05 +0100 |
| commit | e378f63b70a61cd63d5dee92960cc1c24bfc0646 (patch) | |
| tree | df3f800d68cc8b030255e265c7b5cf0e4ebeeeeb /MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | |
| parent | e4500303bb59cd8671af8634881efd8548d8e86a (diff) | |
| parent | d87fe973f3516e20ae4c4ecd8036286deeb4b51d (diff) | |
Merge pull request #16318 from NoFear0411/fix-sar-anamorphic-detection
Fix near-1:1 SAR values falsely flagged as anamorphic
Diffstat (limited to 'MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs')
| -rw-r--r-- | MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index dbe532289..127bdd380 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -863,7 +863,7 @@ namespace MediaBrowser.MediaEncoding.Probing { stream.IsAnamorphic = false; } - else if (string.Equals(streamInfo.SampleAspectRatio, "1:1", StringComparison.Ordinal)) + else if (IsNearSquarePixelSar(streamInfo.SampleAspectRatio)) { stream.IsAnamorphic = false; } @@ -1155,6 +1155,34 @@ namespace MediaBrowser.MediaEncoding.Probing } /// <summary> + /// Determines whether a sample aspect ratio represents square (or near-square) pixels. + /// Some encoders produce SARs like 3201:3200 for content that is effectively 1:1, + /// which would be falsely classified as anamorphic by an exact string comparison. + /// A 1% tolerance safely covers encoder rounding artifacts while preserving detection + /// of genuine anamorphic content (closest standard is PAL 4:3 at 16:15 = 6.67% off). + /// </summary> + /// <param name="sar">The sample aspect ratio string in "N:D" format.</param> + /// <returns><c>true</c> if the SAR is within 1% of 1:1; otherwise <c>false</c>.</returns> + internal static bool IsNearSquarePixelSar(string sar) + { + if (string.IsNullOrEmpty(sar)) + { + return false; + } + + var parts = sar.Split(':'); + if (parts.Length == 2 + && double.TryParse(parts[0], CultureInfo.InvariantCulture, out var num) + && double.TryParse(parts[1], CultureInfo.InvariantCulture, out var den) + && den > 0) + { + return IsClose(num / den, 1.0, 0.01); + } + + return string.Equals(sar, "1:1", StringComparison.Ordinal); + } + + /// <summary> /// Gets a frame rate from a string value in ffprobe output /// This could be a number or in the format of 2997/125. /// </summary> |
