浏览代码

修改音频文件合成调用方式

syh 5 年之前
父节点
当前提交
aec4d8ccf7

+ 19 - 11
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/EduLessonController.java

@@ -3,25 +3,14 @@ package org.jeecg.modules.ctop.controller;
 import cn.com.ctop.manage.modules.edu.entity.EduLesson;
 import cn.com.ctop.manage.modules.edu.service.IEduLessonService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.aspect.annotation.AutoLog;
-import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.modules.ctop.entity.DramaInfo;
-import org.jeecg.modules.system.entity.SysCategory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
 import java.util.List;
 
 @Slf4j
@@ -47,6 +36,25 @@ public class EduLessonController {
         result.setSuccess(true);
         return result;
     }
+
+    @GetMapping(value = "/system/lesson")
+    public Result<List<String>> getSystemLessonList() {
+        Result<List<String>> result = new Result<>();
+        List<String> list = eduLessonService.getTitleList("系统操作");
+        result.setResult(list);
+        result.setSuccess(true);
+        return result;
+    }
+
+    @GetMapping(value = "/system/topic")
+    public Result<List<String>> getSystemTopicList(String title) {
+        Result<List<String>> result = new Result<>();
+        List<String> list = eduLessonService.getTopicList("系统操作", title);
+        result.setResult(list);
+        result.setSuccess(true);
+        return result;
+    }
+
     @GetMapping(value = "/ocean/lesson")
     public Result<List<String>> getOceanLessonList(){
         Result<List<String>> result = new Result<>();

+ 3 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaishouEffectAdInfoController.java

@@ -64,9 +64,10 @@ public class KuaishouEffectAdInfoController {
                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                              HttpServletRequest req) {
-        Result<IPage<KuaishouEffectAdInfo>> result = new Result<IPage<KuaishouEffectAdInfo>>();
+        Result<IPage<KuaishouEffectAdInfo>> result = new Result<>();
         QueryWrapper<KuaishouEffectAdInfo> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouEffectAdInfo, req.getParameterMap());
-        Page<KuaishouEffectAdInfo> page = new Page<KuaishouEffectAdInfo>(pageNo, pageSize);
+        queryWrapper.orderByDesc("create_time");
+        Page<KuaishouEffectAdInfo> page = new Page<>(pageNo, pageSize);
         IPage<KuaishouEffectAdInfo> pageList = kuaishouEffectAdInfoService.page(page, queryWrapper);
         result.setSuccess(true);
         result.setResult(pageList);

+ 5 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaishouHotPhotoInfoController.java

@@ -49,16 +49,18 @@ public class KuaishouHotPhotoInfoController {
                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                              @RequestParam(name = "sortType", defaultValue = "1") Integer sortType,
                                                              HttpServletRequest req) {
-        Result<IPage<KuaishouHotPhotoInfo>> result = new Result<IPage<KuaishouHotPhotoInfo>>();
+        Result<IPage<KuaishouHotPhotoInfo>> result = new Result<>();
         QueryWrapper<KuaishouHotPhotoInfo> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouHotPhotoInfo, req.getParameterMap());
         if (sortType == 1) {
-            queryWrapper.orderByDesc("playing_time");
+            queryWrapper.orderByDesc("create_time");
         } else if (sortType == 2) {
+            queryWrapper.orderByDesc("playing_time");
+        } else if (sortType == 3) {
             queryWrapper.orderByDesc("like_time");
         } else {
             queryWrapper.orderByDesc("comment_time");
         }
-        Page<KuaishouHotPhotoInfo> page = new Page<KuaishouHotPhotoInfo>(pageNo, pageSize);
+        Page<KuaishouHotPhotoInfo> page = new Page<>(pageNo, pageSize);
         IPage<KuaishouHotPhotoInfo> pageList = kuaishouHotPhotoInfoService.page(page, queryWrapper);
         result.setSuccess(true);
         result.setResult(pageList);

+ 3 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaishouInspiredAdController.java

@@ -64,9 +64,10 @@ public class KuaishouInspiredAdController {
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                            HttpServletRequest req) {
-        Result<IPage<KuaishouInspiredAd>> result = new Result<IPage<KuaishouInspiredAd>>();
+        Result<IPage<KuaishouInspiredAd>> result = new Result<>();
         QueryWrapper<KuaishouInspiredAd> queryWrapper = QueryGenerator.initQueryWrapper(kuaishouInspiredAd, req.getParameterMap());
-        Page<KuaishouInspiredAd> page = new Page<KuaishouInspiredAd>(pageNo, pageSize);
+        queryWrapper.orderByDesc("create_time");
+        Page<KuaishouInspiredAd> page = new Page<>(pageNo, pageSize);
         IPage<KuaishouInspiredAd> pageList = kuaishouInspiredAdService.page(page, queryWrapper);
         result.setSuccess(true);
         result.setResult(pageList);

+ 5 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CrawlerServiceImpl.java

@@ -217,19 +217,20 @@ public class CrawlerServiceImpl implements ICrawlerService {
             log.info("效果广告数据获取完成");
             return;
         }
-        List<KuaishouEffectAdInfo> adInfos = new ArrayList<>();
+//        List<KuaishouEffectAdInfo> adInfos = new ArrayList<>();
         for (int i = 0; i < effectAds.size(); i++) {
             JSONObject ad = effectAds.getJSONObject(i);
             Long contentId = ad.getLong("contentId");
             if (null != contentId) {
                 JSONObject content = getEffectAdDetail(contentId).getJSONObject("data").getJSONObject("effectAdDetail");
                 KuaishouEffectAdInfo adInfo = new KuaishouEffectAdInfo(content);
-                adInfos.add(adInfo);
+                effectAdInfoService.saveOrUpdate(adInfo);
+                //                adInfos.add(adInfo);
             }
         }
-        if (adInfos.size() > 0) {
+        /*if (adInfos.size() > 0) {
             effectAdInfoService.replaceBatch(adInfos);
-        }
+        }*/
         loadeffectAdByPage(pageSize, pageNum + 1);
     }
 

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/opencv/service/IFfmpegService.java

@@ -16,4 +16,6 @@ public interface IFfmpegService {
     void mergeImageToVideo(String imagePath, Integer frameNumber, String videoFilePath);
 
     Map<String, Object> videoMerge(JSONObject data, String userId);
+
+    void videoSplitToImage(String srcFilePath, String splitSrcPath);
 }

+ 59 - 13
jeecg-boot-module-system/src/main/java/org/jeecg/modules/opencv/service/impl/FfmpegServiceImpl.java

@@ -11,7 +11,6 @@ import org.jeecg.modules.opencv.service.IModelVideoCompositeInfoService;
 import org.jeecg.modules.opencv.service.IModelVideoInfoConfigService;
 import org.jeecg.modules.opencv.service.IModelVideoInfoService;
 import org.jeecg.modules.opencv.utils.ImageUtils;
-import org.jeecg.modules.opencv.utils.VideoProcessing;
 import org.opencv.core.Core;
 import org.opencv.core.Mat;
 import org.opencv.core.Size;
@@ -136,7 +135,7 @@ public class FfmpegServiceImpl implements IFfmpegService {
             while ((line = br.readLine()) != null) {
                 result.append(line + "\n");
             }
-            log.info("FFMPEG视频转换进程错误信息:" + result.toString());
+//            log.info("FFMPEG视频转换进程错误信息:" + result.toString());
 
             result = new StringBuffer();
             line = null;
@@ -144,7 +143,7 @@ public class FfmpegServiceImpl implements IFfmpegService {
             while ((line = br2.readLine()) != null) {
                 result.append(line + "\n");
             }
-            log.info("FFMPEG视频转换进程输出内容为:" + result.toString());
+//            log.info("FFMPEG视频转换进程输出内容为:" + result.toString());
         } catch (IOException e2) {
             e2.printStackTrace();
         } finally {
@@ -317,15 +316,24 @@ public class FfmpegServiceImpl implements IFfmpegService {
         String finalVideoPath = PropertiesUtils.getValue("kuaishou_config", "model_video_final_path");
 
         String fillFilePath = LoadFileUtil.downLoadFromUrl(url, fillVideoPath);
+        Long current1 = System.currentTimeMillis();
+        log.info("替换视频下载完成:总时长{}毫秒", current1 - current);
         String srcFilePath = LoadFileUtil.downLoadFromUrl(videoInfo.getModelVideoUrl(), srcVideoPath);
-
+        Long current2 = System.currentTimeMillis();
+        log.info("模板文件下载完成:总时长{}毫秒", current2 - current1);
         String splitSrcPath = srcVideoPath + current + File.separator;
+        LoadFileUtil.checkFile(splitSrcPath);
         String splitFillPath = fillVideoPath + current + File.separator;
+        LoadFileUtil.checkFile(splitFillPath);
         String splitFinalPath = finalVideoPath + current + File.separator;
         LoadFileUtil.checkFile(splitFinalPath);
         //1:切分视频
-        VideoProcessing.grabberVideoFramer(srcFilePath, splitSrcPath);
-        VideoProcessing.grabberVideoFramer(fillFilePath, splitFillPath);
+        videoSplitToImage(srcFilePath, splitSrcPath);
+        Long current3 = System.currentTimeMillis();
+        log.info("模板文件切分完成:总时长{}毫秒", current3 - current2);
+        videoSplitToImage(fillFilePath, splitFillPath);
+        Long current4 = System.currentTimeMillis();
+        log.info("填充文件切分完成:总时长{}毫秒", current4 - current3);
         ModelVideoInfoConfig config = configService.getByModelId(videoInfo.getId());
         if (null == config) {
             log.error("配置文件尚未配置=>modelId:{}", videoInfo.getId());
@@ -339,13 +347,13 @@ public class FfmpegServiceImpl implements IFfmpegService {
             //视频替换结束帧数
             int exchangeEndFrameNum = config.getFullScreenEndFrame();
             //2.1 复制原始视频无变化图片
-            for (int i = 0; i < exchangeStartFrameNum; i++) {
+            for (int i = 1; i < exchangeStartFrameNum; i++) {
                 Mat srcNoChangeImage = Imgcodecs.imread(splitSrcPath + i + ".jpg");
                 Imgcodecs.imwrite(splitFinalPath + i + ".jpg", srcNoChangeImage);
             }
 
             //2.2 转场动画(从fill文件夹的第一帧开始)
-            String getImageName = splitFillPath + "0.jpg";
+            String getImageName = splitFillPath + "1.jpg";
             Mat image = Imgcodecs.imread(getImageName, Imgcodecs.IMREAD_COLOR);
             //(1)径向模糊图片
             Mat radialBlur = ImageUtils.radialBlur(image);
@@ -369,7 +377,7 @@ public class FfmpegServiceImpl implements IFfmpegService {
             Imgcodecs.imwrite(splitFinalPath + exchangeStartFrameNum + ".jpg", wholeImage);
             exchangeStartFrameNum++;
             //2.3复制填充视频无变化图片
-            int checkNum = 1;
+            int checkNum = 2;
             for (int i = exchangeStartFrameNum; i < exchangeEndFrameNum; i++) {
                 String fillImagePath = splitFillPath + checkNum + ".jpg";
                 File file = new File(fillImagePath);
@@ -381,33 +389,45 @@ public class FfmpegServiceImpl implements IFfmpegService {
                 }
                 checkNum++;
             }
+            Long current5 = System.currentTimeMillis();
+            log.info("图片替换完成:总时长{}毫秒", current5 - current4);
             //3开始合成视频
             //3.1 抽取音频文件
             String srcM4aFilePath = splitSrcPath + "src.m4a";
             getM4aFromMp4(srcFilePath, srcM4aFilePath);
-
+            Long current6 = System.currentTimeMillis();
+            log.info("抽取模板音频文件完成:总时长{}毫秒", current6 - current4);
             String fillM4aFilePath = splitSrcPath + "fill.m4a";
             getM4aFromMp4(fillFilePath, fillM4aFilePath);
+            Long current7 = System.currentTimeMillis();
+            log.info("抽取填充音频文件完成:总时长{}毫秒", current7 - current6);
             //3.2 截取源模板音频文件
             String cutM4aFilePath = splitSrcPath + "cut.m4a";
             //计算需要截取的音频时长
             String secondStr = getSecond(exchangeStartFrameNum);
             cutM4a(srcM4aFilePath, cutM4aFilePath, "00:00:00.000", secondStr);
-
+            Long current8 = System.currentTimeMillis();
+            log.info("音频文件截取完成:总时长{}毫秒", current8 - current7);
             //3.3 合并两个音频文件
             String finalM4aFilePath = splitSrcPath + "final.m4a";
             audioMosaic(cutM4aFilePath, fillM4aFilePath, finalM4aFilePath);
-
+            Long current9 = System.currentTimeMillis();
+            log.info("音频文件合成完成:总时长{}毫秒", current9 - current8);
             //3.4 将最终生成的图片合成为视频
             String noVoiceVideoFilePath = splitSrcPath + "novoice.mp4";
             mergeImageToVideo(splitFinalPath, 25, noVoiceVideoFilePath);
+            Long current10 = System.currentTimeMillis();
+            log.info("图片合成视频完成:总时长{}毫秒", current10 - current9);
             //3.5 合并视频和音频
             String finalVideoFilePath = splitSrcPath + "final.mp4";
             mergeAudioAndVideo(noVoiceVideoFilePath, finalM4aFilePath, finalVideoFilePath);
+            Long current11 = System.currentTimeMillis();
+            log.info("视频合成完成:总时长{}毫秒", current11 - current10);
             //3.6 上传视频文件至OSS并返回url存入数据库
             InputStream inputStream = new FileInputStream(finalVideoFilePath);
             String finalUrl = OSSUtils.uploadFile2OSS(inputStream, "model/final/", videoInfo.getId() + "_" + current + ".mp4");
-            System.out.println(finalUrl);
+            Long current12 = System.currentTimeMillis();
+            log.info("文件上传oss完成:总时长{}毫秒", current12 - current11);
             ModelVideoCompositeInfo compositeInfo = new ModelVideoCompositeInfo(userId, videoInfo, finalUrl);
             compositeInfoService.saveOrUpdate(compositeInfo);
             //删除文件
@@ -423,6 +443,32 @@ public class FfmpegServiceImpl implements IFfmpegService {
         return null;
     }
 
+    @Override
+    public void videoSplitToImage(String srcFilePath, String splitSrcPath) {
+        StringBuffer command = new StringBuffer();
+        command.append(FFMPEG_PATH);
+        command.append(" -i ");
+        command.append(srcFilePath);
+        command.append(" -threads 5");
+        command.append(" -preset");
+        command.append(" ultrafast ");
+        command.append(splitSrcPath + "%d.jpg");
+        Runtime runtime = Runtime.getRuntime();
+        Process pro = null;
+        try {
+            pro = runtime.exec(new String[]{"sh", "-c", command.toString()});
+            printProcessMsg(pro);
+            int status = pro.waitFor();
+            if (status == 0) {
+                log.info("视频切分成功:{}", command.toString());
+            } else {
+                log.info("视频切分失败:{}", command.toString());
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     private void deleteFile(String splitSrcPath, String splitFillPath, String splitFinalPath, String srcFilePath, String fillFilePath) {
         LoadFileUtil.delFile(splitFillPath);
         LoadFileUtil.delFile(splitSrcPath);

+ 0 - 1
jeecg-boot-module-system/src/main/resources/application-prod.yml

@@ -143,7 +143,6 @@ mybatis-plus:
 jeecg:
   ffmpeg:
     bin: ffmpeg
-  #    bin: D:\java\ffmpeg\bin\ffmpeg.exe
   path:
     #文件上传根目录 设置
     upload: /mnt/upload

+ 8 - 5
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -7,7 +7,6 @@ import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.CtopAdConstant;
 import cn.com.ctop.common.module.utils.HttpUtils;
-import cn.com.ctop.common.module.utils.OSSUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
@@ -21,12 +20,12 @@ import org.jeecg.modules.ctop.service.IBytedanceFundDailyService;
 import org.jeecg.modules.ctop.service.IPerformanceSaleService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.opencv.core.Mat;
+import org.opencv.videoio.VideoCapture;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.io.FileInputStream;
-import java.io.InputStream;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
@@ -302,8 +301,12 @@ public class SampleTest {
 
     @Test
     public void test() throws Exception {
-        InputStream file = new FileInputStream("D:\\data\\模板视频\\原始模板4.mp4");
-        OSSUtils.uploadFile2OSS(file, "model/video/", "1234.mp4");
+        VideoCapture capture = new VideoCapture("D:\\data\\模板视频\\模板3\\原始模板3.mp4");
+        int frameCnt = 0;
+        int num = 0;
+        Mat mat = new Mat();
+        capture.read(mat);
+
     }