lh 2 ay önce
ebeveyn
işleme
171539f388

+ 36 - 2
app/Console/Commands/CheckVideoGenerationTasksCommand.php

@@ -90,7 +90,7 @@ class CheckVideoGenerationTasksCommand extends Command
                 // 查询视频生成任务状态
                 $videoTask = DB::table('mp_generate_video_tasks')
                     ->where('id', $videoTaskId)
-                    ->select('id', 'status', 'result_url', 'last_frame_url', 'error_message')
+                    ->select('id', 'status', 'result_url', 'last_frame_url', 'error_message', 'result_json', 'extra_params')
                     ->first();
 
                 if (!$videoTask) {
@@ -114,12 +114,46 @@ class CheckVideoGenerationTasksCommand extends Command
                         $updateData['last_frame_url'] = $videoTask->last_frame_url;
                     }
                     
+                    // 计算视频时长
+                    $video_duration = 0;
+                    if (!empty($videoTask->result_json)) {
+                        $resultJson = is_array($videoTask->result_json) ? $videoTask->result_json : json_decode($videoTask->result_json, true);
+                        
+                        if (isset($resultJson['duration'])) {
+                            // 如果直接返回duration,使用该值
+                            $video_duration = (int)$resultJson['duration'];
+                        } elseif (isset($resultJson['frames']) && isset($resultJson['framespersecond'])) {
+                            // 如果返回frames和framespersecond,计算时长
+                            $frames = (int)$resultJson['frames'];
+                            $fps = (int)$resultJson['framespersec8ond'];
+                            if ($fps > 0) {
+                                $video_duration = (int)floor($frames / $fps);
+                            }
+                        }
+                    }
+                    
+                    // 如果没有计算出时长,使用任务表中的设定值
+                    if ($video_duration <= 0 && !empty($videoTask->extra_params)) {
+                        $extraParams = is_array($videoTask->extra_params) ? $videoTask->extra_params : json_decode($videoTask->extra_params, true);
+                        if (isset($extraParams['duration'])) {
+                            $video_duration = (int)$extraParams['duration'];
+                        }
+                    }
+                    
+                    // 只有当video_duration > 0时才添加到更新数据中
+                    if ($video_duration > 0) {
+                        $updateData['video_duration'] = $video_duration;
+                        $updateData['video_time_point_start'] = 0;
+                        $updateData['video_time_point_end'] = $video_duration;
+                    }
+                    
                     $successCount++;
                     
                     dLog('command')->info('分镜视频生成成功', [
                         'segment_id' => $segmentId,
                         'video_task_id' => $videoTaskId,
-                        'video_url' => $videoTask->result_url
+                        'video_url' => $videoTask->result_url,
+                        'video_duration' => $video_duration
                     ]);
                     
                 } elseif ($videoTask->status === 'failed') {