Просмотр исходного кода

全能模式新增首个片段视频首帧图的逻辑

lh 1 неделя назад
Родитель
Сommit
829923d3e2

+ 5 - 0
app/Http/Controllers/Anime/AnimeController.php

@@ -2922,6 +2922,11 @@ class AnimeController extends BaseController
                         'updated_at' => date('Y-m-d H:i:s')
                     ]);
                 
+                // 如果是全能模式,并且是第一集的第一个片段,将act_id存入Redis
+                if ((int)$episodeNumber === 1 && (int)$act->act_number === 1) {
+                    Redis::sadd('anime_act_first_frame_urls', $act->id);
+                }
+                
                 $actTasks[] = [
                     'act_id' => $act->id,
                     'task_id' => $task->id,

+ 28 - 0
app/Services/AIGeneration/AIVideoGenerationService.php

@@ -8,6 +8,7 @@ use App\Models\AIElement;
 use App\Services\VolcEngineService;
 use GuzzleHttp\Client;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Redis;
 
 class AIVideoGenerationService
 {
@@ -2600,7 +2601,34 @@ class AIVideoGenerationService
                     // 添加视频生成对话记录
                     $this->addVideoGenerationRecords($task, $segment_id, $statusInfo['result_url']);
                     
+                    // 如果是全能模式的首帧图,则提取视频第一帧并更新anime表
+                    $act_id = getProp($task, 'alias_act_id');
+                    if (!empty($act_id) && Redis::sismember('anime_act_first_frame_urls', $act_id)) {
+                        $anime_id = DB::table('mp_episode_segments')->where('id', $act_id)->value('anime_id');
+                        if ($anime_id) {
+                            // 提取视频第一帧
+                            $videoUrl = $segmentUpdateData['video_url'];
+                            $firstFrameUrl = getVideoFirstFrame($videoUrl, 'anime_first_frames', 'tos');
+                            
+                            if ($firstFrameUrl) {
+                                // 更新anime表
+                                DB::table('mp_animes')->where('id', $anime_id)->update([
+                                    'first_frame_url' => $firstFrameUrl,
+                                    'updated_at' => date('Y-m-d H:i:s')
+                                ]);
+                                
+                                dLog('video_frame')->info('全能模式首帧图更新成功', [
+                                    'act_id' => $act_id,
+                                    'anime_id' => $anime_id,
+                                    'first_frame_url' => $firstFrameUrl
+                                ]);
+                            }
+                        }
+                    }
+                    
                     DB::commit();
+                    // 从Redis中移除
+                    Redis::srem('anime_act_first_frame_urls', $act_id);
                     
                 } catch (\Exception $e) {
                     DB::rollBack();

+ 10 - 1
app/Services/Anime/AnimeService.php

@@ -4211,8 +4211,10 @@ class AnimeService
         }
         
         $act = (array)$act;
-
+        $anime_id = getProp($act, 'anime_id');
         $episode_id = getProp($act, 'episode_id');
+        $anime = DB::table('mp_animes')->where('id', $anime_id)->first();
+        $ace_mode = getProp($anime, 'ace_mode');
         $episode = DB::table('mp_anime_episodes')->where('id', $episode_id)->first();
         if (!$ratio) $ratio = getProp($episode, 'ratio', '9:16');
         if (!$video_resolution) $video_resolution = getProp($episode, 'video_resolution', '720p');
@@ -4454,6 +4456,13 @@ class AnimeService
             'updated_at' => date('Y-m-d H:i:s')
         ]);
         
+        // 如果是全能模式,并且是第一集的第一个片段,将act_id存入Redis
+        $episode_number = getProp($act, 'episode_number');
+        $act_number = getProp($act, 'act_number');
+        if ((int)$ace_mode === 1 && (int)$episode_number === 1 && (int)$act_number === 1) {
+            Redis::sadd('anime_act_first_frame_urls', $act_id);
+        }
+        
         return [
             'task_id' => $task->id,
             'status' => $task->status,