瀏覽代碼

增加视频水印方法

xuzuoyun 5 年之前
父節點
當前提交
afc93ff194
共有 2 個文件被更改,包括 59 次插入0 次删除
  1. 58 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/MpsUtils.java
  2. 1 0
      pom.xml

+ 58 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/MpsUtils.java

@@ -269,6 +269,64 @@ public class MpsUtils {
         return jobId;
         return jobId;
     }
     }
 
 
+    public String videoWaterMark(String videoPath,String waterMarkPath,String watermarkTemplateId){
+        String jobId = "";
+        IAcsClient client = getClient();
+        String pipelineId = getPipelineId(client);
+        SubmitJobsRequest request = new SubmitJobsRequest();
+        JSONObject videoWatermarkInput = new JSONObject();
+        videoWatermarkInput.put("Location", ossLocation);
+        videoWatermarkInput.put("Bucket", ossBucket);
+        try {
+            videoWatermarkInput.put("Object", URLEncoder.encode(videoPath, "utf-8"));
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException("videoWatetmark Input URL encode failed");
+        }
+        JSONObject videoWatermark = new JSONObject();
+        videoWatermark.put("WaterMarkTemplateId", watermarkTemplateId);
+        videoWatermark.put("Type", "Image");
+        videoWatermark.put("InputFile", videoWatermarkInput);
+        videoWatermark.put("ReferPos", "BottomLeft");
+        videoWatermark.put("Height", "240");
+        videoWatermark.put("Dx", "0");
+        videoWatermark.put("Dy", "0");
+        String outputOSSObject;
+        try {
+            outputOSSObject = URLEncoder.encode(waterMarkPath, "utf-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException("output URL encode failed");
+        }
+        JSONObject output = new JSONObject();
+        output.put("OutputObject", outputOSSObject);
+        JSONArray watermarks = new JSONArray();
+        watermarks.add(videoWatermark);
+        output.put("WaterMarks", watermarks.toJSONString());
+        // Outputs
+        JSONArray outputs = new JSONArray();
+        outputs.add(output);
+        request.setOutputs(outputs.toJSONString());
+        request.setOutputBucket(ossBucket);
+        request.setOutputLocation(ossLocation);
+        // PipelineId
+        request.setPipelineId(pipelineId);
+        SubmitJobsResponse response;
+        try {
+            response = client.getAcsResponse(request);
+            System.out.println("RequestId is:"+response.getRequestId());
+            if (response.getJobResultList().get(0).getSuccess()) {
+                jobId = response.getJobResultList().get(0).getJob().getJobId();
+                System.out.println("JobId is:" + response.getJobResultList().get(0).getJob().getJobId());
+            } else {
+                System.out.println("SubmitJobs Failed code:" + response.getJobResultList().get(0).getCode() +
+                        " message:" + response.getJobResultList().get(0).getMessage());
+            }
+        } catch (ServerException e) {
+            e.printStackTrace();
+        } catch (ClientException e) {
+            e.printStackTrace();
+        }
+        return jobId;
+    }
 
 
 
 
     public String getPipelineId(IAcsClient client){
     public String getPipelineId(IAcsClient client){

+ 1 - 0
pom.xml

@@ -67,6 +67,7 @@
             <id>maven-3rdparty</id>
             <id>maven-3rdparty</id>
             <url>https://packages.atlassian.com/maven-3rdparty/</url>
             <url>https://packages.atlassian.com/maven-3rdparty/</url>
         </repository>
         </repository>
+
     </repositories>
     </repositories>
 
 
     <properties>
     <properties>