浏览代码

导览录制下载

dsx 1 年之前
父节点
当前提交
d8fc931bec

+ 1 - 0
src/main/java/com/fdkankan/scene/entity/DownloadTourVideo.java

@@ -29,6 +29,7 @@ public class DownloadTourVideo implements Serializable {
     private Long id;
 
     /**
+     *
      * 场景码
      */
     @TableField("num")

+ 26 - 1
src/main/java/com/fdkankan/scene/schedule/ScheduleJob.java

@@ -1,7 +1,11 @@
 package com.fdkankan.scene.schedule;
 
+import com.alibaba.fastjson.JSON;
+import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisLockUtil;
 import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.scene.entity.DownloadTourVideo;
+import com.fdkankan.scene.service.IDownloadTourVideoService;
 import com.fdkankan.scene.service.ISceneAsynOperLogService;
 import com.fdkankan.scene.service.ISceneDownLoadService;
 import lombok.extern.log4j.Log4j2;
@@ -9,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.nio.charset.StandardCharsets;
+
 @Log4j2
 @Component
 public class ScheduleJob {
@@ -21,6 +27,8 @@ public class ScheduleJob {
     ISceneDownLoadService sceneDownLoadService;
     @Autowired
     private RedisLockUtil redisLockUtil;
+    @Autowired
+    private IDownloadTourVideoService downloadTourVideoService;
 
     /**
      * 每天凌晨一点执行
@@ -44,7 +52,24 @@ public class ScheduleJob {
 
     @Scheduled(cron = "0/2 * * * * ? ")
     public void transferTourVideo() throws Exception {
-        sceneDownLoadService.processV3();
+        String lockKey = "lock:transfer:tour:video";
+        boolean lock = redisLockUtil.lock("lock:transfer:tour:video", RedisKey.EXPIRE_TIME_10_MINUTE);
+        if(!lock){
+            return;
+        }
+        String task = (String) redisUtil.lGetIndex("transfer:tour:video", 0L);
+        try {
+            log.info("开始导览视频转换,content:{}", task);
+            DownloadTourVideo downloadTourVideo = JSON.parseObject(task, DownloadTourVideo.class);
+            downloadTourVideoService.transferTourVideo(downloadTourVideo);
+            //视频转换完毕后才出队,防止服务重启,可以重新开始任务
+            redisUtil.lLeftPop("transfer:tour:video");
+            log.info("结束导览视频,content:{}", task);
+        }catch (Exception e){
+            log.error("导览视频转换失败,转换任务:{}", task, e);
+        }finally {
+            redisLockUtil.unlockLua(lockKey);
+        }
     }
 
 

+ 12 - 3
src/main/java/com/fdkankan/scene/service/impl/DownloadTourVideoServiceImpl.java

@@ -14,9 +14,13 @@ import com.fdkankan.model.constants.UploadFilePath;
 import com.fdkankan.model.utils.CreateObjUtil;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.scene.entity.DownloadTourVideo;
+import com.fdkankan.scene.entity.ScenePlus;
+import com.fdkankan.scene.entity.ScenePlusExt;
 import com.fdkankan.scene.mapper.IDownloadTourVideoMapper;
 import com.fdkankan.scene.oss.OssUtil;
 import com.fdkankan.scene.service.IDownloadTourVideoService;
+import com.fdkankan.scene.service.IScenePlusExtService;
+import com.fdkankan.scene.service.IScenePlusService;
 import com.fdkankan.scene.util.MergeVideoUtil;
 import com.fdkankan.scene.vo.DownloadTourVideoVO;
 import com.fdkankan.web.response.ResultData;
@@ -44,6 +48,10 @@ public class DownloadTourVideoServiceImpl extends ServiceImpl<IDownloadTourVideo
     private OssUtil ossUtil;
     @Autowired
     private RedisUtil redisUtil;
+    @Autowired
+    private IScenePlusService scenePlusService;
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
 
     @Override
     public DownloadTourVideo getWaitingByNum(String num) {
@@ -116,6 +124,9 @@ public class DownloadTourVideoServiceImpl extends ServiceImpl<IDownloadTourVideo
 
         String destPath = null;
         try {
+            ScenePlus scenePlus = scenePlusService.getById(downloadTourVideo.getNum());
+            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+            String bucket = scenePlusExt.getYunFileBucket();
             String destFileName = UUID.randomUUID().toString() + ".mp4";
             destPath = ConstantFilePath.SCENE_V4_PATH + downloadTourVideo.getNum() + "/tour/" + destFileName;
             File destFile = new File(destPath);
@@ -126,9 +137,7 @@ public class DownloadTourVideoServiceImpl extends ServiceImpl<IDownloadTourVideo
             MergeVideoUtil.ffmpegFormatMp4(srcPath, destPath);
             //上传到oss
             String ossPath = String.format(UploadFilePath.DOWNLOADS_TOUR_VIDEO, downloadTourVideo.getNum()) + downloadTourVideo.getFileName();
-            Map<String, String> headers = new HashMap<>();
-            headers.put(HttpHeaders.CONTENT_TYPE, "application/octet-stream");
-//            ossUtil.uploadFile(ossPath, destPath, false);
+            ossUtil.uploadFile(bucket, ossPath, destPath, false);
             downloadTourVideo.setDownloadPath(ossPath);
             downloadTourVideo.setState(1);
             this.updateById(downloadTourVideo);

+ 3 - 10
src/main/java/com/fdkankan/scene/util/MergeVideoUtil.java

@@ -194,17 +194,10 @@ public class MergeVideoUtil {
     //测试
     public static void main(String[] args) throws Exception {//定义需要复制文件的路径
 
-        String srcPath = "H:\\mergevideo\\";
-        String destName = "mergedVideo.mp4";
-        String destFullPath = "H:\\mergevideo\\" + destName;
-        Set<String> list = new HashSet<>();
-        List<String> list1 = new LinkedList<>();
-        list1.add(srcPath + "1.mp4");
-        list1.add(srcPath + "2.mp4");
-        list1.add(srcPath + "3.mp4");
+        String srcPath = "C:\\Users\\dsx\\Desktop\\a2b214e8-8cc5-40be-91af-3b9dc1507ce7.mp4";
+        String destFullPath = "C:\\Users\\dsx\\Desktop\\aaa.mp4";
 
-        MergeVideoUtil.mergeVideo(list1, destFullPath);
+        MergeVideoUtil.ffmpegFormatMp4(srcPath, destFullPath);
 
-        MergeVideoUtil.fetchFrame(FileUtil.file(destFullPath), FileUtil.file(srcPath + "1.jpg"));
     }
 }