优化ffmpeg混流

This commit is contained in:
nilaoda 2022-08-27 13:07:07 +08:00
parent ed4f1b196e
commit dab86d0c7b
4 changed files with 30 additions and 11 deletions

View File

@ -115,6 +115,7 @@ namespace N_m3u8DL_RE.DownloadManager
{ {
speedContainer.ResetVars(); speedContainer.ResetVars();
bool useAACFilter = false; //ffmpeg合并flag bool useAACFilter = false; //ffmpeg合并flag
List<Mediainfo> mediaInfos = new();
ConcurrentDictionary<MediaSegment, DownloadResult?> FileDic = new(); ConcurrentDictionary<MediaSegment, DownloadResult?> FileDic = new();
var segments = streamSpec.Playlist?.MediaParts.SelectMany(m => m.MediaSegments); var segments = streamSpec.Playlist?.MediaParts.SelectMany(m => m.MediaSegments);
@ -203,9 +204,9 @@ namespace N_m3u8DL_RE.DownloadManager
if (!readInfo) if (!readInfo)
{ {
Logger.WarnMarkUp(ResString.readingInfo); Logger.WarnMarkUp(ResString.readingInfo);
var mediainfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.MyOptions.FFmpegBinaryPath!, result.ActualFilePath); mediaInfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.MyOptions.FFmpegBinaryPath!, result.ActualFilePath);
mediainfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp())); mediaInfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp()));
ChangeSpecInfo(streamSpec, mediainfos, ref useAACFilter); ChangeSpecInfo(streamSpec, mediaInfos, ref useAACFilter);
readInfo = true; readInfo = true;
} }
} }
@ -246,9 +247,9 @@ namespace N_m3u8DL_RE.DownloadManager
} }
//ffmpeg读取信息 //ffmpeg读取信息
Logger.WarnMarkUp(ResString.readingInfo); Logger.WarnMarkUp(ResString.readingInfo);
var mediainfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.MyOptions.FFmpegBinaryPath!, result!.ActualFilePath); mediaInfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.MyOptions.FFmpegBinaryPath!, result!.ActualFilePath);
mediainfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp())); mediaInfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp()));
ChangeSpecInfo(streamSpec, mediainfos, ref useAACFilter); ChangeSpecInfo(streamSpec, mediaInfos, ref useAACFilter);
readInfo = true; readInfo = true;
} }
@ -543,7 +544,14 @@ namespace N_m3u8DL_RE.DownloadManager
//记录所有文件信息 //记录所有文件信息
if (File.Exists(output)) if (File.Exists(output))
OutputFiles.Add(new OutputFile() { Index = task.Id, FilePath = output, LangCode = streamSpec.Language, Description = streamSpec.Name }); OutputFiles.Add(new OutputFile()
{
Index = task.Id,
FilePath = output,
LangCode = streamSpec.Language,
Description = streamSpec.Name,
Mediainfos = mediaInfos
});
return true; return true;
} }

View File

@ -76,7 +76,7 @@ namespace N_m3u8DL_RE.Downloader
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.WarnMarkUp($"{ex.Message} retryCount: {retryCount}"); Logger.WarnMarkUp($"[grey]{ex.Message.EscapeMarkup()} retryCount: {retryCount}[/]");
Logger.Debug(ex.ToString()); Logger.Debug(ex.ToString());
if (retryCount-- > 0) if (retryCount-- > 0)
{ {

View File

@ -12,5 +12,6 @@ namespace N_m3u8DL_RE.Entity
public required string FilePath { get; set; } public required string FilePath { get; set; }
public string? LangCode { get; set; } public string? LangCode { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public List<Mediainfo> Mediainfos { get; set; } = new();
} }
} }

View File

@ -158,7 +158,7 @@ namespace N_m3u8DL_RE.Util
//MAP //MAP
for (int i = 0; i < files.Length; i++) for (int i = 0; i < files.Length; i++)
{ {
command.Append($" -map {i}:0 "); command.Append($" -map {i} ");
} }
if (mp4) if (mp4)
@ -170,15 +170,25 @@ namespace N_m3u8DL_RE.Util
command.Append(" -map_metadata -1 "); command.Append(" -map_metadata -1 ");
//LANG and NAME //LANG and NAME
var streamIndex = 0;
for (int i = 0; i < files.Length; i++) for (int i = 0; i < files.Length; i++)
{ {
//转换语言代码 //转换语言代码
ConvertLangCodeAndDisplayName(files[i]); ConvertLangCodeAndDisplayName(files[i]);
command.Append($" -metadata:s:{i} language=\"{files[i].LangCode ?? "und"}\" "); command.Append($" -metadata:s:{streamIndex} language=\"{files[i].LangCode ?? "und"}\" ");
if (!string.IsNullOrEmpty(files[i].Description)) if (!string.IsNullOrEmpty(files[i].Description))
{ {
command.Append($" -metadata:s:{i} title=\"{files[i].Description}\" "); command.Append($" -metadata:s:{streamIndex} title=\"{files[i].Description}\" ");
} }
/**
* -metadata:s:xx标记的是 xx个流的metadata
* 使files的index
* metadata错位的情况
*/
if (files[i].Mediainfos.Count > 0)
streamIndex += files[i].Mediainfos.Count;
else
streamIndex++;
} }
command.Append($" -metadata date=\"{dateString}\" -ignore_unknown -copy_unknown "); command.Append($" -metadata date=\"{dateString}\" -ignore_unknown -copy_unknown ");