配置 ffmpegRecord 写入临时文件
This commit is contained in:
parent
ccbb1ad186
commit
5611bbbe38
@ -18,13 +18,31 @@ public class FfmpegSupportService {
|
|||||||
private final FfmpegConfig ffmpegConfig;
|
private final FfmpegConfig ffmpegConfig;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public Executor downloadToStream(String input, long time, TimeUnit unit, ExecuteStreamHandler streamHandler, ExecuteResultHandler executeResultHandler) {
|
public Executor downloadToStream(String input, String out, long time, TimeUnit unit, ExecuteStreamHandler streamHandler, ExecuteResultHandler executeResultHandler) {
|
||||||
FfmpegConfig.Rtp rtp = ffmpegConfig.getRtp();
|
FfmpegConfig.Rtp rtp = ffmpegConfig.getRtp();
|
||||||
FfmpegConfig.Debug debug = ffmpegConfig.getDebug();
|
FfmpegConfig.Debug debug = ffmpegConfig.getDebug();
|
||||||
String inputParam = debug.getDownload() ? rtp.getDownload() : StringUtils.joinWith(" ", rtp.getDownload(), input);
|
String inputParam = debug.getDownload() ? rtp.getDownload() : StringUtils.joinWith(" ", rtp.getDownload(), input);
|
||||||
log.info("视频输入参数 {}", inputParam);
|
log.info("视频输入参数 {}", inputParam);
|
||||||
|
|
||||||
String outputParam = debug.getOutput() ? rtp.getOutput() : StringUtils.joinWith(" ", rtp.getOutput(), "-");
|
String outputParam = debug.getOutput() ? rtp.getOutput() : StringUtils.joinWith(" ", rtp.getOutput(), out);
|
||||||
|
log.info("视频输出参数 {}", outputParam);
|
||||||
|
|
||||||
|
return ffmpegExecutor(inputParam, outputParam, time, unit, streamHandler, executeResultHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public Executor downloadToStream(String input, long time, TimeUnit unit, ExecuteStreamHandler streamHandler, ExecuteResultHandler executeResultHandler) {
|
||||||
|
return downloadToStream(input, "-", time, unit, streamHandler, executeResultHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
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);
|
||||||
|
log.info("视频输入参数 {}", inputParam);
|
||||||
|
|
||||||
|
String outputParam = debug.getOutput() ? rtp.getOutput() : StringUtils.joinWith(" ", rtp.getOutput(), out);
|
||||||
log.info("视频输出参数 {}", outputParam);
|
log.info("视频输出参数 {}", outputParam);
|
||||||
|
|
||||||
return ffmpegExecutor(inputParam, outputParam, time, unit, streamHandler, executeResultHandler);
|
return ffmpegExecutor(inputParam, outputParam, time, unit, streamHandler, executeResultHandler);
|
||||||
@ -32,15 +50,7 @@ public class FfmpegSupportService {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public Executor playbackToStream(String input, long time, TimeUnit unit, ExecuteStreamHandler streamHandler, ExecuteResultHandler executeResultHandler) {
|
public Executor playbackToStream(String input, long time, TimeUnit unit, ExecuteStreamHandler streamHandler, ExecuteResultHandler executeResultHandler) {
|
||||||
FfmpegConfig.Rtp rtp = ffmpegConfig.getRtp();
|
return playbackToStream(input, "-", time, unit, streamHandler, executeResultHandler);
|
||||||
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
|
@SneakyThrows
|
||||||
|
@ -236,26 +236,32 @@ public class VideoService {
|
|||||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||||
String fileName = callId + ".mp4";
|
String fileName = callId + ".mp4";
|
||||||
File file = new File(tmpDir, fileName);
|
File file = new File(tmpDir, fileName);
|
||||||
|
Executor executor;
|
||||||
|
DefaultExecuteResultHandler executeResultHandler = mediaStatus(device,callId);
|
||||||
if(ffmpegConfig.getUseTmpFile()) {
|
if(ffmpegConfig.getUseTmpFile()) {
|
||||||
if(!file.exists()){
|
if(!file.exists()){
|
||||||
log.info("创建临时文件 {}", fileName);
|
log.info("创建临时文件 {}", fileName);
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
}
|
}
|
||||||
outputStream = new FileOutputStream(file);
|
outputStream = new PipedOutputStream();
|
||||||
|
String filePath = file.getAbsolutePath();
|
||||||
|
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
|
||||||
|
if(proxySipConfig.isUsePlaybackToDownload()){
|
||||||
|
executor = ffmpegSupportService.playbackToStream(url, filePath, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
||||||
|
} else {
|
||||||
|
executor = ffmpegSupportService.downloadToStream(url, filePath, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
outputStream = response.getOutputStream();
|
outputStream = response.getOutputStream();
|
||||||
|
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
|
||||||
|
if(proxySipConfig.isUsePlaybackToDownload()){
|
||||||
|
executor = ffmpegSupportService.playbackToStream(url, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
||||||
|
} else {
|
||||||
|
executor = ffmpegSupportService.downloadToStream(url, time, TimeUnit.SECONDS,streamHandler,executeResultHandler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream, System.err);
|
|
||||||
DefaultExecuteResultHandler executeResultHandler = mediaStatus(device,callId);
|
|
||||||
DateTime startTime = DateUtil.date();
|
DateTime startTime = DateUtil.date();
|
||||||
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);
|
log.info("开始录制 {}", url);
|
||||||
ScheduledFuture<?> schedule = scheduledExecutorService.schedule(() -> {
|
ScheduledFuture<?> schedule = scheduledExecutorService.schedule(() -> {
|
||||||
log.info("到达结束时间, 结束录制 {}", url);
|
log.info("到达结束时间, 结束录制 {}", url);
|
||||||
|
Loading…
Reference in New Issue
Block a user