fix: скейлинг
fix: скейлинг
This commit is contained in:
@@ -98,6 +98,11 @@ export function selectProfiles(
|
||||
sourceBitrate?: number
|
||||
): VideoProfile[] {
|
||||
const profiles: VideoProfile[] = [];
|
||||
const aspect = inputWidth / inputHeight;
|
||||
const isNear = (value: number, target: number, eps: number = 0.01) =>
|
||||
Math.abs(value - target) < eps;
|
||||
const isNear16x9 = isNear(aspect, 16 / 9);
|
||||
const isNear4x3 = isNear(aspect, 4 / 3);
|
||||
|
||||
// Standard 30 FPS profiles (always created)
|
||||
const baseProfiles = DEFAULT_PROFILES.filter(profile => {
|
||||
@@ -106,9 +111,21 @@ export function selectProfiles(
|
||||
|
||||
// Add standard 30fps profiles with bitrate limit
|
||||
for (const profile of baseProfiles) {
|
||||
// Сохраняем соотношение сторон: при типовом 16:9 оставляем штатную ширину,
|
||||
// иначе рассчитываем по исходному AR (и делаем ширину чётной)
|
||||
const height = profile.height;
|
||||
let width = profile.width;
|
||||
if (!isNear16x9 && !isNear4x3) {
|
||||
width = Math.round(height * aspect);
|
||||
if (width % 2 !== 0) width -= 1; // чётные для кодека
|
||||
if (width < 2) width = 2;
|
||||
}
|
||||
|
||||
profiles.push({
|
||||
...profile,
|
||||
videoBitrate: calculateBitrate(profile.width, profile.height, 30, sourceBitrate),
|
||||
width,
|
||||
height,
|
||||
videoBitrate: calculateBitrate(width, height, 30, sourceBitrate),
|
||||
fps: 30
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user