/** * 根据视频比例计算输出分辨率 * * 规则: * - 长边固定 1920 * - 短边按 1920 × (短/长) 计算,对齐到偶数 * - 9:16 → 1080×1920(竖屏) * - 16:9 → 1920×1080(横屏) * - 1:1 → 1920×1920 * - 无法解析时 fallback 到 1080×1920 */ export interface Resolution { width: number height: number } export function calculateResolution(ratio: string): Resolution { if (!ratio) return { width: 1080, height: 1920 } if (ratio.includes(":")) { const [rw, rh] = ratio.split(":").map(Number) if (rw > 0 && rh > 0) { const [longSide, shortSide] = rw < rh ? [rh, rw] : [rw, rh] const baseLong = 1920 const baseShort = Math.round((baseLong * shortSide) / longSide) const evenShort = baseShort - (baseShort % 2) if (rw < rh) { // 竖屏:短边是宽,长边是高 return { width: evenShort, height: baseLong } } else { // 横屏:长边是宽,短边是高 return { width: baseLong, height: evenShort } } } return { width: 1080, height: 1920 } } if (ratio.includes("x")) { const [wStr, hStr] = ratio.split("x") const w = parseInt(wStr, 10) || 1080 const h = parseInt(hStr, 10) || 1920 return { width: w, height: h } } return { width: 1080, height: 1920 } }