补充信息/完善
This commit is contained in:
parent
34a6ba040d
commit
84e0addf53
@ -25,6 +25,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RecordService {
|
||||
/**
|
||||
* 写入 flv 响应头信息
|
||||
* @param response HttpServletResponse 响应
|
||||
*/
|
||||
public void header(HttpServletResponse response) {
|
||||
response.setContentType("video/x-flv");
|
||||
response.setHeader("Accept-Ranges", "none");
|
||||
@ -32,6 +36,13 @@ public class RecordService {
|
||||
response.setHeader("Content-Disposition","attachment; filename=\"record.flv\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* 录制视频 并写入 响应
|
||||
* @param request HttpServletRequest 请求
|
||||
* @param response HttpServletResponse 同步响应
|
||||
* @param url 要录制的视频地址
|
||||
* @param time 录制时长 (单位: 秒)
|
||||
*/
|
||||
@SneakyThrows
|
||||
public void record(HttpServletRequest request, HttpServletResponse response, String url, long time) {
|
||||
AsyncContext asyncContext = request.startAsync();
|
||||
@ -47,11 +58,17 @@ public class RecordService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 录制视频 并写入 异步响应
|
||||
* @param response AsyncContext.getResponse 异步响应
|
||||
* @param url 要录制的视频地址
|
||||
* @param time 录制时长 (单位: 秒)
|
||||
*/
|
||||
@SneakyThrows
|
||||
public void record(ServletResponse response, String url, long time) {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
log.info("url {}", url);
|
||||
log.info("准备录制 url {}, time: {}", url, time);
|
||||
// FFmpeg 调试日志
|
||||
// FFmpegLogCallback.set();
|
||||
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(url);
|
||||
@ -78,12 +95,12 @@ public class RecordService {
|
||||
recorder.setFormat("flv");
|
||||
recorder.setVideoOption("threads", String.valueOf(Runtime.getRuntime().availableProcessors())); // 解码线程数
|
||||
recorder.start(grabber.getFormatContext());
|
||||
log.info("开始录像");
|
||||
log.info("开始录制 {}", url);
|
||||
|
||||
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||
AtomicBoolean record = new AtomicBoolean(true);
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
log.info("到达结束时间, 结束录制");
|
||||
log.info("到达结束时间, 结束录制 {}", url);
|
||||
record.set(false);
|
||||
}, time, TimeUnit.SECONDS);
|
||||
try {
|
||||
@ -103,7 +120,7 @@ public class RecordService {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException ignore){}
|
||||
|
||||
log.info("结束录制");
|
||||
log.info("结束录制 {}", url);
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ spring:
|
||||
username: root
|
||||
password: 123456a
|
||||
url: jdbc:mysql://192.168.1.241:3306/gb28181_docking_platform?createDatabaseIfNotExist=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
|
||||
profiles:
|
||||
active: local
|
||||
# profiles:
|
||||
# active: local
|
||||
cloud:
|
||||
openfeign:
|
||||
httpclient:
|
||||
@ -44,6 +44,6 @@ media:
|
||||
|
||||
proxy:
|
||||
wvp:
|
||||
url: http://192.168.3.13:18978
|
||||
url: http://192.168.1.241:18978
|
||||
user: admin
|
||||
passwd: admin
|
||||
|
Loading…
Reference in New Issue
Block a user