Skip to content

Commit

Permalink
multipass fix, ffmpeg
Browse files Browse the repository at this point in the history
wrong interpretation o
  • Loading branch information
Anime4000 committed Jan 17, 2022
1 parent 44fdf6d commit 33b7a4b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
17 changes: 14 additions & 3 deletions IFME/MediaEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using IFME.OSManager;

Expand Down Expand Up @@ -274,14 +275,15 @@ 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;

if (vc.Mode[item.Encoder.Mode].MultiPass)
{
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.");

Expand All @@ -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
Expand Down Expand Up @@ -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 ";
Expand Down
20 changes: 20 additions & 0 deletions IFME/ProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions IFME/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
6 changes: 4 additions & 2 deletions IFME/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 33b7a4b

Please sign in to comment.