|
|
@@ -3372,7 +3372,7 @@ class AnimeService
|
|
|
->where('anime_id', $animeId)
|
|
|
->where('episode_id', $episodeId)
|
|
|
->orderBy('segment_number')
|
|
|
- ->select('segment_id', 'segment_number', 'video_url', 'audio_url')
|
|
|
+ ->select('segment_id', 'segment_number', 'video_url', 'audio_url', 'video_time_point_start', 'video_time_point_end')
|
|
|
->get();
|
|
|
|
|
|
if ($segments->isEmpty()) {
|
|
|
@@ -3396,6 +3396,8 @@ class AnimeService
|
|
|
'sequence' => $sequence++,
|
|
|
'video_url' => $segment->video_url,
|
|
|
'audio_url' => $segment->audio_url,
|
|
|
+ 'video_time_point_start' => $segment->video_time_point_start,
|
|
|
+ 'video_time_point_end' => $segment->video_time_point_end
|
|
|
];
|
|
|
}
|
|
|
|
|
|
@@ -3411,6 +3413,16 @@ class AnimeService
|
|
|
'updated_at' => $now
|
|
|
]);
|
|
|
|
|
|
+ // 更新剧集表的任务ID和状态
|
|
|
+ DB::table('mp_anime_episodes')
|
|
|
+ ->where('anime_id', $animeId)
|
|
|
+ ->where('episode_id', $episodeId)
|
|
|
+ ->update([
|
|
|
+ 'complete_video_task_id' => $taskId,
|
|
|
+ 'complete_video_task_status' => '执行中',
|
|
|
+ 'updated_at' => $now
|
|
|
+ ]);
|
|
|
+
|
|
|
dLog('anime')->info('创建完整视频合成任务', [
|
|
|
'task_id' => $taskId,
|
|
|
'anime_id' => $animeId,
|
|
|
@@ -3420,21 +3432,162 @@ class AnimeService
|
|
|
|
|
|
// 请求远程服务器执行生成
|
|
|
$client = new Client(['timeout' => 600, 'verify' => false]);
|
|
|
- $result = $client->get("http://122.9.129.83:5000/api/anime/genVideo?taskId={$taskId}");
|
|
|
- $response = $result->getBody()->getContents();
|
|
|
- $response_arr = json_decode($response, true);
|
|
|
- if (!isset($response_arr['code']) || (int)$response_arr['code'] !== 0) {
|
|
|
- $error_msg = isset($response_arr['msg']) ? $response_arr['msg'] : '未知错误';
|
|
|
- dLog('anime')->error('火山合成完整视频失败', ['error' => $error_msg, 'task_id' => $taskId]);
|
|
|
- Utils::throwError('20003:火山合成完整视频失败');
|
|
|
+ try {
|
|
|
+ $result = $client->get("http://122.9.129.83:5000/api/anime/genVideo?taskId={$taskId}");
|
|
|
+ $response = $result->getBody()->getContents();
|
|
|
+ $response_arr = json_decode($response, true);
|
|
|
+ if (!isset($response_arr['code']) || (int)$response_arr['code'] !== 0) {
|
|
|
+ $error_msg = isset($response_arr['msg']) ? $response_arr['msg'] : '未知错误';
|
|
|
+ dLog('anime')->error('火山合成完整视频失败', ['error' => $error_msg, 'task_id' => $taskId]);
|
|
|
+
|
|
|
+ // 更新任务状态为失败
|
|
|
+ DB::table('mp_complete_video_tasks')
|
|
|
+ ->where('id', $taskId)
|
|
|
+ ->update([
|
|
|
+ 'generate_status' => '执行失败',
|
|
|
+ 'error_message' => $error_msg,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 同步更新剧集表状态
|
|
|
+ DB::table('mp_anime_episodes')
|
|
|
+ ->where('complete_video_task_id', $taskId)
|
|
|
+ ->update([
|
|
|
+ 'complete_video_task_status' => '执行失败',
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Utils::throwError('20003:火山合成完整视频失败: ' . $error_msg);
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ dLog('anime')->error('调用远程服务器失败', ['error' => $e->getMessage(), 'task_id' => $taskId]);
|
|
|
+
|
|
|
+ // 更新任务状态为失败
|
|
|
+ DB::table('mp_complete_video_tasks')
|
|
|
+ ->where('id', $taskId)
|
|
|
+ ->update([
|
|
|
+ 'generate_status' => '执行失败',
|
|
|
+ 'error_message' => $e->getMessage(),
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 同步更新剧集表状态
|
|
|
+ DB::table('mp_anime_episodes')
|
|
|
+ ->where('complete_video_task_id', $taskId)
|
|
|
+ ->update([
|
|
|
+ 'complete_video_task_status' => '执行失败',
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Utils::throwError('20003:调用远程服务器失败: ' . $e->getMessage());
|
|
|
}
|
|
|
|
|
|
+ // 开始轮询任务状态
|
|
|
+ $maxAttempts = 60; // 5分钟 = 60次 * 5秒
|
|
|
+ $pollInterval = 5; // 每5秒轮询一次
|
|
|
+ $attempt = 0;
|
|
|
+
|
|
|
+ dLog('anime')->info('开始轮询任务状态', ['task_id' => $taskId]);
|
|
|
+
|
|
|
+ while ($attempt < $maxAttempts) {
|
|
|
+ sleep($pollInterval);
|
|
|
+ $attempt++;
|
|
|
+
|
|
|
+ // 查询任务状态
|
|
|
+ $task = DB::table('mp_complete_video_tasks')
|
|
|
+ ->where('id', $taskId)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if (!$task) {
|
|
|
+ dLog('anime')->error('任务不存在', ['task_id' => $taskId]);
|
|
|
+ Utils::throwError('20003:任务不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ dLog('anime')->info('轮询任务状态', [
|
|
|
+ 'task_id' => $taskId,
|
|
|
+ 'attempt' => $attempt,
|
|
|
+ 'status' => $task->generate_status
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 检查任务是否完成
|
|
|
+ if ($task->generate_status === '执行成功') {
|
|
|
+ // 同步更新剧集表状态
|
|
|
+ DB::table('mp_anime_episodes')
|
|
|
+ ->where('anime_id', $animeId)
|
|
|
+ ->where('episode_id', $episodeId)
|
|
|
+ ->update([
|
|
|
+ 'complete_video_task_status' => '执行成功',
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ dLog('anime')->info('视频合成任务完成', [
|
|
|
+ 'task_id' => $taskId,
|
|
|
+ 'video_url' => $task->complete_video_url,
|
|
|
+ 'attempts' => $attempt
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'task_id' => $taskId,
|
|
|
+ 'anime_id' => $animeId,
|
|
|
+ 'episode_id' => $episodeId,
|
|
|
+ 'segment_count' => count($generateJson),
|
|
|
+ 'generate_status' => '执行成功',
|
|
|
+ 'complete_video_url' => $task->complete_video_url,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查任务是否失败
|
|
|
+ if ($task->generate_status === '执行失败') {
|
|
|
+ // 同步更新剧集表状态
|
|
|
+ DB::table('mp_anime_episodes')
|
|
|
+ ->where('anime_id', $animeId)
|
|
|
+ ->where('episode_id', $episodeId)
|
|
|
+ ->update([
|
|
|
+ 'complete_video_task_status' => '执行失败',
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $errorMessage = $task->error_message ?? '未知错误';
|
|
|
+ dLog('anime')->error('视频合成任务失败', [
|
|
|
+ 'task_id' => $taskId,
|
|
|
+ 'error' => $errorMessage,
|
|
|
+ 'attempts' => $attempt
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'task_id' => $taskId,
|
|
|
+ 'anime_id' => $animeId,
|
|
|
+ 'episode_id' => $episodeId,
|
|
|
+ 'segment_count' => count($generateJson),
|
|
|
+ 'generate_status' => '执行失败',
|
|
|
+ 'error_message' => $errorMessage
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 超时处理
|
|
|
+ dLog('anime')->warning('视频合成任务超时', [
|
|
|
+ 'task_id' => $taskId,
|
|
|
+ 'max_attempts' => $maxAttempts,
|
|
|
+ 'timeout_seconds' => $maxAttempts * $pollInterval
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 更新任务状态为超时
|
|
|
+ DB::table('mp_complete_video_tasks')
|
|
|
+ ->where('id', $taskId)
|
|
|
+ ->update([
|
|
|
+ 'generate_status' => '超时',
|
|
|
+ 'error_message' => '任务执行超时(5分钟)',
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
return [
|
|
|
'task_id' => $taskId,
|
|
|
'anime_id' => $animeId,
|
|
|
'episode_id' => $episodeId,
|
|
|
'segment_count' => count($generateJson),
|
|
|
- 'generate_status' => '执行中'
|
|
|
+ 'generate_status' => '超时',
|
|
|
+ 'error_message' => '任务执行超时,请稍后查询任务状态'
|
|
|
];
|
|
|
}
|
|
|
|