头像视频合成支持动态模型
This commit is contained in:
@@ -45,6 +45,8 @@ public class FaceDetectController {
|
||||
@RequestParam(value = "ownerName", required = false) String ownerName,
|
||||
@Parameter(description = "所属人电话", required = false)
|
||||
@RequestParam(value = "ownerPhone", required = false) String ownerPhone,
|
||||
@Parameter(description = "模型名称", required = false)
|
||||
@RequestParam(value = "model", required = false) String model,
|
||||
@Parameter(description = "头像名称", required = false)
|
||||
@RequestParam(value = "avatarName", required = false) String avatarName) {
|
||||
|
||||
@@ -98,6 +100,8 @@ public class FaceDetectController {
|
||||
@RequestParam(value = "ownerPhone", required = false) String ownerPhone,
|
||||
@Parameter(description = "头像名称", required = false)
|
||||
@RequestParam(value = "avatarName", required = false) String avatarName,
|
||||
@Parameter(description = "模型名称", required = false)
|
||||
@RequestParam(value = "model", required = false) String model,
|
||||
@Parameter(description = "短链接有效期(秒),默认1小时", required = false)
|
||||
@RequestParam(value = "expiresInSeconds", defaultValue = "3600") int expiresInSeconds) {
|
||||
|
||||
@@ -149,8 +153,8 @@ public class FaceDetectController {
|
||||
log.info("短链接生成成功: {}", shortUrl);
|
||||
|
||||
// 4. 进行人脸检测
|
||||
log.info("开始进行人脸检测...");
|
||||
com.rj.entity.FaceDetectLog detectLog = faceDetectLogService.detectFaceAndSave(shortUrl, ownerName, ownerPhone, avatarName);
|
||||
log.info("开始进行人脸检测,使用模型: {}", model != null ? model : "默认模型");
|
||||
com.rj.entity.FaceDetectLog detectLog = faceDetectLogService.detectFaceAndSave(shortUrl, ownerName, ownerPhone, avatarName, model);
|
||||
|
||||
// 5. 构建响应结果
|
||||
result.put("success", true);
|
||||
@@ -165,6 +169,7 @@ public class FaceDetectController {
|
||||
result.put("ownerName", ownerName);
|
||||
result.put("ownerPhone", ownerPhone);
|
||||
result.put("avatarName", avatarName);
|
||||
result.put("model", model);
|
||||
|
||||
// 人脸检测结果
|
||||
result.put("faceDetection", detectLog.toString());
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.rj.dto.VideoSynthesisRequestDto;
|
||||
import com.rj.entity.VideoSynthesisLog;
|
||||
import com.rj.mapper.VideoSynthesisLogMapper;
|
||||
import com.rj.service.IVideoSynthesisService;
|
||||
import com.rj.service.MinIOService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -35,6 +36,9 @@ public class VideoSynthesisFromController {
|
||||
|
||||
@Autowired
|
||||
private VideoSynthesisLogMapper videoSynthesisLogMapper;
|
||||
|
||||
@Autowired
|
||||
private MinIOService minIOService;
|
||||
|
||||
/**
|
||||
* 视频合成接口
|
||||
@@ -256,4 +260,144 @@ public class VideoSynthesisFromController {
|
||||
return ResponseEntity.status(500).body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据MinIO路径播放视频
|
||||
*/
|
||||
@GetMapping("/play/{minioPath}")
|
||||
@Operation(summary = "播放视频", description = "根据MinIO路径生成预签名URL播放视频")
|
||||
public ResponseEntity<Map<String, Object>> playVideo(
|
||||
@Parameter(description = "MinIO文件路径", required = true)
|
||||
@PathVariable String minioPath,
|
||||
@Parameter(description = "过期时间(秒),默认7天", required = false)
|
||||
@RequestParam(value = "expires", defaultValue = "900") int expires) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
log.info("开始生成视频播放URL,MinIO路径: {}, 过期时间: {}秒", minioPath, expires);
|
||||
|
||||
// 验证路径格式
|
||||
if (minioPath == null || minioPath.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "MinIO路径不能为空");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
// 清理路径,移除开头的斜杠
|
||||
String cleanPath = minioPath.startsWith("/") ? minioPath.substring(1) : minioPath;
|
||||
|
||||
// 生成预签名URL
|
||||
String presignedUrl = minIOService.getPresignedUrl(cleanPath, expires);
|
||||
|
||||
if (presignedUrl == null || presignedUrl.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "生成预签名URL失败");
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
|
||||
// 构建响应结果
|
||||
result.put("success", true);
|
||||
result.put("message", "视频播放URL生成成功");
|
||||
result.put("minioPath", minioPath);
|
||||
result.put("presignedUrl", presignedUrl);
|
||||
result.put("expires", expires);
|
||||
result.put("expiresInDays", expires / 86400); // 转换为天数
|
||||
|
||||
log.info("视频播放URL生成成功: {}", presignedUrl);
|
||||
return ResponseEntity.ok(result);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成视频播放URL失败: {}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "生成视频播放URL失败: " + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据任务ID播放视频
|
||||
*/
|
||||
@GetMapping("/play/task/{taskId}")
|
||||
@Operation(summary = "根据任务ID播放视频", description = "根据任务ID查找视频并生成播放URL")
|
||||
public ResponseEntity<Map<String, Object>> playVideoByTaskId(
|
||||
@Parameter(description = "任务ID", required = true)
|
||||
@PathVariable String taskId,
|
||||
@Parameter(description = "过期时间(秒),默认7天", required = false)
|
||||
@RequestParam(value = "expires", defaultValue = "604800") int expires) {
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
try {
|
||||
log.info("开始根据任务ID播放视频,任务ID: {}, 过期时间: {}秒", taskId, expires);
|
||||
|
||||
// 根据任务ID查询视频合成记录
|
||||
QueryWrapper<VideoSynthesisLog> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("task_id", taskId);
|
||||
VideoSynthesisLog synthesisLog = videoSynthesisLogMapper.selectOne(queryWrapper);
|
||||
|
||||
if (synthesisLog == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "未找到对应的视频合成记录");
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
if (synthesisLog.getVideoUrl() == null || synthesisLog.getVideoUrl().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "视频URL为空,可能视频还未生成完成");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
// 从videoUrl中提取MinIO路径
|
||||
String videoUrl = synthesisLog.getVideoUrl();
|
||||
String minioPath;
|
||||
|
||||
// 判断是否为MinIO URL格式
|
||||
if (videoUrl.contains("/minio/")) {
|
||||
// 从MinIO URL中提取路径
|
||||
String[] parts = videoUrl.split("/minio/");
|
||||
if (parts.length > 1) {
|
||||
minioPath = parts[1];
|
||||
} else {
|
||||
result.put("success", false);
|
||||
result.put("message", "无法从视频URL中提取MinIO路径");
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
} else {
|
||||
// 假设直接是MinIO路径
|
||||
minioPath = videoUrl;
|
||||
}
|
||||
|
||||
// 生成预签名URL
|
||||
String presignedUrl = minIOService.getPresignedUrl(minioPath, expires);
|
||||
|
||||
if (presignedUrl == null || presignedUrl.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "生成预签名URL失败");
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
|
||||
// 构建响应结果
|
||||
result.put("success", true);
|
||||
result.put("message", "视频播放URL生成成功");
|
||||
result.put("taskId", taskId);
|
||||
result.put("requestId", synthesisLog.getRequestId());
|
||||
result.put("videoName", synthesisLog.getVideoName());
|
||||
result.put("minioPath", minioPath);
|
||||
result.put("presignedUrl", presignedUrl);
|
||||
result.put("expires", expires);
|
||||
result.put("expiresInDays", expires / 86400);
|
||||
result.put("taskStatus", synthesisLog.getTaskStatus());
|
||||
result.put("success", synthesisLog.getSuccess());
|
||||
|
||||
log.info("根据任务ID生成视频播放URL成功: {}", presignedUrl);
|
||||
return ResponseEntity.ok(result);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("根据任务ID生成视频播放URL失败: {}", e.getMessage(), e);
|
||||
result.put("success", false);
|
||||
result.put("message", "生成视频播放URL失败: " + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +361,10 @@ public class MenuController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -331,6 +331,10 @@ public class RoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -337,6 +337,10 @@ public class UserRoleController {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user