|
@@ -7,9 +7,11 @@ import cn.com.ctop.common.module.mapper.MaterialCutFrameMapper;
|
|
import cn.com.ctop.common.module.service.IMaterialCutFrameService;
|
|
import cn.com.ctop.common.module.service.IMaterialCutFrameService;
|
|
import cn.com.ctop.common.module.service.IMaterialCutFrameTaskService;
|
|
import cn.com.ctop.common.module.service.IMaterialCutFrameTaskService;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
|
+import cn.com.ctop.common.module.utils.CosUtil;
|
|
import cn.com.ctop.common.module.utils.LoadFileUtil;
|
|
import cn.com.ctop.common.module.utils.LoadFileUtil;
|
|
import cn.com.ctop.common.module.utils.MpsUtils;
|
|
import cn.com.ctop.common.module.utils.MpsUtils;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.aliyuncs.DefaultAcsClient;
|
|
import com.aliyuncs.DefaultAcsClient;
|
|
import com.aliyuncs.IAcsClient;
|
|
import com.aliyuncs.IAcsClient;
|
|
@@ -20,7 +22,9 @@ import com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobResponse;
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.google.gson.JsonObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -224,5 +228,94 @@ public class MaterialCutFrameServiceImpl extends ServiceImpl<MaterialCutFrameMap
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ //腾讯云抽帧
|
|
|
|
+ @Override
|
|
|
|
+ public void getCosCutFrame(String url, String materialId) throws IOException {
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ QueryWrapper<MaterialCutFrameTask> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("video_signature", materialId);
|
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
|
+ MaterialCutFrameTask checkCutFrame = cutFrameTaskService.getOne(queryWrapper);
|
|
|
|
+ if (!Check.isNull(checkCutFrame)) {
|
|
|
|
+ log.info("已存推荐封面");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //抽帧ossOutputObject1
|
|
|
|
+ String ossOutputObject1 = "/cutFrame/" + materialId + "/_";
|
|
|
|
+ String replaceUrl = url.replace("https://" + CosUtil.bucket + ".cos.ap-chongqing.myqcloud.com", ""); //地址
|
|
|
|
+ String resp = CosUtil.processMedia(replaceUrl, ossOutputObject1);
|
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
|
+ String jobId = respJson.getString("TaskId"); //{"Response": {"TaskId": "2600000655-WorkflowTask-c0b385f27c4993437029b5da175542aet0","RequestId": "4c23ce23-087f-4d4b-b73b-907d77d6d78d" } }
|
|
|
|
+ MaterialCutFrameTask cutFrameTask = new MaterialCutFrameTask();
|
|
|
|
+ cutFrameTask.setJobStatus(0);
|
|
|
|
+ cutFrameTask.setJobId(jobId);
|
|
|
|
+ cutFrameTask.setVideoSignature(materialId);
|
|
|
|
+ cutFrameTaskService.save(cutFrameTask);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //抽帧任务状态查询,如果完成则把抽帧入库
|
|
|
|
+ @Override
|
|
|
|
+ public void loadCosCutFrame(String jobId, String videoSignature) {
|
|
|
|
+ try {
|
|
|
|
+ String resp = CosUtil.describeTaskDetail(jobId);
|
|
|
|
+ if(StringUtils.isBlank(resp)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
|
+ String status = respJson.getString("Status");
|
|
|
|
+
|
|
|
|
+ if(!"FINISH".equals(status)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONArray resultSetArray = respJson.getJSONObject("WorkflowTask").getJSONArray("MediaProcessResultSet");
|
|
|
|
+ if (Check.isNull(resultSetArray)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject resultSetObject = resultSetArray.getJSONObject(0);
|
|
|
|
+ if (Check.isNull(resultSetObject)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONArray snapshotArray = resultSetObject.getJSONObject("SampleSnapshotTask").getJSONObject("Output").getJSONArray("ImagePathSet");
|
|
|
|
+
|
|
|
|
+ if (Check.isNull(snapshotArray)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int i=0; i< snapshotArray.size(); i++){
|
|
|
|
+ String imagePath = snapshotArray.getString(i);
|
|
|
|
+ String urlStr = "https://" + CosUtil.bucket + ".cos.ap-chongqing.myqcloud.com" + imagePath;
|
|
|
|
+
|
|
|
|
+ //下载到本地获取图片md5
|
|
|
|
+ String cutFramePath = LoadFileUtil.downLoadFromUrl(urlStr, imageUpLoadPath);
|
|
|
|
+ String cutFrameMd5 = LoadFileUtil.getMD5(cutFramePath);
|
|
|
|
+
|
|
|
|
+ MaterialCutFrame cutFrame = new MaterialCutFrame();
|
|
|
|
+ cutFrame.setSignature(cutFrameMd5);
|
|
|
|
+ cutFrame.setUrl(urlStr);
|
|
|
|
+ cutFrame.setVideoSignature(videoSignature);
|
|
|
|
+ cutFrame.setImageIndex(i);
|
|
|
|
+ this.save(cutFrame);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QueryWrapper<MaterialCutFrameTask> updateQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ updateQueryWrapper.eq("job_id", jobId);
|
|
|
|
+ updateQueryWrapper.eq("video_signature", videoSignature);
|
|
|
|
+ MaterialCutFrameTask updateTask = new MaterialCutFrameTask();
|
|
|
|
+ updateTask.setJobStatus(1);
|
|
|
|
+ cutFrameTaskService.update(updateTask, updateQueryWrapper);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|