diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/ffmpeg/FfmpegSupportService.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/ffmpeg/FfmpegSupportService.java index 19f1be1..93caa90 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/ffmpeg/FfmpegSupportService.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/ffmpeg/FfmpegSupportService.java @@ -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); diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/gb28181/Gb28181DownloadService.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/gb28181/Gb28181DownloadService.java index fe01e51..feb934d 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/gb28181/Gb28181DownloadService.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/gb28181/Gb28181DownloadService.java @@ -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)); } }); } diff --git a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/video/VideoService.java b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/video/VideoService.java index 72694dc..a40d417 100644 --- a/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/video/VideoService.java +++ b/gb28181-wvp-proxy-service/src/main/java/cn/skcks/docking/gb28181/wvp/service/video/VideoService.java @@ -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); }