parent
4f4701f153
commit
56c3445455
@ -1,10 +1,16 @@
|
||||
package com.dsideal.aiSupport.Test;
|
||||
|
||||
import com.dsideal.aiSupport.Util.JiMengUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dsideal.aiSupport.Util.JiMeng.JmText2VideoUtil;
|
||||
|
||||
public class JiMengVideo {
|
||||
public static void getProgres(JSONObject jo){
|
||||
//{"code":10000,"data":{"task_id":"9346984050829536199"},"time_elapsed":"49.494514ms","message":"Success","request_id":"20250512185250C35CA218D7AD2B8B5B66","status":10000}
|
||||
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
String prompt = "蓝色毛绒玩具在超市里拖地,结果拖把洒出好多五颜六色的粉末,接着把粉末洒向镜头前,镜头随之穿过粉末";
|
||||
//JiMengUtil.generateVideo(prompt);
|
||||
JSONObject jo = JmText2VideoUtil.generateVideo(prompt);
|
||||
System.out.println(jo);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.dsideal.aiSupport.Util.JiMeng;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
|
||||
public class JmImageUtil extends JmCommon {
|
||||
|
||||
/**
|
||||
* 生成图片
|
||||
*
|
||||
* @param prompt 提示词
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void generateImage(String prompt, String saveImgPath) throws Exception {
|
||||
JSONObject req = new JSONObject();
|
||||
req.put("req_key", "jimeng_high_aes_general_v21_L");
|
||||
req.put("prompt", prompt);
|
||||
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), "CVProcess");
|
||||
JSONObject jo = JSON.parseObject(responseBody);
|
||||
String imgBase64 = jo.getJSONObject("data").getJSONArray("binary_data_base64").getFirst().toString();
|
||||
// 对 Base64 字符串进行解码
|
||||
Base64.Decoder decoder = Base64.getDecoder();
|
||||
byte[] bytes = decoder.decode(imgBase64);
|
||||
|
||||
try (OutputStream os = new FileOutputStream(saveImgPath)) { // 使用-with try-resources 自动关闭资源
|
||||
os.write(bytes);
|
||||
os.flush(); // 刷新缓冲区,确保数据写入文件
|
||||
System.out.println("文件保存成功!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.dsideal.aiSupport.Util.JiMeng;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class JmText2VideoUtil extends JmCommon {
|
||||
|
||||
/**
|
||||
* 生成视频
|
||||
*
|
||||
* @param prompt 提示词
|
||||
* @throws Exception
|
||||
*/
|
||||
public static JSONObject generateVideo(String prompt) throws Exception {
|
||||
JSONObject req = new JSONObject();
|
||||
req.put("req_key", "jimeng_vgfm_t2v_l20");
|
||||
req.put("prompt", prompt);
|
||||
String responseBody = doRequest("POST", new HashMap<>(), req.toString().getBytes(), "CVSync2AsyncSubmitTask");
|
||||
return JSON.parseObject(responseBody);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue