Forráskód Böngészése

fix 视频自动去水印

zoujiajian 2 éve
szülő
commit
2cb913f6c8

+ 1 - 1
luma/src/main/java/com/yhlxj/service/midjourney/LumaService.java

@@ -23,7 +23,7 @@ public interface LumaService {
 
     SubmitResult getVideoTaskInfoByTaskId(LumaUser user, Long rid) throws Exception;
 
-    void submitVideoNotify(String json);
+    void submitVideoNotify(String json) throws Exception;
 
     SubmitResult extendedVideo(LumaUser user, SubmitVideoDTO videoDTO) throws Exception;
 

+ 19 - 3
luma/src/main/java/com/yhlxj/service/midjourney/impl/LumaServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
@@ -189,7 +190,9 @@ public class LumaServiceImpl implements LumaService {
                 lumaUserConversation.setStatus(submitResult.getState());
                 SubmitResult.Video video = submitResult.getVideo();
                 lumaUserConversation.setFinishTime(System.currentTimeMillis());
-                lumaUserConversation.setVideoUrl(video.getUrl());
+                //出水印
+                String removeVideoWatermarkUrl = removeVideoWatermark(lumaUserConversation.getTaskId());
+                lumaUserConversation.setVideoUrl(removeVideoWatermarkUrl);
                 lumaUserConversation.setThumbnail(video.getThumbnail());
                 TASK_EXECUTOR.execute(() -> {
                     //同步
@@ -201,7 +204,7 @@ public class LumaServiceImpl implements LumaService {
     }
 
     @Override
-    public void submitVideoNotify(String json) {
+    public void submitVideoNotify(String json) throws Exception {
         log.info("notifyHook:{}", json);
         if (StrUtil.isEmpty(json)) {
             return;
@@ -220,7 +223,8 @@ public class LumaServiceImpl implements LumaService {
         conversation.setStatus(videoTaskData.getState());
         VideoTask.Video video = videoTaskData.getVideo();
         if (video != null) {
-            conversation.setVideoUrl(video.getUrl());
+            String removeVideoWatermarkUrl = removeVideoWatermark(conversation.getTaskId());
+            conversation.setVideoUrl(removeVideoWatermarkUrl);
             conversation.setThumbnail(video.getThumbnail());
         }
         conversation.setFailReason(videoTask.getFail_reason());
@@ -471,4 +475,16 @@ public class LumaServiceImpl implements LumaService {
         log.info("上传视频结果:url:{},json:{}", url, result);
         return result;
     }
+
+    /**
+     * 去水印
+     */
+    public String removeVideoWatermark(String taskId) throws Exception {
+        String url = LUMA_BASE_URL + String.format("/luma/generations/%s/download_video_url", taskId);
+        HttpRequest request = HttpRequest.get(url).header("Authorization", AUTH).setConnectionTimeout(10000);
+        HttpResponse execute = request.execute();
+        String body = execute.body();
+        JSONObject re = Jsons.parseObject(body, JSONObject.class);
+        return re.getStr("url");
+    }
 }

+ 1 - 1
luma/src/main/java/com/yhlxj/web/mirror/LumaController.java

@@ -156,7 +156,7 @@ public class LumaController {
      * 回调
      */
     @PostMapping("/video/notify")
-    public void submitVideoNotify(HttpServletRequest request) throws IOException {
+    public void submitVideoNotify(HttpServletRequest request) throws Exception {
         log.info("提交视频接口回调notifyHook");
         InputStream inputStream = request.getInputStream();
         byte[] bytes = IoKit.toBytes(inputStream);