|
@@ -0,0 +1,749 @@
|
|
|
+package cn.com.ctop.track.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.track.service.MediaService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.qcloud.vod.VodUploadClient;
|
|
|
+import com.qcloud.vod.model.VodUploadRequest;
|
|
|
+import com.qcloud.vod.model.VodUploadResponse;
|
|
|
+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.vod.v20180717.VodClient;
|
|
|
+import com.tencentcloudapi.vod.v20180717.models.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static java.util.Collections.shuffle;
|
|
|
+
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class MediaServiceImpl implements MediaService {
|
|
|
+
|
|
|
+ public static Integer count = 0;
|
|
|
+ public static Integer qianIndex = 0;
|
|
|
+ public static Integer houIndex = 0;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void test() {
|
|
|
+ VodUploadClient client = new VodUploadClient("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ JSONArray qianTieArray = new JSONArray();
|
|
|
+ String qianTiePath = "D:\\file\\a";
|
|
|
+ JSONArray files = getFiles(qianTiePath);
|
|
|
+ for (int i = 0; i < files.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(files.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+ // log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ qianTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray houTieArray = new JSONArray();
|
|
|
+ String houTiePath = "D:\\file\\b";
|
|
|
+ JSONArray houTieFiles = getFiles(houTiePath);
|
|
|
+ for (int i = 0; i < houTieFiles.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(houTieFiles.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+// log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ houTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < qianTieArray.size(); i++) {
|
|
|
+ String s = qianTieArray.getString(i);
|
|
|
+ list2(qianTieArray, s, houTieArray);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> list2(JSONArray list, String value, JSONArray houTieArray) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ String s = list.getString(i);
|
|
|
+ if (s.equals(value)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ this.list3(list, value, s, houTieArray);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<String> list3(JSONArray list, String value1, String value2, JSONArray houTieArray) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ String value3 = list.getString(i);
|
|
|
+ if (value3.equals(value1) || value3.equals(value2)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (int j = 0; j < houTieArray.size(); j++) {
|
|
|
+ String houtie = houTieArray.getString(j);
|
|
|
+ JSONArray jieGuoList = new JSONArray();
|
|
|
+ jieGuoList.add(value1);
|
|
|
+ jieGuoList.add(value2);
|
|
|
+ jieGuoList.add(value3);
|
|
|
+ jieGuoList.add(houtie);
|
|
|
+ count++;
|
|
|
+ this.editMedia(jieGuoList, "束荣莉-金曲-四批次" + "_" + count);
|
|
|
+ System.err.println(count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void vodUpload() throws Exception {
|
|
|
+ VodUploadClient client = new VodUploadClient("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ JSONArray qianTieArray = new JSONArray();
|
|
|
+ String qianTiePath = "D:\\file\\a";
|
|
|
+ JSONArray files = getFiles(qianTiePath);
|
|
|
+ for (int i = 0; i < files.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(files.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+ // log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ qianTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray houTieArray = new JSONArray();
|
|
|
+ String houTiePath = "D:\\file\\b";
|
|
|
+ JSONArray houTieFiles = getFiles(houTiePath);
|
|
|
+ for (int i = 0; i < houTieFiles.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(houTieFiles.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+// log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ houTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer count = 0;
|
|
|
+ for (int i = 0; i < qianTieArray.size(); i++) {
|
|
|
+ String qianTieFileId = qianTieArray.getString(i);
|
|
|
+ for (int j = 0; j < houTieArray.size(); j++) {
|
|
|
+ String houtieFileId = houTieArray.getString(j);
|
|
|
+
|
|
|
+ JSONArray ids = new JSONArray();
|
|
|
+ ids.add(qianTieFileId);
|
|
|
+ ids.add(houtieFileId);
|
|
|
+ editMedia(ids, "来玩削削削_女_" + count);
|
|
|
+ count++;
|
|
|
+ System.err.println(count);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void test2() {
|
|
|
+
|
|
|
+ VodUploadClient client = new VodUploadClient("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ JSONArray qianTieArray = new JSONArray();
|
|
|
+ String qianTiePath = "D:\\file\\a";
|
|
|
+ JSONArray files = getFiles(qianTiePath);
|
|
|
+ for (int i = 0; i < files.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(files.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+ // log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ qianTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray zhongList = new JSONArray();
|
|
|
+ String zhongTiePath = "D:\\file\\b";
|
|
|
+ JSONArray zhongFiles = getFiles(zhongTiePath);
|
|
|
+ for (int i = 0; i < zhongFiles.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(zhongFiles.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+// log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ zhongList.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+/* List<String> houList = new ArrayList<>();
|
|
|
+ String houTiePath = "D:\\file\\c";
|
|
|
+ JSONArray houTieFiles = getFiles(houTiePath);
|
|
|
+ for (int i = 0; i < houTieFiles.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(houTieFiles.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+// log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ houList.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < zhongList.size(); i++) {
|
|
|
+ String s = zhongList.getString(i);
|
|
|
+ JSONArray array = pipei1(i, s, qianTieArray);
|
|
|
+ // JSONArray array1 = pipei2(i, houList, array);
|
|
|
+ editMedia(array, "乐刷刷_06-01_女_" + count);
|
|
|
+ count++;
|
|
|
+ System.err.println(count);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void test3() {
|
|
|
+ VodUploadClient client = new VodUploadClient("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ JSONArray qianTieArray = new JSONArray();
|
|
|
+ String qianTiePath = "D:\\file\\a";
|
|
|
+ JSONArray files = getFiles(qianTiePath);
|
|
|
+ for (int i = 0; i < files.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(files.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+ // log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ qianTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ JSONArray houTieArray = new JSONArray();
|
|
|
+ String houTiePath = "D:\\file\\b";
|
|
|
+ JSONArray houTieFiles = getFiles(houTiePath);
|
|
|
+ for (int i = 0; i < houTieFiles.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(houTieFiles.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+// log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ houTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<List<Object>> partition = Lists.partition(qianTieArray, 3);
|
|
|
+ for (int i = 0; i < partition.size(); i++) {
|
|
|
+ List<Object> objects = partition.get(i);
|
|
|
+ JSONArray array = JSONArray.parseArray(String.valueOf(objects));
|
|
|
+ houTiePipei(array, houTieArray);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ shuffle(qianTieArray);
|
|
|
+ List<List<Object>> partition1 = Lists.partition(qianTieArray, 3);
|
|
|
+ for (int i = 0; i < partition1.size(); i++) {
|
|
|
+ List<Object> objects = partition1.get(i);
|
|
|
+ JSONArray array = JSONArray.parseArray(String.valueOf(objects));
|
|
|
+ houTiePipei(array, houTieArray);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ shuffle(qianTieArray);
|
|
|
+ List<List<Object>> partition2 = Lists.partition(qianTieArray, 3);
|
|
|
+ for (int i = 0; i < partition2.size(); i++) {
|
|
|
+ List<Object> objects = partition2.get(i);
|
|
|
+ JSONArray array = JSONArray.parseArray(String.valueOf(objects));
|
|
|
+ houTiePipei(array, houTieArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void test4() {
|
|
|
+ VodUploadClient client = new VodUploadClient("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ JSONArray qianTieArray = new JSONArray();
|
|
|
+ String qianTiePath = "D:\\file\\a";
|
|
|
+ JSONArray files = getFiles(qianTiePath);
|
|
|
+ for (int i = 0; i < files.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(files.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+ // log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ qianTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONArray houTieArray = new JSONArray();
|
|
|
+ String houTiePath = "D:\\file\\b";
|
|
|
+ JSONArray houTieFiles = getFiles(houTiePath);
|
|
|
+ for (int i = 0; i < houTieFiles.size(); i++) {
|
|
|
+ VodUploadRequest request = new VodUploadRequest();
|
|
|
+ request.setMediaFilePath(houTieFiles.getString(i));
|
|
|
+ try {
|
|
|
+ VodUploadResponse response = client.upload("ap-chongqing", request);
|
|
|
+// log.info("Upload FileId = {}", response.getFileId());
|
|
|
+ houTieArray.add(response.getFileId());
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 业务方进行异常处理
|
|
|
+ log.error("Upload Err", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < houTieArray.size(); i++) {
|
|
|
+
|
|
|
+ String b = houTieArray.getString(i);
|
|
|
+ JSONArray array = pipei4(i, b, qianTieArray);
|
|
|
+ editMedia(array, "金曲多多-2022-07-04" + i);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private JSONArray pipei4(Integer index, String b, JSONArray array) {
|
|
|
+ JSONArray ids = new JSONArray();
|
|
|
+ int size = array.size() - 1;
|
|
|
+ if (index <= size) {
|
|
|
+ String s = array.getString(index);
|
|
|
+ ids.add(s);
|
|
|
+ ids.add(b);
|
|
|
+ } else {
|
|
|
+ String s = array.getString(qianIndex);
|
|
|
+ qianIndex++;
|
|
|
+ if (qianIndex == size + 1) {
|
|
|
+ qianIndex = 0;
|
|
|
+ }
|
|
|
+ ids.add(s);
|
|
|
+ ids.add(b);
|
|
|
+
|
|
|
+ }
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void houTiePipei(JSONArray qiantieArray, JSONArray houtieArray) {
|
|
|
+ if (qiantieArray.size() < 3) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < houtieArray.size(); i++) {
|
|
|
+ String string = houtieArray.getString(i);
|
|
|
+ JSONArray qiantie = JSONArray.parseArray(qiantieArray.toJSONString());
|
|
|
+ qiantie.add(string);
|
|
|
+ System.err.println(count);
|
|
|
+ editMedia(qiantie, "2022-06-17_金曲_" + count);
|
|
|
+ count++;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private JSONArray pipei1(Integer index, String value, JSONArray qianList) {
|
|
|
+
|
|
|
+ JSONArray ids = new JSONArray();
|
|
|
+ int size = qianList.size() - 1;
|
|
|
+ if (index <= size) {
|
|
|
+ String s = qianList.getString(index);
|
|
|
+ ids.add(s);
|
|
|
+ ids.add(value);
|
|
|
+ } else {
|
|
|
+ String s = qianList.getString(qianIndex);
|
|
|
+ qianIndex++;
|
|
|
+ if (qianIndex == size + 1) {
|
|
|
+ qianIndex = 0;
|
|
|
+ }
|
|
|
+ ids.add(s);
|
|
|
+ ids.add(value);
|
|
|
+
|
|
|
+ }
|
|
|
+ return ids;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private JSONArray pipei2(Integer index, List<String> houList, JSONArray ids) {
|
|
|
+
|
|
|
+
|
|
|
+ int size = houList.size() - 1;
|
|
|
+ if (index <= size) {
|
|
|
+ String s = houList.get(index);
|
|
|
+ ids.add(s);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ String s = houList.get(houIndex);
|
|
|
+ houIndex++;
|
|
|
+ if (houIndex == size + 1) {
|
|
|
+ houIndex = 0;
|
|
|
+ }
|
|
|
+ ids.add(s);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return ids;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void editMedia(JSONArray ids, String fileName) {
|
|
|
+ try {
|
|
|
+ // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
|
|
+ // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
+ Credential cred = new Credential("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("vod.tencentcloudapi.com");
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ VodClient client = new VodClient(cred, "", clientProfile);
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ EditMediaRequest req = new EditMediaRequest();
|
|
|
+ // 返回的resp是一个EditMediaResponse的实例,与请求对象对应
|
|
|
+ JSONArray fileArray = new JSONArray();
|
|
|
+ /* JSONArray ids = new JSONArray();
|
|
|
+ ids.add(fileId1);
|
|
|
+ ids.add(fileId2);*/
|
|
|
+ for (int i = 0; i < ids.size(); i++) {
|
|
|
+ JSONObject fileJson = new JSONObject();
|
|
|
+ fileJson.put("FileId", ids.getString(i));
|
|
|
+ fileArray.add(fileJson);
|
|
|
+ }
|
|
|
+ req.set("FileInfos", fileArray);
|
|
|
+ req.setInputType("File");
|
|
|
+ EditMediaOutputConfig editMediaOutputConfig1 = new EditMediaOutputConfig();
|
|
|
+ editMediaOutputConfig1.setMediaName(fileName);
|
|
|
+ req.setOutputConfig(editMediaOutputConfig1);
|
|
|
+ EditMediaResponse resp = client.EditMedia(req);
|
|
|
+ // 输出json格式的字符串回包
|
|
|
+ System.out.println(EditMediaResponse.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getTask(String taskId) {
|
|
|
+ try {
|
|
|
+ // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
|
|
+ // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
+ Credential cred = new Credential("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("vod.tencentcloudapi.com");
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ VodClient client = new VodClient(cred, "", clientProfile);
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ DescribeTaskDetailRequest req = new DescribeTaskDetailRequest();
|
|
|
+ req.setTaskId(taskId);
|
|
|
+
|
|
|
+ // 返回的resp是一个DescribeTaskDetailResponse的实例,与请求对象对应
|
|
|
+ DescribeTaskDetailResponse resp = client.DescribeTaskDetail(req);
|
|
|
+ // 输出json格式的字符串回包
|
|
|
+ System.out.println(DescribeTaskDetailResponse.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void splitMedia(String fileId) {
|
|
|
+ try {
|
|
|
+ // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
|
|
+ // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
+ Credential cred = new Credential("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("vod.tencentcloudapi.com");
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ VodClient client = new VodClient(cred, "", clientProfile);
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ SplitMediaRequest req = new SplitMediaRequest();
|
|
|
+ req.setFileId(fileId);
|
|
|
+
|
|
|
+
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ /* JSONObject splitJson = new JSONObject();
|
|
|
+ splitJson.put("StartTimeOffset", 0);
|
|
|
+ splitJson.put("EndTimeOffset", 2);
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject splitJson1 = new JSONObject();
|
|
|
+ splitJson1.put("StartTimeOffset", 3);
|
|
|
+ splitJson1.put("EndTimeOffset", 26);*/
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject splitJson2 = new JSONObject();
|
|
|
+ splitJson2.put("StartTimeOffset", 28.5);
|
|
|
+ splitJson2.put("EndTimeOffset", 31);
|
|
|
+ /* array.add(splitJson);
|
|
|
+ array.add(splitJson1);*/
|
|
|
+ array.add(splitJson2);
|
|
|
+ req.set("Segments", array);
|
|
|
+ // 返回的resp是一个SplitMediaResponse的实例,与请求对象对应
|
|
|
+ SplitMediaResponse resp = client.SplitMedia(req);
|
|
|
+ // 输出json格式的字符串回包
|
|
|
+ System.out.println(SplitMediaResponse.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void composeMedia(JSONArray videoArray, JSONArray audioArray, Integer videoMute) {
|
|
|
+ try {
|
|
|
+ // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
|
|
+ // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
+ Credential cred = new Credential("AKIDPcZGgphIcfRxCF1XmjQqzqRlnY3GCrFN", "tVqvjFUS9ZhY8RTEiJeiV1GEvMVNyJM8");
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("vod.tencentcloudapi.com");
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ VodClient client = new VodClient(cred, "", clientProfile);
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ ComposeMediaRequest req = new ComposeMediaRequest();
|
|
|
+ for (int i = 0; i < videoArray.size(); i++) {
|
|
|
+ String videoId = videoArray.getString(i);
|
|
|
+ for (int j = 0; j < audioArray.size(); j++) {
|
|
|
+ String audioId = audioArray.getString(j);
|
|
|
+
|
|
|
+
|
|
|
+ MediaTrack[] mediaTracks1 = new MediaTrack[2];
|
|
|
+ MediaTrack mediaTrack1 = new MediaTrack();
|
|
|
+ mediaTrack1.setType("Video");
|
|
|
+
|
|
|
+ MediaTrackItem[] mediaTrackItems1 = new MediaTrackItem[1];
|
|
|
+ MediaTrackItem mediaTrackItem1 = new MediaTrackItem();
|
|
|
+ mediaTrackItem1.setType("Video");
|
|
|
+ VideoTrackItem videoTrackItem1 = new VideoTrackItem();
|
|
|
+ videoTrackItem1.setSourceMedia(videoId);
|
|
|
+
|
|
|
+ AudioTransform[] audioTransforms1 = new AudioTransform[1];
|
|
|
+ AudioTransform audioTransform1 = new AudioTransform();
|
|
|
+ audioTransform1.setType("Volume");
|
|
|
+ AudioVolumeParam audioVolumeParam1 = new AudioVolumeParam();
|
|
|
+ audioVolumeParam1.setMute(Long.valueOf(videoMute));
|
|
|
+ audioTransform1.setVolumeParam(audioVolumeParam1);
|
|
|
+
|
|
|
+ audioTransforms1[0] = audioTransform1;
|
|
|
+
|
|
|
+ videoTrackItem1.setAudioOperations(audioTransforms1);
|
|
|
+
|
|
|
+ mediaTrackItem1.setVideoItem(videoTrackItem1);
|
|
|
+
|
|
|
+ AudioTrackItem audioTrackItem1 = new AudioTrackItem();
|
|
|
+ audioTrackItem1.setSourceMedia(audioId);
|
|
|
+
|
|
|
+ mediaTrackItem1.setAudioItem(audioTrackItem1);
|
|
|
+
|
|
|
+ mediaTrackItems1[0] = mediaTrackItem1;
|
|
|
+
|
|
|
+ mediaTrack1.setTrackItems(mediaTrackItems1);
|
|
|
+
|
|
|
+ mediaTracks1[0] = mediaTrack1;
|
|
|
+
|
|
|
+ MediaTrack mediaTrack2 = new MediaTrack();
|
|
|
+ mediaTrack2.setType("Audio");
|
|
|
+
|
|
|
+ MediaTrackItem[] mediaTrackItems2 = new MediaTrackItem[1];
|
|
|
+ MediaTrackItem mediaTrackItem2 = new MediaTrackItem();
|
|
|
+ mediaTrackItem2.setType("Audio");
|
|
|
+ AudioTrackItem audioTrackItem2 = new AudioTrackItem();
|
|
|
+ audioTrackItem2.setSourceMedia(audioId);
|
|
|
+ audioTrackItem2.setSourceMediaStartTime(51F);
|
|
|
+ audioTrackItem2.setDuration(81F);
|
|
|
+
|
|
|
+ mediaTrackItem2.setAudioItem(audioTrackItem2);
|
|
|
+
|
|
|
+ mediaTrackItems2[0] = mediaTrackItem2;
|
|
|
+ mediaTrack2.setTrackItems(mediaTrackItems2);
|
|
|
+ mediaTracks1[1] = mediaTrack2;
|
|
|
+ req.setTracks(mediaTracks1);
|
|
|
+ ComposeMediaOutput composeMediaOutput1 = new ComposeMediaOutput();
|
|
|
+ composeMediaOutput1.setFileName("123344");
|
|
|
+ req.setOutput(composeMediaOutput1);
|
|
|
+ // 返回的resp是一个ComposeMediaResponse的实例,与请求对象对应
|
|
|
+ ComposeMediaResponse resp = client.ComposeMedia(req);
|
|
|
+ // 输出json格式的字符串回包
|
|
|
+ System.out.println(ComposeMediaResponse.toJsonString(resp));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*public static void main(String[] args) {
|
|
|
+ try {
|
|
|
+ // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
|
|
+ // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
+ Credential cred = new Credential("SecretId", "SecretKey");
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("vod.tencentcloudapi.com");
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ VodClient client = new VodClient(cred, "", clientProfile);
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ ComposeMediaRequest req = new ComposeMediaRequest();
|
|
|
+ MediaTrack[] mediaTracks1 = new MediaTrack[2];
|
|
|
+ MediaTrack mediaTrack1 = new MediaTrack();
|
|
|
+ mediaTrack1.setType("Video");
|
|
|
+
|
|
|
+ MediaTrackItem[] mediaTrackItems1 = new MediaTrackItem[1];
|
|
|
+ MediaTrackItem mediaTrackItem1 = new MediaTrackItem();
|
|
|
+ mediaTrackItem1.setType("Video");
|
|
|
+ VideoTrackItem videoTrackItem1 = new VideoTrackItem();
|
|
|
+ videoTrackItem1.setSourceMedia("387702292666447535");
|
|
|
+
|
|
|
+ AudioTransform[] audioTransforms1 = new AudioTransform[1];
|
|
|
+ AudioTransform audioTransform1 = new AudioTransform();
|
|
|
+ audioTransform1.setType("Volume");
|
|
|
+ AudioVolumeParam audioVolumeParam1 = new AudioVolumeParam();
|
|
|
+ audioVolumeParam1.setMute(1L);
|
|
|
+ audioTransform1.setVolumeParam(audioVolumeParam1);
|
|
|
+
|
|
|
+ audioTransforms1[0] = audioTransform1;
|
|
|
+
|
|
|
+ videoTrackItem1.setAudioOperations(audioTransforms1);
|
|
|
+
|
|
|
+ mediaTrackItem1.setVideoItem(videoTrackItem1);
|
|
|
+
|
|
|
+ mediaTrackItems1[0] = mediaTrackItem1;
|
|
|
+
|
|
|
+ mediaTrack1.setTrackItems(mediaTrackItems1);
|
|
|
+
|
|
|
+ mediaTracks1[0] = mediaTrack1;
|
|
|
+
|
|
|
+ MediaTrack mediaTrack2 = new MediaTrack();
|
|
|
+ mediaTrack2.setType("Audio");
|
|
|
+
|
|
|
+ MediaTrackItem[] mediaTrackItems2 = new MediaTrackItem[1];
|
|
|
+ MediaTrackItem mediaTrackItem2 = new MediaTrackItem();
|
|
|
+ mediaTrackItem2.setType("Audio");
|
|
|
+ VideoTrackItem videoTrackItem2 = new VideoTrackItem();
|
|
|
+ videoTrackItem2.setSourceMedia("387702292668811825");
|
|
|
+ mediaTrackItem2.setVideoItem(videoTrackItem2);
|
|
|
+
|
|
|
+ mediaTrackItems2[0] = mediaTrackItem2;
|
|
|
+
|
|
|
+ mediaTrack2.setTrackItems(mediaTrackItems2);
|
|
|
+
|
|
|
+ mediaTracks1[1] = mediaTrack2;
|
|
|
+
|
|
|
+ req.setTracks(mediaTracks1);
|
|
|
+
|
|
|
+ // 返回的resp是一个ComposeMediaResponse的实例,与请求对象对应
|
|
|
+ ComposeMediaResponse resp = client.ComposeMedia(req);
|
|
|
+ // 输出json格式的字符串回包
|
|
|
+ System.out.println(ComposeMediaResponse.toJsonString(resp));
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+*/
|
|
|
+
|
|
|
+/*
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+//路径 这里写一个路径进去
|
|
|
+
|
|
|
+ String path = "D:\\file";
|
|
|
+
|
|
|
+//调用方法
|
|
|
+
|
|
|
+ getFiles(path);
|
|
|
+
|
|
|
+ }
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归获取某路径下的所有文件,文件夹,并输出
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ public static JSONArray getFiles(String path) {
|
|
|
+
|
|
|
+ File file = new File(path);
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ if (file.isDirectory()) {
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ for (int i = 0; i < files.length; i++) {
|
|
|
+ if (files[i].isDirectory()) {
|
|
|
+ getFiles(files[i].getPath());
|
|
|
+ } else {
|
|
|
+ array.add(files[i].getPath());
|
|
|
+ System.out.println("文件:" + files[i].getPath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return array;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|