|
@@ -0,0 +1,148 @@
|
|
|
+package cn.com.ctop.common.module.utils;
|
|
|
+
|
|
|
+import com.tencentcloudapi.common.Credential;
|
|
|
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
+import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
+import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
+import com.tencentcloudapi.mps.v20190612.MpsClient;
|
|
|
+import com.tencentcloudapi.mps.v20190612.models.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.shiro.codec.Base64;
|
|
|
+
|
|
|
+import javax.crypto.Cipher;
|
|
|
+import javax.crypto.spec.IvParameterSpec;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+//@Slf4j
|
|
|
+public class CosUtil {
|
|
|
+ public static final String secretId = "AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets";
|
|
|
+ public static final String secretKey = "tXzuwMfplTTK3c9GFUyETilasvQfePu9";
|
|
|
+ public static final String region = "ap-chongqing";
|
|
|
+ public static final String bucket = "part-1301855440";
|
|
|
+ public static final String host = "https://media-1301855440.cos.ap-chongqing.myqcloud.com";
|
|
|
+
|
|
|
+
|
|
|
+ //创建采样视频截图模板
|
|
|
+ public static void createSampleSnapshotTemplate(){
|
|
|
+ try{
|
|
|
+
|
|
|
+ Credential cred = new Credential(secretId, secretKey);
|
|
|
+
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("mps.tencentcloudapi.com");
|
|
|
+
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+
|
|
|
+ MpsClient client = new MpsClient(cred, region, clientProfile);
|
|
|
+
|
|
|
+ String params = "{\"Name\":\"sampleSnapshotTemplate1\",\"SampleType\":\"Percent\",\"SampleInterval\":7}";
|
|
|
+
|
|
|
+ CreateSampleSnapshotTemplateRequest req = CreateSampleSnapshotTemplateRequest.fromJsonString(params, CreateSampleSnapshotTemplateRequest.class);
|
|
|
+
|
|
|
+ CreateSampleSnapshotTemplateResponse resp = client.CreateSampleSnapshotTemplate(req);
|
|
|
+
|
|
|
+ System.out.println(CreateSampleSnapshotTemplateRequest.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 视频处理模块
|
|
|
+ * 查询已经创建的模板
|
|
|
+ */
|
|
|
+ public static void DescribeSampleSnapshotTemplates(){
|
|
|
+ try{
|
|
|
+ Credential cred = new Credential(secretId, secretKey);
|
|
|
+
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("mps.tencentcloudapi.com");
|
|
|
+
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+
|
|
|
+ MpsClient client = new MpsClient(cred, region, clientProfile);
|
|
|
+
|
|
|
+ String params = "{}";
|
|
|
+ DescribeSampleSnapshotTemplatesRequest req = DescribeSampleSnapshotTemplatesRequest.fromJsonString(params, DescribeSampleSnapshotTemplatesRequest.class);
|
|
|
+
|
|
|
+ DescribeSampleSnapshotTemplatesResponse resp = client.DescribeSampleSnapshotTemplates(req);
|
|
|
+
|
|
|
+ System.out.println(DescribeSampleSnapshotTemplatesRequest.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询抽帧任务状态
|
|
|
+ public static String describeTaskDetail(String taskId){
|
|
|
+ try{
|
|
|
+ Credential cred = new Credential(secretId, secretKey);
|
|
|
+
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("mps.tencentcloudapi.com");
|
|
|
+
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+
|
|
|
+ MpsClient client = new MpsClient(cred, region, clientProfile);
|
|
|
+
|
|
|
+ String params = "{\"TaskId\":\"" + taskId + "\"}";
|
|
|
+ DescribeTaskDetailRequest req = DescribeTaskDetailRequest.fromJsonString(params, DescribeTaskDetailRequest.class);
|
|
|
+
|
|
|
+ DescribeTaskDetailResponse resp = client.DescribeTaskDetail(req);
|
|
|
+
|
|
|
+ System.out.println(DescribeTaskDetailRequest.toJsonString(resp));
|
|
|
+ return DescribeTaskDetailRequest.toJsonString(resp);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //抽帧 42095--已经创建好的采样截图模板,每7%抽一张,一共15张,第一张首帧
|
|
|
+ //videoPath视频路径,包括文件名 高清.mp4 snapshotPath 视频截图路径(包括名字) /高清
|
|
|
+ public static String processMedia(String videoPath, String snapshotPath){
|
|
|
+ try{
|
|
|
+ Credential cred = new Credential(secretId, secretKey);
|
|
|
+
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("mps.tencentcloudapi.com");
|
|
|
+
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+
|
|
|
+ MpsClient client = new MpsClient(cred, region, clientProfile);
|
|
|
+
|
|
|
+ String params = "{\"InputInfo\":{\"Type\":\"COS\",\"CosInputInfo\":{\"Bucket\":\"" + bucket + "\",\"Region\":\"" + region + "\",\"Object\":\"" + videoPath + "\"}},\"MediaProcessTask\":{\"SampleSnapshotTaskSet\":[{\"Definition\":42095,\"OutputStorage\":{\"Type\":\"COS\",\"CosOutputStorage\":{\"Bucket\":\"part-1301855440\",\"Region\":\"" + region + "\"}},\"OutputObjectPath\":\"" + snapshotPath + "\"}]}}";
|
|
|
+
|
|
|
+ ProcessMediaRequest req = ProcessMediaRequest.fromJsonString(params, ProcessMediaRequest.class);
|
|
|
+
|
|
|
+ ProcessMediaResponse resp = client.ProcessMedia(req);
|
|
|
+
|
|
|
+ System.out.println(ProcessMediaRequest.toJsonString(resp));
|
|
|
+ return ProcessMediaRequest.toJsonString(resp);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ //创建采样截图模板
|
|
|
+ createSampleSnapshotTemplate();
|
|
|
+ //查询采样截图模板
|
|
|
+ //DescribeSampleSnapshotTemplates();
|
|
|
+ //查询抽帧任务状态
|
|
|
+ //describeTaskDetail();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|