|
|
@@ -4540,12 +4540,45 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
|
|
|
'size_mb' => round($inputFileSize / 1024 / 1024, 2) . 'MB'
|
|
|
]);
|
|
|
|
|
|
+ // 获取视频分辨率,确保短边为720
|
|
|
+ $ffmpegPath = env('FFMPEG_PATH', 'ffmpeg');
|
|
|
+ $probeCmd = "$ffmpegPath -i \"$inputFile\" 2>&1";
|
|
|
+ $probeOutput = shell_exec($probeCmd);
|
|
|
+
|
|
|
+ // 从FFmpeg输出中提取分辨率
|
|
|
+ preg_match('/Stream.*Video.*?(\d+)x(\d+)/', $probeOutput, $matches);
|
|
|
+ $width = isset($matches[1]) ? (int)$matches[1] : 0;
|
|
|
+ $height = isset($matches[2]) ? (int)$matches[2] : 0;
|
|
|
+
|
|
|
+ // 根据视频方向决定缩放参数
|
|
|
+ // 如果宽度 < 高度,说明是竖屏视频,短边是宽度
|
|
|
+ // 如果宽度 >= 高度,说明是横屏视频,短边是高度
|
|
|
+ if ($width > 0 && $height > 0) {
|
|
|
+ if ($width < $height) {
|
|
|
+ // 竖屏:短边(宽)设为720
|
|
|
+ $scaleFilter = "scale=720:-2:flags=lanczos";
|
|
|
+ dLog('video_upgrade')->info('检测到竖屏视频,短边(宽)设为720', [
|
|
|
+ 'original_size' => "{$width}x{$height}"
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ // 横屏:短边(高)设为720
|
|
|
+ $scaleFilter = "scale=-2:720:flags=lanczos";
|
|
|
+ dLog('video_upgrade')->info('检测到横屏视频,短边(高)设为720', [
|
|
|
+ 'original_size' => "{$width}x{$height}"
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 无法获取分辨率,使用默认的高度720
|
|
|
+ $scaleFilter = "scale=-2:720:flags=lanczos";
|
|
|
+ dLog('video_upgrade')->warning('无法获取视频分辨率,使用默认缩放');
|
|
|
+ }
|
|
|
+
|
|
|
// 输出文件路径
|
|
|
$outputFile = $tempDir . '/' . $uniqueId . '_output.mp4';
|
|
|
|
|
|
// 使用FFmpeg将视频升级到720p,使用高质量的Lanczos算法和锐化滤镜
|
|
|
// 滤镜说明:
|
|
|
- // 1. scale=-2:720:flags=lanczos: 使用Lanczos算法缩放,保持宽高比,高度720,宽度自动计算(-2确保是偶数)
|
|
|
+ // 1. scale: 使用Lanczos算法缩放,保持宽高比,短边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)
|
|
|
@@ -4561,8 +4594,7 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
|
|
|
// -pix_fmt yuv420p: 像素格式,确保兼容性
|
|
|
// -c:a copy: 音频直接复制,不重新编码
|
|
|
// -movflags +faststart: 优化网络播放
|
|
|
- $ffmpegPath = env('FFMPEG_PATH', 'ffmpeg');
|
|
|
- $ffmpegCmd = "$ffmpegPath -i \"$inputFile\" -vf \"scale=-2:720:flags=lanczos,unsharp=5:5:1.0:5:5:0.5,hqdn3d=1.5:1.5:6:6\" -c:v libx264 -preset veryslow -crf 16 -tune film -profile:v high -level 4.1 -pix_fmt yuv420p -c:a copy -movflags +faststart -y \"$outputFile\" 2>&1";
|
|
|
+ $ffmpegCmd = "$ffmpegPath -i \"$inputFile\" -vf \"$scaleFilter,unsharp=5:5:1.0:5:5:0.5,hqdn3d=1.5:1.5:6:6\" -c:v libx264 -preset veryslow -crf 16 -tune film -profile:v high -level 4.1 -pix_fmt yuv420p -c:a copy -movflags +faststart -y \"$outputFile\" 2>&1";
|
|
|
|
|
|
dLog('video_upgrade')->info('开始FFmpeg升级视频到720p', ['command' => $ffmpegCmd]);
|
|
|
$output = shell_exec($ffmpegCmd);
|