优化ffmpeg合并时日志打印及滤镜选择
This commit is contained in:
parent
04eaa64d4e
commit
d9cc09dff8
|
@ -8,6 +8,7 @@ using N_m3u8DL_RE.Downloader;
|
|||
using N_m3u8DL_RE.Entity;
|
||||
using N_m3u8DL_RE.Util;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
|
||||
|
@ -58,7 +59,7 @@ namespace N_m3u8DL_RE.DownloadManager
|
|||
}
|
||||
}
|
||||
|
||||
private void ChangeSpecInfo(StreamSpec streamSpec, List<Mediainfo> mediainfos)
|
||||
private void ChangeSpecInfo(StreamSpec streamSpec, List<Mediainfo> mediainfos, ref bool useAACFilter)
|
||||
{
|
||||
if (!DownloaderConfig.BinaryMerge && mediainfos.Any(m => m.DolbyVison == true))
|
||||
{
|
||||
|
@ -66,6 +67,11 @@ namespace N_m3u8DL_RE.DownloadManager
|
|||
Logger.WarnMarkUp($"[darkorange3_1]{ResString.autoBinaryMerge2}[/]");
|
||||
}
|
||||
|
||||
if (mediainfos.Where(m => m.Type == "Audio").All(m => m.BaseInfo.Contains("aac")))
|
||||
{
|
||||
useAACFilter = true;
|
||||
}
|
||||
|
||||
if (mediainfos.All(m => m.Type == "Audio"))
|
||||
{
|
||||
streamSpec.MediaType = MediaType.AUDIO;
|
||||
|
@ -80,6 +86,7 @@ namespace N_m3u8DL_RE.DownloadManager
|
|||
|
||||
private async Task<bool> DownloadStreamAsync(StreamSpec streamSpec, ProgressTask task)
|
||||
{
|
||||
bool useAACFilter = false; //ffmpeg合并flag
|
||||
ConcurrentDictionary<MediaSegment, DownloadResult?> FileDic = new();
|
||||
|
||||
var segments = streamSpec.Playlist?.MediaParts.SelectMany(m => m.MediaSegments);
|
||||
|
@ -169,7 +176,7 @@ namespace N_m3u8DL_RE.DownloadManager
|
|||
Logger.WarnMarkUp(ResString.readingInfo);
|
||||
var mediainfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.FFmpegBinaryPath!, result.ActualFilePath);
|
||||
mediainfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp()));
|
||||
ChangeSpecInfo(streamSpec, mediainfos);
|
||||
ChangeSpecInfo(streamSpec, mediainfos, ref useAACFilter);
|
||||
readInfo = true;
|
||||
}
|
||||
}
|
||||
|
@ -212,7 +219,7 @@ namespace N_m3u8DL_RE.DownloadManager
|
|||
Logger.WarnMarkUp(ResString.readingInfo);
|
||||
var mediainfos = await MediainfoUtil.ReadInfoAsync(DownloaderConfig.FFmpegBinaryPath!, result!.ActualFilePath);
|
||||
mediainfos.ForEach(info => Logger.InfoMarkUp(info.ToStringMarkUp()));
|
||||
ChangeSpecInfo(streamSpec, mediainfos);
|
||||
ChangeSpecInfo(streamSpec, mediainfos, ref useAACFilter);
|
||||
readInfo = true;
|
||||
}
|
||||
|
||||
|
@ -459,7 +466,7 @@ namespace N_m3u8DL_RE.DownloadManager
|
|||
var files = FileDic.Values.Select(v => v!.ActualFilePath).OrderBy(s => s).ToArray();
|
||||
Logger.InfoMarkUp(ResString.ffmpegMerge);
|
||||
var ext = streamSpec.MediaType == MediaType.AUDIO ? "m4a" : "mp4";
|
||||
mergeSuccess = MergeUtil.MergeByFFmpeg(DownloaderConfig.FFmpegBinaryPath!, files, Path.ChangeExtension(output, null), ext);
|
||||
mergeSuccess = MergeUtil.MergeByFFmpeg(DownloaderConfig.FFmpegBinaryPath!, files, Path.ChangeExtension(output, null), ext, useAACFilter);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using N_m3u8DL_RE.Common.Log;
|
||||
using Spectre.Console;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
@ -44,7 +46,7 @@ namespace N_m3u8DL_RE.Util
|
|||
}
|
||||
}
|
||||
|
||||
public static bool MergeByFFmpeg(string binary, string[] files, string outputPath, string muxFormat,
|
||||
public static bool MergeByFFmpeg(string binary, string[] files, string outputPath, string muxFormat, bool useAACFilter,
|
||||
bool fastStart = false,
|
||||
bool writeDate = true, string poster = "", string audioName = "", string title = "",
|
||||
string copyright = "", string comment = "", string encodingTool = "", string recTime = "")
|
||||
|
@ -58,7 +60,6 @@ namespace N_m3u8DL_RE.Util
|
|||
Path.GetFileName(outputPath) + "_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
|
||||
}
|
||||
|
||||
bool useAACFilter = true;
|
||||
StringBuilder command = new StringBuilder("-loglevel warning -i concat:\"");
|
||||
string ddpAudio = string.Empty;
|
||||
string addPoster = "-map 1 -c:v:1 copy -disposition:v:1 attached_pic";
|
||||
|
@ -109,7 +110,10 @@ namespace N_m3u8DL_RE.Util
|
|||
break;
|
||||
}
|
||||
|
||||
Process.Start(new ProcessStartInfo()
|
||||
Logger.DebugMarkUp($"{binary}: {command}");
|
||||
|
||||
using var p = new Process();
|
||||
p.StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
WorkingDirectory = Path.GetDirectoryName(files[0]),
|
||||
FileName = binary,
|
||||
|
@ -117,7 +121,17 @@ namespace N_m3u8DL_RE.Util
|
|||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false
|
||||
})!.WaitForExit();
|
||||
};
|
||||
p.ErrorDataReceived += (sendProcess, output) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(output.Data))
|
||||
{
|
||||
Logger.WarnMarkUp($"[grey]{output.Data.EscapeMarkup()}[/]");
|
||||
}
|
||||
};
|
||||
p.Start();
|
||||
p.BeginErrorReadLine();
|
||||
p.WaitForExit();
|
||||
|
||||
if (File.Exists($"{outputPath}.{muxFormat}") && new FileInfo($"{outputPath}.{muxFormat}").Length > 0)
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue