|
@@ -9,15 +9,14 @@ import cn.com.ctop.common.module.service.*;
|
|
|
import cn.com.ctop.common.module.utils.*;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.aliyuncs.mts.model.v20140618.QueryJobListResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.tencentcloudapi.mps.v20190612.models.DescribeTaskDetailResponse;
|
|
|
import it.sauronsoftware.jave.Encoder;
|
|
|
import it.sauronsoftware.jave.EncoderException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -27,12 +26,13 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
-import java.net.URLDecoder;
|
|
|
import java.nio.channels.FileChannel;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
-import java.util.regex.Pattern;
|
|
|
+
|
|
|
+import static cn.com.ctop.common.module.utils.CloudVideoProcessUtil.getTaskDetailResponse;
|
|
|
+import static cn.com.ctop.common.module.utils.CloudVideoProcessUtil.videoWatermarkHandle;
|
|
|
|
|
|
/**
|
|
|
* 素材信息
|
|
@@ -43,11 +43,12 @@ import java.util.regex.Pattern;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-@Primary
|
|
|
public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, MaterialInfo> implements IMaterialInfoService {
|
|
|
+
|
|
|
private static ExecutorService uploadExecutorService = Executors.newFixedThreadPool(5);
|
|
|
+
|
|
|
@Resource
|
|
|
- private IVideoWatermarkTemplateService videoWatermarkTemplateService;
|
|
|
+ private ITencentWatermarkTemplateService tencentWatermarkTemplateService;
|
|
|
@Resource
|
|
|
private IVideoWatermarkTaskService videoWatermarkTaskService;
|
|
|
@Autowired
|
|
@@ -58,27 +59,48 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
private MaterialAscriptionMapper materialAscriptionMapper;
|
|
|
@Autowired
|
|
|
private MaterialTagMapper materialTagMapper;
|
|
|
+ @Resource
|
|
|
+ private IMaterialCutFrameService materialCutFrameService;
|
|
|
|
|
|
+ @Value("${oss.replace.replace-value}")
|
|
|
+ private String replaceValue;
|
|
|
+ @Value("${oss.replace.replace-old-value}")
|
|
|
+ private String replaceOldValue;
|
|
|
@Value("${oss.replace.download}")
|
|
|
private String downloadUrl;
|
|
|
|
|
|
@Override
|
|
|
- public void watermarkVideo(String materialId, Integer videoWatermarkTemplateId, String userId) {
|
|
|
- VideoWatermarkTemplate videoWatermarkTemplate = videoWatermarkTemplateService.getById(videoWatermarkTemplateId);
|
|
|
+ public void watermarkVideo(String materialId, Long videoWatermarkTemplateId, String userId) {
|
|
|
+ TencentWatermarkTemplate tentcentWatermarkTemplate = tencentWatermarkTemplateService.getById(videoWatermarkTemplateId);
|
|
|
MaterialInfo materialInfo = this.getById(materialId);
|
|
|
- MpsUtils mpsUtils = new MpsUtils();
|
|
|
- String path = materialInfo.getUrl().substring(materialInfo.getUrl().indexOf('/', 10) + 1, materialInfo.getUrl().length());
|
|
|
- String jobId = mpsUtils.videoWaterMark(path, videoWatermarkTemplate.getTemplatePath(), videoWatermarkTemplate.getTemplateId(), videoWatermarkTemplate.getHeight());
|
|
|
- QueryJobListResponse.Job job = MpsUtils.getJobStatus(jobId);
|
|
|
- VideoWatermarkTask videoWatermarkTask = new VideoWatermarkTask();
|
|
|
- videoWatermarkTask.setJobId(jobId);
|
|
|
- videoWatermarkTask.setUserId(userId);
|
|
|
- videoWatermarkTask.setStatus(job.getState());
|
|
|
- videoWatermarkTaskService.save(videoWatermarkTask);
|
|
|
- materialInfo.setWatermarkCode(jobId);
|
|
|
- this.updateById(materialInfo);
|
|
|
- }
|
|
|
+ String path = materialInfo.getUrl().substring(materialInfo.getUrl().indexOf("/", 10) + 1, materialInfo.getUrl().length());
|
|
|
+ String taskId = videoWatermarkHandle(path, tentcentWatermarkTemplate.getTemplateId());
|
|
|
+ DescribeTaskDetailResponse taskDetailResponse=null;
|
|
|
+ for(int i=0;i<10;i++){
|
|
|
+ try {
|
|
|
+ Thread.sleep(2000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ taskDetailResponse = getTaskDetailResponse(taskId);
|
|
|
+ if(taskDetailResponse.getStatus().equals("FINISH")){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(taskDetailResponse.getStatus().equals("FINISH")){
|
|
|
+ String videoUrl=taskDetailResponse.getWorkflowTask().getMediaProcessResultSet()[0].getTranscodeTask().getOutput().getPath();
|
|
|
+ VideoWatermarkTask videoWatermarkTask = new VideoWatermarkTask();
|
|
|
+ videoWatermarkTask.setVideoUrl(videoUrl);
|
|
|
+ videoWatermarkTask.setVideoId(materialId);
|
|
|
+ videoWatermarkTask.setJobId(taskId);
|
|
|
+ videoWatermarkTask.setUserId(userId);
|
|
|
+ videoWatermarkTask.setStatus(taskDetailResponse.getStatus());
|
|
|
+ videoWatermarkTaskService.save(videoWatermarkTask);
|
|
|
+ materialInfo.setWatermarkCode(taskId);
|
|
|
+ this.updateById(materialInfo);
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
@Override
|
|
|
public MaterialInfo getMaterialInfoByCodeAndProjectId(String code, Long projectId) {
|
|
|
QueryWrapper<MaterialInfo> queryWrapper = new QueryWrapper<>();
|
|
@@ -113,13 +135,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public boolean imgLocation(String fileName) throws IOException {
|
|
|
- String reg = "(mp4|flv|avi|rm|rmvb|wmv|MP4)";
|
|
|
- Pattern p = Pattern.compile(reg);
|
|
|
- return p.matcher(fileName).find();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public Map<String, Object> insert(JSONObject jsonObject) {
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
@@ -171,13 +186,11 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
- @Resource
|
|
|
- private IMaterialCutFrameService materialCutFrameService;
|
|
|
-
|
|
|
private void insertMaterialInfo(String url, String type, JSONObject jsonObject) {
|
|
|
MaterialInfo info = new MaterialInfo();
|
|
|
Long projectId = jsonObject.getLong("projectId");
|
|
|
String code = jsonObject.getString("code");
|
|
|
+ info.setId(code + projectId);
|
|
|
info.setCode(code);
|
|
|
if (!Check.isNull(jsonObject.getString("watermarkUrl"))) {
|
|
|
info.setWatermarkUrl(jsonObject.getString("watermarkUrl"));
|
|
@@ -241,9 +254,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
* @param materialId
|
|
|
* @return
|
|
|
*/
|
|
|
-
|
|
|
- //@Autowired
|
|
|
- //private MaterialInfoMapper materialInfoMapper;
|
|
|
@Override
|
|
|
public JSONObject getDetail(String materialId) {
|
|
|
JSONObject json = new JSONObject();
|
|
@@ -327,7 +337,8 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
log.info("获取素材基本信息,code:{}", materialInfo.getCode());
|
|
|
if (!Check.isNull(materialInfo)) {
|
|
|
long l = System.currentTimeMillis();
|
|
|
- String url = materialInfo.getUrl();
|
|
|
+ String videoUrl = materialInfo.getUrl();
|
|
|
+ String url = videoUrl.replace(replaceOldValue, replaceValue);
|
|
|
log.info("replaceUrl:{}", url);
|
|
|
String localUrl = null;
|
|
|
it.sauronsoftware.jave.MultimediaInfo m = null;
|
|
@@ -369,7 +380,18 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
if (insert > 0) {
|
|
|
log.info("素材基本信息入库完成,用时:{} s", (System.currentTimeMillis() - l) / 1000);
|
|
|
}
|
|
|
-
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ log.info("开始抽帧");
|
|
|
+ materialCutFrameService.getCutFrame(videoUrl, materialInfo.getCode(), secondDuration, height, width);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
} catch (FileNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (IOException e) {
|
|
@@ -457,6 +479,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
MaterialInfo info = new MaterialInfo();
|
|
|
Long projectId = json.getLong("projectId");
|
|
|
String code = json.getString("code");
|
|
|
+ info.setId(code + projectId);
|
|
|
info.setCode(code);
|
|
|
if (!Check.isNull(json.getString("watermarkUrl"))) {
|
|
|
info.setWatermarkUrl(json.getString("watermarkUrl"));
|
|
@@ -472,29 +495,8 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
info.setCreateTime(new Date());
|
|
|
info.setUpdateTime(new Date());
|
|
|
info.setType(type);
|
|
|
-
|
|
|
- MaterialCutFrame cutFrame = materialCutFrameService.getCutFrameByCode(code);
|
|
|
- if (Check.isNull(cutFrame)) {
|
|
|
- String videoUrl = URLDecoder.decode(info.getUrl()).replace("https://media-1301855440.cos.ap-chongqing.myqcloud.com/", "");
|
|
|
- String loadImage = "cutFrame/" + code + "/zero.jpg";
|
|
|
- String coverUrl = CloudVideoProcessUtil.videoCutPictureHandle(videoUrl, loadImage);
|
|
|
- info.setCoverUrl(coverUrl);
|
|
|
- Thread thread = new Thread() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- log.info("开始抽帧");
|
|
|
- materialCutFrameService.getTencentCutFrame(videoUrl, code, coverUrl);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- thread.start();
|
|
|
- } else {
|
|
|
- info.setCoverUrl(cutFrame.getUrl());
|
|
|
- }
|
|
|
this.save(info);
|
|
|
+
|
|
|
JSONArray imageArr = json.getJSONArray("imageArr");
|
|
|
if (!Check.isNull(imageArr)) {
|
|
|
JSONObject imageJson = new JSONObject();
|
|
@@ -542,6 +544,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
|
}
|
|
|
|
|
|
getFile(info);
|
|
|
+
|
|
|
ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
|
} catch (Exception e) {
|
|
|
ResultMapUtils.setResultMap(resultMap, StatusCode.MATERIAL_UPLOAD_FAIL.getCode());
|