|
|
|
@ -10,7 +10,6 @@ import okhttp3.*;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import static com.dsideal.aiSupport.AiSupportApplication.getEnvPrefix;
|
|
|
|
@ -22,6 +21,10 @@ public class DsEmoVideoSynthesis {
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(DsEmoVideoSynthesis.class);
|
|
|
|
|
private static final String API_URL = "https://dashscope.aliyuncs.com/api/v1/services/aigc/image2video/video-synthesis/";
|
|
|
|
|
private static final String API_KEY;
|
|
|
|
|
// 获取项目根目录路径
|
|
|
|
|
protected static String projectRoot = System.getProperty("user.dir").replace("\\", "/") + "/dsAiSupport";
|
|
|
|
|
// 拼接相对路径
|
|
|
|
|
protected static String basePath = projectRoot + "/src/main/java/com/dsideal/aiSupport/Util/DashScope/Example/";
|
|
|
|
|
|
|
|
|
|
public static Prop PropKit; // 配置文件工具
|
|
|
|
|
|
|
|
|
@ -198,6 +201,7 @@ public class DsEmoVideoSynthesis {
|
|
|
|
|
|
|
|
|
|
log.info("视频下载成功,保存路径: {}", savePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 调用人脸检测API
|
|
|
|
|
*
|
|
|
|
@ -256,6 +260,7 @@ public class DsEmoVideoSynthesis {
|
|
|
|
|
|
|
|
|
|
return JSON.parseObject(responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 使用示例
|
|
|
|
|
*/
|
|
|
|
@ -272,18 +277,17 @@ public class DsEmoVideoSynthesis {
|
|
|
|
|
JSONObject result = detectFace(imageUrl, ratio);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 人脸边界框 [x, y, width, height]
|
|
|
|
|
int[] faceBbox = new int[4];
|
|
|
|
|
// 扩展边界框 [x, y, width, height]
|
|
|
|
|
int[] extBbox = new int[4];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 提取人脸边界框数据
|
|
|
|
|
JSONArray faceBboxArray = result.getJSONObject("output").getJSONArray("face_bbox");
|
|
|
|
|
for (int i = 0; i < faceBboxArray.size() && i < 4; i++) {
|
|
|
|
|
faceBbox[i] = faceBboxArray.getIntValue(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 提取扩展边界框数据
|
|
|
|
|
JSONArray extBboxArray = result.getJSONObject("output").getJSONArray("ext_bbox");
|
|
|
|
|
for (int i = 0; i < extBboxArray.size() && i < 4; i++) {
|
|
|
|
@ -327,16 +331,11 @@ public class DsEmoVideoSynthesis {
|
|
|
|
|
if (retryCount >= maxRetries) {
|
|
|
|
|
log.error("查询任务状态超时,已达到最大重试次数: {}", maxRetries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果获取到了视频URL,则下载保存
|
|
|
|
|
if (videoUrl != null && !videoUrl.isEmpty()) {
|
|
|
|
|
// 创建保存目录
|
|
|
|
|
String saveDir = System.getProperty("user.dir") + "/emo_videos";
|
|
|
|
|
// 生成文件名(使用时间戳和任务ID)
|
|
|
|
|
String fileName = "emo_" + System.currentTimeMillis() + "_" + taskId + ".mp4";
|
|
|
|
|
// 完整保存路径
|
|
|
|
|
String savePath = saveDir + "/" + fileName;
|
|
|
|
|
|
|
|
|
|
String savePath = basePath + "/" + fileName;
|
|
|
|
|
// 下载视频
|
|
|
|
|
downloadVideo(videoUrl, savePath);
|
|
|
|
|
}
|
|
|
|
|