소스 검색

视频预览

moshaorui 2 주 전
부모
커밋
07c6b0ee10
1개의 변경된 파일30개의 추가작업 그리고 12개의 파일을 삭제
  1. 30 12
      app/Console/Commands/GeneratePreviewVideo.php

+ 30 - 12
app/Console/Commands/GeneratePreviewVideo.php

@@ -52,10 +52,12 @@ class GeneratePreviewVideo extends Command
         $disk = $this->disk('oss');
 
         //如果目录不存在则创建
-        if (!file_exists(storage_path('tmp/previews'))) {
-            mkdir(storage_path('tmp/previews'), 0777, true);
+        $localPreviewPath = storage_path('tmp/previews');
+        if (!file_exists($localPreviewPath)) {
+            mkdir($localPreviewPath, 0777, true);
         }
 
+
         $reslut = DB::table('site_preview_video')
             ->where('status', '==', 0) // 过滤非空 video 字段
             ->orderBy('id') // 按主键排序确保顺序
@@ -67,21 +69,37 @@ class GeneratePreviewVideo extends Command
                 $video_url = $this->ossUrl($item->video_url);
                 $fileName = basename($video_url);
                 $fileInfo = pathinfo($fileName);
+                //下载$video_url到本地
+                $stream = $disk->readStream($video_url);
+
+                // 将流写入本地文件
+                file_put_contents($localPreviewPath, stream_get_contents($stream));
+                fclose($stream);
+
+                exit;
+
+
                 $previewName = $fileInfo['filename'] . '_preview.' . $fileInfo['extension'];
                 $previewPath = storage_path('tmp/previews/'.$previewName);
-                $this->generatePreview($video_url, $previewPath);
+                //下载$video_url到本地
+                //$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();
-
+                //$disk->putFile($uploadPath,$previewPath);
+
+                DB::table('site_preview_video')
+                    ->where('id', $item->id)
+                    ->update([
+                        'preview_url' => $uploadPath . '/' . $previewName,
+                        'status' => 1
+                    ]);
             } catch (\Exception $e) {
-                $item->remark = $e->getMessage();
-                $item->status = -1;
-                $item->save();
+                DB::table('site_preview_video')
+                    ->where('id', $item->id)
+                    ->update([
+                        'remark' => $e->getMessage(),
+                        'status' => -1
+                    ]);
             }
         }