|
|
@@ -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);
|
|
|
}
|
|
|
|