|
|
@@ -1087,6 +1087,13 @@ function compressVideo($videoUrl, $prefix = 'videos')
|
|
|
|
|
|
// 上传压缩后的视频到云存储
|
|
|
$stream = fopen($outputFile, 'r');
|
|
|
+ if (!$stream) {
|
|
|
+ dLog('video_compress')->error('无法打开压缩后的视频文件', ['file' => $outputFile]);
|
|
|
+ @unlink($inputFile);
|
|
|
+ @unlink($outputFile);
|
|
|
+ return $videoUrl;
|
|
|
+ }
|
|
|
+
|
|
|
$filename = $uniqueId . '.mp4';
|
|
|
|
|
|
// 根据环境变量选择上传方式
|
|
|
@@ -1098,7 +1105,10 @@ function compressVideo($videoUrl, $prefix = 'videos')
|
|
|
$compressedUrl = uploadStreamByTos($prefix, $stream, $filename);
|
|
|
}
|
|
|
|
|
|
- fclose($stream);
|
|
|
+ // 安全关闭文件流
|
|
|
+ if (is_resource($stream)) {
|
|
|
+ fclose($stream);
|
|
|
+ }
|
|
|
|
|
|
// 清理临时文件
|
|
|
@unlink($inputFile);
|
|
|
@@ -1123,6 +1133,11 @@ function compressVideo($videoUrl, $prefix = 'videos')
|
|
|
'trace' => $e->getTraceAsString()
|
|
|
]);
|
|
|
|
|
|
+ // 安全关闭文件流(如果存在)
|
|
|
+ if (isset($stream) && is_resource($stream)) {
|
|
|
+ @fclose($stream);
|
|
|
+ }
|
|
|
+
|
|
|
// 清理可能存在的临时文件
|
|
|
if (isset($inputFile) && file_exists($inputFile)) {
|
|
|
@unlink($inputFile);
|