瀏覽代碼

调整定时任务方法

lh 2 月之前
父節點
當前提交
d7d7847583

+ 30 - 9
app/Console/Commands/CheckVideoGenerationTasksCommand.php

@@ -62,15 +62,16 @@ class CheckVideoGenerationTasksCommand extends Command
      * 
      * @return void
      */
-    private function updateSegmentVideoStatus()
+    private function updateSegmentVideoStatus($videoGenerationService)
     {
         try {
-            // 获取所有状态为"生成中"的分镜
+            // 获取所有状态为"生成中"的分镜(兼容分镜模式和全能模式)
             $segments = DB::table('mp_episode_segments')
                 ->where('video_task_status', '生成中')
                 ->whereNotNull('video_task_id')
                 ->where('video_task_id', '<>', '')
-                ->select('segment_id', 'video_task_id')
+                ->where('created_at', '<', date('Y-m-d H:i:s', strtotime('-24 hours')))
+                ->select('id', 'segment_id', 'video_task_id', 'audio_duration')
                 ->get();
 
             if ($segments->isEmpty()) {
@@ -85,7 +86,9 @@ class CheckVideoGenerationTasksCommand extends Command
 
             foreach ($segments as $segment) {
                 $videoTaskId = $segment->video_task_id;
-                $segmentId = $segment->segment_id;
+                // 兼容两种模式:优先使用segment_id(分镜模式),如果为空则使用id(全能模式的act_id)
+                $recordId = $segment->id;
+                $segmentId = $segment->segment_id ?: $segment->id;
 
                 // 查询视频生成任务状态
                 $videoTask = DB::table('mp_generate_video_tasks')
@@ -95,6 +98,7 @@ class CheckVideoGenerationTasksCommand extends Command
 
                 if (!$videoTask) {
                     dLog('command')->warning('分镜关联的视频任务不存在', [
+                        'record_id' => $recordId,
                         'segment_id' => $segmentId,
                         'video_task_id' => $videoTaskId
                     ]);
@@ -126,7 +130,7 @@ class CheckVideoGenerationTasksCommand extends Command
                         } elseif (isset($resultJson['frames']) && isset($resultJson['framespersecond'])) {
                             // 如果返回frames和framespersecond,计算时长
                             $frames = (int)$resultJson['frames'];
-                            $fps = (int)$resultJson['framespersec8ond'];
+                            $fps = (int)$resultJson['framespersecond'];
                             if ($fps > 0) {
                                 $video_duration = (int)floor($frames / $fps);
                             }
@@ -145,8 +149,22 @@ class CheckVideoGenerationTasksCommand extends Command
                     if ($video_duration > 0) {
                         $updateData['video_duration'] = $video_duration;
                         $updateData['video_time_point_start'] = 0;
-                        // $updateData['video_time_point_end'] = $video_duration;
-                        $updateData['video_time_point_end'] = $segment->audio_duration ?? 0;
+                        
+                        $segment_id = getProp($videoTask, 'alias_segment_id');
+                        $act_id = getProp($videoTask, 'alias_act_id');
+        
+                        if ($segment_id) {
+                            // 分镜模式:使用segment_id查询
+                            $audio_duration = DB::table('mp_episode_segments')->where('segment_id', $segmentId)->value('audio_duration');
+                        } elseif ($act_id) {
+                            // 全能模式(全能模式):如果传入了video_duration直接返回,否则查询audio_duration
+                            if ($video_duration !== null && $video_duration > 0) {
+                                $audio_duration = $video_duration;
+                            }
+                            $audio_duration = DB::table('mp_episode_segments')->where('id', $segmentId)->value('audio_duration');
+                        }
+
+                        $updateData['video_time_point_end'] = $audio_duration ?? 0;
                     }
                     
                     $successCount++;
@@ -155,6 +173,7 @@ class CheckVideoGenerationTasksCommand extends Command
                     $this->addVideoGenerationRecords($videoTask, $segmentId, $videoTask->result_url);
                     
                     dLog('command')->info('分镜视频生成成功', [
+                        'record_id' => $recordId,
                         'segment_id' => $segmentId,
                         'video_task_id' => $videoTaskId,
                         'video_url' => $videoTask->result_url,
@@ -167,11 +186,13 @@ class CheckVideoGenerationTasksCommand extends Command
                     $failedCount++;
                     
                     dLog('command')->error('分镜视频生成失败', [
+                        'record_id' => $recordId,
                         'segment_id' => $segmentId,
                         'video_task_id' => $videoTaskId,
                         'error' => $videoTask->error_message
                     ]);
                     logDB('command', 'error', '分镜视频生成失败', [
+                        'record_id' => $recordId,
                         'segment_id' => $segmentId,
                         'video_task_id' => $videoTaskId,
                         'error' => $videoTask->error_message
@@ -183,9 +204,9 @@ class CheckVideoGenerationTasksCommand extends Command
                     continue;
                 }
 
-                // 更新分镜表
+                // 更新分镜表(使用主键id更新,兼容两种模式)
                 DB::table('mp_episode_segments')
-                    ->where('segment_id', $segmentId)
+                    ->where('id', $recordId)
                     ->update($updateData);
             }
 

+ 8 - 4
app/Services/AIGeneration/AIVideoGenerationService.php

@@ -955,13 +955,15 @@ class AIVideoGenerationService
                     
                     $now = date('Y-m-d H:i:s');
                     
-                    // 获取分镜ID
+                    // 获取分镜ID(兼容分镜模式和全能模式)
                     $segment = DB::table('mp_episode_segments')
                         ->where('video_task_id', $task->id)
                         ->first();
                     
                     if ($segment) {
-                        $segmentId = $segment->segment_id;
+                        // 兼容两种模式
+                        $recordId = $segment->id;
+                        $segmentId = $segment->segment_id ?: $segment->id;
                         $anime_id = $segment->anime_id;
                         $episode_number = $segment->episode_number;
                         $tail_frame = $segment->tail_frame;
@@ -981,11 +983,13 @@ class AIVideoGenerationService
                         if (isset($data['content']['video_duration']) && $data['content']['video_duration'] > 0) {
                             $segmentUpdateData['video_duration'] = $data['content']['video_duration'];
                             $segmentUpdateData['video_time_point_start'] = 0;
-                            $segmentUpdateData['video_time_point_end'] = $segment->audio_duration ?? 0;
+                            $audio_duration = $this->getAudioDuration($task, $segmentId, $segmentUpdateData['video_duration']);
+                            $segmentUpdateData['video_time_point_end'] = $audio_duration ?? 0;
                         }
                         
+                        // 使用主键id更新(兼容两种模式)
                         $updateResult = DB::table('mp_episode_segments')
-                            ->where('segment_id', $segmentId)
+                            ->where('id', $recordId)
                             ->update($segmentUpdateData);
                         
                         if (!$updateResult) {