改成切片保存

This commit is contained in:
zlzw 2024-11-26 18:28:38 +08:00
parent d9919f4d26
commit b5c2153ad0
2 changed files with 13 additions and 7 deletions

View File

@ -109,6 +109,6 @@ public class VideoFileController {
@RequestMapping("/video/play") @RequestMapping("/video/play")
@ResponseBody @ResponseBody
public JSONObject getVideoUrl(String roomId, String videoId) { public JSONObject getVideoUrl(String roomId, String videoId) {
return ResultData.success("/play/"+videoService.getVideoPlay(roomId, videoId)); return ResultData.success("/live/"+videoService.getVideoPlay(roomId, videoId));
} }
} }

View File

@ -134,10 +134,10 @@ public class LiveVideoDownloadService {
public void run() { public void run() {
if (roomInfo.getLiveStatus() == 1) { if (roomInfo.getLiveStatus() == 1) {
String time = DateUtils.format(new Date().getTime(), DATE_FORMAT_10_DASH); String time = DateUtils.format(new Date().getTime(), DATE_FORMAT_10_DASH);
rootPath = new File(bean.getRecordPath() + File.separator + bean.getAnchorName() + File.separator + time + File.separator + roomInfo.getTitle()); rootPath = new File(bean.getRecordPath() + File.separator + bean.getAnchorName() + File.separator + time + File.separator + "[" +
savePath = rootPath.getAbsolutePath() + File.separator + "[" +
DateUtils.format(new Date(), DateUtils.format(new Date(),
"yyyy-MM-dd HH-mm-ss") + "]" + roomInfo.getTitle() + ".flv"; "yyyy-MM-dd HH-mm-ss") + "]" + roomInfo.getTitle());
savePath = rootPath.getAbsolutePath() + File.separator + roomInfo.getTitle() + "-%04d.ts";
if (!rootPath.exists()) { if (!rootPath.exists()) {
rootPath.mkdirs(); rootPath.mkdirs();
} }
@ -286,7 +286,11 @@ public class LiveVideoDownloadService {
// .withNotSymbolParam("-progress", "-") // .withNotSymbolParam("-progress", "-")
// .withNotSymbolParam("-fflags", "+genpts") // .withNotSymbolParam("-fflags", "+genpts")
.withNotSymbolParam("-threads", "8") .withNotSymbolParam("-threads", "8")
.withNotSymbolParam("-bufsize", "10M") // .withNotSymbolParam("-bufsize", "10M")
.withNotSymbolParam("-f", "segment")
.withNotSymbolParam("-segment_time", "60")
.withNotSymbolParam("-segment_format", "flv")
.withParam("-segment_list", rootPath + File.separator + roomInfo.getTitle() + ".m3u8")
.withNotSymbolParam("-c", "copy") .withNotSymbolParam("-c", "copy")
.withNotSymbolParam("-bsf:a", "aac_adtstoasc") .withNotSymbolParam("-bsf:a", "aac_adtstoasc")
// .withNotSymbolParam("-loglevel", "debug") // .withNotSymbolParam("-loglevel", "debug")
@ -423,9 +427,11 @@ public class LiveVideoDownloadService {
} }
liveDatabase.close(); liveDatabase.close();
if (videoInfo != null) { if (videoInfo != null) {
File videoFile = new File(videoInfo.getPath().replace(".flv", ".mp4")); File videoFile = new File(videoInfo.getPath().replace("-%04d.ts", ".m3u8"));
if (!videoFile.exists()) { if (!videoFile.exists()) {
videoFile = new File(videoInfo.getPath()); videoFile = new File(videoInfo.getPath());
}else{
return videoInfo.getPath().replace(new File("live").getAbsolutePath(),"").replace(File.separator,"/").replace("-%04d.ts", ".m3u8");
} }
FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, videoFile, ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class)); FFmpegUtils ffmpeg = FFmpegUtils.segment(videoId, ffmpegPath, videoFile, ConfigTools.load(ConfigTools.CONFIG, "outVideoPath", String.class));
System.out.println(ffmpeg.getCommandDecode()); System.out.println(ffmpeg.getCommandDecode());