Commit a333e5f2ac701c0c7f2155f92fee534fded93784

Authored by panlinlin
1 parent 428e2657

修改录像查询和录像裁剪合并

@@ -21,6 +21,10 @@ @@ -21,6 +21,10 @@
21 <groupId>org.springframework.boot</groupId> 21 <groupId>org.springframework.boot</groupId>
22 <artifactId>spring-boot-starter-web</artifactId> 22 <artifactId>spring-boot-starter-web</artifactId>
23 </dependency> 23 </dependency>
  24 + <dependency>
  25 + <groupId>org.springframework.boot</groupId>
  26 + <artifactId>spring-boot-starter-data-redis</artifactId>
  27 + </dependency>
24 28
25 <dependency> 29 <dependency>
26 <groupId>log4j</groupId> 30 <groupId>log4j</groupId>
@@ -34,6 +38,13 @@ @@ -34,6 +38,13 @@
34 <version>0.6.2</version> 38 <version>0.6.2</version>
35 </dependency> 39 </dependency>
36 40
  41 + <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
  42 + <dependency>
  43 + <groupId>com.alibaba</groupId>
  44 + <artifactId>fastjson</artifactId>
  45 + <version>1.2.73</version>
  46 + </dependency>
  47 +
37 <dependency> 48 <dependency>
38 <groupId>org.springframework.boot</groupId> 49 <groupId>org.springframework.boot</groupId>
39 <artifactId>spring-boot-starter-test</artifactId> 50 <artifactId>spring-boot-starter-test</artifactId>
src/main/java/top/panll/assist/config/RedisConfig.java 0 → 100644
  1 +package top.panll.assist.config;
  2 +
  3 +import com.alibaba.fastjson.parser.ParserConfig;
  4 +import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
  5 +import org.springframework.cache.annotation.CachingConfigurerSupport;
  6 +import org.springframework.context.annotation.Bean;
  7 +import org.springframework.context.annotation.Configuration;
  8 +import org.springframework.data.redis.connection.RedisConnectionFactory;
  9 +import org.springframework.data.redis.core.RedisTemplate;
  10 +import org.springframework.data.redis.listener.RedisMessageListenerContainer;
  11 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  12 +
  13 +/**
  14 + * @Description:Redis中间件配置类,使用spring-data-redis集成,自动从application.yml中加载redis配置
  15 + * @author: swwheihei
  16 + * @date: 2019年5月30日 上午10:58:25
  17 + *
  18 + */
  19 +@Configuration
  20 +public class RedisConfig extends CachingConfigurerSupport {
  21 +
  22 + @Bean("redisTemplate")
  23 + public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
  24 + RedisTemplate<Object, Object> template = new RedisTemplate<>();
  25 + template.setConnectionFactory(redisConnectionFactory);
  26 + // 使用fastjson进行序列化处理,提高解析效率
  27 + FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<Object>(Object.class);
  28 + // value值的序列化采用fastJsonRedisSerializer
  29 + template.setValueSerializer(serializer);
  30 + template.setHashValueSerializer(serializer);
  31 + // key的序列化采用StringRedisSerializer
  32 + template.setKeySerializer(new StringRedisSerializer());
  33 + template.setHashKeySerializer(new StringRedisSerializer());
  34 + template.setConnectionFactory(redisConnectionFactory);
  35 + // 使用fastjson时需设置此项,否则会报异常not support type
  36 + ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
  37 + return template;
  38 + }
  39 +
  40 + /**
  41 + * redis消息监听器容器 可以添加多个监听不同话题的redis监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器
  42 + * 通过反射技术调用消息订阅处理器的相关方法进行一些业务处理
  43 + *
  44 + * @param connectionFactory
  45 + * @return
  46 + */
  47 + @Bean
  48 + RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
  49 +
  50 + RedisMessageListenerContainer container = new RedisMessageListenerContainer();
  51 + container.setConnectionFactory(connectionFactory);
  52 + return container;
  53 + }
  54 +
  55 +}
src/main/java/top/panll/assist/service/FFmpegExecUtils.java
@@ -40,10 +40,10 @@ public class FFmpegExecUtils { @@ -40,10 +40,10 @@ public class FFmpegExecUtils {
40 public FFmpeg ffmpeg; 40 public FFmpeg ffmpeg;
41 41
42 public interface VideoHandEndCallBack { 42 public interface VideoHandEndCallBack {
43 - public void run(String status, double percentage, String result); 43 + void run(String status, double percentage, String result);
44 } 44 }
45 45
46 - public static void mergeOrCutFile(List<File> fils, File dest, VideoHandEndCallBack callBack){ 46 + public void mergeOrCutFile(List<File> fils, File dest, VideoHandEndCallBack callBack){
47 FFmpeg ffmpeg = FFmpegExecUtils.getInstance().ffmpeg; 47 FFmpeg ffmpeg = FFmpegExecUtils.getInstance().ffmpeg;
48 FFprobe ffprobe = FFmpegExecUtils.getInstance().ffprobe; 48 FFprobe ffprobe = FFmpegExecUtils.getInstance().ffprobe;
49 if (fils == null || fils.size() == 0 || ffmpeg == null || ffprobe == null || dest== null || !dest.exists()){ 49 if (fils == null || fils.size() == 0 || ffmpeg == null || ffprobe == null || dest== null || !dest.exists()){
src/main/java/top/panll/assist/service/VideoFileService.java
@@ -2,6 +2,7 @@ package top.panll.assist.service; @@ -2,6 +2,7 @@ package top.panll.assist.service;
2 2
3 import net.bramp.ffmpeg.FFprobe; 3 import net.bramp.ffmpeg.FFprobe;
4 import net.bramp.ffmpeg.probe.FFmpegProbeResult; 4 import net.bramp.ffmpeg.probe.FFmpegProbeResult;
  5 +import net.bramp.ffmpeg.progress.Progress;
5 import org.slf4j.Logger; 6 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 7 import org.slf4j.LoggerFactory;
7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
@@ -82,26 +83,13 @@ public class VideoFileService { @@ -82,26 +83,13 @@ public class VideoFileService {
82 logger.debug("获取[app: {}, stream: {}, statime: {}, endTime: {}]的视频", app, stream, 83 logger.debug("获取[app: {}, stream: {}, statime: {}, endTime: {}]的视频", app, stream,
83 startTimeStr, endTimeStr); 84 startTimeStr, endTimeStr);
84 85
85 - File file = new File(userSettings.getRecord());  
86 - File[] appFiles = file.listFiles((File dir, String name) -> {  
87 - return app.equals(name);  
88 - });  
89 - if (appFiles.length == 0) {  
90 - logger.warn("获取[app: {}, stream: {}, statime: {}, endTime: {}]的视频时未找到目录: {}", app, stream,  
91 - startTimeStr, endTimeStr, app);  
92 - return result;  
93 - }  
94 - File appFile = appFiles[0];  
95 - File[] streamFiles = appFile.listFiles((File dir, String name)-> {  
96 - return stream.equals(name);  
97 - });  
98 - if (streamFiles.length == 0) { 86 + File recordFile = new File(userSettings.getRecord());
  87 + File streamFile = new File(recordFile.getAbsolutePath() + File.separator + app + File.separator + stream);
  88 + if (!streamFile.exists()) {
99 logger.warn("获取[app: {}, stream: {}, statime: {}, endTime: {}]的视频时未找到目录: {}", app, stream, 89 logger.warn("获取[app: {}, stream: {}, statime: {}, endTime: {}]的视频时未找到目录: {}", app, stream,
100 startTimeStr, endTimeStr, stream); 90 startTimeStr, endTimeStr, stream);
101 return result; 91 return result;
102 } 92 }
103 - File streamFile = streamFiles[0];  
104 -  
105 File[] dateFiles = streamFile.listFiles((File dir, String name) -> { 93 File[] dateFiles = streamFile.listFiles((File dir, String name) -> {
106 Date fileDate = null; 94 Date fileDate = null;
107 try { 95 try {
@@ -163,7 +151,13 @@ public class VideoFileService { @@ -163,7 +151,13 @@ public class VideoFileService {
163 151
164 public void mergeOrCut(String app, String stream, Date startTime, Date endTime) { 152 public void mergeOrCut(String app, String stream, Date startTime, Date endTime) {
165 List<File> filesInTime = this.getFilesInTime(app, stream, startTime, endTime); 153 List<File> filesInTime = this.getFilesInTime(app, stream, startTime, endTime);
  154 + File recordFile = new File(userSettings.getRecord());
  155 + File streamFile = new File(recordFile.getAbsolutePath() + File.separator + app + File.separator + stream);
  156 + FFmpegExecUtils.getInstance().mergeOrCutFile(filesInTime, streamFile, (String status, double percentage, String result)->{
  157 + if (status.equals(Progress.Status.END.name())) {
166 158
  159 + }
  160 + });
167 } 161 }
168 162
169 } 163 }
src/main/resources/application-dev.yml
  1 +spring:
  2 + # REDIS数据库配置
  3 + redis:
  4 + # [必须修改] Redis服务器IP, REDIS安装在本机的,使用127.0.0.1
  5 + host: 127.0.0.1
  6 + # [必须修改] 端口号
  7 + port: 6379
  8 + # [可选] 数据库 DB
  9 + database: 8
  10 + # [可选] 访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
  11 + password:
  12 + # [可选] 超时时间
  13 + timeout: 10000
  14 +
1 # [可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口 15 # [可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口
2 server: 16 server:
3 port: 18081 17 port: 18081