|
|
@@ -5245,7 +5245,7 @@ function mapErrorMessage($errorMessage)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 将480p视频升级到720p(使用FFmpeg本地超分)
|
|
|
+ * 将480p视频升级到720p(使用FFmpeg本地超分,强制输出720*1280或1280*720分辨率)
|
|
|
*
|
|
|
* @param string|resource $videoSource 视频URL地址或视频内容(字符串)
|
|
|
* @param string $prefix 上传文件夹前缀(如:'video')
|
|
|
@@ -5346,53 +5346,35 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
|
|
|
'json_parsed' => !empty($videoInfo)
|
|
|
]);
|
|
|
|
|
|
- // 根据视频方向决定缩放参数,确保短边达到720
|
|
|
- // 计算缩放比例,使短边至少为720
|
|
|
+ // 根据视频方向决定目标标准分辨率,强制720*1280(竖屏)或1280*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;
|
|
|
- }
|
|
|
-
|
|
|
dLog('video_upgrade')->info('缩放计算详情', [
|
|
|
'original' => "{$width}x{$height}",
|
|
|
- 'short_side' => $shortSide,
|
|
|
- 'long_side' => $longSide,
|
|
|
- 'scale_ratio' => $scale,
|
|
|
- 'target_short' => $targetShortSide,
|
|
|
- 'target_long' => $targetLongSide,
|
|
|
+ 'target' => $width < $height ? '720x1280' : '1280x720',
|
|
|
'is_portrait' => $width < $height ? 'yes' : 'no'
|
|
|
]);
|
|
|
|
|
|
if ($width < $height) {
|
|
|
- // 竖屏:宽度是短边
|
|
|
- $scaleFilter = "scale={$targetShortSide}:{$targetLongSide}:flags=lanczos";
|
|
|
- dLog('video_upgrade')->info('检测到竖屏视频,短边(宽)设为720', [
|
|
|
+ // 竖屏:强制720*1280(scale保持宽高比 + pad补边)
|
|
|
+ $scaleFilter = "scale=720:1280:flags=lanczos:force_original_aspect_ratio=decrease,pad=720:1280:(ow-iw)/2:(oh-ih)/2";
|
|
|
+ dLog('video_upgrade')->info('检测到竖屏视频,强制720*1280', [
|
|
|
'original_size' => "{$width}x{$height}",
|
|
|
- 'target_size' => "{$targetShortSide}x{$targetLongSide}",
|
|
|
+ 'target_size' => '720x1280',
|
|
|
'scale_filter' => $scaleFilter
|
|
|
]);
|
|
|
} else {
|
|
|
- // 横屏:高度是短边
|
|
|
- $scaleFilter = "scale={$targetLongSide}:{$targetShortSide}:flags=lanczos";
|
|
|
- dLog('video_upgrade')->info('检测到横屏视频,短边(高)设为720', [
|
|
|
+ // 横屏:强制1280*720(scale保持宽高比 + pad补边)
|
|
|
+ $scaleFilter = "scale=1280:720:flags=lanczos:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2";
|
|
|
+ dLog('video_upgrade')->info('检测到横屏视频,强制1280*720', [
|
|
|
'original_size' => "{$width}x{$height}",
|
|
|
- 'target_size' => "{$targetLongSide}x{$targetShortSide}",
|
|
|
+ 'target_size' => '1280x720',
|
|
|
'scale_filter' => $scaleFilter
|
|
|
]);
|
|
|
}
|
|
|
} else {
|
|
|
- // 无法获取分辨率,使用默认的高度720
|
|
|
- $scaleFilter = "scale=-2:720:flags=lanczos";
|
|
|
- dLog('video_upgrade')->warning('无法获取视频分辨率,使用默认缩放');
|
|
|
+ // 无法获取分辨率,默认按横屏1280*720处理
|
|
|
+ $scaleFilter = "scale=1280:720:flags=lanczos:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2";
|
|
|
+ dLog('video_upgrade')->warning('无法获取视频分辨率,默认按1280*720处理');
|
|
|
}
|
|
|
|
|
|
// 输出文件路径
|
|
|
@@ -5400,7 +5382,7 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
|
|
|
|
|
|
// 使用FFmpeg将视频升级到720p,使用高质量的Lanczos算法和锐化滤镜
|
|
|
// 滤镜说明:
|
|
|
- // 1. scale: 使用Lanczos算法缩放,保持宽高比,短边720
|
|
|
+ // 1. scale: 使用Lanczos算法缩放并保持宽高比,pad补边到720*1280或1280*720标准分辨率
|
|
|
// 2. unsharp=5:5:1.0:5:5:0.5: 锐化滤镜,增强细节
|
|
|
// - 5:5:1.0 表示亮度锐化(luma_msize_x:luma_msize_y:luma_amount)
|
|
|
// - 5:5:0.5 表示色度锐化(chroma_msize_x:chroma_msize_y:chroma_amount)
|
|
|
@@ -5469,7 +5451,7 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
|
|
|
|
|
|
dLog('video_upgrade')->info('输出视频分辨率验证', [
|
|
|
'input_original' => "{$width}x{$height}",
|
|
|
- 'expected' => isset($targetShortSide) ? ($width < $height ? "{$targetShortSide}x{$targetLongSide}" : "{$targetLongSide}x{$targetShortSide}") : '未知',
|
|
|
+ 'expected' => ($width > 0 && $height > 0) ? ($width < $height ? '720x1280' : '1280x720') : '1280x720',
|
|
|
'actual_output' => "{$outputWidth}x{$outputHeight}",
|
|
|
'success' => ($outputWidth > 0 && $outputHeight > 0)
|
|
|
]);
|