|
@@ -112,13 +112,34 @@ class GeneratePreviewVideo extends Command
|
|
|
return dd('success');
|
|
|
}
|
|
|
|
|
|
- private function saveLocal($url, $localPath) {
|
|
|
- $remote = fopen($url, 'rb');
|
|
|
+ private function saveLocal($url, $localPath) {
|
|
|
+ // 初始化 cURL 会话
|
|
|
+ $ch = curl_init($url);
|
|
|
+ // 设置 cURL 选项
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回数据而不是直接输出
|
|
|
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // 跟踪重定向
|
|
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 300); // 设置超时时间(秒)
|
|
|
+ // 执行 cURL 请求
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ // 检查是否有错误
|
|
|
+ if (curl_errno($ch)) {
|
|
|
+ $error = 'cURL error: ' . curl_error($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ throw new Exception($error);
|
|
|
+ }
|
|
|
+ // 获取 HTTP 状态码
|
|
|
+ $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
+ curl_close($ch);
|
|
|
+ if ($httpCode != 200) {
|
|
|
+ throw new Exception("HTTP error: {$httpCode}");
|
|
|
+ }
|
|
|
+ // 打开本地文件进行写入
|
|
|
$local = fopen($localPath, 'wb');
|
|
|
- while (!feof($remote)) {
|
|
|
- fwrite($local, fread($remote, 8192)); // 8KB分块
|
|
|
+ if (!$local) {
|
|
|
+ throw new Exception("Failed to open local file: {$localPath}");
|
|
|
}
|
|
|
- fclose($remote);
|
|
|
+ // 将响应数据写入本地文件
|
|
|
+ fwrite($local, $response);
|
|
|
fclose($local);
|
|
|
return $localPath;
|
|
|
}
|
|
@@ -128,7 +149,10 @@ class GeneratePreviewVideo extends Command
|
|
|
if (strpos($url, 'http:') === 0 || strpos($url, 'https:') === 0) {
|
|
|
return $url;
|
|
|
}
|
|
|
- return "https://mietublcom.oss-cn-hongkong.aliyuncs.com".'/'.$url;
|
|
|
+ if (env('PREVIEW_OSS_URL_INTERNAL')) {
|
|
|
+ return env('PREVIEW_OSS_URL_INTERNAL').'/'.$url;
|
|
|
+ }
|
|
|
+ return env('PREVIEW_OSS_URL').'/'.$url;
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -157,7 +181,7 @@ class GeneratePreviewVideo extends Command
|
|
|
$ffmpeg = FFMpeg::create([
|
|
|
'ffmpeg.binaries' => '/usr/bin/ffmpeg',
|
|
|
'ffprobe.binaries' => '/usr/bin/ffprobe',
|
|
|
- 'timeout' => 300
|
|
|
+ 'timeout' => 180
|
|
|
]);
|
|
|
|
|
|
// Open the video
|