Browse Source

Merge branch 'test' into test-cut

yumeng 5 năm trước cách đây
mục cha
commit
6861a6b4f4

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/constant/CosConstant.java

@@ -6,6 +6,8 @@ public class CosConstant {
     public static final String URL="https://media-1301855440.ci.ap-chongqing.myqcloud.com/";
     //jobs接口URL
     public static final String URL_JOBS=URL+"jobs";
+    //snapshot接口URL
+    public static final String URL_SNAPSHOT=URL+"snapshot";
     //截帧模板ID
     public static final String TEMPLATE_ID="t11931b0daf5bf4776b612b4136ad67d00";
     //数据万象队列ID

+ 43 - 1
module-common/src/main/java/cn/com/ctop/common/module/utils/CloudVideoProcessUtil.java

@@ -197,7 +197,43 @@ public class CloudVideoProcessUtil {
         }
         return result;
     }
+    /**
+     *  数据万象获取截图服务
+     */
+    public static String videoCutPictureHandle(String videoPath, String outputPath) {
+        String auth =generateAuth(SECRET_ID,SECRET_KEY,"/snapshot",HttpMethodName.POST);
+        if(auth.isEmpty()){
+            logger.error("腾讯云Authorization获取失败");
+        }
+        //拼接请求数据万象jobs接口的参数
+        JSONObject input = new JSONObject();
+        input.put("Object", videoPath);
+        JSONObject output = new JSONObject();
+        output.put("Region", COS_LOCATION);
+        output.put("Bucket", COS_BUCKET_MEDIA);
+        output.put("Object", outputPath);
+        JSONObject request = new JSONObject();
+        request.put("Input",input);
+        request.put("Output",output);
+        request.put("Time",0);
 
+        //请求media-1301855440.ci.ap-chongqing.myqcloud.com/snapshot 接口
+        HttpHeaders headers = new HttpHeaders();
+        headers.set("Authorization", auth);
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        HttpEntity<String> requestEntity = new HttpEntity<>(request.toJSONString(), headers);
+        String response = null;
+        try {
+            response = restTemplate.exchange(CosConstant.URL_SNAPSHOT, HttpMethod.POST, requestEntity, String.class).getBody();
+        } catch (RestClientException e) {
+            logger.error(e.getMessage());
+        }
+        if(response.isEmpty()){
+            return CosConstant.URL_COS_ADDRESS+"error.jpg";
+        }else{
+            return CosConstant.URL_COS_ADDRESS+outputPath;
+        }
+    }
     /**
      * 获取视频处理服务 MpsClient
      */
@@ -239,12 +275,18 @@ public class CloudVideoProcessUtil {
     }
     private static Map<String,Object> getFrameUrl(String  outputPath){
         Map<String,Object> result=new HashMap<>();
-        for(int i=0;i<15;i++){
+        for(int i=1;i<15;i++){
             result.put(""+i+"",CosConstant.URL_COS_ADDRESS+outputPath.replace("${Number}",""+i+""));
         }
         return result;
     }
 
+    private static Map<String,Object> getPictureUrl(String  outputPath){
+        Map<String,Object> result=new HashMap<>();
+        result.put("0",CosConstant.URL_COS_ADDRESS+outputPath);
+        return result;
+    }
+
     private static Map<String,Object> getErrorUrl(){
         Map<String,Object> result=new HashMap<>();
             result.put("0",CosConstant.URL_COS_ADDRESS+"error.jpg");