From 33b7a4bc4e33ce266fc1263c960e0209175548c3 Mon Sep 17 00:00:00 2001 From: Anime4000 Date: Tue, 18 Jan 2022 07:11:23 +0800 Subject: [PATCH] multipass fix, ffmpeg wrong interpretation o --- IFME/MediaEncoding.cs | 17 ++++++++++++++--- IFME/ProcessManager.cs | 20 ++++++++++++++++++++ IFME/Properties/AssemblyInfo.cs | 4 ++-- IFME/frmMain.cs | 6 ++++-- changelog.txt | 7 ++++++- 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/IFME/MediaEncoding.cs b/IFME/MediaEncoding.cs index 7080f31..e38e978 100644 --- a/IFME/MediaEncoding.cs +++ b/IFME/MediaEncoding.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using IFME.OSManager; @@ -274,7 +275,7 @@ internal static void Video(MediaQueue queue, string tempDir) var cmd_ff = $"-map 0:{item.Id} {ff_trim} {ff_yuv} -vf {string.Join(",", ff_vf)}"; - var cmd_en = $"{en_framecount} {en_res} {en_fps} {en_bit} {en_csp}"; + var cmd_en = $"{en_res} {en_fps} {en_bit} {en_csp}"; var cmd_ff_en = ff ? cmd_ff : cmd_en; @@ -282,6 +283,7 @@ internal static void Video(MediaQueue queue, string tempDir) { var p = 1; var pass = string.Empty; + var realframecount = 0; frmMain.PrintLog("[WARN] Frame count is disable for Multi-pass encoding, Avoid inconsistent across multi-pass."); @@ -298,20 +300,27 @@ internal static void Video(MediaQueue queue, string tempDir) frmMain.PrintLog($"[INFO] Multi-pass encoding: {p} of {item.Encoder.MultiPass}"); if (vc.Args.Pipe) - ProcessManager.Start(tempDir, $"\"{FFmpeg}\" -hide_banner -v error {ff_infps} -i \"{item.File}\" {cmd_ff} {ff_rawcodec} {item.Quality.Command} - | \"{en}\" {vc.Args.Y4M} {vc.Args.Input} {cmd_en} {en_preset} {en_tune} {en_mode} {vc.Args.Command} {item.Encoder.Command} {pass} {vc.Args.Output} {outencfile}"); + realframecount = ProcessManager.Start(tempDir, $"\"{FFmpeg}\" -hide_banner -v error {ff_infps} -i \"{item.File}\" {cmd_ff} {ff_rawcodec} {item.Quality.Command} - | \"{en}\" {vc.Args.Y4M} {vc.Args.Input} {en_framecount} {cmd_en} {en_preset} {en_tune} {en_mode} {vc.Args.Command} {item.Encoder.Command} {pass} {vc.Args.Output} {outencfile}"); else ProcessManager.Start(tempDir, $"\"{en}\" {ff_infps} {vc.Args.Input} \"{(string.IsNullOrEmpty(vc.Args.Y4M) ? item.File : vc.Args.Y4M)}\" {cmd_ff_en} {en_mode} {vc.Args.UnPipe} {item.Encoder.Command} {vc.Args.Command} {pass} {vc.Args.Output} {outencfile}"); + if (p == 1) + en_framecount = $"{vc.Args.FrameCount} {realframecount}"; + ++p; + Thread.Sleep(1500); + } while (p <= item.Encoder.MultiPass); } else { if (vc.Args.Pipe) - ProcessManager.Start(tempDir, $"\"{FFmpeg}\" -hide_banner -v error {ff_infps} -i \"{item.File}\" {cmd_ff} {ff_rawcodec} {item.Quality.Command} - | \"{en}\" {vc.Args.Y4M} {vc.Args.Input} {cmd_en} {en_preset} {en_tune} {en_mode} {vc.Args.Command} {item.Encoder.Command} {vc.Args.Output} {outencfile}"); + ProcessManager.Start(tempDir, $"\"{FFmpeg}\" -hide_banner -v error {ff_infps} -i \"{item.File}\" {cmd_ff} {ff_rawcodec} {item.Quality.Command} - | \"{en}\" {vc.Args.Y4M} {vc.Args.Input} {en_framecount} {cmd_en} {en_preset} {en_tune} {en_mode} {vc.Args.Command} {item.Encoder.Command} {vc.Args.Output} {outencfile}"); else ProcessManager.Start(tempDir, $"\"{en}\" {ff_infps} {vc.Args.Input} \"{(string.IsNullOrEmpty(vc.Args.Y4M) ? item.File : vc.Args.Y4M)}\" {cmd_ff_en} {en_mode} {vc.Args.UnPipe} {item.Encoder.Command} {vc.Args.Command} {vc.Args.Output} {outencfile}"); + + Thread.Sleep(1500); } // Raw file dont have pts (time), need to remux @@ -354,6 +363,8 @@ internal static int Muxing(MediaQueue queue, string tempDir, string saveDir, str frmMain.PrintStatus("Repacking..."); frmMain.PrintLog($"[INFO] Multiplexing encoded files into single file..."); + Thread.Sleep(1500); // Wait NTFS finish updating the content + if (File.Exists(Path.Combine(tempDir, "metadata.ini"))) { metafile = "-f ffmetadata -i metadata.ini "; diff --git a/IFME/ProcessManager.cs b/IFME/ProcessManager.cs index 2639f84..b0903ba 100644 --- a/IFME/ProcessManager.cs +++ b/IFME/ProcessManager.cs @@ -12,6 +12,8 @@ internal class ProcessManager internal static bool IsPause = false; + internal static int TotalFrames = 0; + internal static int Start(string Command) { return new ProcessManager().Run(Command, string.Empty); @@ -63,6 +65,11 @@ private int Run(string Command, string WorkingDirectory) proc.WaitForExit(); ProcessId.Remove(proc.Id); + + if (TotalFrames > 0) + { + return TotalFrames; //x265 + } return proc.ExitCode; } @@ -74,6 +81,19 @@ private void Proc_DataReceived(object sender, DataReceivedEventArgs e) if (!string.IsNullOrEmpty(e.Data)) { + var tf = @"(?<=encoded\s) ?\d+(?=> frames in \d+.\d+)?"; //x265 encoded total frame + var tfm = Regex.Matches(e.Data, tf, RegexOptions.IgnoreCase); + if (tfm.Count > 0) + { + if (tfm.Count > 0) + { + if (!int.TryParse(tfm[0].Value, out TotalFrames)) + TotalFrames = 0; + } + + return; + } + var p = @"(frame[ ]{1,}\d+)|(\d+.\d+[ ]{1,}kbps)|(\d+.\d+[ ]{1,}fps)"; var x = Regex.Matches(e.Data, p, RegexOptions.IgnoreCase); if (x.Count >= 3) diff --git a/IFME/Properties/AssemblyInfo.cs b/IFME/Properties/AssemblyInfo.cs index f250ed0..cabcf0f 100644 --- a/IFME/Properties/AssemblyInfo.cs +++ b/IFME/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("22.01.02")] -[assembly: AssemblyFileVersion("22.01.02")] +[assembly: AssemblyVersion("22.01.18")] +[assembly: AssemblyFileVersion("22.01.18")] diff --git a/IFME/frmMain.cs b/IFME/frmMain.cs index 6be0c7d..4b3802c 100644 --- a/IFME/frmMain.cs +++ b/IFME/frmMain.cs @@ -2117,15 +2117,17 @@ private void bgThread_DoWork(object sender, DoWorkEventArgs e) // Mux var errCodeMux = MediaEncoding.Muxing(mq, tempSes, txtOutputPath.Text, saveFileName); - // Check Muxing is failed or sucess - if (errCodeMux > 0) + // Check FFmpeg Muxing is failed (negative) or sucess/warning (positive) + if (errCodeMux < 0) { Extensions.DirectoryCopy(tempSes, Path.Combine(txtOutputPath.Text, "[Muxing Failed]", $"{saveFileName}"), true); PrintLog("[ERR ] FFmpeg failed to merge raw files... Check [Muxing Failed] folder to manual muxing..."); + PrintLog($"[ERR ] FFmpeg return code {errCodeMux}"); } else { PrintLog("[ OK ] Multiplexing files was successfully!"); + PrintLog($"[DEBG] FFmpeg return code {errCodeMux}"); } // Delete Temporary Session Folder diff --git a/changelog.txt b/changelog.txt index 172cc49..ae9ef22 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ -Version 22.01.02 Alpha (True Eternity) +Version 22.01.18 Alpha (True Eternity) +-------------------------------------- +[fixed] Wrong interpretation of FFmpeg return code, negative means error/something bad, positive means ok/warning. +[fixed] Multipass for x265 (dirty fix) + +Version 22.01.02 Alpha (True Eternity) -------------------------------------- [fixed] Hard Sub with MKV cause wrong data because previous subtitle and fonts copied over [fixed] Extra space when Pre/Post fix in file name