From ae3328b029272bbb23aa5ea28ab68d9ab0058741 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Wed, 19 Aug 2015 08:31:45 +0200 Subject: [PATCH] Take care of mp3 conversion settings --- .../ConversionJobs/ConversionJob_FFMPEG.cs | 59 ++++++++++++++++++- Application/FileConverter/ConversionPreset.cs | 13 ++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index b052922..d8e727d 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -1,5 +1,7 @@ // License: http://www.gnu.org/licenses/gpl.html GPL version 3. +using System.Windows.Markup.Localizer; + namespace FileConverter.ConversionJobs { using System; @@ -53,7 +55,24 @@ namespace FileConverter.ConversionJobs switch (this.ConversionPreset.OutputType) { case OutputType.Mp3: - arguments = string.Format("-n -stats -i \"{0}\" -qscale:a 2 \"{1}\"", this.InputFilePath, this.OutputFilePath); + string encoderArgs = string.Empty; + EncodingMode encodingMode = this.ConversionPreset.GetSettingsValue("Encoding"); + int encodingQuality = this.ConversionPreset.GetSettingsValue("Bitrate"); + switch (encodingMode) + { + case EncodingMode.VBR: + encoderArgs = string.Format("-codec:a libmp3lame -q:a {0}", this.VBRBitrateToQualityIndex(encodingQuality)); + break; + + case EncodingMode.CBR: + encoderArgs = string.Format("-codec:a libmp3lame -b:a {0}k", encodingQuality); + break; + + default: + break; + } + + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); break; case OutputType.Ogg: @@ -77,6 +96,44 @@ namespace FileConverter.ConversionJobs this.ffmpegProcessStartInfo.Arguments = arguments; } + private int VBRBitrateToQualityIndex(int bitrate) + { + switch (bitrate) + { + case 245: + return 0; + + case 225: + return 1; + + case 190: + return 2; + + case 175: + return 3; + + case 165: + return 4; + + case 130: + return 5; + + case 115: + return 6; + + case 100: + return 7; + + case 85: + return 8; + + case 65: + return 9; + } + + throw new Exception("Unknown VBR bitrate."); + } + protected override void Convert() { if (this.ConversionPreset == null) diff --git a/Application/FileConverter/ConversionPreset.cs b/Application/FileConverter/ConversionPreset.cs index 6d397a2..dc9da6d 100644 --- a/Application/FileConverter/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset.cs @@ -164,6 +164,19 @@ namespace FileConverter return this.GetDefaultValue(settingsKey); } + public T GetSettingsValue(string settingsKey) + { + string settingsValue = this.GetSettingsValue(settingsKey); + + Type type = typeof(T); + if (type.IsEnum) + { + return (T)System.Enum.Parse(type, settingsValue); + } + + return (T)System.Convert.ChangeType(settingsValue, type); + } + [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) {