mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-22 18:41:48 +01:00
Take care of mp3 conversion settings
This commit is contained in:
1 parent
c9d2c77340
commit
ae3328b029
2 files changed
+71
-1
No files matched your search
@@ -1,5 +1,7 @@
|
||||
// <copyright file="ConversionJob_FFMPEG.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
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<EncodingMode>("Encoding");
|
||||
int encodingQuality = this.ConversionPreset.GetSettingsValue<int>("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)
|
||||
|
||||
@@ -164,6 +164,19 @@ namespace FileConverter
|
||||
return this.GetDefaultValue(settingsKey);
|
||||
}
|
||||
|
||||
public T GetSettingsValue<T>(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)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user