完善 时长统计 及 临时文件回收
This commit is contained in:
parent
5152136f97
commit
79fc31dd6e
@ -21,7 +21,7 @@ public class FfmpegSupportService {
|
||||
public Executor downloadToStream(String input, String out, long time, TimeUnit unit, ExecuteStreamHandler streamHandler, ExecuteResultHandler executeResultHandler) {
|
||||
FfmpegConfig.Rtp rtp = ffmpegConfig.getRtp();
|
||||
FfmpegConfig.Debug debug = ffmpegConfig.getDebug();
|
||||
String inputParam = debug.getDownload() ? rtp.getDownload() : StringUtils.joinWith(" ", rtp.getDownload(), input);
|
||||
String inputParam = debug.getDownload() ? rtp.getDownload() : StringUtils.joinWith(" ", "-y", rtp.getDownload(), input);
|
||||
log.info("视频输入参数 {}", inputParam);
|
||||
|
||||
String outputParam = debug.getOutput() ? rtp.getOutput() : StringUtils.joinWith(" ", rtp.getOutput(), out);
|
||||
@ -39,7 +39,7 @@ public class FfmpegSupportService {
|
||||
public Executor playbackToStream(String input, String out, long time, TimeUnit unit, ExecuteStreamHandler streamHandler, ExecuteResultHandler executeResultHandler){
|
||||
FfmpegConfig.Rtp rtp = ffmpegConfig.getRtp();
|
||||
FfmpegConfig.Debug debug = ffmpegConfig.getDebug();
|
||||
String inputParam = debug.getInput() ? rtp.getInput() : StringUtils.joinWith(" ", rtp.getInput(), input);
|
||||
String inputParam = debug.getInput() ? rtp.getInput() : StringUtils.joinWith(" ", "-y", rtp.getInput(), input);
|
||||
log.info("视频输入参数 {}", inputParam);
|
||||
|
||||
String outputParam = debug.getOutput() ? rtp.getOutput() : StringUtils.joinWith(" ", rtp.getOutput(), out);
|
||||
|
@ -1,9 +1,6 @@
|
||||
package cn.skcks.docking.gb28181.wvp.service.gb28181;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.date.*;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.skcks.docking.gb28181.common.json.JsonException;
|
||||
@ -184,6 +181,7 @@ public class Gb28181DownloadService {
|
||||
AsyncContext asyncContext = request.startAsync();
|
||||
asyncContext.setTimeout(0);
|
||||
asyncContext.start(()->{
|
||||
DateTime start = DateUtil.date();
|
||||
HttpServletResponse asyncResponse = (HttpServletResponse)asyncContext.getResponse();
|
||||
try{
|
||||
if(proxySipConfig.isUseRecordInfoQueryBeforeDownload()){
|
||||
@ -230,15 +228,17 @@ public class Gb28181DownloadService {
|
||||
} else if (videoInfo == null) {
|
||||
writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败"));
|
||||
} else if (wvpProxyConfig.getUseFfmpeg()) {
|
||||
videoService.ffmpegRecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime, endTime, DateUnit.SECOND) + 60, videoInfo.getDevice(), videoInfo.getCallId());
|
||||
videoService.ffmpegRecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime, endTime, DateUnit.SECOND) + 15, videoInfo.getDevice(), videoInfo.getCallId());
|
||||
} else {
|
||||
videoService.javaCVrecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime, endTime, DateUnit.SECOND) + 60);
|
||||
videoService.javaCVrecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime, endTime, DateUnit.SECOND) + 15);
|
||||
}
|
||||
asyncContext.complete();
|
||||
});
|
||||
} catch(Exception e) {
|
||||
writeErrorToResponse(asyncResponse, JsonResponse.error(e.getMessage()));
|
||||
} finally {
|
||||
DateTime end = DateUtil.date();
|
||||
asyncContext.complete();
|
||||
log.info("下载总耗时: {}, deviceCode {}, startTime {}, endTime {}", DateUtil.between(start,end, DateUnit.SECOND), deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -357,6 +357,7 @@ public class Gb28181DownloadService {
|
||||
AsyncContext asyncContext = request.startAsync();
|
||||
asyncContext.setTimeout(0);
|
||||
asyncContext.start(()->{
|
||||
DateTime start = DateUtil.date();
|
||||
HttpServletResponse asyncResponse = (HttpServletResponse)asyncContext.getResponse();
|
||||
try{
|
||||
download(deviceCode, startTime,endTime).whenComplete((videoInfo, e)->{
|
||||
@ -367,16 +368,20 @@ public class Gb28181DownloadService {
|
||||
writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败"));
|
||||
} else if(wvpProxyConfig.getUseFfmpeg()){
|
||||
scheduledExecutorService.submit(()->{
|
||||
videoService.ffmpegRecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 60,videoInfo.getDevice(),videoInfo.getCallId());
|
||||
videoService.ffmpegRecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 15,videoInfo.getDevice(),videoInfo.getCallId());
|
||||
});
|
||||
} else {
|
||||
videoService.javaCVrecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 60);
|
||||
videoService.javaCVrecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 15);
|
||||
}
|
||||
asyncContext.complete();
|
||||
|
||||
});
|
||||
} catch(Exception e) {
|
||||
writeErrorToResponse(asyncResponse, JsonResponse.error(e.getMessage()));
|
||||
|
||||
} finally {
|
||||
DateTime end = DateUtil.date();
|
||||
asyncContext.complete();
|
||||
log.info("下载总耗时: {}, deviceCode {}, startTime {}, endTime {}", DateUtil.between(start,end, DateUnit.SECOND), deviceCode, DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -273,6 +273,9 @@ public class VideoService {
|
||||
if(ffmpegConfig.getUseTmpFile()) {
|
||||
ServletOutputStream servletOutputStream = response.getOutputStream();
|
||||
IoUtil.copy(new FileInputStream(file), servletOutputStream);
|
||||
response.flushBuffer();
|
||||
servletOutputStream.close();
|
||||
System.gc();
|
||||
boolean delete = file.delete();
|
||||
log.info("删除临时文件 {} => {}", file, delete);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user