From 08e40abe8c3d3eaa0131f777fa8e32a94c848b9c Mon Sep 17 00:00:00 2001 From: sinsanction <1602723930@qq.com> Date: Sat, 30 Dec 2023 14:32:13 +0800 Subject: [PATCH] fix FFmpegPipeQAAC's progress display --- .../Audio/FFmpegPipeQAACEncoder.cs | 30 +++++++++++++++++-- .../OKEGui/JobProcessor/Demuxer/EACDemuxer.cs | 1 + OKEGui/OKEGui/Model/Info/AudioInfo.cs | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/OKEGui/OKEGui/JobProcessor/Audio/FFmpegPipeQAACEncoder.cs b/OKEGui/OKEGui/JobProcessor/Audio/FFmpegPipeQAACEncoder.cs index 4120d401..1f286b08 100644 --- a/OKEGui/OKEGui/JobProcessor/Audio/FFmpegPipeQAACEncoder.cs +++ b/OKEGui/OKEGui/JobProcessor/Audio/FFmpegPipeQAACEncoder.cs @@ -13,12 +13,15 @@ internal class FFmpegPipeQAACEncoder : CommandlineJobProcessor private ManualResetEvent retrieved = new ManualResetEvent(false); private Action _progressCallback; private static readonly NLog.Logger Logger = NLog.LogManager.GetLogger("FFmpegPipeQAACEncoder"); + private readonly int audioLength; // TODO: 变更编码参数 public FFmpegPipeQAACEncoder(AudioJob j, Action progressCallback, int bitrate = Constants.QAACBitrate) : base() { _progressCallback = progressCallback; + this.audioLength = j.Info.Length; + executable = Path.Combine(Environment.SystemDirectory, "cmd.exe"); FileInfo ffmpegPath = new FileInfo(Constants.ffmpegPath); FileInfo QAACPath = new FileInfo(Constants.QAACPath); @@ -32,11 +35,31 @@ public FFmpegPipeQAACEncoder(AudioJob j, Action progressCallback, int bi public override void ProcessLine(string line, StreamType stream) { - Regex rAnalyze = new Regex("\\[([0-9.]+)%\\]"); + // hh:mm:ss.mss + Regex rAnalyze1 = new Regex(@"(\d*):(\d*):(\d*).(\d*) \("); + // mm:ss.mss + Regex rAnalyze2 = new Regex(@"(\d*):(\d*).(\d*) \("); double p = 0; - if (rAnalyze.IsMatch(line)) + if (rAnalyze1.IsMatch(line)) + { + string[] match = rAnalyze1.Split(line); + int hour = int.Parse(match[1]); + int minute = int.Parse(match[2]); + int second = int.Parse(match[3]); + p = (hour * 3600 + minute * 60 + second) * 1.0 / this.audioLength * 100; + Logger.Trace($"{hour * 3600 + minute * 60 + second}, {this.audioLength}, {p}\n"); + if (p > 1) + { + _progressCallback(p); + } + } + else if (rAnalyze2.IsMatch(line)) { - double.TryParse(rAnalyze.Split(line)[1], out p); + string[] match = rAnalyze2.Split(line); + int minute = int.Parse(match[1]); + int second = int.Parse(match[2]); + p = (minute * 60 + second) * 1.0 / this.audioLength * 100; + Logger.Trace($"{minute * 60 + second}, {this.audioLength}, {p}\n"); if (p > 1) { _progressCallback(p); @@ -47,6 +70,7 @@ public override void ProcessLine(string line, StreamType stream) Logger.Debug(line); if (line.Contains(".done")) { + _progressCallback(100); SetFinish(); } if (line.Contains("ERROR")) diff --git a/OKEGui/OKEGui/JobProcessor/Demuxer/EACDemuxer.cs b/OKEGui/OKEGui/JobProcessor/Demuxer/EACDemuxer.cs index b4aa5b82..c5d9c6cb 100644 --- a/OKEGui/OKEGui/JobProcessor/Demuxer/EACDemuxer.cs +++ b/OKEGui/OKEGui/JobProcessor/Demuxer/EACDemuxer.cs @@ -435,6 +435,7 @@ public MediaFile Extract(Action progressCallback) case TrackType.Audio: AudioInfo audioInfo = JobAudio[audioId++]; audioInfo.DupOrEmpty = item.DupOrEmpty; + audioInfo.Length = item.Length; mf.AddTrack(new AudioTrack(file, audioInfo)); break; case TrackType.Subtitle: diff --git a/OKEGui/OKEGui/Model/Info/AudioInfo.cs b/OKEGui/OKEGui/Model/Info/AudioInfo.cs index 4e556052..8dea0752 100644 --- a/OKEGui/OKEGui/Model/Info/AudioInfo.cs +++ b/OKEGui/OKEGui/Model/Info/AudioInfo.cs @@ -7,6 +7,7 @@ public class AudioInfo : Info public string OutputCodec; public int Bitrate = Constants.QAACBitrate; public bool Lossy = false; + public int Length; public AudioInfo() : base() {