fix(canvas): 视频设置 - 按渠道能力隐藏尺寸并联动分辨率宽高
This commit is contained in:
1 parent
6d77c250c1
commit
4b75504f75
15 files changed
+196
-50
No files matched your search
@@ -38,3 +38,29 @@ export function formatVideoResolutionLabel(value: string | number | undefined) {
|
||||
if (/^\d+$/.test(normalized)) return `${normalized}P`;
|
||||
return normalized.replace(/^(\d+)p/i, "$1P");
|
||||
}
|
||||
|
||||
export function videoDimensionsForRatioAndResolution(ratio: string | undefined, resolution: string | number | undefined) {
|
||||
const ratioMatch = String(ratio || "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace("×", "x")
|
||||
.match(/^(\d+(?:\.\d+)?)(?::|x)(\d+(?:\.\d+)?)$/);
|
||||
if (!ratioMatch) return undefined;
|
||||
|
||||
const ratioWidth = Number(ratioMatch[1]);
|
||||
const ratioHeight = Number(ratioMatch[2]);
|
||||
if (!Number.isFinite(ratioWidth) || !Number.isFinite(ratioHeight) || ratioWidth <= 0 || ratioHeight <= 0) return undefined;
|
||||
|
||||
const normalizedResolution = normalizeVideoResolution(resolution);
|
||||
const resolutionMatch = normalizedResolution.match(/^(\d+)(?:p)?/i);
|
||||
const shortEdge = Number(resolutionMatch?.[1]);
|
||||
if (!Number.isFinite(shortEdge) || shortEdge <= 0) return undefined;
|
||||
|
||||
const aspect = ratioWidth / ratioHeight;
|
||||
if (aspect >= 1) return { width: evenDimension(shortEdge * aspect), height: shortEdge };
|
||||
return { width: shortEdge, height: evenDimension(shortEdge / aspect) };
|
||||
}
|
||||
|
||||
function evenDimension(value: number) {
|
||||
return Math.max(2, Math.round(value / 2) * 2);
|
||||
}
|
||||
Reference in new issue
Block a user