/video 支持某些特殊情况下使用 实时回放 代替下载

This commit is contained in:
shikong 2023-10-09 14:52:36 +08:00
parent c2dcf6d931
commit 4fc4d3a863
5 changed files with 32 additions and 2 deletions

View File

@ -32,6 +32,11 @@ public class ProxySipConfig {
private StreamMode streamMode = StreamMode.TCP_PASSIVE;
/**
* 某些特殊情况下 使用 视频回放点播 代替 下载
*/
private boolean usePlaybackToDownload = false;
@Bean
public SipConfig sipConfig(){
SipConfig sipConfig = new SipConfig();

View File

@ -30,6 +30,19 @@ public class FfmpegSupportService {
return ffmpegExecutor(inputParam, outputParam, time, unit, streamHandler, executeResultHandler);
}
@SneakyThrows
public Executor playbackToStream(String input, 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);
log.info("视频输入参数 {}", inputParam);
String outputParam = debug.getOutput() ? rtp.getOutput() : StringUtils.joinWith(" ", rtp.getOutput(), "-");
log.info("视频输出参数 {}", outputParam);
return ffmpegExecutor(inputParam, outputParam, time, unit, streamHandler, executeResultHandler);
}
@SneakyThrows
public Executor ffmpegExecutor(String inputParam,String outputParam, long time, TimeUnit unit,ExecuteStreamHandler streamHandler,ExecuteResultHandler executeResultHandler){
FfmpegConfig.Rtp rtp = ffmpegConfig.getRtp();

View File

@ -238,7 +238,12 @@ public class VideoService {
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream);
DefaultExecuteResultHandler executeResultHandler = mediaStatus(device,callId);
DateTime startTime = DateUtil.date();
Executor executor = ffmpegSupportService.downloadToStream(url, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
Executor executor;
if(proxySipConfig.isUsePlaybackToDownload()){
executor = ffmpegSupportService.playbackToStream(url, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
} else {
executor = ffmpegSupportService.downloadToStream(url, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
}
log.info("开始录制 {}", url);
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
ScheduledFuture<?> schedule = scheduledExecutorService.schedule(() -> {
@ -265,7 +270,12 @@ public class VideoService {
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, errorStream);
DefaultExecuteResultHandler defaultExecuteResultHandler = new DefaultExecuteResultHandler();
DateTime startTime = DateUtil.date();
Executor executor = ffmpegSupportService.downloadToStream(url, time, TimeUnit.SECONDS,streamHandler,defaultExecuteResultHandler);
Executor executor;
if(proxySipConfig.isUsePlaybackToDownload()){
executor = ffmpegSupportService.playbackToStream(url, time, TimeUnit.SECONDS,streamHandler,defaultExecuteResultHandler);
} else {
executor = ffmpegSupportService.downloadToStream(url, time, TimeUnit.SECONDS,streamHandler,defaultExecuteResultHandler);
}
log.info("开始录制 {}", url);
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
ScheduledFuture<?> schedule = scheduledExecutorService.schedule(() -> {

View File

@ -57,6 +57,7 @@ proxy:
ip:
- 10.10.10.20
stream-mode: tcp_passive
use-playback-to-download: false
# - 192.168.1.241
ffmpeg-support:
ffmpeg: D:\Soft\Captura\ffmpeg\ffmpeg.exe

View File

@ -65,6 +65,7 @@ proxy:
# - 192.168.3.10
# - 192.168.1.241
stream-mode: tcp_passive
use-playback-to-download: true
ffmpeg-support:
ffmpeg: /usr/bin/ffmpeg/ffmpeg