diff --git a/media/src/services/mediainfo.py b/media/src/services/mediainfo.py index eb4722c..0cfd607 100644 --- a/media/src/services/mediainfo.py +++ b/media/src/services/mediainfo.py @@ -9,6 +9,19 @@ class MediaInfoService: def get_info(file_path: Path): return {} + @staticmethod + def classify_resolution(width: int, height: int) -> str: + """按宽高综合判定画质档位。 + + 不能只看高度:2.39:1 的 4K 片源裁掉黑边后高度只有 ~1608, + 用 h>2000 会把 3840×1608 误判成 1080p。宽度才是可靠判据。 + """ + if width >= 3000 or height >= 1600: + return "2160p" + if width >= 1700 or height >= 900: + return "1080p" + return "720p" + @staticmethod def get_scene_tags(f_path: Path): """ @@ -32,12 +45,14 @@ class MediaInfoService: v_stream = next((s for s in data.get('streams', []) if s['codec_type'] == 'video'), {}) - h = int(v_stream.get('height', 1080)) if v_stream.get('height') else 1080 - - if (h > 2000 and mbps > config.REMUX_BITRATE_4K) or (h <= 2000 and mbps > config.REMUX_BITRATE_1080P): - tags['is_remux'] = True + w = int(v_stream.get('width') or 0) + h = int(v_stream.get('height') or 1080) - tags['res'] = "2160p" if h > 2000 else ("1080p" if h > 700 else "720p") + tags['res'] = MediaInfoService.classify_resolution(w, h) + remux_threshold = (config.REMUX_BITRATE_4K if tags['res'] == "2160p" + else config.REMUX_BITRATE_1080P) + if mbps > remux_threshold: + tags['is_remux'] = True codec_name = v_stream.get('codec_name', '') if '265' in codec_name or 'hevc' in codec_name: