ffmpegRecord调整
This commit is contained in:
parent
0b3a80bce1
commit
87423c734f
@ -95,7 +95,8 @@ public class Gb28181DownloadService {
|
|||||||
@Qualifier(DefaultVideoExecutor.EXECUTOR_BEAN_NAME)
|
@Qualifier(DefaultVideoExecutor.EXECUTOR_BEAN_NAME)
|
||||||
private final Executor executor;
|
private final Executor executor;
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
private final ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(64);
|
||||||
|
|
||||||
private final ConcurrentMap<String, DeferredResult<JsonResponse<String>>> requestMap = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, DeferredResult<JsonResponse<String>>> requestMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final RealtimeManager realtimeManager;
|
private final RealtimeManager realtimeManager;
|
||||||
@ -368,13 +369,12 @@ public class Gb28181DownloadService {
|
|||||||
} else if(videoInfo == null){
|
} else if(videoInfo == null){
|
||||||
writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败"));
|
writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败"));
|
||||||
} else if(wvpProxyConfig.getUseFfmpeg()){
|
} else if(wvpProxyConfig.getUseFfmpeg()){
|
||||||
scheduledExecutorService.submit(()->{
|
executor.execute(()->{
|
||||||
videoService.ffmpegRecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 15,videoInfo.getDevice(),videoInfo.getCallId());
|
videoService.ffmpegRecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 15,videoInfo.getDevice(),videoInfo.getCallId());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
videoService.javaCVrecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 15);
|
videoService.javaCVrecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
writeErrorToResponse(asyncResponse, JsonResponse.error(e.getMessage()));
|
writeErrorToResponse(asyncResponse, JsonResponse.error(e.getMessage()));
|
||||||
|
@ -232,14 +232,13 @@ public class VideoService {
|
|||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void ffmpegRecord(ServletResponse response, String url, long time, WvpProxyDevice device,String callId){
|
public void ffmpegRecord(ServletResponse response, String url, long time, WvpProxyDevice device,String callId){
|
||||||
OutputStream outputStream;
|
|
||||||
String tmpDir = ffmpegConfig.getTmpDir();
|
String tmpDir = ffmpegConfig.getTmpDir();
|
||||||
String fileName = callId + ".mp4";
|
String fileName = callId + ".mp4";
|
||||||
File file = new File(tmpDir, fileName);
|
File file = new File(tmpDir, fileName);
|
||||||
Executor executor;
|
Executor executor;
|
||||||
DefaultExecuteResultHandler executeResultHandler = mediaStatus(device,callId);
|
DefaultExecuteResultHandler executeResultHandler = mediaStatus(device,callId);
|
||||||
if(ffmpegConfig.getUseTmpFile()) {
|
if(ffmpegConfig.getUseTmpFile()) {
|
||||||
outputStream = new PipedOutputStream();
|
OutputStream outputStream = new PipedOutputStream();
|
||||||
String filePath = file.getAbsolutePath();
|
String filePath = file.getAbsolutePath();
|
||||||
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
|
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
|
||||||
if(proxySipConfig.isUsePlaybackToDownload()){
|
if(proxySipConfig.isUsePlaybackToDownload()){
|
||||||
@ -248,7 +247,7 @@ public class VideoService {
|
|||||||
executor = ffmpegSupportService.downloadToStream(url, filePath, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
executor = ffmpegSupportService.downloadToStream(url, filePath, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
outputStream = response.getOutputStream();
|
OutputStream outputStream = response.getOutputStream();
|
||||||
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
|
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
|
||||||
if(proxySipConfig.isUsePlaybackToDownload()){
|
if(proxySipConfig.isUsePlaybackToDownload()){
|
||||||
executor = ffmpegSupportService.playbackToStream(url, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
executor = ffmpegSupportService.playbackToStream(url, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
||||||
@ -268,13 +267,11 @@ public class VideoService {
|
|||||||
schedule.cancel(true);
|
schedule.cancel(true);
|
||||||
DateTime endTime = DateUtil.date();
|
DateTime endTime = DateUtil.date();
|
||||||
log.info("录制进程结束 {}, 录制耗时: {}", url, DateUtil.between(startTime,endTime, DateUnit.SECOND));
|
log.info("录制进程结束 {}, 录制耗时: {}", url, DateUtil.between(startTime,endTime, DateUnit.SECOND));
|
||||||
outputStream.close();
|
|
||||||
|
|
||||||
if(ffmpegConfig.getUseTmpFile()) {
|
if(ffmpegConfig.getUseTmpFile()) {
|
||||||
ServletOutputStream servletOutputStream = response.getOutputStream();
|
ServletOutputStream servletOutputStream = response.getOutputStream();
|
||||||
IoUtil.copy(new FileInputStream(file), servletOutputStream);
|
IoUtil.copy(new FileInputStream(file), servletOutputStream);
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
servletOutputStream.close();
|
|
||||||
System.gc();
|
System.gc();
|
||||||
boolean delete = file.delete();
|
boolean delete = file.delete();
|
||||||
log.info("删除临时文件 {} => {}", file, delete);
|
log.info("删除临时文件 {} => {}", file, delete);
|
||||||
|
Loading…
Reference in New Issue
Block a user