mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-21 10:01:58 +01:00
Added: New output type: MKV
Video encoder: H264 Audio encoder: AAC
This commit is contained in:
1 parent
fb15d8e833
commit
d4d8e175e8
8 files changed
+180
-4
No files matched your search
@@ -145,6 +145,21 @@ namespace FileConverter.Controls
|
||||
sliderControl.Ticks.Add(500);
|
||||
break;
|
||||
}
|
||||
|
||||
case EncodingMode.AacVBR:
|
||||
{
|
||||
sliderControl.Minimum = 52;
|
||||
sliderControl.Maximum = 208;
|
||||
sliderControl.SelectionStart = 72;
|
||||
sliderControl.SelectionEnd = 136;
|
||||
sliderControl.Ticks.Clear();
|
||||
sliderControl.Ticks.Add(52);
|
||||
sliderControl.Ticks.Add(72);
|
||||
sliderControl.Ticks.Add(104);
|
||||
sliderControl.Ticks.Add(136);
|
||||
sliderControl.Ticks.Add(208);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
encodingQualitySliderControl.CoerceValue(EncodingQualitySliderControl.BitrateProperty);
|
||||
|
||||
@@ -98,7 +98,21 @@ namespace FileConverter.ConversionJobs
|
||||
break;
|
||||
|
||||
case OutputType.Flac:
|
||||
arguments = string.Format("-n -stats -i \"{0}\" \"{1}\"", this.InputFilePath, this.OutputFilePath);
|
||||
{
|
||||
arguments = string.Format("-n -stats -i \"{0}\" \"{1}\"", this.InputFilePath, this.OutputFilePath);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case OutputType.Mkv:
|
||||
{
|
||||
int videoEncodingQuality = this.ConversionPreset.GetSettingsValue<int>("VideoQuality");
|
||||
string videoEncodingSpeed = this.ConversionPreset.GetSettingsValue<string>("VideoEncodingSpeed");
|
||||
int audioEncodingQuality = this.ConversionPreset.GetSettingsValue<int>("Bitrate");
|
||||
string encoderArgs = string.Format("-c:v libx264 -preset {0} -crf {1} -c:a aac -q:a {2} -strict experimental", this.H264EncodingSpeedToPreset(videoEncodingSpeed), this.H264QualityToCRF(videoEncodingQuality), this.AACBitrateToQualityIndex(audioEncodingQuality));
|
||||
arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -267,6 +281,82 @@ namespace FileConverter.ConversionJobs
|
||||
throw new Exception("Unknown Wav encoding.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert video quality index to H264 constant rate factor.
|
||||
/// </summary>
|
||||
/// <param name="quality">The quality index.</param>
|
||||
/// <returns>Returns the H264 constant rate factor.</returns>
|
||||
/// The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible.
|
||||
/// A lower value is a higher quality and a subjectively sane range is 18-28.
|
||||
/// https://trac.ffmpeg.org/wiki/Encode/H.264
|
||||
private int H264QualityToCRF(int quality)
|
||||
{
|
||||
return 51 - quality;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert video encoding speed to H264 preset.
|
||||
/// </summary>
|
||||
/// <param name="encodingSpeed">The encoding speed.</param>
|
||||
/// <returns>The H264 preset.</returns>
|
||||
private string H264EncodingSpeedToPreset(string encodingSpeed)
|
||||
{
|
||||
switch (encodingSpeed)
|
||||
{
|
||||
case "Ultra Fast":
|
||||
return "ultrafast";
|
||||
|
||||
case "Super Fast":
|
||||
return "superfast";
|
||||
|
||||
case "Very Fast":
|
||||
return "veryfast";
|
||||
|
||||
case "Faster":
|
||||
return "faster";
|
||||
|
||||
case "Fast":
|
||||
return "fast";
|
||||
|
||||
case "Medium":
|
||||
return "medium";
|
||||
|
||||
case "Slow":
|
||||
return "slow";
|
||||
|
||||
case "Slower":
|
||||
return "slower";
|
||||
|
||||
case "Very Slow":
|
||||
return "veryslow";
|
||||
}
|
||||
|
||||
throw new Exception("Unknown H264 encoding speed.");
|
||||
}
|
||||
|
||||
private int AACBitrateToQualityIndex(int bitrate)
|
||||
{
|
||||
switch (bitrate)
|
||||
{
|
||||
case 52:
|
||||
return 1;
|
||||
|
||||
case 72:
|
||||
return 2;
|
||||
|
||||
case 104:
|
||||
return 3;
|
||||
|
||||
case 136:
|
||||
return 4;
|
||||
|
||||
case 208:
|
||||
return 5;
|
||||
}
|
||||
|
||||
throw new Exception("Unknown VBR bitrate.");
|
||||
}
|
||||
|
||||
private void ParseFFMPEGOutput(string input)
|
||||
{
|
||||
Match match = this.durationRegex.Match(input);
|
||||
|
||||
@@ -344,6 +344,17 @@ namespace FileConverter
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case OutputType.Mkv:
|
||||
switch (settingsKey)
|
||||
{
|
||||
case "Bitrate":
|
||||
case "VideoQuality":
|
||||
case "VideoEncodingSpeed":
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -354,7 +365,7 @@ namespace FileConverter
|
||||
{
|
||||
if (outputType == OutputType.Wav)
|
||||
{
|
||||
this.InitializeSettingsValue("Encoding", "Wav16");
|
||||
this.InitializeSettingsValue("Encoding", EncodingMode.Wav16.ToString());
|
||||
}
|
||||
|
||||
if (outputType == OutputType.Mp3)
|
||||
@@ -368,6 +379,17 @@ namespace FileConverter
|
||||
this.InitializeSettingsValue("Bitrate", "160");
|
||||
}
|
||||
|
||||
if (outputType == OutputType.Flac)
|
||||
{
|
||||
}
|
||||
|
||||
if (outputType == OutputType.Mkv)
|
||||
{
|
||||
this.InitializeSettingsValue("VideoQuality", "28");
|
||||
this.InitializeSettingsValue("VideoEncodingSpeed", "veryslow");
|
||||
this.InitializeSettingsValue("Bitrate", "104");
|
||||
}
|
||||
|
||||
this.OnPropertyChanged("Settings");
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,7 @@ namespace FileConverter
|
||||
Mp3CBR,
|
||||
|
||||
OggVBR,
|
||||
|
||||
AacVBR,
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace FileConverter
|
||||
public enum OutputType
|
||||
{
|
||||
None,
|
||||
Mkv,
|
||||
Mp3,
|
||||
Ogg,
|
||||
Flac,
|
||||
|
||||
@@ -31,6 +31,12 @@ namespace FileConverter.Windows
|
||||
set;
|
||||
}
|
||||
|
||||
public DataTemplate MkvSettingsDataTemplate
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container)
|
||||
{
|
||||
if (item == null)
|
||||
@@ -50,6 +56,9 @@ namespace FileConverter.Windows
|
||||
|
||||
case OutputType.Ogg:
|
||||
return this.OggSettingsDataTemplate;
|
||||
|
||||
case OutputType.Mkv:
|
||||
return this.MkvSettingsDataTemplate;
|
||||
}
|
||||
|
||||
return this.DefaultDataTemplate;
|
||||
|
||||
@@ -99,11 +99,47 @@
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
||||
|
||||
<DataTemplate x:Key="MkvSettingsDataTemplate">
|
||||
<StackPanel>
|
||||
<Label Content="Video" FontWeight="Bold" />
|
||||
<DockPanel>
|
||||
<Label Content="Quality :" />
|
||||
<Slider x:Name="QualitySlider" Value="{Binding SelectedPreset.Settings, ConverterParameter=VideoQuality|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=23}"
|
||||
Margin="0,2,0,0" VerticalAlignment="Top" AutoToolTipPlacement="TopLeft" IsSnapToTickEnabled="True" IsSelectionRangeEnabled="True" SelectionStart="23" SelectionEnd="33" Minimum="0" Maximum="51" TickPlacement="BottomRight" SmallChange="3" LargeChange="6" TickFrequency="1" Foreground="#004B82" />
|
||||
</DockPanel>
|
||||
<Label Content="Recommended quality range in blue" Foreground="#E5004B82" FontSize="11" />
|
||||
|
||||
<DockPanel>
|
||||
<Label Content="Encoding speed :" />
|
||||
<ComboBox SelectedValue="{Binding SelectedPreset.Settings, ConverterParameter=VideoEncodingSpeed|System.String, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=veryslow}">
|
||||
<System:String>Ultra Fast</System:String>
|
||||
<System:String>Super Fast</System:String>
|
||||
<System:String>Very Fast</System:String>
|
||||
<System:String>Faster</System:String>
|
||||
<System:String>Fast</System:String>
|
||||
<System:String>Medium</System:String>
|
||||
<System:String>Slow</System:String>
|
||||
<System:String>Slower</System:String>
|
||||
<System:String>Very Slow</System:String>
|
||||
</ComboBox>
|
||||
</DockPanel>
|
||||
|
||||
<Label Content="Audio" FontWeight="Bold" />
|
||||
<DockPanel>
|
||||
<Label Content="Quality :" />
|
||||
<controls:EncodingQualitySliderControl x:Name="EncodingQualitySlider" EncodingMode="AacVBR"
|
||||
Bitrate="{Binding SelectedPreset.Settings, ConverterParameter=Bitrate|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay, TargetNullValue=52}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
||||
<windows:ConversionSettingsTemplateSelector x:Key="ConversionSettingsSelector"
|
||||
DefaultDataTemplate="{StaticResource EmptyDataTemplate}"
|
||||
WavSettingsDataTemplate="{StaticResource WavSettingsDataTemplate}"
|
||||
Mp3SettingsDataTemplate="{StaticResource Mp3SettingsDataTemplate}"
|
||||
OggSettingsDataTemplate="{StaticResource OggSettingsDataTemplate}" />
|
||||
OggSettingsDataTemplate="{StaticResource OggSettingsDataTemplate}"
|
||||
MkvSettingsDataTemplate="{StaticResource MkvSettingsDataTemplate}" />
|
||||
</Window.Resources>
|
||||
<Window.Title>
|
||||
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
|
||||
|
||||
@@ -35,7 +35,8 @@ namespace FileConverter
|
||||
OutputType[] outputTypes = new[]
|
||||
{
|
||||
OutputType.Flac,
|
||||
OutputType.Mp3,
|
||||
OutputType.Mkv,
|
||||
OutputType.Mp3,
|
||||
OutputType.Ogg,
|
||||
OutputType.Wav,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user