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