|
@@ -51,24 +51,40 @@ class GeneratePreviewVideo extends Command
|
|
|
{
|
|
|
$disk = $this->disk('oss');
|
|
|
|
|
|
+ //如果目录不存在则创建
|
|
|
+ if (!file_exists(storage_path('tmp/previews'))) {
|
|
|
+ mkdir(storage_path('tmp/previews'), 0777, true);
|
|
|
+ }
|
|
|
+
|
|
|
$reslut = DB::table('site_preview_video')
|
|
|
->where('status', '==', 0) // 过滤非空 video 字段
|
|
|
->orderBy('id') // 按主键排序确保顺序
|
|
|
+ ->limit(1) // 限制处理 1 条
|
|
|
->get();
|
|
|
|
|
|
foreach ($reslut as $item) {
|
|
|
- $video_url = $this->ossUrl($item->video_url);
|
|
|
- echo $video_url.'/n';
|
|
|
- $fileName = basename($video_url);
|
|
|
- $fileInfo = pathinfo($fileName);
|
|
|
- $previewName = $fileInfo['filename'] . '_preview.' . $fileInfo['extension'];
|
|
|
- $previewPath = storage_path('tmp/previews/'.$previewName);
|
|
|
- $this->generatePreview($video_url, $previewPath);
|
|
|
- dd($previewPath);
|
|
|
- exit;
|
|
|
+ try {
|
|
|
+ $video_url = $this->ossUrl($item->video_url);
|
|
|
+ $fileName = basename($video_url);
|
|
|
+ $fileInfo = pathinfo($fileName);
|
|
|
+ $previewName = $fileInfo['filename'] . '_preview.' . $fileInfo['extension'];
|
|
|
+ $previewPath = storage_path('tmp/previews/'.$previewName);
|
|
|
+ $this->generatePreview($video_url, $previewPath);
|
|
|
+ //上传到OSS
|
|
|
+ $uploadPath = 'videos/uploads/previews/'. date('Ym');
|
|
|
+ $disk->putFile($uploadPath,$previewPath);
|
|
|
+
|
|
|
+ $item->preview_url = $uploadPath. '/'. $previewName;
|
|
|
+ $item->status = 1;
|
|
|
+ $item->save();
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $item->remark = $e->getMessage();
|
|
|
+ $item->status = -1;
|
|
|
+ $item->save();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//$this->importVideo();
|
|
|
return Command::SUCCESS;
|
|
|
}
|
|
@@ -93,10 +109,8 @@ class GeneratePreviewVideo extends Command
|
|
|
$video->filters()->clip(TimeCode::fromSeconds(0), TimeCode::fromSeconds($this->timeSecond));
|
|
|
|
|
|
// 输出为H.264编码的MP4
|
|
|
- //$format = new \FFMpeg\Format\Video\X264('aac');
|
|
|
- $format = new \FFMpeg\Format\Video\X264('libfdk_aac');
|
|
|
+ $format = new \FFMpeg\Format\Video\X264();
|
|
|
$video->save($format, $outputPath);
|
|
|
-
|
|
|
return $outputPath;
|
|
|
}
|
|
|
|