diff --git a/media/src/services/mediainfo.py b/media/src/services/mediainfo.py index 72d6eea..ca05418 100644 --- a/media/src/services/mediainfo.py +++ b/media/src/services/mediainfo.py @@ -11,30 +11,35 @@ class MediaInfoService: @staticmethod def classify_resolution(width: int, height: int) -> str: - """按宽高综合判定画质档位。 + """按宽高综合判定画质档位(覆盖 8K ~ 360p)。 - 要点: - - 以「宽度」为主判据:2.39:1 的 4K 片源裁掉黑边后高度只有 ~1608, - 用 h>2000 会误判成 1080p; - - 但不能只看高度下限:2560×1920 这类 4:3 老片其实只有 1080p 档, - 用 h>=1600 会误报成 2160p; - - 4:3 的 1440×1080 宽度不够 1700,靠高度 >=900 补回 1080p; - - 竖屏(手机直拍 1080×1920)先翻转成横向再判。 + 1. 竖屏(手机直拍 1080×1920)先翻转成横向; + 2. 折算「等效 16:9 高度」v = max(h, w*9/16): + - 2.39:1 的 4K 裁切(3840×1608)v=2160 → 仍判 2160p; + - 16:9 片源 v 就是真实高度; + - 4:3 片源 v 取真实高度(2560×1920 → v=1920,不会误报 4K); + 3. 再按 v 落档:8K / 4K / 1440p / 1080p / 720p / 576p / 480p / 360p。 """ if height > width: # 竖屏 → 按横向处理 width, height = height, width - if width >= 3000: # 3840 / 4096 宽的 4K - return "2160p" - if width >= 1700: # 1920 宽(含 1920×800 等 scope) + equivalent = max(height, round(width * 9 / 16)) + + if equivalent >= 4000: + return "4320p" # 8K + if equivalent >= 2000: + return "2160p" # 4K(含 2.39:1 裁切) + if equivalent >= 1400: + return "1440p" # 2K / 4:3 的 2560×1920 + if equivalent >= 1000: return "1080p" - if height >= 900: # 4:3 的 1440×1080 - return "1080p" - if width >= 1000: # 1280×720 / 1024×576 + if equivalent >= 700: return "720p" - if height >= 600: - return "720p" - return "480p" + if equivalent >= 520: + return "576p" # 1024×576 一类 + if equivalent >= 400: + return "480p" + return "360p" @staticmethod def get_scene_tags(f_path: Path):