From 49fd93c34ff8dd1ac28a4c90bcbd4ee866709f41 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Mon, 8 Aug 2022 22:56:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ffmpeg=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DownloadManager/SimpleDownloadManager.cs | 13 ++++++++----- src/N_m3u8DL-RE/Util/MergeUtil.cs | 7 ++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs index 01284dd..80d6226 100644 --- a/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs +++ b/src/N_m3u8DL-RE/DownloadManager/SimpleDownloadManager.cs @@ -333,32 +333,35 @@ namespace N_m3u8DL_RE.DownloadManager output = Path.ChangeExtension(output, Path.GetExtension(path)); } + bool mergeSuccess = false; //合并 if (!DownloaderConfig.SkipMerge) { //对于fMP4,自动开启二进制合并 - if (!DownloaderConfig.BinaryMerge && mp4InitFile != "") + if (!DownloaderConfig.BinaryMerge && streamSpec.MediaType != MediaType.SUBTITLES && mp4InitFile != "") { DownloaderConfig.BinaryMerge = true; Logger.WarnMarkUp($"[white on darkorange3_1]{ResString.autoBinaryMerge}[/]"); } - if (DownloaderConfig.BinaryMerge) + //字幕也使用二进制合并 + if (DownloaderConfig.BinaryMerge || streamSpec.MediaType == MediaType.SUBTITLES) { Logger.InfoMarkUp(ResString.binaryMerge); var files = FileDic.Values.Select(v => v!.ActualFilePath).OrderBy(s => s).ToArray(); MergeUtil.CombineMultipleFilesIntoSingleFile(files, output); + mergeSuccess = true; } else { var files = FileDic.Values.Select(v => v!.ActualFilePath).OrderBy(s => s).ToArray(); Logger.InfoMarkUp(ResString.ffmpegMerge); - MergeUtil.MergeByFFmpeg(DownloaderConfig.FFmpegBinaryPath!, files, Path.ChangeExtension(output, null), "mp4"); + mergeSuccess = MergeUtil.MergeByFFmpeg(DownloaderConfig.FFmpegBinaryPath!, files, Path.ChangeExtension(output, null), "mp4"); } } //删除临时文件夹 - if (!DownloaderConfig.SkipMerge && DownloaderConfig.DelAfterDone) + if (!DownloaderConfig.SkipMerge && DownloaderConfig.DelAfterDone && mergeSuccess) { var files = FileDic.Values.Select(v => v!.ActualFilePath); foreach (var file in files) @@ -372,7 +375,7 @@ namespace N_m3u8DL_RE.DownloadManager } //调用mp4decrypt解密 - if (File.Exists(output) && !DownloaderConfig.MP4RealTimeDecryption && DownloaderConfig.Keys != null && DownloaderConfig.Keys.Length > 0) + if (mergeSuccess && File.Exists(output) && !DownloaderConfig.MP4RealTimeDecryption && DownloaderConfig.Keys != null && DownloaderConfig.Keys.Length > 0) { if (totalCount >= 1 && streamSpec.Playlist!.MediaParts.First().MediaSegments.First().EncryptInfo.Method != Common.Enum.EncryptMethod.NONE) { diff --git a/src/N_m3u8DL-RE/Util/MergeUtil.cs b/src/N_m3u8DL-RE/Util/MergeUtil.cs index 4a6e7a2..779793d 100644 --- a/src/N_m3u8DL-RE/Util/MergeUtil.cs +++ b/src/N_m3u8DL-RE/Util/MergeUtil.cs @@ -44,7 +44,7 @@ namespace N_m3u8DL_RE.Util } } - public static void MergeByFFmpeg(string binary, string[] files, string outputPath, string muxFormat, + public static bool MergeByFFmpeg(string binary, string[] files, string outputPath, string muxFormat, bool fastStart = false, bool writeDate = true, string poster = "", string audioName = "", string title = "", string copyright = "", string comment = "", string encodingTool = "", string recTime = "") @@ -111,6 +111,11 @@ namespace N_m3u8DL_RE.Util RedirectStandardError = true, UseShellExecute = false })!.WaitForExit(); + + if (File.Exists(outputPath) && new FileInfo(outputPath).Length > 0) + return true; + + return false; } } }