/device/video.mp4 contentType 改为 application/octet-stream

This commit is contained in:
shikong 2023-10-10 10:05:30 +08:00
parent 0bf1eb6615
commit 5a35e37687
2 changed files with 34 additions and 1 deletions

View File

@ -72,6 +72,6 @@ public class VideoController {
Date endTime = DateUtil.offsetMillisecond(reqEndTime, (int) back);
log.info("请求的时间范围 {} ~ {}", reqStartTime, reqEndTime);
log.info("偏移后的时间范围 {} ~ {}", startTime, endTime);
gb28181DownloadService.video(request,response,req.getDeviceCode(), startTime, endTime, req.getFileHeader());
gb28181DownloadService.videoStream(request,response,req.getDeviceCode(), startTime, endTime);
}
}

View File

@ -93,6 +93,12 @@ public class Gb28181DownloadService {
response.setHeader("Connection", "close");
}
public void streamHeader(HttpServletResponse response) {
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.setHeader("Accept-Ranges", "none");
response.setHeader("Connection", "close");
}
public void header(HttpServletResponse response, String fileName) {
header(response);
response.setHeader("Content-Disposition",
@ -158,6 +164,33 @@ public class Gb28181DownloadService {
});
}
@SneakyThrows
public void videoStream(HttpServletRequest request, HttpServletResponse response, String deviceCode, Date startTime, Date endTime) {
AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(0);
asyncContext.start(()->{
HttpServletResponse asyncResponse = (HttpServletResponse)asyncContext.getResponse();
try{
download(deviceCode, startTime,endTime).whenComplete((videoInfo, e)->{
streamHeader(asyncResponse);
if(e != null){
writeErrorToResponse(asyncResponse, JsonResponse.error(e.getMessage()));
} else if(videoInfo == null){
writeErrorToResponse(asyncResponse, JsonResponse.error("下载失败"));
} else if(wvpProxyConfig.getUseFfmpeg()){
videoService.ffmpegRecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 60,videoInfo.getDevice(),videoInfo.getCallId());
} else {
videoService.javaCVrecord(asyncResponse, videoInfo.getUrl(), DateUtil.between(startTime,endTime,DateUnit.SECOND) + 60);
}
asyncContext.complete();
});
} catch(Exception e) {
writeErrorToResponse(asyncResponse, JsonResponse.error(e.getMessage()));
asyncContext.complete();
}
});
}
private void writeFileHeader(HttpServletResponse response, String deviceCode, Date startTime, Date endTime, Boolean fileHeader){
if(fileHeader){
header(response, StringUtils.joinWith("_",