|
|
|
@ -0,0 +1,56 @@
|
|
|
|
|
package com.dsideal.aiSupport.Util.JiMeng;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
public class JmImageToVideo extends JmCommon {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 提交图生视频任务(使用图片URL)
|
|
|
|
|
*
|
|
|
|
|
* @param imageUrls 图片URL数组
|
|
|
|
|
* @return 任务ID
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject submitImageToVideoTaskWithUrls(List<String> imageUrls, String prompt) throws Exception {
|
|
|
|
|
// 创建请求体
|
|
|
|
|
JSONObject req = new JSONObject();
|
|
|
|
|
req.put("req_key", "jimeng_vgfm_i2v_l20");
|
|
|
|
|
|
|
|
|
|
// 添加图片URL数组
|
|
|
|
|
JSONArray urlArray = new JSONArray();
|
|
|
|
|
urlArray.addAll(imageUrls);
|
|
|
|
|
req.put("image_urls", urlArray);
|
|
|
|
|
req.put("prompt", prompt);
|
|
|
|
|
|
|
|
|
|
// 使用JmCommon中的doRequest方法发送请求
|
|
|
|
|
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), "CVSync2AsyncSubmitTask");
|
|
|
|
|
|
|
|
|
|
// 将响应结果转换为JSONObject并返回
|
|
|
|
|
return JSON.parseObject(responseBody);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询任务结果
|
|
|
|
|
*
|
|
|
|
|
* @param taskId 任务ID
|
|
|
|
|
* @return 任务结果
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static JSONObject queryTaskResult(String taskId) throws Exception {
|
|
|
|
|
return JmQueryTask.queryTaskResult(taskId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
// 示例2:使用图片URL
|
|
|
|
|
//20250512193833EC925A844CCDE58DC8B6
|
|
|
|
|
List<String> imageUrls = new ArrayList<>();
|
|
|
|
|
imageUrls.add("https://dsideal.obs.myhuaweicloud.com/HuangHai/%E5%A4%87%E4%BB%BD/%E5%B0%8F%E4%B9%94%E5%A4%B4%E5%83%8F.jpg"); // 替换为实际图片URL
|
|
|
|
|
String prompt = "眨眨眼";
|
|
|
|
|
JSONObject submitResult = submitImageToVideoTaskWithUrls(imageUrls, prompt);
|
|
|
|
|
System.out.println("提交结果: " + submitResult);
|
|
|
|
|
}
|
|
|
|
|
}
|