|
@@ -19,6 +19,7 @@ import com.tencent.cloud.Response;
|
|
|
import com.tencent.cloud.Statement;
|
|
import com.tencent.cloud.Statement;
|
|
|
import com.tencent.cloud.cos.util.Jackson;
|
|
import com.tencent.cloud.cos.util.Jackson;
|
|
|
import com.tencentcloudapi.common.Credential;
|
|
import com.tencentcloudapi.common.Credential;
|
|
|
|
|
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
import com.tencentcloudapi.mps.v20190612.MpsClient;
|
|
import com.tencentcloudapi.mps.v20190612.MpsClient;
|
|
@@ -290,7 +291,7 @@ public class TencentCloudCosService implements ITencentCloudCosService {
|
|
|
return input.replace("course", "course_transcode_100301");
|
|
return input.replace("course", "course_transcode_100301");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void submitTranscodeJob(String inputPath,String outputPath) {
|
|
|
|
|
|
|
+ public String submitTranscodeJob(String inputPath,String outputPath) {
|
|
|
try {
|
|
try {
|
|
|
// 输入文件配置(COS路径)
|
|
// 输入文件配置(COS路径)
|
|
|
MpsClient client = createMpsClient();
|
|
MpsClient client = createMpsClient();
|
|
@@ -332,8 +333,115 @@ public class TencentCloudCosService implements ITencentCloudCosService {
|
|
|
// 提交任务
|
|
// 提交任务
|
|
|
ProcessMediaResponse resp = client.ProcessMedia(req);
|
|
ProcessMediaResponse resp = client.ProcessMedia(req);
|
|
|
System.out.println("任务提交成功,JobId: " + resp.getTaskId());
|
|
System.out.println("任务提交成功,JobId: " + resp.getTaskId());
|
|
|
|
|
+ return resp.getTaskId();
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R videoTranscode(Long videoId) {
|
|
|
|
|
+ FsUserCourseVideo fsUserCourseVideo = courseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
|
|
+ //查出未转码的视频
|
|
|
|
|
+ FsVideoResource video = videoResourceMapper.selectByFileKey(fsUserCourseVideo.getFileKey());
|
|
|
|
|
+ String inputPath = "/"+video.getFileKey();
|
|
|
|
|
+ String outputPath = "/"+replaceCourse(video.getFileKey());
|
|
|
|
|
+ String taskId = submitTranscodeJob(inputPath,outputPath);
|
|
|
|
|
+ FsVideoResource videoMap = new FsVideoResource();
|
|
|
|
|
+ videoMap.setId(video.getId());
|
|
|
|
|
+ videoMap.setIsTranscode(1);
|
|
|
|
|
+ videoResourceMapper.updateById(videoMap);
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok(taskId);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 简单查询任务状态(基于你提供的JSON结构)
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean queryTaskSimple(MpsClient client, String taskId) throws TencentCloudSDKException {
|
|
|
|
|
+ DescribeTaskDetailRequest req = new DescribeTaskDetailRequest();
|
|
|
|
|
+ req.setTaskId(taskId);
|
|
|
|
|
+
|
|
|
|
|
+ DescribeTaskDetailResponse resp = client.DescribeTaskDetail(req);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("任务查询结果:");
|
|
|
|
|
+ System.out.println("任务ID: " + taskId);
|
|
|
|
|
+ System.out.println("主状态: " + resp.getStatus());
|
|
|
|
|
+ System.out.println("任务类型: " + resp.getTaskType());
|
|
|
|
|
+ System.out.println("创建时间: " + resp.getCreateTime());
|
|
|
|
|
+
|
|
|
|
|
+ if (resp.getFinishTime() != null && !resp.getFinishTime().isEmpty()) {
|
|
|
|
|
+ System.out.println("完成时间: " + resp.getFinishTime());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String status = resp.getStatus();
|
|
|
|
|
+
|
|
|
|
|
+ // 判断任务状态
|
|
|
|
|
+ switch (status) {
|
|
|
|
|
+ case "PROCESSING":
|
|
|
|
|
+ System.out.println("任务处理中...");
|
|
|
|
|
+ return true;
|
|
|
|
|
+
|
|
|
|
|
+ case "FINISH":
|
|
|
|
|
+ // 检查工作流任务详情
|
|
|
|
|
+ WorkflowTask workflowTask = resp.getWorkflowTask();
|
|
|
|
|
+ if (workflowTask == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("工作流状态: " + workflowTask.getStatus());
|
|
|
|
|
+ System.out.println("工作流消息: " + workflowTask.getMessage());
|
|
|
|
|
+
|
|
|
|
|
+ // 如果工作流状态不是FINISH,说明可能没真正完成
|
|
|
|
|
+ if (!"FINISH".equals(workflowTask.getStatus())) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查错误码
|
|
|
|
|
+ if (workflowTask.getErrCode() != null && workflowTask.getErrCode() != 0) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("任务已完成");
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+ case "FAIL":
|
|
|
|
|
+ System.out.println("任务失败");
|
|
|
|
|
+ // 打印失败详情
|
|
|
|
|
+ printFailureDetails(resp);
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ System.out.println("未知状态: " + status);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static void printFailureDetails(DescribeTaskDetailResponse resp) {
|
|
|
|
|
+ WorkflowTask workflowTask = resp.getWorkflowTask();
|
|
|
|
|
+ if (workflowTask != null) {
|
|
|
|
|
+ System.out.println("工作流错误码: " + workflowTask.getErrCode());
|
|
|
|
|
+ System.out.println("工作流错误消息: " + workflowTask.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
|
|
+ public R updateUrl(Long videoId, String taskId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ MpsClient client = createMpsClient();
|
|
|
|
|
+ if (queryTaskSimple(client,taskId)){
|
|
|
|
|
+ return R.error("未完成请稍后在操作!");
|
|
|
|
|
+ }
|
|
|
|
|
+ FsUserCourseVideo fsUserCourseVideo = courseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
|
|
+ //查出未转码的视频
|
|
|
|
|
+ FsVideoResource video = videoResourceMapper.selectByFileKey(fsUserCourseVideo.getFileKey());
|
|
|
|
|
+ updateSingleVideo(video);
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return R.error(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|