From 3bf8ca9ceaf2f93b63b564879cc78b4dacf3516b Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Thu, 24 Dec 2020 12:31:16 +0100 Subject: [PATCH] Higher aac/opus bitrates - can be changed in config --- Code/AudioVideo/FFmpegCommands.cs | 4 ++-- Code/AudioVideo/FFmpegUtils.cs | 8 ++++---- Code/Forms/SettingsForm.Designer.cs | 8 ++++---- Code/IO/Config.cs | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Code/AudioVideo/FFmpegCommands.cs b/Code/AudioVideo/FFmpegCommands.cs index 05cb78a..a454c4b 100644 --- a/Code/AudioVideo/FFmpegCommands.cs +++ b/Code/AudioVideo/FFmpegCommands.cs @@ -207,7 +207,7 @@ namespace Flowframes Logger.Log($"[FFCmds] Extracting audio from {inputFile} to {outFile}", true); //string ext = GetAudioExt(inputFile); outFile = Path.ChangeExtension(outFile, ".ogg"); - string args = $" -loglevel panic -i {inputFile.Wrap()} -vn -acodec libopus -b:a 320k {outFile.Wrap()}"; + string args = $" -loglevel panic -i {inputFile.Wrap()} -vn -acodec libopus -b:a 256k {outFile.Wrap()}"; await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden); if (AvProcess.lastOutputFfmpeg.ToLower().Contains("error") && File.Exists(outFile)) // If broken file was written File.Delete(outFile); @@ -235,7 +235,7 @@ namespace Flowframes // tempPath = Path.ChangeExtension(tempPath, "mkv"); // } string aCodec = Utils.GetAudioEnc(Utils.GetCodec(Interpolate.current.outMode)); - int aKbits = Utils.GetAudioBitrate(aCodec); + int aKbits = Utils.GetAudioKbits(aCodec); string args = $" -i {inputFile.Wrap()} -stream_loop {looptimes} -i {audioPath.Wrap()} -shortest -c:v copy -c:a {aCodec} -b:a {aKbits}k {tempPath.Wrap()}"; await AvProcess.RunFfmpeg(args, AvProcess.LogMode.Hidden); if (AvProcess.lastOutputFfmpeg.Contains("Invalid data")) diff --git a/Code/AudioVideo/FFmpegUtils.cs b/Code/AudioVideo/FFmpegUtils.cs index 1f1e8ff..358eb08 100644 --- a/Code/AudioVideo/FFmpegUtils.cs +++ b/Code/AudioVideo/FFmpegUtils.cs @@ -83,14 +83,14 @@ namespace Flowframes.AudioVideo return "aac"; } - public static int GetAudioBitrate (string codec) + public static int GetAudioKbits (string codec) { if (codec.Trim().ToLower() == "aac") - return 128; + return Config.GetInt("aacBitrate", 160); if (codec.Trim().ToLower().Contains("opus")) - return 112; + return Config.GetInt("opusBitrate", 128); - return 160; + return 192; } public static string GetExt(Interpolate.OutMode outMode, bool dot = true) diff --git a/Code/Forms/SettingsForm.Designer.cs b/Code/Forms/SettingsForm.Designer.cs index 1fc8910..2b817a4 100644 --- a/Code/Forms/SettingsForm.Designer.cs +++ b/Code/Forms/SettingsForm.Designer.cs @@ -1046,9 +1046,9 @@ this.label58.Location = new System.Drawing.Point(420, 301); this.label58.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label58.Name = "label58"; - this.label58.Size = new System.Drawing.Size(82, 13); + this.label58.Size = new System.Drawing.Size(255, 13); this.label58.TabIndex = 65; - this.label58.Text = "Lower is better. "; + this.label58.Text = "Lower is better. Use slightly higher values than h265!"; // // vp9Crf // @@ -1272,9 +1272,9 @@ this.label16.Location = new System.Drawing.Point(420, 271); this.label16.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7); this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(82, 13); + this.label16.Size = new System.Drawing.Size(224, 13); this.label16.TabIndex = 39; - this.label16.Text = "Lower is better. "; + this.label16.Text = "Lower is better. Use higher values than h264! "; // // label14 // diff --git a/Code/IO/Config.cs b/Code/IO/Config.cs index 356a119..0a6a559 100644 --- a/Code/IO/Config.cs +++ b/Code/IO/Config.cs @@ -74,6 +74,12 @@ namespace Flowframes.IO return Get(key, Type.Int).GetInt(); } + public static int GetInt(string key, int defaultVal) + { + WriteIfDoesntExist(key, defaultVal.ToString()); + return GetInt(key); + } + public static float GetFloat(string key) { return float.Parse(Get(key, Type.Float), CultureInfo.InvariantCulture); @@ -84,6 +90,14 @@ namespace Flowframes.IO return Get(key, Type.Float).Replace(",", "."); } + static void WriteIfDoesntExist (string key, string val) + { + foreach (string line in cachedLines) + if (line.Contains(key + "|")) + return; + Set(key, val); + } + public enum Type { String, Int, Float, Bool } private static string WriteDefaultValIfExists(string key, Type type) {