From b5c2153ad0f631199cd5b2026a4dcea235fc79e8 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Tue, 26 Nov 2024 18:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E6=88=90=E5=88=87=E7=89=87=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/VideoFileController.java | 2 +- .../services/LiveVideoDownloadService.java | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java b/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java index d563b2e..a6d863e 100644 --- a/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java +++ b/src/main/java/com/yutou/bilibili/Controllers/VideoFileController.java @@ -109,6 +109,6 @@ public class VideoFileController { @RequestMapping("/video/play") @ResponseBody public JSONObject getVideoUrl(String roomId, String videoId) { - return ResultData.success("/play/"+videoService.getVideoPlay(roomId, videoId)); + return ResultData.success("/live/"+videoService.getVideoPlay(roomId, videoId)); } } diff --git a/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java b/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java index c2feccc..f963f10 100644 --- a/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java +++ b/src/main/java/com/yutou/bilibili/services/LiveVideoDownloadService.java @@ -134,10 +134,10 @@ public class LiveVideoDownloadService { public void run() { if (roomInfo.getLiveStatus() == 1) { 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()); - savePath = rootPath.getAbsolutePath() + File.separator + "[" + + rootPath = new File(bean.getRecordPath() + File.separator + bean.getAnchorName() + File.separator + time + File.separator + "[" + 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()) { rootPath.mkdirs(); } @@ -220,7 +220,7 @@ public class LiveVideoDownloadService { String url = urlInfo.getHost() + codec.getBaseUrl() + urlInfo.getExtra(); - Log.i("下载直播",rawResponse,codec.toString(),urlInfo.toString(),"URL:"+url); + Log.i("下载直播", rawResponse, codec.toString(), urlInfo.toString(), "URL:" + url); if (bean.getRecordLiveModel() == 1) { javaRecord(url, response); @@ -286,7 +286,11 @@ public class LiveVideoDownloadService { // .withNotSymbolParam("-progress", "-") // .withNotSymbolParam("-fflags", "+genpts") .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("-bsf:a", "aac_adtstoasc") // .withNotSymbolParam("-loglevel", "debug") @@ -423,9 +427,11 @@ public class LiveVideoDownloadService { } liveDatabase.close(); 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()) { 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)); System.out.println(ffmpeg.getCommandDecode());