lh 1 giorno fa
parent
commit
8a286e0330
1 ha cambiato i file con 41 aggiunte e 15 eliminazioni
  1. 41 15
      app/Libs/Helpers.php

+ 41 - 15
app/Libs/Helpers.php

@@ -4541,20 +4541,33 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
         ]);
 
         // 获取视频分辨率,确保短边为720
+        // 使用 ffprobe 的 JSON 输出,这是最可靠的方式
+        $ffprobePath = env('FFPROBE_PATH', 'ffprobe');
         $ffmpegPath = env('FFMPEG_PATH', 'ffmpeg');
-        $probeCmd = "$ffmpegPath -i \"$inputFile\" 2>&1";
+        
+        // 获取视频流信息,使用JSON格式输出
+        $probeCmd = "$ffprobePath -v quiet -print_format json -show_streams \"$inputFile\"";
         $probeOutput = shell_exec($probeCmd);
+        $videoInfo = json_decode($probeOutput, true);
         
-        // 从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;
+        $width = 0;
+        $height = 0;
+        
+        // 从JSON中提取视频流的宽高
+        if (isset($videoInfo['streams']) && is_array($videoInfo['streams'])) {
+            foreach ($videoInfo['streams'] as $stream) {
+                if (isset($stream['codec_type']) && $stream['codec_type'] === 'video') {
+                    $width = isset($stream['width']) ? (int)$stream['width'] : 0;
+                    $height = isset($stream['height']) ? (int)$stream['height'] : 0;
+                    break;
+                }
+            }
+        }
         
-        dLog('video_upgrade')->info('FFmpeg探测结果', [
-            'probe_output' => substr($probeOutput, 0, 500),
-            'matches' => $matches,
+        dLog('video_upgrade')->info('ffprobe获取视频分辨率', [
             'width' => $width,
-            'height' => $height
+            'height' => $height,
+            'json_parsed' => !empty($videoInfo)
         ]);
         
         // 根据视频方向决定缩放参数,确保短边达到720
@@ -4660,16 +4673,29 @@ function upgrade480pTo720p($videoSource, $prefix = 'video', $isContent = false)
         
         chmod($outputFile, 0664);
 
-        // 验证输出视频的分辨率
-        $verifyCmd = "$ffmpegPath -i \"$outputFile\" 2>&1";
+        // 验证输出视频的分辨率(使用JSON格式,最可靠)
+        $verifyCmd = "$ffprobePath -v quiet -print_format json -show_streams \"$outputFile\"";
         $verifyOutput = shell_exec($verifyCmd);
-        preg_match('/Stream.*Video.*?(\d+)x(\d+)/', $verifyOutput, $verifyMatches);
-        $outputWidth = isset($verifyMatches[1]) ? (int)$verifyMatches[1] : 0;
-        $outputHeight = isset($verifyMatches[2]) ? (int)$verifyMatches[2] : 0;
+        $outputVideoInfo = json_decode($verifyOutput, true);
+        
+        $outputWidth = 0;
+        $outputHeight = 0;
+        
+        if (isset($outputVideoInfo['streams']) && is_array($outputVideoInfo['streams'])) {
+            foreach ($outputVideoInfo['streams'] as $stream) {
+                if (isset($stream['codec_type']) && $stream['codec_type'] === 'video') {
+                    $outputWidth = isset($stream['width']) ? (int)$stream['width'] : 0;
+                    $outputHeight = isset($stream['height']) ? (int)$stream['height'] : 0;
+                    break;
+                }
+            }
+        }
         
         dLog('video_upgrade')->info('输出视频分辨率验证', [
+            'input_original' => "{$width}x{$height}",
             'expected' => isset($targetShortSide) ? ($width < $height ? "{$targetShortSide}x{$targetLongSide}" : "{$targetLongSide}x{$targetShortSide}") : '未知',
-            'actual' => "{$outputWidth}x{$outputHeight}"
+            'actual_output' => "{$outputWidth}x{$outputHeight}",
+            'success' => ($outputWidth > 0 && $outputHeight > 0)
         ]);
 
         $outputFileSize = filesize($outputFile);