From 72cd93c589bf6892a7e699a4a67395721af43367 Mon Sep 17 00:00:00 2001 From: n00mkrad Date: Tue, 20 Jul 2021 20:52:34 +0200 Subject: [PATCH] Integrated pix_fmt option for MP4/MKV/WEBM/MOV --- Code/Forms/SettingsForm.Designer.cs | 51 +++++++++++++++-------------- Code/Forms/SettingsForm.cs | 4 +-- Code/IO/Config.cs | 1 + Code/Media/FFmpegUtils.cs | 28 +++++++++++----- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Code/Forms/SettingsForm.Designer.cs b/Code/Forms/SettingsForm.Designer.cs index 72c2bc6..7e6cdad 100644 --- a/Code/Forms/SettingsForm.Designer.cs +++ b/Code/Forms/SettingsForm.Designer.cs @@ -187,7 +187,7 @@ this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.resetBtn = new HTAlt.WinForms.HTButton(); this.label75 = new System.Windows.Forms.Label(); - this.mp4Colors = new System.Windows.Forms.ComboBox(); + this.pixFmt = new System.Windows.Forms.ComboBox(); this.settingsTabList.SuspendLayout(); this.generalTab.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.info1)).BeginInit(); @@ -1615,7 +1615,7 @@ // // tabListPage1 // - this.tabListPage1.Controls.Add(this.mp4Colors); + this.tabListPage1.Controls.Add(this.pixFmt); this.tabListPage1.Controls.Add(this.label75); this.tabListPage1.Controls.Add(this.label13); this.tabListPage1.Controls.Add(this.vp9Crf); @@ -1644,7 +1644,7 @@ // this.label13.AutoSize = true; this.label13.ForeColor = System.Drawing.Color.Silver; - this.label13.Location = new System.Drawing.Point(393, 131); + this.label13.Location = new System.Drawing.Point(393, 101); this.label13.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(225, 13); @@ -1655,7 +1655,7 @@ // this.vp9Crf.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); this.vp9Crf.ForeColor = System.Drawing.Color.White; - this.vp9Crf.Location = new System.Drawing.Point(280, 128); + this.vp9Crf.Location = new System.Drawing.Point(280, 98); this.vp9Crf.Maximum = new decimal(new int[] { 60, 0, @@ -1674,7 +1674,7 @@ // this.mp4Crf.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); this.mp4Crf.ForeColor = System.Drawing.Color.White; - this.mp4Crf.Location = new System.Drawing.Point(280, 98); + this.mp4Crf.Location = new System.Drawing.Point(280, 68); this.mp4Crf.Maximum = new decimal(new int[] { 60, 0, @@ -1807,7 +1807,7 @@ // label57 // this.label57.AutoSize = true; - this.label57.Location = new System.Drawing.Point(10, 130); + this.label57.Location = new System.Drawing.Point(10, 100); this.label57.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label57.Name = "label57"; this.label57.Size = new System.Drawing.Size(176, 13); @@ -1857,7 +1857,7 @@ // this.label14.AutoSize = true; this.label14.ForeColor = System.Drawing.Color.Silver; - this.label14.Location = new System.Drawing.Point(393, 101); + this.label14.Location = new System.Drawing.Point(393, 71); this.label14.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(225, 13); @@ -1867,7 +1867,7 @@ // label12 // this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(10, 100); + this.label12.Location = new System.Drawing.Point(10, 70); this.label12.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(260, 13); @@ -2198,28 +2198,29 @@ // label75 // this.label75.AutoSize = true; - this.label75.Location = new System.Drawing.Point(10, 70); + this.label75.Location = new System.Drawing.Point(10, 130); this.label75.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label75.Name = "label75"; - this.label75.Size = new System.Drawing.Size(122, 13); + this.label75.Size = new System.Drawing.Size(190, 13); this.label75.TabIndex = 114; - this.label75.Text = "MP4/MKV: Color Format"; + this.label75.Text = "MP4/MKV/WEBM/MOV: Color Format"; // - // mp4Colors + // pixFmt // - this.mp4Colors.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - this.mp4Colors.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.mp4Colors.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.mp4Colors.ForeColor = System.Drawing.Color.White; - this.mp4Colors.FormattingEnabled = true; - this.mp4Colors.Items.AddRange(new object[] { - "yuv420p (8-Bit Color, 4:2:0 Sampling)", + this.pixFmt.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.pixFmt.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.pixFmt.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.pixFmt.ForeColor = System.Drawing.Color.White; + this.pixFmt.FormattingEnabled = true; + this.pixFmt.Items.AddRange(new object[] { + "yuv420p (8-Bit Color, 4:2:0 Sampling - Recommended)", "yuv444p (8-Bit Color, 4:4:4 Sampling - May not work with some encoders!)", - "yuv420p10le (10-Bit Color, 4:2:0 Sampling - May not work with some encoders!)"}); - this.mp4Colors.Location = new System.Drawing.Point(280, 67); - this.mp4Colors.Name = "mp4Colors"; - this.mp4Colors.Size = new System.Drawing.Size(400, 21); - this.mp4Colors.TabIndex = 115; + "yuv420p10le (10-Bit Color, 4:2:0 Sampling - May not work with some encoders!)", + "yuv444p10le (10-Bit Color, 4:4:4 Sampling - May not work with some encoders!)"}); + this.pixFmt.Location = new System.Drawing.Point(280, 127); + this.pixFmt.Name = "pixFmt"; + this.pixFmt.Size = new System.Drawing.Size(400, 21); + this.pixFmt.TabIndex = 115; // // SettingsForm // @@ -2425,7 +2426,7 @@ private System.Windows.Forms.Label label58; private System.Windows.Forms.Panel autoEncBlockPanel; private HTAlt.WinForms.HTButton resetBtn; - private System.Windows.Forms.ComboBox mp4Colors; + private System.Windows.Forms.ComboBox pixFmt; private System.Windows.Forms.Label label75; } } \ No newline at end of file diff --git a/Code/Forms/SettingsForm.cs b/Code/Forms/SettingsForm.cs index bd5b383..2a38760 100644 --- a/Code/Forms/SettingsForm.cs +++ b/Code/Forms/SettingsForm.cs @@ -107,7 +107,7 @@ namespace Flowframes.Forms ConfigParser.SaveGuiElement(fixOutputDuration); // Encoding ConfigParser.SaveComboxIndex(mp4Enc); - ConfigParser.SaveComboxIndex(mp4Colors); + ConfigParser.SaveComboxIndex(pixFmt); Config.Set(mp4CrfConfigKey, mp4Crf.Value.ToString()); ConfigParser.SaveGuiElement(vp9Crf); ConfigParser.SaveComboxIndex(proResProfile); @@ -168,7 +168,7 @@ namespace Flowframes.Forms ConfigParser.LoadGuiElement(fixOutputDuration); // Encoding ConfigParser.LoadComboxIndex(mp4Enc); - ConfigParser.LoadComboxIndex(mp4Colors); + ConfigParser.LoadComboxIndex(pixFmt); ConfigParser.LoadGuiElement(vp9Crf); ConfigParser.LoadComboxIndex(proResProfile); ConfigParser.LoadGuiElement(aviCodec); diff --git a/Code/IO/Config.cs b/Code/IO/Config.cs index 357ff95..20a8887 100644 --- a/Code/IO/Config.cs +++ b/Code/IO/Config.cs @@ -362,6 +362,7 @@ namespace Flowframes.IO minOutVidLength, minVidLength, mp4Enc, + pixFmt, mpdecimateMode, ncnnGpus, ncnnThreads, diff --git a/Code/Media/FFmpegUtils.cs b/Code/Media/FFmpegUtils.cs index 6d73ba3..73d0e6b 100644 --- a/Code/Media/FFmpegUtils.cs +++ b/Code/Media/FFmpegUtils.cs @@ -54,49 +54,49 @@ namespace Flowframes.Media public static string GetEncArgs (Codec codec) { - string args = $"-c:v { GetEnc(codec)} "; + string args = $"-c:v {GetEnc(codec)} "; if(codec == Codec.H264) { string preset = Config.Get(Config.Key.ffEncPreset).ToLower().Remove(" "); - args += $"-crf {Config.GetInt(Config.Key.h264Crf)} -preset {preset} -pix_fmt yuv420p"; + args += $"-crf {Config.GetInt(Config.Key.h264Crf)} -preset {preset} -pix_fmt {GetPixFmt()}"; } if (codec == Codec.H265) { string preset = Config.Get(Config.Key.ffEncPreset).ToLower().Remove(" "); int crf = Config.GetInt(Config.Key.h265Crf); - args += $"{(crf > 0 ? $"-crf {crf}" : "-x265-params lossless=1")} -preset {preset} -pix_fmt yuv420p"; + args += $"{(crf > 0 ? $"-crf {crf}" : "-x265-params lossless=1")} -preset {preset} -pix_fmt {GetPixFmt()}"; } if (codec == Codec.H264NVENC) { int cq = (Config.GetInt(Config.Key.h264Crf) * 1.1f).RoundToInt(); - args += $"-b:v 0 {(cq > 0 ? $"-cq {cq} -preset p7" : "-preset lossless")} -pix_fmt yuv420p"; + args += $"-b:v 0 {(cq > 0 ? $"-cq {cq} -preset p7" : "-preset lossless")} -pix_fmt {GetPixFmt()}"; } if (codec == Codec.H265NVENC) { int cq = (Config.GetInt(Config.Key.h265Crf) * 1.1f).RoundToInt(); - args += $"-b:v 0 {(cq > 0 ? $"-cq {cq} -preset p7" : "-preset lossless")} -pix_fmt yuv420p"; + args += $"-b:v 0 {(cq > 0 ? $"-cq {cq} -preset p7" : "-preset lossless")} -pix_fmt {GetPixFmt()}"; } if (codec == Codec.AV1) { int cq = (Config.GetInt(Config.Key.av1Crf) * 1.0f).RoundToInt(); - args += $"-b:v 0 -qp {cq} -g 240 {GetSvtAv1Speed()} -tile_rows 2 -tile_columns 2 -pix_fmt yuv420p"; + args += $"-b:v 0 -qp {cq} -g 240 {GetSvtAv1Speed()} -tile_rows 2 -tile_columns 2 -pix_fmt {GetPixFmt()}"; } if (codec == Codec.VP9) { int crf = Config.GetInt(Config.Key.vp9Crf); string qualityStr = (crf > 0) ? $"-b:v 0 -crf {crf}" : "-lossless 1"; - args += $"{qualityStr} {GetVp9Speed()} -tile-columns 2 -tile-rows 2 -row-mt 1 -pix_fmt yuv420p"; + args += $"{qualityStr} {GetVp9Speed()} -tile-columns 2 -tile-rows 2 -row-mt 1 -pix_fmt {GetPixFmt()}"; } if(codec == Codec.ProRes) { - args += $"-profile:v {Config.GetInt(Config.Key.proResProfile)} -pix_fmt yuv420p"; + args += $"-profile:v {Config.GetInt(Config.Key.proResProfile)} -pix_fmt {GetPixFmt()}"; } if (codec == Codec.AviRaw) @@ -139,6 +139,18 @@ namespace Flowframes.Media return $"-preset {arg}"; } + static string GetPixFmt () + { + switch (Config.GetInt(Config.Key.pixFmt)) + { + case 0: return "yuv420p"; + case 1: return "yuv444p"; + case 2: return "yuv420p10le"; + } + + return "yuv420p"; + } + public static bool ContainerSupportsAllAudioFormats (Interpolate.OutMode outMode, List codecs) { if(codecs.Count < 1)