Przeglądaj źródła

修正图生视频参数设置

cmy 4 tygodni temu
rodzic
commit
3827926943

+ 45 - 40
src/main/java/com/backendsys/modules/ai/volcengine/service/impl/VolcengineVideoTaskServiceImpl.java

@@ -75,28 +75,29 @@ public class VolcengineVideoTaskServiceImpl extends ServiceImpl<VolcengineVideoT
 
         // 图生视频功能 构建请求参数
         // 文本提示词与参数组合
-        if (StringUtils.isNotBlank(volcengineVideoTask.getText())) {
-            StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
-            if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
-                text.append(" --rs ").append(volcengineVideoTask.getResolution());
-            }
-            if(volcengineVideoTask.getDuration() != null) {
-                text.append(" --dur ").append(volcengineVideoTask.getDuration());
-            }
-            if(volcengineVideoTask.getCamerafixed() != null) {
-                if (volcengineVideoTask.getCamerafixed() == 1) {
-                    text.append(" --cf true");
-                } else {
-                    text.append(" --cf false");
-                }
+        if (StringUtils.isBlank(volcengineVideoTask.getText())) {
+            volcengineVideoTask.setText("");
+        }
+        StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
+        if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
+            text.append(" --rs ").append(volcengineVideoTask.getResolution());
+        }
+        if(volcengineVideoTask.getDuration() != null) {
+            text.append(" --dur ").append(volcengineVideoTask.getDuration());
+        }
+        if(volcengineVideoTask.getCamerafixed() != null) {
+            if (volcengineVideoTask.getCamerafixed() == 1) {
+                text.append(" --cf true");
+            } else {
+                text.append(" --cf false");
             }
-
-            contents.add(CreateContentGenerationTaskRequest.Content.builder()
-                    .type("text")
-                    .text(text.toString())
-                    .build());
         }
 
+        contents.add(CreateContentGenerationTaskRequest.Content.builder()
+                .type("text")
+                .text(text.toString())
+                .build());
+
         // 首帧图片 (若仅需使用文本生成视频功能,可将此部分内容进行注释处理。)
         contents.add(CreateContentGenerationTaskRequest.Content.builder()
                 .type("image_url")
@@ -253,28 +254,30 @@ public class VolcengineVideoTaskServiceImpl extends ServiceImpl<VolcengineVideoT
 
         // 图生视频功能 构建请求参数
         // 文本提示词与参数组合
-        if (StringUtils.isNotBlank(volcengineVideoTask.getText())) {
-            StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
-            if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
-                text.append(" --rs ").append(volcengineVideoTask.getResolution());
-            }
-            if(volcengineVideoTask.getDuration() != null) {
-                text.append(" --dur ").append(volcengineVideoTask.getDuration());
-            }
-            if(volcengineVideoTask.getCamerafixed() != null) {
-                if (volcengineVideoTask.getCamerafixed() == 1) {
-                    text.append(" --cf true");
-                } else {
-                    text.append(" --cf false");
-                }
+        if (StringUtils.isBlank(volcengineVideoTask.getText())) {
+            volcengineVideoTask.setText("");
+        }
+        StringBuilder text = new StringBuilder(volcengineVideoTask.getText());
+        if(StringUtils.isNotBlank(volcengineVideoTask.getResolution())) {
+            text.append(" --rs ").append(volcengineVideoTask.getResolution());
+        }
+        if(volcengineVideoTask.getDuration() != null) {
+            text.append(" --dur ").append(volcengineVideoTask.getDuration());
+        }
+        if(volcengineVideoTask.getCamerafixed() != null) {
+            if (volcengineVideoTask.getCamerafixed() == 1) {
+                text.append(" --cf true");
+            } else {
+                text.append(" --cf false");
             }
-
-            contents.add(CreateContentGenerationTaskRequest.Content.builder()
-                    .type("text")
-                    .text(text.toString())
-                    .build());
         }
 
+        contents.add(CreateContentGenerationTaskRequest.Content.builder()
+                .type("text")
+                .text(text.toString())
+                .build());
+
+
         // 首帧图片 (若仅需使用文本生成视频功能,可将此部分内容进行注释处理。)
         contents.add(CreateContentGenerationTaskRequest.Content.builder()
                 .type("image_url")
@@ -282,12 +285,14 @@ public class VolcengineVideoTaskServiceImpl extends ServiceImpl<VolcengineVideoT
                         .url(volcengineVideoTask.getImg_url())
                         .build())
                 .build());
+
+        String notifyUrl = domain+ "/api/ai/volcengine/video/notify";
         // 创建视频生成任务
         CreateContentGenerationTaskRequest createRequest = CreateContentGenerationTaskRequest.builder()
                 .model(volcengineVideoTask.getModel())
                 .content(contents)
-                // todo callback_url 回调地址
-//                .callbackUrl()
+                // 回调地址
+                .callbackUrl(notifyUrl)
                 .build();
 
         dataBean.setUser_id(volcengineVideoTaskDetail.getUser_id());

+ 22 - 19
src/main/java/com/backendsys/modules/sdk/volcengine/service/impl/VolcengineImage2VideoServiceImpl.java

@@ -35,27 +35,30 @@ public class VolcengineImage2VideoServiceImpl implements VolcengineImage2VideoSe
 
         // 图生视频功能
         // 文本提示词与参数组合
-        if (StringUtils.isNotBlank(params.getText())) {
-            StringBuilder text = new StringBuilder(params.getText());
-            if(StringUtils.isNotBlank(params.getResolution())) {
-                text.append(" --rs ").append(params.getResolution());
-            }
-            if(params.getDuration() != null) {
-                text.append(" --dur ").append(params.getDuration());
-            }
-            if(params.getCamerafixed() != null) {
-                if (params.getCamerafixed() == 1) {
-                    text.append(" --cf true");
-                } else {
-                    text.append(" --cf false");
-                }
-            }
+        if (StringUtils.isBlank(params.getText())) {
+            params.setText("");
+        }
 
-            contents.add(CreateContentGenerationTaskRequest.Content.builder()
-                    .type("text")
-                    .text(text.toString())
-                    .build());
+        StringBuilder text = new StringBuilder(params.getText());
+        if(StringUtils.isNotBlank(params.getResolution())) {
+            text.append(" --rs ").append(params.getResolution());
+        }
+        if(params.getDuration() != null) {
+            text.append(" --dur ").append(params.getDuration());
         }
+        if(params.getCamerafixed() != null) {
+            if (params.getCamerafixed() == 1) {
+                text.append(" --cf true");
+            } else {
+                text.append(" --cf false");
+            }
+        }
+
+        contents.add(CreateContentGenerationTaskRequest.Content.builder()
+                .type("text")
+                .text(text.toString())
+                .build());
+
 
         // 首帧图片 (若仅需使用文本生成视频功能,可将此部分内容进行注释处理。)
         contents.add(CreateContentGenerationTaskRequest.Content.builder()

+ 4 - 3
src/main/resources/mapper/ai/volcengine/VolcengineVideoTaskDao.xml

@@ -73,7 +73,7 @@
     <!-- 收藏任务映射 -->
     <resultMap id="resultMapTaskCollect" type="com.backendsys.modules.ai.volcengine.entity.VolcengineVideoTask" extends="baseTaskMap">
         <collection select="queryDetailCollectById" property="detail_list" javaType="java.util.List"
-                    ofType="com.backendsys.modules.ai.volcengine.entity.VolcengineVideoTaskDetail" column="{id=id, user_id=user_id}">
+                    ofType="com.backendsys.modules.ai.volcengine.entity.VolcengineVideoTaskDetail" column="{id=id, param_user_id=param_user_id}">
             <id property="id" column="id" />
             <result property="user_id" column="user_id" />
             <result property="task_id" column="task_id" />
@@ -137,7 +137,8 @@
             resultMap="resultMapTaskCollect">
         SELECT
                <include refid="includeVolcengineVideoTask" />
-               , 1 AS is_collect
+               , 1 AS is_collect,
+                #{dto.user_id} as param_user_id
         FROM ai_volcengine_video_task avvt
         INNER JOIN (
             SELECT
@@ -168,7 +169,7 @@
         INNER JOIN ai_volcengine_video_collect avc
             ON avc.task_id = avvtd.task_id
             AND avc.task_detail_id = avvtd.id
-            AND avc.user_id = #{user_id}
+            AND avc.user_id = #{param_user_id}
         WHERE avvtd.task_id = #{id}
         ORDER BY update_time DESC
     </select>