Skip to content

Commit

Permalink
various fix Anime4000#218
Browse files Browse the repository at this point in the history
  • Loading branch information
Anime4000 committed Jun 16, 2021
1 parent cd37093 commit afe05ba
Show file tree
Hide file tree
Showing 21 changed files with 1,697 additions and 272 deletions.
25 changes: 23 additions & 2 deletions IFME/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,34 @@
</System.Windows.Forms.ApplicationConfigurationSection>
<userSettings>
<IFME.Properties.Settings>
<setting name="OutputFolder" serializeAs="String">
<setting name="UpgradeRequired" serializeAs="String">
<value>True</value>
</setting>
<setting name="PrefixText" serializeAs="String">
<value>[IFME]</value>
</setting>
<setting name="PostfixText" serializeAs="String">
<value />
</setting>
<setting name="FolderOutput" serializeAs="String">
<value />
</setting>
<setting name="Username" serializeAs="String">
<value />
</setting>
<setting name="UpgradeRequired" serializeAs="String">
<setting name="PrefixMode" serializeAs="String">
<value>2</value>
</setting>
<setting name="PostfixMode" serializeAs="String">
<value>0</value>
</setting>
<setting name="FolderTemporary" serializeAs="String">
<value />
</setting>
<setting name="PluginsDisabled" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000,aaaaaaaa-0000-0000-0000-000000000000,ffffffff-ffff-ffff-ffff-ffffffffffff</value>
</setting>
<setting name="TestEncoder" serializeAs="String">
<value>True</value>
</setting>
</IFME.Properties.Settings>
Expand Down
9 changes: 9 additions & 0 deletions IFME/IFME.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
<DependentUpon>frmMain.cs</DependentUpon>
</Compile>
<Compile Include="frmMain.Status.cs" />
<Compile Include="frmOptions.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmOptions.Designer.cs">
<DependentUpon>frmOptions.cs</DependentUpon>
</Compile>
<Compile Include="frmSplashScreen.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -116,6 +122,9 @@
<EmbeddedResource Include="frmMain.resx">
<DependentUpon>frmMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmOptions.resx">
<DependentUpon>frmOptions.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmSplashScreen.resx">
<DependentUpon>frmSplashScreen.cs</DependentUpon>
</EmbeddedResource>
Expand Down
65 changes: 30 additions & 35 deletions IFME/MediaEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ internal static void Audio(MediaQueue queue, string tempDir)

frmMain.PrintStatus($"Encoding, Audio #{i}");

if (item.Copy && queue.OutputFormat == MediaContainer.MKV)
{
frmMain.PrintLog("[INFO] Extract audio file...");

ProcessManager.Start(tempDir, $"\"{FFmpeg}\" -hide_banner -v error -i \"{item.File}\" -map 0:{item.Id} -c:a copy -y \"audio{i:D4}_{item.Lang}.mka\"");
continue;
}

if (Plugins.Items.Audio.TryGetValue(item.Encoder.Id, out PluginsAudio codec))
{
frmMain.PrintLog("[INFO] Encoding audio file...");
Expand All @@ -92,7 +84,7 @@ internal static void Audio(MediaQueue queue, string tempDir)

var trim = (queue.Trim.Enable ? $"-ss {queue.Trim.Start} -t {queue.Trim.Duration}" : string.Empty);

var qu = ac.Mode[md].Args.IsDisable() ? string.Empty : $"{ac.Mode[md].Args} {ac.Mode[md].QualityPrefix}{item.Encoder.Quality}{ac.Mode[md].QualityPostfix}";
var qu = string.IsNullOrEmpty(ac.Mode[md].Args) ? string.Empty : $"{ac.Mode[md].Args} {ac.Mode[md].QualityPrefix}{item.Encoder.Quality}{ac.Mode[md].QualityPostfix}";
var hz = item.Encoder.SampleRate == 0 ? string.Empty : $"-ar {item.Encoder.SampleRate}";
var ch = item.Encoder.Channel == 0 ? string.Empty : $"-ac {item.Encoder.Channel}";

Expand Down Expand Up @@ -128,13 +120,15 @@ internal static void Video(MediaQueue queue, string tempDir)
var vc = codec.Video;

var en = vc.Encoder.Find(b => b.BitDepth == item.Quality.BitDepth).Binary;


var ff = string.Equals(Path.GetFileNameWithoutExtension(en).ToLowerInvariant(), "ffmpeg");

var mode = item.Encoder.Mode;

var outrawfile = $"raw-v{i:D4}_{item.Lang}.{vc.Extension}";
var outfmtfile = $"video{i:D4}_{item.Lang}.{codec.Format[0]}";
var outencfile = vc.RawOutput ? outrawfile : outfmtfile;

var mode = item.Encoder.Mode;

var val_w = item.Quality.Width >= 128 ? item.Quality.Width : item.Quality.OriginalWidth;
var val_h = item.Quality.Height >= 128 ? item.Quality.Height : item.Quality.OriginalHeight;
var val_fps = item.Quality.FrameRate >= 5 ? item.Quality.FrameRate : 23.976;
Expand All @@ -154,7 +148,7 @@ internal static void Video(MediaQueue queue, string tempDir)
var en_csp = string.Empty;
var en_preset = string.Empty;
var en_tune = string.Empty;
var en_quality = string.Empty;
var en_mode = string.Empty;
var en_framecount = string.Empty;

// FFmpeg RAW Type
Expand Down Expand Up @@ -233,48 +227,49 @@ internal static void Video(MediaQueue queue, string tempDir)
}

// Encoder Preset
if (!vc.Args.Preset.IsDisable() && !item.Encoder.Preset.IsDisable())
if (!string.IsNullOrEmpty(vc.Args.Preset) && !string.IsNullOrEmpty(item.Encoder.Preset))
{
en_preset = $"{vc.Args.Preset} {item.Encoder.Preset}";
}

// Encoder Tune
if (!vc.Args.Tune.IsDisable() && !item.Encoder.Tune.IsDisable())
if (!string.IsNullOrEmpty(vc.Args.Tune) && !string.IsNullOrEmpty(item.Encoder.Tune))
{
en_tune = $"{vc.Args.Tune} {item.Encoder.Tune}";
}

// Encoder Mode
if (!vc.Mode[mode].Args.IsDisable())
if (!string.IsNullOrEmpty(vc.Mode[mode].Args))
{
en_quality = $"{vc.Mode[mode].Args} {vc.Mode[mode].Prefix}{item.Encoder.Value}{vc.Mode[mode].Postfix}";
en_mode = $"{vc.Mode[mode].Args} {vc.Mode[mode].Prefix}{item.Encoder.Value}{vc.Mode[mode].Postfix}";
}

// Encoder Frame Count
if (!vc.Args.FrameCount.IsDisable())
if (!string.IsNullOrEmpty(vc.Args.FrameCount))
{
if (item.Quality.FrameCount > 0)
en_framecount = $"{vc.Args.FrameCount} {item.Quality.FrameCount}";
}

// Parse FFmpeg filter
var ffmpeg_filter = string.Join(",", ff_vf);

// Make commands
var args_ffinput = $"{ff_infps} -i \"{item.File}\"";
var args_eninput = $"{vc.Args.Input} \"{item.File}\"";

var ffmpeg_command = $"{ff_trim} -map 0:{item.Id} {ff_yuv} -vf {ffmpeg_filter} {item.Quality.Command}";
var encoder_command = $"{en_res} {en_fps} {en_bit} {en_csp} {en_preset} {en_tune} {en_quality} {en_framecount}";
// Copy Streams
if (codec.GUID.Equals(new Guid("00000000-0000-0000-0000-000000000000")))
{
frmMain.PrintStatus($"Copying, Video #{i}");
frmMain.PrintLog($"[INFO] Copying video stream...");

var ffmpeg_encoder = string.Equals(Path.GetFileNameWithoutExtension(en).ToLowerInvariant(), "ffmpeg") ? $"{ff_infps} {args_eninput} {ffmpeg_command}" : $"{args_eninput} {encoder_command}";
ProcessManager.Start(tempDir, $"\"{FFmpeg}\" {vc.Args.Input} \"{item.File}\" {vc.Args.UnPipe} {vc.Args.Output} {outencfile}");
continue;
}

// begin encoding
// Begin encoding
frmMain.PrintStatus($"Encoding, Video #{i}");
frmMain.PrintLog($"[INFO] Encoding video file...");

// Tell You
frmMain.PrintLog($"[INFO] Video filter command is: {ffmpeg_filter}");
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_ff_en = ff ? cmd_ff : cmd_en;

if (vc.Mode[item.Encoder.Mode].MultiPass)
{
Expand All @@ -296,9 +291,9 @@ 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 {args_ffinput} {ffmpeg_command} {ff_rawcodec} - | \"{en}\" {vc.Args.Input} {vc.Args.Y4M} {encoder_command} {pass} {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} {cmd_en} {en_preset} {en_tune} {en_mode} {vc.Args.Command} {item.Encoder.Command} {pass} {vc.Args.Output} {outencfile}");
else
ProcessManager.Start(tempDir, $"\"{en}\" {ffmpeg_encoder} {vc.Args.UnPipe} {pass} {item.Encoder.Command} {vc.Args.Command} {vc.Args.Output} {outencfile}");
ProcessManager.Start(tempDir, $"\"{en}\" {ff_infps} {vc.Args.Input} \"{(string.IsNullOrEmpty(vc.Args.Y4M) ? item.File : vc.Args.Y4M)}\" {cmd_ff_en} {vc.Args.UnPipe} {item.Encoder.Command} {vc.Args.Command} {pass} {vc.Args.Output} {outencfile}");

++p;

Expand All @@ -307,9 +302,9 @@ internal static void Video(MediaQueue queue, string tempDir)
else
{
if (vc.Args.Pipe)
ProcessManager.Start(tempDir, $"\"{FFmpeg}\" -hide_banner -v error {args_ffinput} {ffmpeg_command} {ff_rawcodec} - | \"{en}\" {vc.Args.Input} {vc.Args.Y4M} {encoder_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} {cmd_en} {en_preset} {en_tune} {en_mode} {vc.Args.Command} {item.Encoder.Command} {vc.Args.Output} {outencfile}");
else
ProcessManager.Start(tempDir, $"\"{en}\" {ffmpeg_encoder} {vc.Args.UnPipe} {item.Encoder.Command} {vc.Args.Output} {outencfile}");
ProcessManager.Start(tempDir, $"\"{en}\" {ff_infps} {vc.Args.Input} \"{(string.IsNullOrEmpty(vc.Args.Y4M) ? item.File : vc.Args.Y4M)}\" {cmd_ff_en} {vc.Args.UnPipe} {item.Encoder.Command} {vc.Args.Command} {vc.Args.Output} {outencfile}");
}

// Raw file dont have pts (time), need to remux
Expand Down
1 change: 0 additions & 1 deletion IFME/MediaQueue/MediaQueueAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace IFME
public partial class MediaQueueAudio : MediaQueueCommon
{
public MediaQueueAudioEncoder Encoder { get; set; } = new MediaQueueAudioEncoder();
public bool Copy { get; set; } = false;
public string Command { get; set; }
public string CommandFilter { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions IFME/MediaQueue/MediaQueueParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace IFME
public static class MediaQueueParse
{
public static Guid CurrentId_Video { get; set; } = new Guid("deadbeef-0265-0265-0265-026502650265");
public static Guid CurrentId_Audio { get; set; } = new Guid("deadbeef-0aac-0aac-0aac-0aac0aac0aac");
public static Guid CurrentId_Audio { get; set; } = new Guid("aaaaaaaa-0000-0000-0000-000000000000");


public static MediaQueueVideo Video(string path, FFmpeg.StreamVideo data, bool isImageSeq = false)
Expand Down Expand Up @@ -80,7 +80,7 @@ public static MediaQueueAudio Audio(string path, FFmpeg.StreamAudio data)
Mode = 0,
Quality = Plugins.Items.Audio[CurrentId_Audio].Audio.Mode[0].Default,
SampleRate = Plugins.Items.Audio[CurrentId_Audio].Audio.SampleRateDefault,
Channel = ch,
Channel = Plugins.Items.Audio[CurrentId_Audio].Audio.ChannelDefault,
Command = string.Empty
}
};
Expand Down
4 changes: 3 additions & 1 deletion IFME/Plugins/Plugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public class Plugins
{
public class Items
{
public static Dictionary<Guid, PluginsAudio> Audio { get; set; } = new Dictionary<Guid, PluginsAudio>();
public static Dictionary<Guid, PluginsCommon> Lists { get; set; } = new Dictionary<Guid, PluginsCommon>();

public static Dictionary<Guid, PluginsAudio> Audio { get; set; } = new Dictionary<Guid, PluginsAudio>();
public static Dictionary<Guid, PluginsVideo> Video { get; set; } = new Dictionary<Guid, PluginsVideo>();
}
}
Expand Down
Loading

0 comments on commit afe05ba

Please sign in to comment.