PR #23391 opened by Jun Zhao (mypopydev) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23391 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23391.patch
Per ITU-T H.264 (ISO/IEC 14496-10) Annex E.2.1 and ITU-T H.265 (ISO/IEC 23008-2) Annex E.3.1, when sar_width or sar_height is zero the sample aspect ratio shall be considered unspecified. Internally ffmpeg represents an unspecified SAR as 0/1, while fractions with a zero denominator are not handled properly (den=0 is silently changed to den=1 in h264_ps.c, turning an invalid 20480/0 into a "valid" but impossibly extreme 20480/1); so we bridge the gap by replacing x/0 with 0/1. An av_log warning is added so an invalid SAR in the bitstream is diagnosed rather than silently overwritten. This fixes a problem with some video files provided by game OddBallers when executed with Wine/Proton, which report SAR 20480/0. Based on patch by Giovanni Mascellani <[email protected]>. Fixes: ticket #23321 Signed-off-by: Jun Zhao <[email protected]> >From 052ecc6244f39023be54f5a2eb51d8075b1dc4d9 Mon Sep 17 00:00:00 2001 From: Jun Zhao <[email protected]> Date: Sun, 7 Jun 2026 18:38:05 +0800 Subject: [PATCH] avcodec/h2645_vui: interpret a degenerate SAR as unspecified Per ITU-T H.264 (ISO/IEC 14496-10) Annex E.2.1 and ITU-T H.265 (ISO/IEC 23008-2) Annex E.3.1, when sar_width or sar_height is zero the sample aspect ratio shall be considered unspecified. Internally ffmpeg represents an unspecified SAR as 0/1, while fractions with a zero denominator are not handled properly (den=0 is silently changed to den=1 in h264_ps.c, turning an invalid 20480/0 into a "valid" but impossibly extreme 20480/1); so we bridge the gap by replacing x/0 with 0/1. An av_log warning is added so an invalid SAR in the bitstream is diagnosed rather than silently overwritten. This fixes a problem with some video files provided by game OddBallers when executed with Wine/Proton, which report SAR 20480/0. Based on patch by Giovanni Mascellani <[email protected]>. Fixes: ticket #23321 Signed-off-by: Jun Zhao <[email protected]> --- libavcodec/h2645_vui.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/h2645_vui.c b/libavcodec/h2645_vui.c index 0e576c1563..fb16ec99e6 100644 --- a/libavcodec/h2645_vui.c +++ b/libavcodec/h2645_vui.c @@ -46,6 +46,12 @@ void ff_h2645_decode_common_vui_params(GetBitContext *gb, H2645VUI *vui, void *l else if (vui->aspect_ratio_idc == EXTENDED_SAR) { vui->sar.num = get_bits(gb, 16); vui->sar.den = get_bits(gb, 16); + if (!vui->sar.num || !vui->sar.den) { + av_log(logctx, AV_LOG_WARNING, + "Invalid SAR %d/%d in bitstream, treating as unspecified.\n", + vui->sar.num, vui->sar.den); + vui->sar = (AVRational){ 0, 1 }; + } } else av_log(logctx, AV_LOG_WARNING, "Unknown SAR index: %u.\n", vui->aspect_ratio_idc); -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
