Advanced Options

Added several advanced options.
This commit is contained in:
Jordan Wages 2018-07-03 23:26:42 -05:00
parent 2e73a77538
commit 3af7fd2b2c
8 changed files with 214 additions and 21 deletions

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace butterflow_ui
{
/// <summary> Values that represent a flow filter type used for optical flow calculations. </summary>
[Serializable]
public enum FlowFilterType
{
/// <summary> Box. </summary>
box,
/// <summary> Guassian. </summary>
guassian
}
}

View File

@ -249,6 +249,24 @@ namespace butterflow_ui.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to Flow Filter.
/// </summary>
public static string FlowFilterLabel {
get {
return ResourceManager.GetString("FlowFilterLabel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Filter used for optical flow estimation..
/// </summary>
public static string FlowFilterTooltip {
get {
return ResourceManager.GetString("FlowFilterTooltip", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Height.
/// </summary>
@ -303,6 +321,24 @@ namespace butterflow_ui.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to Keep Subregions.
/// </summary>
public static string KeepSubregionsLabel {
get {
return ResourceManager.GetString("KeepSubregionsLabel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Renders subregions not explicitly specified..
/// </summary>
public static string KeepSubregionsTooltip {
get {
return ResourceManager.GetString("KeepSubregionsTooltip", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Levels.
/// </summary>

View File

@ -240,12 +240,24 @@
<data name="FastPyramidsTooltip" xml:space="preserve">
<value />
</data>
<data name="FlowFilterLabel" xml:space="preserve">
<value>Flow Filter</value>
</data>
<data name="FlowFilterTooltip" xml:space="preserve">
<value>Filter used for optical flow estimation.</value>
</data>
<data name="IterationsLabel" xml:space="preserve">
<value>Pyramid iterations</value>
</data>
<data name="IterationsTooltip" xml:space="preserve">
<value>The number of iterations to use for each pyramid layer.</value>
</data>
<data name="KeepSubregionsLabel" xml:space="preserve">
<value>Keep Subregions</value>
</data>
<data name="KeepSubregionsTooltip" xml:space="preserve">
<value>Renders subregions not explicitly specified.</value>
</data>
<data name="LevelsLabel" xml:space="preserve">
<value>Levels</value>
</data>

View File

@ -11,12 +11,18 @@
x:Name="butterflowUIWindow"
Title="{x:Static loc:Localization.Title}" Height="600" Width="800">
<Window.Resources>
<ObjectDataProvider x:Key="enumDataProvider" MethodName="GetValues"
<ObjectDataProvider x:Key="enumRegionTypeDataProvider" MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="butterflow_ui:RegionType"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ObjectDataProvider x:Key="enumFlowFilterTypeDataProvider" MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="butterflow_ui:FlowFilterType"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<DockPanel>
<Menu DockPanel.Dock="Top">
@ -109,7 +115,7 @@
<RadioButton GroupName="PlaybackRate" Checked="PlaybackRateRadioButton_Checked" Content="{x:Static loc:Localization._120fpsLabel}" Tag="120" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption LabelValue="{x:Static loc:Localization.CustomPlaybackRateLabel}" DescriptionValue="{x:Static loc:Localization.PlaybackRateDescription}">
<TextBox Text="{Binding OptionsConfiguration.PlaybackRate, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding OptionsConfiguration.PlaybackRate, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}" GotFocus="TextBox_GotFocus" />
</butterflow_ui:ButterflowOption>
</StackPanel>
</butterflow_ui:ButterflowOption>
@ -157,7 +163,18 @@
</Button>
<butterflow_ui:ButterflowOption Grid.Column="2" LabelValue="{x:Static loc:Localization.HeightLabel}">
<TextBox Text="{Binding OptionsConfiguration.Height, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" IsReadOnly="{Binding OptionsConfiguration.LockAspectRatio, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding OptionsConfiguration.Height, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" IsReadOnly="{Binding OptionsConfiguration.LockAspectRatio, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlColor}}" />
<Style.Triggers>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background" Value="Gray" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</butterflow_ui:ButterflowOption>
</Grid>
</butterflow_ui:ButterflowOption>
@ -176,7 +193,7 @@
<TextBlock Text="{Binding Start, Converter={x:Static gu:TimeSpanToStringConverter.Default}}" ToolTip="{Binding Start}"/>
<TextBlock Text="{x:Static loc:Localization.EndLabel}" />
<TextBlock Text="{Binding End, Converter={x:Static gu:TimeSpanToStringConverter.Default}}" ToolTip="{Binding End}"/>
<ComboBox ItemsSource="{Binding Source={StaticResource enumDataProvider}}" SelectedItem="{Binding SubregionType, Mode=TwoWay}"/>
<ComboBox ItemsSource="{Binding Source={StaticResource enumRegionTypeDataProvider}}" SelectedItem="{Binding SubregionType, Mode=TwoWay}"/>
<TextBox MinWidth="35" Text="{Binding Value, Mode=TwoWay}" />
<TextBlock Text="{x:Static loc:Localization.ToEndLabel}" />
<CheckBox IsChecked="{Binding ToEnd, Mode=TwoWay}" />
@ -185,6 +202,9 @@
</ListView.ItemTemplate>
</ListView>
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption DescriptionValue="{x:Static loc:Localization.KeepSubregionsTooltip}">
<CheckBox IsChecked="{Binding OptionsConfiguration.KeepSubregions, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}" Content="{x:Static loc:Localization.KeepSubregionsLabel}" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption DescriptionValue="{x:Static loc:Localization.SmoothMotionTooltip}">
<CheckBox IsChecked="{Binding OptionsConfiguration.SmoothMotion, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}" Content="{x:Static loc:Localization.SmoothMotionLabel}" />
</butterflow_ui:ButterflowOption>
@ -195,19 +215,22 @@
<TextBox Text="{Binding OptionsConfiguration.PyramidScale, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption LabelValue="{x:Static loc:Localization.LevelsLabel}" DescriptionValue="{x:Static loc:Localization.LevelsTooltip}">
<TextBox Text="{Binding OptionsConfiguration.PyramidScale, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
<TextBox Text="{Binding OptionsConfiguration.Levels, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption LabelValue="{x:Static loc:Localization.WindowSizeLabel}" DescriptionValue="{x:Static loc:Localization.WindowSizeTooltip}">
<TextBox Text="{Binding OptionsConfiguration.PyramidScale, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
<TextBox Text="{Binding OptionsConfiguration.WindowSize, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption LabelValue="{x:Static loc:Localization.IterationsLabel}" DescriptionValue="{x:Static loc:Localization.IterationsTooltip}">
<TextBox Text="{Binding OptionsConfiguration.PyramidScale, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
<TextBox Text="{Binding OptionsConfiguration.Iterations, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption LabelValue="{x:Static loc:Localization.PixelNeighborhoodLabel}" DescriptionValue="{x:Static loc:Localization.PixelNeighborhoodTooltip}">
<TextBox Text="{Binding OptionsConfiguration.PyramidScale, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
<TextBox Text="{Binding OptionsConfiguration.PixelNeighborhood, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption LabelValue="{x:Static loc:Localization.SmoothDerivativeLabel}" DescriptionValue="{x:Static loc:Localization.SmoothDerivativeTooltip}">
<TextBox Text="{Binding OptionsConfiguration.PyramidScale, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
<TextBox Text="{Binding OptionsConfiguration.SmoothDerivativeStandardDeviation, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=LostFocus}" />
</butterflow_ui:ButterflowOption>
<butterflow_ui:ButterflowOption LabelValue="{x:Static loc:Localization.FlowFilterLabel}" DescriptionValue="{x:Static loc:Localization.FlowFilterTooltip}">
<ComboBox ItemsSource="{Binding Source={StaticResource enumFlowFilterTypeDataProvider}}" SelectedItem="{Binding OptionsConfiguration.FlowFilterType, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type butterflow_ui:MainWindow}}, UpdateSourceTrigger=PropertyChanged}"/>
</butterflow_ui:ButterflowOption>
</StackPanel>
</ScrollViewer>

View File

@ -47,6 +47,39 @@ namespace butterflow_ui
InitializeComponent();
}
#region Methods
/// <summary> Gets the recursive children of a <paramref name="parent"/> element that are of type <typeparamref name="T"/>. </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="parent"> The parent element. </param>
/// <returns>
/// An enumerator that allows foreach to be used to process the recursive childrens in this
/// collection.
/// </returns>
private IEnumerable<T> GetRecursiveChildren<T>(object parent) where T : DependencyObject
{
if (parent is DependencyObject)
{
var list = new List<T>();
foreach (var child in LogicalTreeHelper.GetChildren((DependencyObject)parent))
{
if (child is DependencyObject)
{
if (child is T)
{
list.Add((T)child);
}
list.AddRange(GetRecursiveChildren<T>((DependencyObject)child));
}
}
return list;
}
return Enumerable.Empty<T>();
}
/// <summary> Butterflow wrapper parsed console output recieved. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> The ButterflowOutputArgs to process. </param>
@ -234,5 +267,21 @@ namespace butterflow_ui
}
}
}
/// <summary> Event handler. Called by TextBox for got focus events. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> Routed event information. </param>
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
//Clear all the radio buttons because we got focus from the user in the playbackrate textbox.
var playbackRateRadioButtons = GetRecursiveChildren<RadioButton>(this.butterflowUIWindow);
foreach(var radioButton in playbackRateRadioButtons)
{
radioButton.IsChecked = false;
}
}
#endregion
}
}

View File

@ -16,6 +16,14 @@ namespace butterflow_ui
{
#region Members
private const decimal DEFAULT_PYRAMID_SCALE = 0.5m;
private const int DEFAULT_LEVELS = 3;
private const int DEFAULT_WINDOW_SIZE = 25;
private const int DEFAULT_ITERATIONS = 3;
private const int DEFAULT_PIXEL_NEIGHBORHOOD = 5;
private const decimal DEFAULT_SMOOTH_DERIVATIVE_STANDARD_DEVIATION = 1.1m;
private const FlowFilterType DEFAULT_FLOW_FILTER_TYPE = FlowFilterType.box;
/// <summary> An interpreter used to ensure numeric input is correctly calculated. </summary>
private InputInterpreter interpreter = new InputInterpreter();
/// <summary> The aspect ratio used for calculating heights when the aspect ratio is locked. </summary>
@ -25,7 +33,7 @@ namespace butterflow_ui
private bool keepAudio;
private int width;
private int height;
private bool keepAspectRatio;
private bool keepSubRegions;
private bool losslessQuality;
private bool smoothMotion;
private bool lockAspectRatio;
@ -38,6 +46,7 @@ namespace butterflow_ui
private int iterations;
private int pixelNeighborhood;
private decimal smoothDerivativeStandardDeviation;
private FlowFilterType flowFilterType = FlowFilterType.box;
private ObservableCollection<ButterflowSubregion> subregions = new ObservableCollection<ButterflowSubregion>();
#endregion
@ -109,7 +118,7 @@ namespace butterflow_ui
}
set
{
if (value)
if (value && this.width != 0 && this.height != 0)
{
this.aspectRatio = Convert.ToDecimal(this.height) / Convert.ToDecimal(this.width);
}
@ -162,17 +171,17 @@ namespace butterflow_ui
}
}
/// <summary> Gets or sets a value indicating whether the keep aspect ratio of the input video file for the output video file. </summary>
/// <value> True if keep aspect ratio, false if not. </value>
public bool KeepAspectRatio
/// <summary> Gets or sets a value indicating whether the keep subregions that are not explicitly specified. </summary>
/// <value> True if keeping subregions not explicitly specified, false if not. </value>
public bool KeepSubregions
{
get
{
return this.keepAspectRatio;
return this.keepSubRegions;
}
set
{
this.keepAspectRatio = value;
this.keepSubRegions = value;
OnPropertyChanged();
}
}
@ -312,7 +321,13 @@ namespace butterflow_ui
set
{
interpreter.Interpret(value);
this.pixelNeighborhood = interpreter.Int;
// Per butterflow's documentation, the valid range for --poly-n is {5,7}
if (interpreter.Int >= 5 || interpreter.Int <= 7)
{
this.pixelNeighborhood = interpreter.Int;
}
OnPropertyChanged();
}
}
@ -333,6 +348,21 @@ namespace butterflow_ui
}
}
/// <summary> Gets or sets the type of the flow filter used for optical flow calculations. </summary>
/// <value> The type of the flow filter used for optical flow calculations. </value>
public FlowFilterType FlowFilterType
{
get
{
return this.flowFilterType;
}
set
{
this.flowFilterType = value;
OnPropertyChanged();
}
}
/// <summary> Gets or sets the subregions of the video on which to work. </summary>
/// <value> The subregions of the video. </value>
public ObservableCollection<ButterflowSubregion> Subregions
@ -355,12 +385,24 @@ namespace butterflow_ui
/// <summary> Default constructor. </summary>
public OptionsConfiguration()
{
// Set default values
this.pyramidScale = DEFAULT_PYRAMID_SCALE;
this.levels = DEFAULT_LEVELS;
this.windowSize = DEFAULT_WINDOW_SIZE;
this.iterations = DEFAULT_ITERATIONS;
this.pixelNeighborhood = DEFAULT_PIXEL_NEIGHBORHOOD;
this.smoothDerivativeStandardDeviation = DEFAULT_SMOOTH_DERIVATIVE_STANDARD_DEVIATION;
this.flowFilterType = DEFAULT_FLOW_FILTER_TYPE;
AddConstantCallProperty("CommandLineOutput");
this.subregions.CollectionChanged += SubregionsCollectionChanged;
this.subregions.CollectionChanged += Subregions_CollectionChanged; ;
}
private void SubregionsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
/// <summary> Event handler. Called by Subregions for collection changed events. </summary>
/// <param name="sender"> Source of the event. </param>
/// <param name="e"> Notify collection changed event information. </param>
private void Subregions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.NewItems != null)
{
@ -393,9 +435,9 @@ namespace butterflow_ui
/// <returns> This object as a string. </returns>
public string ToButterflowArguments()
{
var stringBuilder = new StringBuilder("-v "); //Verbose
var stringBuilder = new StringBuilder("-v "); // Verbose
if (this.KeepAspectRatio)
if (this.LockAspectRatio)
{
stringBuilder.AppendFormat("-vs {0}:-1 ", this.Width);
}
@ -435,6 +477,17 @@ namespace butterflow_ui
stringBuilder.Append(" ");
}
if (this.KeepSubregions) stringBuilder.Append("-k ");
if (this.SmoothMotion) stringBuilder.Append("-sm ");
if (this.FastPyramid) stringBuilder.Append("--fast-pyr ");
if (this.pyramidScale != DEFAULT_PYRAMID_SCALE) stringBuilder.AppendFormat("--pyr-scale {0} ", this.PyramidScale);
if (this.levels != DEFAULT_LEVELS) stringBuilder.AppendFormat("--levels {0} ", this.Levels);
if (this.windowSize != DEFAULT_WINDOW_SIZE) stringBuilder.AppendFormat("--winsize {0} ", this.WindowSize);
if (this.iterations != DEFAULT_ITERATIONS) stringBuilder.AppendFormat("--iters {0} ", this.Iterations);
if (this.pixelNeighborhood != DEFAULT_PIXEL_NEIGHBORHOOD) stringBuilder.AppendFormat("--poly-n {0} ", this.PixelNeighborhood);
if (this.smoothDerivativeStandardDeviation != DEFAULT_SMOOTH_DERIVATIVE_STANDARD_DEVIATION) stringBuilder.AppendFormat("--poly-s {0} ", this.SmoothDerivativeStandardDeviation);
if (this.FlowFilterType != DEFAULT_FLOW_FILTER_TYPE) stringBuilder.AppendFormat("-ff {0} ", this.FlowFilterType);
return stringBuilder.ToString();
}

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace butterflow_ui
{
/// <summary> Values that represent subregion types. </summary>
[Serializable]
public enum RegionType
{
/// <summary> Speed. </summary>

View File

@ -60,6 +60,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="FlowFilterType.cs" />
<Compile Include="PropertyChangedAlerter.cs" />
<Compile Include="RegionType.cs" />
<Page Include="Icons.xaml">