Skip to content

Commit

Permalink
Improve Implementation of chunking
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Apr 26, 2024
1 parent 2fa0232 commit de5c025
Show file tree
Hide file tree
Showing 24 changed files with 432 additions and 309 deletions.
166 changes: 166 additions & 0 deletions NotEnoughAV1Encodes/Controls/ChunkingTab.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<UserControl x:Class="NotEnoughAV1Encodes.Controls.ChunkingTab"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:NotEnoughAV1Encodes.Controls"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="1085">
<Grid>
<GroupBox x:Name="GroupBoxQueueParallel" Header="{lex:Loc}" Margin="10,137,10,0" Height="82" VerticalAlignment="Top" mah:ControlsHelper.ContentCharacterCasing="Normal">
<Grid Background="{Binding BackgroundColor}">
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="UIElement.IsEnabled" Value="False" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMode}" Value="1">
<Setter Property="UIElement.IsEnabled" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMode}" Value="2">
<Setter Property="UIElement.IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Label x:Name="LabelQueueParallelWorkers" Content="{lex:Loc}" MinWidth="100" MaxWidth="150" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" FontWeight="Bold" HorizontalAlignment="Left" />
<TextBox x:Name="TextBoxQueueParallelWorkers" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AcceptsReturn="True" Text="2" PreviewTextInput="NumberValidationTextBox" Width="80" Margin="120,0,0,0">
<TextBox.ToolTip>Sets the amount of videos in the queue to encode in parallel</TextBox.ToolTip>
</TextBox>
</Grid>
</GroupBox>
<GroupBox x:Name="GroupBoxWorkersAndSplitting" Header="{lex:Loc}" Margin="10,52,10,0" Height="80" VerticalAlignment="Top" mah:ControlsHelper.ContentCharacterCasing="Normal">
<Grid Background="{Binding BackgroundColor}">
<Grid.Style>
<Style TargetType="Grid">
<Setter Property="UIElement.IsEnabled" Value="False" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMode}" Value="0">
<Setter Property="UIElement.IsEnabled" Value="True" />
</DataTrigger>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMode}" Value="2">
<Setter Property="UIElement.IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100" MaxWidth="120"/>
<ColumnDefinition MinWidth="100"/>
<ColumnDefinition MinWidth="100" MaxWidth="120"/>
<ColumnDefinition MinWidth="100"/>
<ColumnDefinition MinWidth="100" MaxWidth="120"/>
<ColumnDefinition MinWidth="100"/>
<ColumnDefinition MinWidth="150" MaxWidth="150"/>
<ColumnDefinition MinWidth="100"/>
</Grid.ColumnDefinitions>
<Label x:Name="LabelWorkerCount" Grid.Column="0" Content="{lex:Loc}" MinWidth="100" MaxWidth="150" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" FontWeight="Bold" HorizontalAlignment="Left"/>
<TextBox Grid.Column="1" x:Name="TextBoxWorkerCount" Text="{Binding WorkerCount}" PreviewTextInput="NumberValidationTextBox" Height="28" MinWidth="90" MaxWidth="110" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Label x:Name="LabelSplittingMethod" Grid.Column="2" Content="{lex:Loc}" MinWidth="100" MaxWidth="150" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" FontWeight="Bold" HorizontalAlignment="Left"/>
<ComboBox Grid.Column="3" x:Name="ComboBoxChunkingMethod" Height="28" MinWidth="100" MaxWidth="140" HorizontalAlignment="Left" SelectedIndex="{Binding ChunkingMethod}">
<ComboBoxItem Content="Equal Chunking" IsSelected="True"/>
<ComboBoxItem Content="PySceneDetect"/>
<ComboBoxItem Content="Disable"/>
</ComboBox>
<Label x:Name="LabelReencodeMethod" Grid.Column="4" Content="{lex:Loc}" MinWidth="100" MaxWidth="150" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" FontWeight="Bold" HorizontalAlignment="Left">
<Label.Style>
<Style TargetType="Label" BasedOn="{StaticResource MahApps.Styles.Label}">
<Setter Property="UIElement.Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMethod}" Value="0">
<Setter Property="UIElement.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<ComboBox Grid.Column="5" x:Name="ComboBoxReencodeMethod" Height="28" MinWidth="100" MaxWidth="140" HorizontalAlignment="Left" SelectedIndex="{Binding ReencodeMethod}">
<ComboBoxItem Content="x264" IsSelected="True"/>
<ComboBoxItem Content="ffv1"/>
<ComboBoxItem Content="utvideo"/>
<ComboBoxItem Content="copy (not reencoding)"/>
<ComboBox.Style>
<Style TargetType="ComboBox" BasedOn="{StaticResource MahApps.Styles.ComboBox}">
<Setter Property="UIElement.Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMethod}" Value="0">
<Setter Property="UIElement.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
<Label x:Name="LabelChunkLength" Grid.Column="6" Content="{lex:Loc}" MinWidth="100" MaxWidth="150" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" FontWeight="Bold" HorizontalAlignment="Left">
<Label.Style>
<Style TargetType="Label" BasedOn="{StaticResource MahApps.Styles.Label}">
<Setter Property="UIElement.Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMethod}" Value="0">
<Setter Property="UIElement.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<TextBox Grid.Column="7" x:Name="TextBoxChunkLength" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AcceptsReturn="True" Text="{Binding ChunkLength}" PreviewTextInput="NumberValidationTextBox" Width="80">
<TextBox.ToolTip>Sets the chunk length in seconds. Recommended: 10</TextBox.ToolTip>
<TextBox.Style>
<Style TargetType="TextBox" BasedOn="{StaticResource MahApps.Styles.TextBox}">
<Setter Property="UIElement.Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMethod}" Value="0">
<Setter Property="UIElement.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Label x:Name="LabelThreshold" Grid.Column="4" Content="{lex:Loc}" MinWidth="100" MaxWidth="150" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" FontWeight="Bold" HorizontalAlignment="Left">
<Label.Style>
<Style TargetType="Label" BasedOn="{StaticResource MahApps.Styles.Label}">
<Setter Property="UIElement.Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMethod}" Value="1">
<Setter Property="UIElement.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
<TextBox Grid.Column="5" x:Name="TextBoxPySceneDetectThreshold" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AcceptsReturn="True" Text="{Binding PySceneDetectThreshold}" PreviewTextInput="NumberValidationTextBox" Width="80">
<TextBox.ToolTip>Sets the threshold of scenedetection. (Default 30)</TextBox.ToolTip>
<TextBox.Style>
<Style TargetType="TextBox" BasedOn="{StaticResource MahApps.Styles.TextBox}">
<Setter Property="UIElement.Visibility" Value="Hidden" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedIndex, ElementName=ComboBoxChunkingMethod}" Value="1">
<Setter Property="UIElement.Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
</GroupBox>

<ComboBox x:Name="ComboBoxChunkingMode" HorizontalAlignment="Left" Margin="76,10,0,0" VerticalAlignment="Top" Width="140" SelectedIndex="{Binding ChunkingMode}">
<ComboBoxItem Content="Chunking" IsSelected="True"/>
<ComboBoxItem Content="Queue"/>
<ComboBoxItem Content="Chunking + Queue"/>
</ComboBox>
<Label Content="Mode:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="61"/>
<GroupBox x:Name="GroupBoxModeDescription" Margin="10,225,10,10" Header="{lex:Loc}" mah:ControlsHelper.ContentCharacterCasing="Normal">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Name="LabelModeDescription1" Text="{lex:Loc}" />
<TextBlock Name="LabelModeDescription2" Grid.Row="1" Text="{lex:Loc}" />
<TextBlock Name="LabelModeDescription3" Grid.Row="2" Text="{lex:Loc}" />
</Grid>
</GroupBox>
</Grid>
</UserControl>
21 changes: 21 additions & 0 deletions NotEnoughAV1Encodes/Controls/ChunkingTab.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Windows.Input;

namespace NotEnoughAV1Encodes.Controls
{
public partial class ChunkingTab : UserControl
{
public ChunkingTab()
{
InitializeComponent();
}

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);
}
}
}
11 changes: 1 addition & 10 deletions NotEnoughAV1Encodes/Controls/MainWindowTopButtons.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,7 @@ private void ButtonOpenSource_Click(object sender, EventArgs e)
mainWindow.SummaryTabControl.LabelVideoLength.Content = mainWindow.videoDB.MIDuration;
mainWindow.SummaryTabControl.LabelVideoResolution.Content = mainWindow.videoDB.MIWidth + "x" + mainWindow.videoDB.MIHeight;
mainWindow.SummaryTabControl.LabelVideoColorFomat.Content = mainWindow.videoDB.MIChromaSubsampling;

mainWindow.SummaryTabControl.ComboBoxChunkingMethod.SelectedIndex = queueElement.ChunkingMethod;
mainWindow.SummaryTabControl.ComboBoxReencodeMethod.SelectedIndex = queueElement.ReencodeMethod;
mainWindow.VideoTabVideoOptimizationControl.CheckBoxTwoPassEncoding.IsOn = queueElement.Passes == 2;
mainWindow.SummaryTabControl.TextBoxChunkLength.Text = queueElement.ChunkLength.ToString();
mainWindow.SummaryTabControl.TextBoxPySceneDetectThreshold.Text = queueElement.PySceneDetectThreshold.ToString();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -357,11 +352,7 @@ private void AddToQueue(string identifier, bool skipSubs)
queueElement.FilterCommand = mainWindow.FiltersTabControl.GenerateVideoFilters();
queueElement.FrameCount = mainWindow.videoDB.MIFrameCount;
queueElement.EncodingMethod = mainWindow.VideoTabVideoPartialControl.ComboBoxVideoEncoder.SelectedIndex;
queueElement.ChunkingMethod = mainWindow.SummaryTabControl.ComboBoxChunkingMethod.SelectedIndex;
queueElement.ReencodeMethod = mainWindow.SummaryTabControl.ComboBoxReencodeMethod.SelectedIndex;
queueElement.Passes = mainWindow.VideoTabVideoOptimizationControl.CheckBoxTwoPassEncoding.IsOn ? 2 : 1;
queueElement.ChunkLength = int.Parse(mainWindow.SummaryTabControl.TextBoxChunkLength.Text);
queueElement.PySceneDetectThreshold = float.Parse(mainWindow.SummaryTabControl.TextBoxPySceneDetectThreshold.Text);
queueElement.VFR = mainWindow.VideoTabVideoPartialControl.CheckBoxVideoVFR.IsChecked == true;
queueElement.Preset = mainWindow.PresetSettings;
queueElement.VideoDB = mainWindow.videoDB;
Expand Down Expand Up @@ -437,7 +428,7 @@ private void PreAddToQueue()
// Add Job to Queue
AddToQueue(mainWindow.uid, false);

Dispatcher.BeginInvoke((Action)(() => mainWindow.TabControl.SelectedIndex = 7));
Dispatcher.BeginInvoke((Action)(() => mainWindow.TabControl.SelectedIndex = 8));

// Reset Unique Identifier
mainWindow.uid = null;
Expand Down
2 changes: 0 additions & 2 deletions NotEnoughAV1Encodes/Controls/QueueTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@
</ListBox.ItemTemplate>
</ListBox>
</GroupBox>
<Label x:Name="LabelEncodeQueueParallel" Content="{lex:Loc}" Margin="0,1,67,0" VerticalAlignment="Top" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" HorizontalAlignment="Right" Width="398"/>
<mah:ToggleSwitch x:Name="ToggleSwitchQueueParallel" VerticalAlignment="Top" Width="49" HorizontalAlignment="Right" Margin="0,-1,-97,0" Height="30" Content=" " Toggled="ToggleSwitchQueueParallel_Toggled"/>
<ComboBox x:Name="ComboBoxSortQueueBy" HorizontalAlignment="Left" Margin="366,3,0,0" VerticalAlignment="Top" Width="161" SelectionChanged="ComboBoxSortQueueBy_SelectionChanged">
<ComboBoxItem Content="{lex:Loc SortByOldest}" IsSelected="True"/>
<ComboBoxItem Content="{lex:Loc SortByNewest}"/>
Expand Down
21 changes: 0 additions & 21 deletions NotEnoughAV1Encodes/Controls/QueueTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,6 @@ public void SortQueue()
}
}

private void ToggleSwitchQueueParallel_Toggled(object sender, RoutedEventArgs e)
{
if (MainWindow.startupLock) return;

// Get MainWindow instance to access UI elements
MainWindow mainWindow = Application.Current.MainWindow as MainWindow;

mainWindow.settingsDB.QueueParallel = ToggleSwitchQueueParallel.IsOn;
try
{
Directory.CreateDirectory(Path.Combine(Global.AppData, "NEAV1E"));
File.WriteAllText(Path.Combine(Global.AppData, "NEAV1E", "settings.json"), JsonConvert.SerializeObject(mainWindow.settingsDB, Formatting.Indented));
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}

private void ButtonEditSelectedItem_Click(object sender, RoutedEventArgs e)
{
if (MainWindow.ProgramState != 0) return;
Expand Down Expand Up @@ -217,12 +201,7 @@ private void ButtonEditSelectedItem_Click(object sender, RoutedEventArgs e)
mainWindow.SummaryTabControl.LabelVideoLength.Content = mainWindow.videoDB.MIDuration;
mainWindow.SummaryTabControl.LabelVideoResolution.Content = mainWindow.videoDB.MIWidth + "x" + mainWindow.videoDB.MIHeight;
mainWindow.SummaryTabControl.LabelVideoColorFomat.Content = mainWindow.videoDB.MIChromaSubsampling;

mainWindow.SummaryTabControl.ComboBoxChunkingMethod.SelectedIndex = tmp.ChunkingMethod;
mainWindow.SummaryTabControl.ComboBoxReencodeMethod.SelectedIndex = tmp.ReencodeMethod;
mainWindow.VideoTabVideoOptimizationControl.CheckBoxTwoPassEncoding.IsOn = tmp.Passes == 2;
mainWindow.SummaryTabControl.TextBoxChunkLength.Text = tmp.ChunkLength.ToString();
mainWindow.SummaryTabControl.TextBoxPySceneDetectThreshold.Text = tmp.PySceneDetectThreshold.ToString();

try
{
Expand Down

0 comments on commit de5c025

Please sign in to comment.