Skip to content

Commit

Permalink
fix FFmpegPipeQAAC's progress display
Browse files Browse the repository at this point in the history
  • Loading branch information
sinsanction committed Jan 3, 2024
1 parent 3293008 commit 08e40ab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
30 changes: 27 additions & 3 deletions OKEGui/OKEGui/JobProcessor/Audio/FFmpegPipeQAACEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ internal class FFmpegPipeQAACEncoder : CommandlineJobProcessor
private ManualResetEvent retrieved = new ManualResetEvent(false);
private Action<double> _progressCallback;
private static readonly NLog.Logger Logger = NLog.LogManager.GetLogger("FFmpegPipeQAACEncoder");
private readonly int audioLength;

// TODO: 变更编码参数
public FFmpegPipeQAACEncoder(AudioJob j, Action<double> 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);
Expand All @@ -32,11 +35,31 @@ public FFmpegPipeQAACEncoder(AudioJob j, Action<double> 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);
Expand All @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions OKEGui/OKEGui/JobProcessor/Demuxer/EACDemuxer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ public MediaFile Extract(Action<double, EACProgressType> 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:
Expand Down
1 change: 1 addition & 0 deletions OKEGui/OKEGui/Model/Info/AudioInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 08e40ab

Please sign in to comment.