Skip to content

Commit

Permalink
Preset: Add Option for Audio Codec and Bitrate Depending on Channels #80
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Dec 27, 2021
1 parent 4f86cb9 commit d6bc9ed
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 15 deletions.
5 changes: 4 additions & 1 deletion NotEnoughAV1Encodes/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@
<ComboBoxItem Content="aomenc (AV1)" />
<ComboBoxItem Content="rav1e (AV1)" />
<ComboBoxItem Content="svt-av1 (AV1)" />
<Separator />
<ComboBoxItem Content="x265 (HEVC FFmpeg)" />
<ComboBoxItem Content="x264 (AVC FFmpeg)" />
</ComboBox>
<Label Content="{lex:Loc LabelBitDepth}" HorizontalAlignment="Left" Margin="19,54,0,0" VerticalAlignment="Top" Width="111" />
<ComboBox x:Name="ComboBoxVideoBitDepth" SelectedIndex="{Binding BitDepth}" HorizontalAlignment="Left" Margin="135,52,0,0" VerticalAlignment="Top" Width="70" Height="30" VerticalContentAlignment="Center">
Expand Down Expand Up @@ -820,7 +823,7 @@
<Label x:Name="LabelCodec" Grid.Column="2" IsEnabled="{Binding IsOn, ElementName=ToggleOnOff}" Content="{lex:Loc LabelCodec}" HorizontalAlignment="Right" VerticalContentAlignment="Center"/>
<ComboBox Grid.Column="3" IsEnabled="{Binding IsOn, ElementName=ToggleOnOff}" x:Name="ComboBoxAudioCodec" VerticalAlignment="Center" SelectedIndex="{Binding Codec}">
<ComboBox.ToolTip>Sets the Audio Encoder. Recommended: Opus</ComboBox.ToolTip>
<ComboBoxItem Content="Opus" IsSelected="True" />
<ComboBoxItem Content="Opus" />
<ComboBoxItem Content="AC3" />
<ComboBoxItem Content="EAC3" />
<ComboBoxItem Content="AAC" />
Expand Down
12 changes: 10 additions & 2 deletions NotEnoughAV1Encodes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void ButtonOpenSource_Click(object sender, RoutedEventArgs e)
outname = outname.Replace("{presetname}", preset);
videoDB.OutputPath = Path.Combine(output, outname + outputContainer);
videoDB.OutputFileName = Path.GetFileName(videoDB.OutputPath);
videoDB.ParseMediaInfo();
videoDB.ParseMediaInfo(PresetSettings);

try { ListBoxAudioTracks.Items.Clear(); } catch { }
try { ListBoxAudioTracks.ItemsSource = null; } catch { }
Expand Down Expand Up @@ -300,7 +300,7 @@ private void SingleFileInput(string path)
// Single File Input
videoDB = new();
videoDB.InputPath = path;
videoDB.ParseMediaInfo();
videoDB.ParseMediaInfo(PresetSettings);

try { ListBoxAudioTracks.Items.Clear(); } catch { }
try { ListBoxAudioTracks.ItemsSource = null; } catch { }
Expand Down Expand Up @@ -420,6 +420,14 @@ private void ButtonSavePreset_Click(object sender, RoutedEventArgs e)
{
Directory.CreateDirectory(Path.Combine(Global.AppData, "NEAV1E", "Presets"));
PresetSettings.PresetBatchName = savePresetDialog.PresetBatchName;
PresetSettings.AudioCodecMono = savePresetDialog.AudioCodecMono;
PresetSettings.AudioCodecStereo = savePresetDialog.AudioCodecStereo;
PresetSettings.AudioCodecSixChannel = savePresetDialog.AudioCodecSixChannel;
PresetSettings.AudioCodecEightChannel = savePresetDialog.AudioCodecEightChannel;
PresetSettings.AudioBitrateMono = savePresetDialog.AudioBitrateMono;
PresetSettings.AudioBitrateStereo = savePresetDialog.AudioBitrateStereo;
PresetSettings.AudioBitrateSixChannel = savePresetDialog.AudioBitrateSixChannel;
PresetSettings.AudioBitrateEightChannel = savePresetDialog.AudioBitrateEightChannel;
File.WriteAllText(Path.Combine(Global.AppData, "NEAV1E", "Presets", savePresetDialog.PresetName + ".json"), JsonConvert.SerializeObject(PresetSettings, Formatting.Indented));
ComboBoxPresets.Items.Clear();
LoadPresets();
Expand Down
11 changes: 11 additions & 0 deletions NotEnoughAV1Encodes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ public class Settings
public string CustomSettings { get; set; }
public string PresetBatchName { get; set; } = "{filename}";

// Audio
public int AudioCodecMono { get; set; } = 0;
public int AudioBitrateMono { get; set; } = 64;
public int AudioCodecStereo { get; set; } = 0;
public int AudioBitrateStereo { get; set; } = 128;
public int AudioCodecSixChannel { get; set; } = 0;
public int AudioBitrateSixChannel { get; set; } = 256;
public int AudioCodecEightChannel { get; set; } = 0;
public int AudioBitrateEightChannel { get; set; } = 450;


// Filters
public bool FilterCrop { get; set; }
public bool FilterResize { get; set; }
Expand Down
16 changes: 13 additions & 3 deletions NotEnoughAV1Encodes/Video/VideoDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class VideoDB

public List<Subtitle.SubtitleTracks> SubtitleTracks { get; set; }

public void ParseMediaInfo()
public void ParseMediaInfo(Settings settings)
{
if (!string.IsNullOrEmpty(InputPath))
{
Expand Down Expand Up @@ -57,19 +57,29 @@ public void ParseMediaInfo()
int channels = 1;
try { channels = int.Parse(mediaInfo.Get(StreamKind.Audio, i, "Channels")); } catch { }

int bitrate = 128;
int codec = 0;
switch (channels)
{
case 1:
channels = 0;
bitrate = settings.AudioBitrateMono;
codec = settings.AudioCodecMono;
break;
case 2:
channels = 1;
bitrate = settings.AudioBitrateStereo;
codec = settings.AudioCodecStereo;
break;
case 6:
channels = 2;
bitrate = settings.AudioBitrateSixChannel;
codec = settings.AudioCodecSixChannel;
break;
case 8:
channels = 3;
bitrate = settings.AudioBitrateEightChannel;
codec = settings.AudioCodecEightChannel;
break;
default:
break;
Expand All @@ -91,8 +101,8 @@ public void ParseMediaInfo()
{
Active = true,
Index = i,
Codec = 0,
Bitrate = "128",
Codec = codec,
Bitrate = bitrate.ToString(),
Languages = resources.MediaLanguages.LanguageKeys,
Language = lang,
CustomName = name,
Expand Down
74 changes: 65 additions & 9 deletions NotEnoughAV1Encodes/Views/SavePresetDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,71 @@
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="NotEnoughAV1Encodes"
lex:ResxLocalizationProvider.DefaultDictionary="Strings"
Title="Save Preset" Height="255" Width="340" ResizeMode="NoResize" mah:ControlsHelper.ContentCharacterCasing="Normal">
Title="Save Preset" Height="360" Width="421" ResizeMode="NoResize" mah:ControlsHelper.ContentCharacterCasing="Normal">
<Grid>
<Label x:Name="LabelPresetName" Content="{lex:Loc}" HorizontalAlignment="Center" Margin="0,10,0,0" VerticalAlignment="Top" Width="280" HorizontalContentAlignment="Center"/>
<TextBox x:Name="TextBoxPresetName" HorizontalAlignment="Center" Margin="0,36,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="280"/>
<Button x:Name="ButtonSave" Content="{lex:Loc ButtonExit}" HorizontalAlignment="Center" Margin="0,193,0,0" VerticalAlignment="Top" Width="280" mah:ControlsHelper.ContentCharacterCasing="Normal" Click="ButtonSave_Click"/>
<Label x:Name="LabelBatchFileName" Content="{lex:Loc}" HorizontalAlignment="Center" VerticalAlignment="Top" Width="280" HorizontalContentAlignment="Center" Margin="0,74,0,0"/>
<TextBox x:Name="TextBoxBatchFileName" HorizontalAlignment="Center" Margin="0,105,0,0" VerticalAlignment="Top" Width="280" Text="{}{filename} [AV1][1080p]" Height="10"/>
<Label x:Name="LabelAvailableBatchFilename" Content="{lex:Loc}" HorizontalAlignment="Center" Margin="0,136,0,0" VerticalAlignment="Top" Height="27" Width="280" FontStyle="Italic"/>
<Label x:Name="LabelAvailableBatchPresetName" Content="{lex:Loc}" HorizontalAlignment="Center" Margin="0,158,0,0" VerticalAlignment="Top" Height="30" Width="280" FontStyle="Italic"/>

<Label x:Name="LabelPresetName" Content="{lex:Loc}" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="105" HorizontalContentAlignment="Left"/>
<TextBox x:Name="TextBoxPresetName" HorizontalAlignment="Left" Margin="118,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="280"/>
<Button x:Name="ButtonSave" Content="{lex:Loc ButtonExit}" HorizontalAlignment="Left" Margin="240,289,0,0" VerticalAlignment="Top" Width="158" mah:ControlsHelper.ContentCharacterCasing="Normal" Click="ButtonSave_Click" Height="36"/>
<Label x:Name="LabelBatchFileName" Content="{lex:Loc}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="105" HorizontalContentAlignment="Left" Margin="10,41,0,0"/>
<TextBox x:Name="TextBoxBatchFileName" HorizontalAlignment="Left" Margin="118,41,0,0" VerticalAlignment="Top" Width="280" Text="{}{filename} [AV1][1080p]" Height="10"/>
<Label x:Name="LabelAvailableBatchFilename" Content="{lex:Loc}" HorizontalAlignment="Left" Margin="118,67,0,0" VerticalAlignment="Top" Height="27" Width="280" FontStyle="Italic"/>
<Label x:Name="LabelAvailableBatchPresetName" Content="{lex:Loc}" HorizontalAlignment="Left" Margin="118,85,0,0" VerticalAlignment="Top" Height="30" Width="280" FontStyle="Italic"/>
<Label x:Name="LabelDefaultAudioBehavior" Content="{lex:Loc}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" HorizontalContentAlignment="Left" Margin="10,120,0,0" Height="28"/>
<Label x:Name="LabelCodec" Content="1.0 :" Margin="10,148,0,0" Width="100" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" HorizontalContentAlignment="Right"/>
<ComboBox x:Name="ComboBoxAudioCodecMono" VerticalAlignment="Top" Margin="118,148,0,0" HorizontalAlignment="Left" Width="104">
<ComboBox.ToolTip>Sets the Audio Encoder. Recommended: Opus</ComboBox.ToolTip>
<ComboBoxItem Content="Opus" IsSelected="True" />
<ComboBoxItem Content="AC3" />
<ComboBoxItem Content="EAC3" />
<ComboBoxItem Content="AAC" />
<ComboBoxItem Content="MP3" />
<ComboBoxItem Content="Copy Audio" />
</ComboBox>
<Label x:Name="LabelBitrate" Content="{lex:Loc LabelBitrate}" Margin="235,148,0,0" Width="94" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<TextBox x:Name="TextBoxAudioBitrateMono" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AcceptsReturn="True" PreviewTextInput="NumberValidationTextBox" Width="70" Margin="328,148,0,0" Text="64">
<TextBox.ToolTip>Sets the audio bitrate. Recommended for Opus: 96 - 128 for Stereo</TextBox.ToolTip>
</TextBox>
<Label x:Name="LabelCodec_Copy" Content="2.0 :" Margin="10,179,0,0" Width="100" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" HorizontalContentAlignment="Right"/>
<Label x:Name="LabelCodec_Copy1" Content="5.1 :" Margin="10,210,0,0" Width="100" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" HorizontalContentAlignment="Right"/>
<ComboBox x:Name="ComboBoxAudioCodecStereo" VerticalAlignment="Top" Margin="118,179,0,0" HorizontalAlignment="Left" Width="104">
<ComboBox.ToolTip>Sets the Audio Encoder. Recommended: Opus</ComboBox.ToolTip>
<ComboBoxItem Content="Opus" IsSelected="True" />
<ComboBoxItem Content="AC3" />
<ComboBoxItem Content="EAC3" />
<ComboBoxItem Content="AAC" />
<ComboBoxItem Content="MP3" />
<ComboBoxItem Content="Copy Audio" />
</ComboBox>
<Label x:Name="LabelBitrate_Copy" Content="{lex:Loc LabelBitrate}" Margin="235,179,0,0" Width="94" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<TextBox x:Name="TextBoxAudioBitrateStereo" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AcceptsReturn="True" PreviewTextInput="NumberValidationTextBox" Width="70" Margin="328,179,0,0" Text="128">
<TextBox.ToolTip>Sets the audio bitrate. Recommended for Opus: 96 - 128 for Stereo</TextBox.ToolTip>
</TextBox>
<ComboBox x:Name="ComboBoxAudioCodecSixChannel" VerticalAlignment="Top" Margin="118,210,0,0" HorizontalAlignment="Left" Width="104">
<ComboBox.ToolTip>Sets the Audio Encoder. Recommended: Opus</ComboBox.ToolTip>
<ComboBoxItem Content="Opus" IsSelected="True" />
<ComboBoxItem Content="AC3" />
<ComboBoxItem Content="EAC3" />
<ComboBoxItem Content="AAC" />
<ComboBoxItem Content="MP3" />
<ComboBoxItem Content="Copy Audio" />
</ComboBox>
<Label x:Name="LabelBitrate_Copy1" Content="{lex:Loc LabelBitrate}" Margin="235,210,0,0" Width="94" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<TextBox x:Name="TextBoxAudioBitrateSixChannel" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AcceptsReturn="True" PreviewTextInput="NumberValidationTextBox" Width="70" Margin="328,210,0,0" Text="256">
<TextBox.ToolTip>Sets the audio bitrate. Recommended for Opus: 96 - 128 for Stereo</TextBox.ToolTip>
</TextBox>
<ComboBox x:Name="ComboBoxAudioCodecEightChannel" VerticalAlignment="Top" Margin="118,241,0,0" HorizontalAlignment="Left" Width="104">
<ComboBox.ToolTip>Sets the Audio Encoder. Recommended: Opus</ComboBox.ToolTip>
<ComboBoxItem Content="Opus" IsSelected="True" />
<ComboBoxItem Content="AC3" />
<ComboBoxItem Content="EAC3" />
<ComboBoxItem Content="AAC" />
<ComboBoxItem Content="MP3" />
<ComboBoxItem Content="Copy Audio" />
</ComboBox>
<Label x:Name="LabelBitrate_Copy2" Content="{lex:Loc LabelBitrate}" Margin="235,241,0,0" Width="94" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<TextBox x:Name="TextBoxAudioBitrateEightChannel" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AcceptsReturn="True" PreviewTextInput="NumberValidationTextBox" Width="70" Margin="328,241,0,0" Text="450">
<TextBox.ToolTip>Sets the audio bitrate. Recommended for Opus: 96 - 128 for Stereo</TextBox.ToolTip>
</TextBox>
<Label x:Name="LabelCodec_Copy2" Content="7.1 :" Margin="10,241,0,0" Width="100" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" HorizontalContentAlignment="Right"/>
</Grid>
</mah:MetroWindow>
29 changes: 29 additions & 0 deletions NotEnoughAV1Encodes/Views/SavePresetDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
using ControlzEx.Theming;
using MahApps.Metro.Controls;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Input;

namespace NotEnoughAV1Encodes.Views
{
public partial class SavePresetDialog : MetroWindow
{
public string PresetName { get; set; }
public string PresetBatchName { get; set; }
public int AudioCodecMono { get; set; }
public int AudioBitrateMono { get; set; }
public int AudioCodecStereo { get; set; }
public int AudioBitrateStereo { get; set; }
public int AudioCodecSixChannel { get; set; }
public int AudioBitrateSixChannel { get; set; }
public int AudioCodecEightChannel { get; set; }
public int AudioBitrateEightChannel { get; set; }
public bool Quit { get; set; }
public SavePresetDialog(string _theme)
{
InitializeComponent();
try { ThemeManager.Current.ChangeTheme(this, _theme); } catch { }
}

private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
// Validates that the TextBox Input are only numbers
Regex regex = new("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}

private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(TextBoxPresetName.Text))
Expand All @@ -24,6 +41,18 @@ private void ButtonSave_Click(object sender, RoutedEventArgs e)
}
PresetName = TextBoxPresetName.Text;
PresetBatchName = TextBoxBatchFileName.Text;
// Mono Audio
AudioCodecMono = ComboBoxAudioCodecMono.SelectedIndex;
AudioBitrateMono = int.Parse(TextBoxAudioBitrateMono.Text);
// Stereo Audio
AudioCodecStereo = ComboBoxAudioCodecStereo.SelectedIndex;
AudioBitrateMono = int.Parse(TextBoxAudioBitrateStereo.Text);
// 5.1 Audio
AudioCodecSixChannel = ComboBoxAudioCodecSixChannel.SelectedIndex;
AudioBitrateSixChannel = int.Parse(TextBoxAudioBitrateSixChannel.Text);
// 7.1 Audio
AudioCodecEightChannel = ComboBoxAudioCodecEightChannel.SelectedIndex;
AudioBitrateEightChannel = int.Parse(TextBoxAudioBitrateEightChannel.Text);
Quit = true;
Close();
}
Expand Down
9 changes: 9 additions & 0 deletions NotEnoughAV1Encodes/resources/lang/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions NotEnoughAV1Encodes/resources/lang/Strings.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
<data name="LabelContainer" xml:space="preserve">
<value>Container:</value>
</data>
<data name="LabelDefaultAudioBehavior" xml:space="preserve">
<value>Standard Audio Einstellungen:</value>
</data>
<data name="LabelDeinterlace" xml:space="preserve">
<value>Deinterlace:</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions NotEnoughAV1Encodes/resources/lang/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@
<data name="LabelDefault" xml:space="preserve">
<value>Default:</value>
</data>
<data name="LabelDefaultAudioBehavior" xml:space="preserve">
<value>Default Audio Behavior:</value>
</data>
<data name="LabelDeinterlace" xml:space="preserve">
<value>Deinterlace:</value>
</data>
Expand Down

0 comments on commit d6bc9ed

Please sign in to comment.