From 3ec2f909611ca6d794ea96badda935443d4e0041 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Wed, 13 Mar 2024 16:22:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=20ffmpegRecord?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/wvp/service/video/VideoService.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 08b6f37..c718d73 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 @@ -3,7 +3,6 @@ package cn.skcks.docking.gb28181.wvp.service.video; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.io.IoUtil; import cn.skcks.docking.gb28181.core.sip.utils.SipUtil; import cn.skcks.docking.gb28181.wvp.config.ProxySipConfig; import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig; @@ -32,7 +31,9 @@ import org.bytedeco.javacv.FFmpegFrameRecorder; import org.bytedeco.javacv.FrameGrabber; import org.springframework.stereotype.Service; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; import java.util.Optional; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -231,9 +232,8 @@ public class VideoService { @SneakyThrows public void ffmpegRecord(ServletResponse response, String url, long time, WvpProxyDevice device,String callId){ ServletOutputStream outputStream = response.getOutputStream(); - PipedOutputStream pipedOutputStream = new PipedOutputStream(); ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); - PumpStreamHandler streamHandler = new PumpStreamHandler(pipedOutputStream, errorStream); + PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream); DefaultExecuteResultHandler executeResultHandler = mediaStatus(device,callId); DateTime startTime = DateUtil.date(); Executor executor; @@ -249,13 +249,10 @@ public class VideoService { log.info("结束录制 {}", url); }, time, TimeUnit.SECONDS); executeResultHandler.waitFor(); - - DataInputStream is = new DataInputStream(new PipedInputStream(pipedOutputStream)); - IoUtil.copy(is,outputStream); - schedule.cancel(true); DateTime endTime = DateUtil.date(); log.info("录制进程结束 {}, 录制耗时: {}", url, DateUtil.between(startTime,endTime, DateUnit.SECOND)); + outputStream.close(); } /**