|
|
@@ -4550,21 +4550,35 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
|
|
|
$width = isset($matches[1]) ? (int)$matches[1] : 0;
|
|
|
$height = isset($matches[2]) ? (int)$matches[2] : 0;
|
|
|
|
|
|
- // 根据视频方向决定缩放参数
|
|
|
- // 如果宽度 < 高度,说明是竖屏视频,短边是宽度
|
|
|
- // 如果宽度 >= 高度,说明是横屏视频,短边是高度
|
|
|
+ // 根据视频方向决定缩放参数,确保短边达到720
|
|
|
+ // 计算缩放比例,使短边至少为720
|
|
|
if ($width > 0 && $height > 0) {
|
|
|
+ $shortSide = min($width, $height);
|
|
|
+ $longSide = max($width, $height);
|
|
|
+ $targetShortSide = 720;
|
|
|
+
|
|
|
+ // 计算缩放后的长边尺寸
|
|
|
+ $scale = $targetShortSide / $shortSide;
|
|
|
+ $targetLongSide = round($longSide * $scale);
|
|
|
+
|
|
|
+ // 确保是偶数(视频编码要求)
|
|
|
+ if ($targetLongSide % 2 !== 0) {
|
|
|
+ $targetLongSide += 1;
|
|
|
+ }
|
|
|
+
|
|
|
if ($width < $height) {
|
|
|
- // 竖屏:短边(宽)设为720
|
|
|
- $scaleFilter = "scale=720:-2:flags=lanczos";
|
|
|
+ // 竖屏:宽度是短边
|
|
|
+ $scaleFilter = "scale={$targetShortSide}:{$targetLongSide}:flags=lanczos";
|
|
|
dLog('video_upgrade')->info('检测到竖屏视频,短边(宽)设为720', [
|
|
|
- 'original_size' => "{$width}x{$height}"
|
|
|
+ 'original_size' => "{$width}x{$height}",
|
|
|
+ 'target_size' => "{$targetShortSide}x{$targetLongSide}"
|
|
|
]);
|
|
|
} else {
|
|
|
- // 横屏:短边(高)设为720
|
|
|
- $scaleFilter = "scale=-2:720:flags=lanczos";
|
|
|
+ // 横屏:高度是短边
|
|
|
+ $scaleFilter = "scale={$targetLongSide}:{$targetShortSide}:flags=lanczos";
|
|
|
dLog('video_upgrade')->info('检测到横屏视频,短边(高)设为720', [
|
|
|
- 'original_size' => "{$width}x{$height}"
|
|
|
+ 'original_size' => "{$width}x{$height}",
|
|
|
+ 'target_size' => "{$targetLongSide}x{$targetShortSide}"
|
|
|
]);
|
|
|
}
|
|
|
} else {
|