Commit ede562fc6099abadea033202d10e0a607943d5e8

Authored by 648540858
1 parent 061b35eb

修改下载文件名格式为:stream_callId.mp4, 查询合并文件列表增加app,stream, callId过滤参数

src/main/java/top/panll/assist/controller/RecordController.java
@@ -73,9 +73,12 @@ public class RecordController { @@ -73,9 +73,12 @@ public class RecordController {
73 @GetMapping(value = "/file/download/task/list") 73 @GetMapping(value = "/file/download/task/list")
74 @ResponseBody 74 @ResponseBody
75 public List<MergeOrCutTaskInfo> getTaskListForDownload( 75 public List<MergeOrCutTaskInfo> getTaskListForDownload(
  76 + @RequestParam(required = false) String app,
  77 + @RequestParam(required = false) String stream,
  78 + @RequestParam(required = false) String callId,
76 @RequestParam(required = false) String taskId, 79 @RequestParam(required = false) String taskId,
77 @RequestParam(required = false) Boolean isEnd){ 80 @RequestParam(required = false) Boolean isEnd){
78 - List<MergeOrCutTaskInfo> taskList = videoFileService.getTaskListForDownload(isEnd, taskId); 81 + List<MergeOrCutTaskInfo> taskList = videoFileService.getTaskListForDownload(app, stream, callId, isEnd, taskId);
79 if (taskList == null) { 82 if (taskList == null) {
80 throw new ControllerException(ErrorCode.ERROR100); 83 throw new ControllerException(ErrorCode.ERROR100);
81 } 84 }
src/main/java/top/panll/assist/service/FFmpegExecUtils.java
@@ -77,7 +77,7 @@ public class FFmpegExecUtils implements InitializingBean{ @@ -77,7 +77,7 @@ public class FFmpegExecUtils implements InitializingBean{
77 } 77 }
78 78
79 @Async 79 @Async
80 - public void mergeOrCutFile(List<File> fils, File dest, String destFileName, VideoHandEndCallBack callBack){ 80 + public void mergeOrCutFile(List<File> fils, File dest, String destFileName, VideoHandEndCallBack callBack){
81 81
82 if (fils == null || fils.size() == 0 || ffmpeg == null || ffprobe == null || dest== null || !dest.exists()){ 82 if (fils == null || fils.size() == 0 || ffmpeg == null || ffprobe == null || dest== null || !dest.exists()){
83 callBack.run("error", 0.0, null); 83 callBack.run("error", 0.0, null);
@@ -129,15 +129,15 @@ public class FFmpegExecUtils implements InitializingBean{ @@ -129,15 +129,15 @@ public class FFmpegExecUtils implements InitializingBean{
129 double percentage = progress.out_time_ns / duration_ns; 129 double percentage = progress.out_time_ns / duration_ns;
130 130
131 // Print out interesting information about the progress 131 // Print out interesting information about the progress
132 - System.out.println(String.format(  
133 - "[%.0f%%] status:%s frame:%d time:%s ms fps:%.0f speed:%.2fx",  
134 - percentage * 100,  
135 - progress.status,  
136 - progress.frame,  
137 - FFmpegUtils.toTimecode(progress.out_time_ns, TimeUnit.NANOSECONDS),  
138 - progress.fps.doubleValue(),  
139 - progress.speed  
140 - )); 132 +// System.out.println(String.format(
  133 +// "[%.0f%%] status:%s frame:%d time:%s ms fps:%.0f speed:%.2fx",
  134 +// percentage * 100,
  135 +// progress.status,
  136 +// progress.frame,
  137 +// FFmpegUtils.toTimecode(progress.out_time_ns, TimeUnit.NANOSECONDS),
  138 +// progress.fps.doubleValue(),
  139 +// progress.speed
  140 +// ));
141 141
142 if (progress.status.equals(Progress.Status.END)){ 142 if (progress.status.equals(Progress.Status.END)){
143 callBack.run(progress.status.name(), percentage, recordFileResultPath); 143 callBack.run(progress.status.name(), percentage, recordFileResultPath);
src/main/java/top/panll/assist/service/VideoFileService.java
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.data.redis.core.RedisTemplate; 10 import org.springframework.data.redis.core.RedisTemplate;
11 import org.springframework.stereotype.Service; 11 import org.springframework.stereotype.Service;
12 import org.springframework.util.DigestUtils; 12 import org.springframework.util.DigestUtils;
  13 +import org.springframework.util.ObjectUtils;
13 import top.panll.assist.controller.bean.ControllerException; 14 import top.panll.assist.controller.bean.ControllerException;
14 import top.panll.assist.controller.bean.ErrorCode; 15 import top.panll.assist.controller.bean.ErrorCode;
15 import top.panll.assist.dto.*; 16 import top.panll.assist.dto.*;
@@ -211,22 +212,24 @@ public class VideoFileService { @@ -211,22 +212,24 @@ public class VideoFileService {
211 assert videoTaskInfo.getFilePathList() != null; 212 assert videoTaskInfo.getFilePathList() != null;
212 assert !videoTaskInfo.getFilePathList().isEmpty(); 213 assert !videoTaskInfo.getFilePathList().isEmpty();
213 String taskId = DigestUtils.md5DigestAsHex(String.valueOf(System.currentTimeMillis()).getBytes()); 214 String taskId = DigestUtils.md5DigestAsHex(String.valueOf(System.currentTimeMillis()).getBytes());
214 - logger.info("[录像合并] 开始合并, 任务ID:{}: ", taskId); 215 + String logInfo = String.format("app: %S, stream: %S, callId: %S, 任务ID:%S",
  216 + videoTaskInfo.getApp(), videoTaskInfo.getStream(), videoTaskInfo.getCallId(), taskId);
  217 + logger.info("[录像合并] 开始合并,{} ", logInfo);
215 List<File> fileList = new ArrayList<>(); 218 List<File> fileList = new ArrayList<>();
216 for (String filePath : videoTaskInfo.getFilePathList()) { 219 for (String filePath : videoTaskInfo.getFilePathList()) {
217 File file = new File(filePath); 220 File file = new File(filePath);
218 if (!file.exists()) { 221 if (!file.exists()) {
219 - logger.info("[录像合并] 失败, 任务ID:{}, 文件不存在: {}", taskId, filePath); 222 + logger.info("[录像合并] 失败,{} ", logInfo);
220 throw new ControllerException(ErrorCode.ERROR100.getCode(), filePath + "文件不存在"); 223 throw new ControllerException(ErrorCode.ERROR100.getCode(), filePath + "文件不存在");
221 } 224 }
222 - logger.info("[录像合并] 添加文件, 任务ID:{}, 文件: {}", taskId, filePath); 225 + logger.info("[录像合并] 添加文件,{}, 文件: {}", logInfo, filePath);
223 fileList.add(file); 226 fileList.add(file);
224 } 227 }
225 228
226 File recordFile = new File(userSettings.getRecordTempPath() ); 229 File recordFile = new File(userSettings.getRecordTempPath() );
227 if (!recordFile.exists()) { 230 if (!recordFile.exists()) {
228 if (!recordFile.mkdirs()) { 231 if (!recordFile.mkdirs()) {
229 - logger.info("[录像合并] 失败, 任务ID:{}, 创建临时目录失败", taskId); 232 + logger.info("[录像合并] 失败,{}, 创建临时目录失败", logInfo);
230 throw new ControllerException(ErrorCode.ERROR100.getCode(), "创建临时目录失败"); 233 throw new ControllerException(ErrorCode.ERROR100.getCode(), "创建临时目录失败");
231 } 234 }
232 } 235 }
@@ -238,29 +241,30 @@ public class VideoFileService { @@ -238,29 +241,30 @@ public class VideoFileService {
238 mergeOrCutTaskInfo.setStartTime(videoTaskInfo.getStartTime()); 241 mergeOrCutTaskInfo.setStartTime(videoTaskInfo.getStartTime());
239 mergeOrCutTaskInfo.setEndTime(videoTaskInfo.getEndTime()); 242 mergeOrCutTaskInfo.setEndTime(videoTaskInfo.getEndTime());
240 mergeOrCutTaskInfo.setCreateTime(simpleDateFormatForTime.format(System.currentTimeMillis())); 243 mergeOrCutTaskInfo.setCreateTime(simpleDateFormatForTime.format(System.currentTimeMillis()));
  244 + String destFileName = videoTaskInfo.getStream() + "_" + videoTaskInfo.getCallId();
241 if (fileList.size() == 1) { 245 if (fileList.size() == 1) {
242 246
243 // 文件只有一个则不合并,直接复制过去 247 // 文件只有一个则不合并,直接复制过去
244 mergeOrCutTaskInfo.setPercentage("1"); 248 mergeOrCutTaskInfo.setPercentage("1");
245 // 处理文件路径 249 // 处理文件路径
246 - String recordFileResultPath = recordFile.getAbsolutePath() + File.separator + taskId + ".mp4";  
247 - String relativize = taskId + ".mp4"; 250 +
  251 + String recordFileResultPath = recordFile.getAbsolutePath() + File.separator + destFileName + ".mp4";
248 try { 252 try {
249 Files.copy(fileList.get(0).toPath(), Paths.get(recordFileResultPath)); 253 Files.copy(fileList.get(0).toPath(), Paths.get(recordFileResultPath));
250 } catch (IOException e) { 254 } catch (IOException e) {
251 - logger.info("[录像合并] 失败, 任务ID:{}", taskId, e); 255 + logger.info("[录像合并] 失败, {}", logInfo, e);
252 throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage()); 256 throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
253 } 257 }
254 - mergeOrCutTaskInfo.setRecordFile("/download/" + relativize.toString()); 258 + mergeOrCutTaskInfo.setRecordFile("/download/" + destFileName + ".mp4");
255 if (videoTaskInfo.getRemoteHost() != null) { 259 if (videoTaskInfo.getRemoteHost() != null) {
256 - mergeOrCutTaskInfo.setDownloadFile(videoTaskInfo.getRemoteHost() + "/download.html?url=download/" + relativize);  
257 - mergeOrCutTaskInfo.setPlayFile(videoTaskInfo.getRemoteHost() + "/download/" + relativize); 260 + mergeOrCutTaskInfo.setDownloadFile(videoTaskInfo.getRemoteHost() + "/download.html?url=download/" + destFileName + ".mp4");
  261 + mergeOrCutTaskInfo.setPlayFile(videoTaskInfo.getRemoteHost() + "/download/" + destFileName + ".mp4");
258 } 262 }
259 String key = String.format("%S_%S_%S", AssistConstants.MERGEORCUT , userSettings.getId(), mergeOrCutTaskInfo.getId()); 263 String key = String.format("%S_%S_%S", AssistConstants.MERGEORCUT , userSettings.getId(), mergeOrCutTaskInfo.getId());
260 redisUtil.set(key, mergeOrCutTaskInfo); 264 redisUtil.set(key, mergeOrCutTaskInfo);
261 logger.info("[录像合并] 成功, 任务ID:{}", taskId); 265 logger.info("[录像合并] 成功, 任务ID:{}", taskId);
262 }else { 266 }else {
263 - ffmpegExecUtils.mergeOrCutFile(fileList, recordFile, taskId, (status, percentage, result)->{ 267 + ffmpegExecUtils.mergeOrCutFile(fileList, recordFile, destFileName, (status, percentage, result)->{
264 // 发出redis通知 268 // 发出redis通知
265 if (status.equals(Progress.Status.END.name())) { 269 if (status.equals(Progress.Status.END.name())) {
266 mergeOrCutTaskInfo.setPercentage("1"); 270 mergeOrCutTaskInfo.setPercentage("1");
@@ -272,7 +276,7 @@ public class VideoFileService { @@ -272,7 +276,7 @@ public class VideoFileService {
272 mergeOrCutTaskInfo.setDownloadFile(videoTaskInfo.getRemoteHost() + "/download.html?url=download/" + relativize); 276 mergeOrCutTaskInfo.setDownloadFile(videoTaskInfo.getRemoteHost() + "/download.html?url=download/" + relativize);
273 mergeOrCutTaskInfo.setPlayFile(videoTaskInfo.getRemoteHost() + "/download/" + relativize); 277 mergeOrCutTaskInfo.setPlayFile(videoTaskInfo.getRemoteHost() + "/download/" + relativize);
274 } 278 }
275 - logger.info("[录像合并] 成功, 任务ID:{}", taskId); 279 + logger.info("[录像合并] 成功, {}", logInfo);
276 }else { 280 }else {
277 mergeOrCutTaskInfo.setPercentage(percentage + ""); 281 mergeOrCutTaskInfo.setPercentage(percentage + "");
278 } 282 }
@@ -336,7 +340,9 @@ public class VideoFileService { @@ -336,7 +340,9 @@ public class VideoFileService {
336 return dateFileList; 340 return dateFileList;
337 } 341 }
338 342
339 - public List<MergeOrCutTaskInfo> getTaskListForDownload(Boolean idEnd, String taskId) { 343 + public List<MergeOrCutTaskInfo> getTaskListForDownload(String app, String stream, String callId, Boolean isEnd, String taskId) {
  344 + logger.info("[查询录像合成列表] app: {}, stream: {}, callId: {}, isEnd: {}, taskId: {}",
  345 + app, stream, callId, isEnd, taskId);
340 ArrayList<MergeOrCutTaskInfo> result = new ArrayList<>(); 346 ArrayList<MergeOrCutTaskInfo> result = new ArrayList<>();
341 if (taskId == null) { 347 if (taskId == null) {
342 taskId = "*"; 348 taskId = "*";
@@ -346,19 +352,27 @@ public class VideoFileService { @@ -346,19 +352,27 @@ public class VideoFileService {
346 for (int i = 0; i < taskCatch.size(); i++) { 352 for (int i = 0; i < taskCatch.size(); i++) {
347 String keyItem = taskCatch.get(i).toString(); 353 String keyItem = taskCatch.get(i).toString();
348 MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(keyItem); 354 MergeOrCutTaskInfo mergeOrCutTaskInfo = (MergeOrCutTaskInfo)redisUtil.get(keyItem);
349 - if (mergeOrCutTaskInfo != null && mergeOrCutTaskInfo.getPercentage() != null){  
350 - if (idEnd != null ) {  
351 - if (idEnd) {  
352 - if (Double.parseDouble(mergeOrCutTaskInfo.getPercentage()) == 1){  
353 - result.add(mergeOrCutTaskInfo); 355 + if (mergeOrCutTaskInfo != null){
  356 + if ((!ObjectUtils.isEmpty(app) && !mergeOrCutTaskInfo.getApp().equals(app))
  357 + || (!ObjectUtils.isEmpty(stream) && !mergeOrCutTaskInfo.getStream().equals(stream))
  358 + || (!ObjectUtils.isEmpty(callId) && !mergeOrCutTaskInfo.getCallId().equals(callId))
  359 + ) {
  360 + continue;
  361 + }
  362 + if (mergeOrCutTaskInfo.getPercentage() != null){
  363 + if (isEnd != null ) {
  364 + if (isEnd) {
  365 + if (Double.parseDouble(mergeOrCutTaskInfo.getPercentage()) == 1){
  366 + result.add(mergeOrCutTaskInfo);
  367 + }
  368 + }else {
  369 + if (Double.parseDouble(mergeOrCutTaskInfo.getPercentage()) < 1){
  370 + result.add((MergeOrCutTaskInfo)redisUtil.get(keyItem));
  371 + }
354 } 372 }
355 }else { 373 }else {
356 - if (Double.parseDouble(mergeOrCutTaskInfo.getPercentage()) < 1){  
357 - result.add((MergeOrCutTaskInfo)redisUtil.get(keyItem));  
358 - } 374 + result.add((MergeOrCutTaskInfo)redisUtil.get(keyItem));
359 } 375 }
360 - }else {  
361 - result.add((MergeOrCutTaskInfo)redisUtil.get(keyItem));  
362 } 376 }
363 } 377 }
364 } 378 }