|
@@ -1,20 +1,20 @@
|
|
package cn.com.ctop.common.module.service.impl;
|
|
package cn.com.ctop.common.module.service.impl;
|
|
|
|
|
|
-import cn.com.ctop.common.module.entity.MaterialAscription;
|
|
|
|
-import cn.com.ctop.common.module.entity.MaterialInfo;
|
|
|
|
-import cn.com.ctop.common.module.entity.MaterialParameter;
|
|
|
|
-import cn.com.ctop.common.module.entity.MaterialTag;
|
|
|
|
|
|
+import cn.com.ctop.common.module.entity.*;
|
|
import cn.com.ctop.common.module.mapper.MaterialAscriptionMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialAscriptionMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialInfoMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialTagMapper;
|
|
import cn.com.ctop.common.module.mapper.MaterialTagMapper;
|
|
import cn.com.ctop.common.module.service.IMaterialInfoService;
|
|
import cn.com.ctop.common.module.service.IMaterialInfoService;
|
|
|
|
+import cn.com.ctop.common.module.service.IVideoWatermarkTaskService;
|
|
|
|
+import cn.com.ctop.common.module.service.IVideoWatermarkTemplateService;
|
|
import cn.com.ctop.common.module.utils.*;
|
|
import cn.com.ctop.common.module.utils.*;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.aliyuncs.mts.model.v20140618.QueryJobListResponse;
|
|
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 it.sauronsoftware.jave.Encoder;
|
|
|
|
|
|
+import it.sauronsoftware.jave.Encoder;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -33,6 +33,8 @@ import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
+// import it.sauronsoftware.jave.Encoder;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 素材信息
|
|
* 素材信息
|
|
*
|
|
*
|
|
@@ -44,6 +46,26 @@ import java.util.regex.Pattern;
|
|
@Service
|
|
@Service
|
|
public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, MaterialInfo> implements IMaterialInfoService {
|
|
public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, MaterialInfo> implements IMaterialInfoService {
|
|
private static ExecutorService uploadExecutorService = Executors.newFixedThreadPool(5);
|
|
private static ExecutorService uploadExecutorService = Executors.newFixedThreadPool(5);
|
|
|
|
+ @Autowired
|
|
|
|
+ private IVideoWatermarkTemplateService videoWatermarkTemplateService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IVideoWatermarkTaskService videoWatermarkTaskService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void watermarkVideo(String materialId, Integer videoWatermarkTemplateId, String userId) {
|
|
|
|
+ VideoWatermarkTemplate videoWatermarkTemplate = videoWatermarkTemplateService.getById(videoWatermarkTemplateId);
|
|
|
|
+ MaterialInfo materialInfo = this.getById(materialId);
|
|
|
|
+ MpsUtils mpsUtils = new MpsUtils();
|
|
|
|
+ String jobId = mpsUtils.videoWaterMark(materialInfo.getUrl(), 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);
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public MaterialInfo getMaterialInfoByCode(String code) {
|
|
public MaterialInfo getMaterialInfoByCode(String code) {
|
|
@@ -89,7 +111,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
public Map<String, Object> insert(JSONObject jsonObject) {
|
|
public Map<String, Object> insert(JSONObject jsonObject) {
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
try {
|
|
try {
|
|
- // Boolean isVideo = imgLocation(jsonObject.getString("url"));
|
|
|
|
String type = jsonObject.getString("type");
|
|
String type = jsonObject.getString("type");
|
|
MaterialInfo info = new MaterialInfo();
|
|
MaterialInfo info = new MaterialInfo();
|
|
info.setId(jsonObject.getString("code"));
|
|
info.setId(jsonObject.getString("code"));
|
|
@@ -146,7 +167,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- // getFile(info);
|
|
|
|
|
|
+ getFile(info);
|
|
ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
ResultMapUtils.setResultMap(resultMap, StatusCode.MATERIAL_UPLOAD_FAIL.getCode());
|
|
ResultMapUtils.setResultMap(resultMap, StatusCode.MATERIAL_UPLOAD_FAIL.getCode());
|
|
@@ -238,8 +259,6 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
return json;
|
|
return json;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -252,63 +271,60 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
|
|
@Autowired
|
|
@Autowired
|
|
private MaterialParameterMapper materialParameterMapper;
|
|
private MaterialParameterMapper materialParameterMapper;
|
|
|
|
|
|
- /* public void getFile(MaterialInfo materialInfo) {
|
|
|
|
- *//* uploadExecutorService.submit(new Runnable() {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public void getFile(MaterialInfo materialInfo) {
|
|
|
|
+ uploadExecutorService.submit(new Runnable() {
|
|
@Override
|
|
@Override
|
|
- public void run() {*//*
|
|
|
|
- try {
|
|
|
|
- System.err.println("开始获取素材基本信息");
|
|
|
|
- System.err.println(materialInfo);
|
|
|
|
- if (!Check.isNull(materialInfo)) {
|
|
|
|
- String url = materialInfo.getUrl();
|
|
|
|
- long l = System.currentTimeMillis();
|
|
|
|
- //PropertiesUtils.getValue("kuaishou_config", "video_sava_path")
|
|
|
|
- String localUrl = LoadFileUtil.downLoadFromUrl(url, PropertiesUtils.getValue("kuaishou_config", "video_sava_path"));
|
|
|
|
- File file = new File(localUrl);
|
|
|
|
- it.sauronsoftware.jave.Encoder encoder = new Encoder();
|
|
|
|
- *//*try {*//*
|
|
|
|
- it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(file);
|
|
|
|
- long duration = m.getDuration();
|
|
|
|
- long secondDuration = duration / 1000;
|
|
|
|
- MaterialParameter materialParameter = new MaterialParameter();
|
|
|
|
- materialParameter.setMaterialId(materialInfo.getId());
|
|
|
|
- // 视频秒数
|
|
|
|
- materialParameter.setSecond(secondDuration);
|
|
|
|
- // 视频格式
|
|
|
|
- materialParameter.setFormat(m.getFormat());
|
|
|
|
- // 视频宽
|
|
|
|
- materialParameter.setWidth(String.valueOf(m.getVideo().getSize().getWidth()));
|
|
|
|
- // 视频高
|
|
|
|
- materialParameter.setHeight(String.valueOf(m.getVideo().getSize().getHeight()));
|
|
|
|
-
|
|
|
|
- FileInputStream fis = new FileInputStream(file);
|
|
|
|
- FileChannel fc = fis.getChannel();
|
|
|
|
- BigDecimal fileSize = new BigDecimal(fc.size());
|
|
|
|
- String size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
|
|
|
|
- materialParameter.setSize(size);
|
|
|
|
-
|
|
|
|
- Map<String, Object> deleteMap = new HashMap<>();
|
|
|
|
- deleteMap.put("material_id", materialInfo.getId());
|
|
|
|
- materialParameterMapper.deleteByMap(deleteMap);
|
|
|
|
-
|
|
|
|
- int insert = materialParameterMapper.insert(materialParameter);
|
|
|
|
- if (insert > 0) {
|
|
|
|
- log.info("素材基本信息入库完成,用时:{} s", (System.currentTimeMillis() - l) / 1000);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- System.err.println(2222222);
|
|
|
|
- *//* } catch (Exception e) {
|
|
|
|
|
|
+ public void run() {
|
|
|
|
+ try {
|
|
|
|
+ log.info("获取素材基本信息,code:{}", materialInfo.getCode());
|
|
|
|
+ if (!Check.isNull(materialInfo)) {
|
|
|
|
+ String url = materialInfo.getUrl();
|
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
|
+ String localUrl = LoadFileUtil.downLoadFromUrl(url, PropertiesUtils.getValue("kuaishou_config", "video_sava_path"));
|
|
|
|
+ File file = new File(localUrl);
|
|
|
|
+ it.sauronsoftware.jave.Encoder encoder = new Encoder();
|
|
|
|
+ try {
|
|
|
|
+ it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(file);
|
|
|
|
+ long duration = m.getDuration();
|
|
|
|
+ long secondDuration = duration / 1000;
|
|
|
|
+ MaterialParameter materialParameter = new MaterialParameter();
|
|
|
|
+ materialParameter.setMaterialId(materialInfo.getId());
|
|
|
|
+ // 视频秒数
|
|
|
|
+ materialParameter.setSecond(secondDuration);
|
|
|
|
+ // 视频格式
|
|
|
|
+ materialParameter.setFormat(m.getFormat());
|
|
|
|
+ // 视频宽
|
|
|
|
+ materialParameter.setWidth(String.valueOf(m.getVideo().getSize().getWidth()));
|
|
|
|
+ // 视频高
|
|
|
|
+ materialParameter.setHeight(String.valueOf(m.getVideo().getSize().getHeight()));
|
|
|
|
+ FileInputStream fis = new FileInputStream(file);
|
|
|
|
+ FileChannel fc = fis.getChannel();
|
|
|
|
+ BigDecimal fileSize = new BigDecimal(fc.size());
|
|
|
|
+ String size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
|
|
|
|
+ materialParameter.setSize(size);
|
|
|
|
+ materialParameter.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
|
+ deleteMap.put("material_id", materialInfo.getId());
|
|
|
|
+ materialParameterMapper.deleteByMap(deleteMap);
|
|
|
|
+ int insert = materialParameterMapper.insert(materialParameter);
|
|
|
|
+ if (insert > 0) {
|
|
|
|
+ log.info("素材基本信息入库完成,用时:{} s", (System.currentTimeMillis() - l) / 1000);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- } *//**//*finally {
|
|
|
|
- file.delete();
|
|
|
|
- }*//*
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- *//* }
|
|
|
|
- });*//*
|
|
|
|
- }*/
|
|
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|