优化ffmpeg使用场景

This commit is contained in:
nilaoda 2022-08-08 22:56:36 +08:00
parent 0f7340980c
commit 49fd93c34f
2 changed files with 14 additions and 6 deletions

View File

@ -333,32 +333,35 @@ namespace N_m3u8DL_RE.DownloadManager
output = Path.ChangeExtension(output, Path.GetExtension(path)); output = Path.ChangeExtension(output, Path.GetExtension(path));
} }
bool mergeSuccess = false;
//合并 //合并
if (!DownloaderConfig.SkipMerge) if (!DownloaderConfig.SkipMerge)
{ {
//对于fMP4自动开启二进制合并 //对于fMP4自动开启二进制合并
if (!DownloaderConfig.BinaryMerge && mp4InitFile != "") if (!DownloaderConfig.BinaryMerge && streamSpec.MediaType != MediaType.SUBTITLES && mp4InitFile != "")
{ {
DownloaderConfig.BinaryMerge = true; DownloaderConfig.BinaryMerge = true;
Logger.WarnMarkUp($"[white on darkorange3_1]{ResString.autoBinaryMerge}[/]"); Logger.WarnMarkUp($"[white on darkorange3_1]{ResString.autoBinaryMerge}[/]");
} }
if (DownloaderConfig.BinaryMerge) //字幕也使用二进制合并
if (DownloaderConfig.BinaryMerge || streamSpec.MediaType == MediaType.SUBTITLES)
{ {
Logger.InfoMarkUp(ResString.binaryMerge); Logger.InfoMarkUp(ResString.binaryMerge);
var files = FileDic.Values.Select(v => v!.ActualFilePath).OrderBy(s => s).ToArray(); var files = FileDic.Values.Select(v => v!.ActualFilePath).OrderBy(s => s).ToArray();
MergeUtil.CombineMultipleFilesIntoSingleFile(files, output); MergeUtil.CombineMultipleFilesIntoSingleFile(files, output);
mergeSuccess = true;
} }
else else
{ {
var files = FileDic.Values.Select(v => v!.ActualFilePath).OrderBy(s => s).ToArray(); var files = FileDic.Values.Select(v => v!.ActualFilePath).OrderBy(s => s).ToArray();
Logger.InfoMarkUp(ResString.ffmpegMerge); 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); var files = FileDic.Values.Select(v => v!.ActualFilePath);
foreach (var file in files) foreach (var file in files)
@ -372,7 +375,7 @@ namespace N_m3u8DL_RE.DownloadManager
} }
//调用mp4decrypt解密 //调用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) if (totalCount >= 1 && streamSpec.Playlist!.MediaParts.First().MediaSegments.First().EncryptInfo.Method != Common.Enum.EncryptMethod.NONE)
{ {

View File

@ -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 fastStart = false,
bool writeDate = true, string poster = "", string audioName = "", string title = "", bool writeDate = true, string poster = "", string audioName = "", string title = "",
string copyright = "", string comment = "", string encodingTool = "", string recTime = "") string copyright = "", string comment = "", string encodingTool = "", string recTime = "")
@ -111,6 +111,11 @@ namespace N_m3u8DL_RE.Util
RedirectStandardError = true, RedirectStandardError = true,
UseShellExecute = false UseShellExecute = false
})!.WaitForExit(); })!.WaitForExit();
if (File.Exists(outputPath) && new FileInfo(outputPath).Length > 0)
return true;
return false;
} }
} }
} }