diff --git a/butterflow-ui/ButterflowWrapper.cs b/butterflow-ui/ButterflowWrapper.cs
new file mode 100644
index 0000000..818ec71
--- /dev/null
+++ b/butterflow-ui/ButterflowWrapper.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace butterflow_ui
+{
+ public class ButterflowWrapper
+ {
+ #region Members
+
+ /// Full pathname of the butterflow executable file.
+ private Lazy executablePath = new Lazy(() => Path.Combine(Assembly.GetExecutingAssembly().Location, "ThirdPartyCompiled", "butterflow.exe"));
+
+ #endregion
+
+ #region Methods
+
+ /// Runs butterflow with the given .
+ /// The options configuration.
+ public void Run(OptionsConfiguration optionsConfiguration)
+ {
+ string arguments = optionsConfiguration.ToButterflowArguments();
+
+ Run(arguments);
+ }
+
+ public void Probe(string videoFile)
+ {
+ string arguments = string.Format("-prb \"{0}\"", videoFile);
+ }
+
+ /// Runs butterflow with the given .
+ /// Options for controlling the operation.
+ private void Run(string arguments)
+ {
+ var processStartInfo = new ProcessStartInfo(executablePath.Value, arguments);
+
+ processStartInfo.CreateNoWindow = true;
+ processStartInfo.UseShellExecute = false;
+ processStartInfo.RedirectStandardOutput = true;
+ }
+
+ #endregion
+ }
+}
diff --git a/butterflow-ui/Icons.xaml b/butterflow-ui/Icons.xaml
index 2126e1c..bd141f6 100644
--- a/butterflow-ui/Icons.xaml
+++ b/butterflow-ui/Icons.xaml
@@ -31,4 +31,85 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/butterflow-ui/MainWindow.xaml b/butterflow-ui/MainWindow.xaml
index 4c00cce..df8c327 100644
--- a/butterflow-ui/MainWindow.xaml
+++ b/butterflow-ui/MainWindow.xaml
@@ -11,9 +11,21 @@
diff --git a/butterflow-ui/MainWindow.xaml.cs b/butterflow-ui/MainWindow.xaml.cs
index 662827b..dd64c5d 100644
--- a/butterflow-ui/MainWindow.xaml.cs
+++ b/butterflow-ui/MainWindow.xaml.cs
@@ -21,6 +21,13 @@ namespace butterflow_ui
///
public partial class MainWindow : Window
{
+ #region Members
+
+ /// True if the media element is playing a video, false if not.
+ private bool isPlaying = false;
+
+ #endregion
+
#region Properties
/// Gets or sets the butyterflow options configuration.
@@ -47,11 +54,12 @@ namespace butterflow_ui
var result = ofd.ShowDialog(this);
if (result.HasValue && result.Value)
{
- txtFileName.Text = ofd.FileName;
- mediaPreview.Source = new Uri(ofd.FileName);
- this.OptionsConfiguration.Width = mediaPreview.NaturalVideoWidth.ToString();
- this.OptionsConfiguration.Height = mediaPreview.NaturalVideoHeight.ToString();
+ this.OptionsConfiguration.VideoInput = ofd.FileName;
+ //Hack to get the first frame to display in the media preview element.
+ //This also triggers the MediaOpened event so we can get the metadata from the element.
+ mediaPreview.Play();
+ mediaPreview.Pause();
}
}
@@ -68,5 +76,70 @@ namespace butterflow_ui
this.OptionsConfiguration.PlaybackRate = tag;
}
}
+
+ /// Event handler. Called by bntVideoPlay for click events.
+ /// Source of the event.
+ /// Routed event information.
+ private void bntVideoPlay_Click(object sender, RoutedEventArgs e)
+ {
+ if (!this.isPlaying && this.mediaPreview.Source.IsFile)
+ {
+ this.isPlaying = true;
+ this.mediaPreview.Play();
+
+ this.PlayPauseButtonIcon.Template = Application.Current.Resources["PauseIcon"] as ControlTemplate;
+ }
+ else
+ {
+ this.isPlaying = false;
+ this.mediaPreview.Pause();
+
+ this.PlayPauseButtonIcon.Template = Application.Current.Resources["PlayIcon"] as ControlTemplate;
+ }
+ }
+
+ /// Event handler. Called by bntVideoStop for click events.
+ /// Source of the event.
+ /// Routed event information.
+ private void bntVideoStop_Click(object sender, RoutedEventArgs e)
+ {
+ this.isPlaying = false;
+ this.PlayPauseButtonIcon.Template = Application.Current.Resources["PlayIcon"] as ControlTemplate;
+ this.mediaPreview.Stop();
+ }
+
+ /// Event handler. Called by bntVideoForward for click events.
+ /// Source of the event.
+ /// Routed event information.
+ private void bntVideoForward_Click(object sender, RoutedEventArgs e)
+ {
+ this.mediaPreview.Position.Add(TimeSpan.FromSeconds(5));
+ }
+
+ /// Event handler. Called by bntVideoBackward for click events.
+ /// Source of the event.
+ /// Routed event information.
+ private void bntVideoBackward_Click(object sender, RoutedEventArgs e)
+ {
+ this.mediaPreview.Position.Subtract(TimeSpan.FromSeconds(5));
+ }
+
+ /// Event handler. Called by mediaPreview for media opened events.
+ /// Source of the event.
+ /// Routed event information.
+ private void mediaPreview_MediaOpened(object sender, RoutedEventArgs e)
+ {
+ this.OptionsConfiguration.Width = this.mediaPreview.NaturalVideoWidth.ToString();
+ this.OptionsConfiguration.Height = this.mediaPreview.NaturalVideoHeight.ToString();
+ }
+
+ /// Event handler. Called by mediaPreview for media ended events.
+ /// Source of the event.
+ /// Routed event information.
+ private void mediaPreview_MediaEnded(object sender, RoutedEventArgs e)
+ {
+ this.isPlaying = false;
+ this.PlayPauseButtonIcon.Template = Application.Current.Resources["PlayIcon"] as ControlTemplate;
+ }
}
}
diff --git a/butterflow-ui/OptionsConfiguration.cs b/butterflow-ui/OptionsConfiguration.cs
index ff14b80..3a6e0ce 100644
--- a/butterflow-ui/OptionsConfiguration.cs
+++ b/butterflow-ui/OptionsConfiguration.cs
@@ -18,18 +18,32 @@ namespace butterflow_ui
/// Occurs when a property value changes.
public event PropertyChangedEventHandler PropertyChanged;
+ /// An interpreter used to ensure numeric input is correctly calculated.
private InputInterpreter interpreter = new InputInterpreter();
private string playbackRate;
private bool keepAudio;
private int width;
private int height;
+ private bool keepAspectRatio;
private bool losslessQuality;
+ private string videoInput;
+ private string videoOutput;
#endregion
#region Properties
+ /// Gets the command line output given the current configuration.
+ /// The command line output.
+ public string CommandLineOutput
+ {
+ get
+ {
+ return ToButterflowArguments();
+ }
+ }
+
/// Gets or sets the playback rate.
/// The playback rate.
public string PlaybackRate
@@ -60,8 +74,8 @@ namespace butterflow_ui
}
}
- /// Gets or sets the width.
- /// The width.
+ /// Gets or sets the width of the video output.
+ /// The width of the video output.
public string Width
{
get
@@ -76,8 +90,8 @@ namespace butterflow_ui
}
}
- /// Gets or sets the height.
- /// The height.
+ /// Gets or sets the height of the video output.
+ /// The height of the video output.
public string Height
{
get
@@ -92,6 +106,21 @@ namespace butterflow_ui
}
}
+ /// Gets or sets a value indicating whether the keep aspect ratio of the input video file for the output video file.
+ /// True if keep aspect ratio, false if not.
+ public bool KeepAspectRatio
+ {
+ get
+ {
+ return this.keepAspectRatio;
+ }
+ set
+ {
+ this.keepAspectRatio = value;
+ OnPropertyChanged("KeepAspectRatio");
+ }
+ }
+
/// Gets or sets a value indicating whether the result is rendered in lossless quality.
/// True if lossless quality is selected, false if not.
public bool LosslessQuality
@@ -107,6 +136,36 @@ namespace butterflow_ui
}
}
+ /// Gets or sets the video input file path.
+ /// The video input file path.
+ public string VideoInput
+ {
+ get
+ {
+ return this.videoInput;
+ }
+ set
+ {
+ this.videoInput = value;
+ OnPropertyChanged("VideoInput");
+ }
+ }
+
+ /// Gets or sets the video output file path.
+ /// The video output file path.
+ public string VideoOutput
+ {
+ get
+ {
+ return this.videoOutput;
+ }
+ set
+ {
+ this.videoOutput = value;
+ OnPropertyChanged("VideoOutput");
+ }
+ }
+
#endregion
#region Methods
@@ -116,6 +175,39 @@ namespace butterflow_ui
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CommandLineOutput"));
+ }
+
+ /// Converts this object to a butterflow options.
+ /// This object as a string.
+ public string ToButterflowArguments()
+ {
+ var stringBuilder = new StringBuilder("-v "); //Verbose
+
+ if(this.KeepAspectRatio)
+ {
+ stringBuilder.AppendFormat("-vs {0}:-1 ", this.Width);
+ }
+ else
+ {
+ stringBuilder.AppendFormat("-vs {0}:{1} ", this.Width, this.Height);
+ }
+
+ stringBuilder.AppendFormat("-r {0} ", this.PlaybackRate);
+
+ if (this.KeepAudio) stringBuilder.Append("-audio ");
+ if (this.LosslessQuality) stringBuilder.Append("-l ");
+
+ stringBuilder.AppendFormat("\"{0}\"", this.VideoInput);
+
+ return stringBuilder.ToString();
+ }
+
+ /// Returns a string that represents the current object.
+ /// A string that represents the current object.
+ public override string ToString()
+ {
+ return ToButterflowArguments();
}
#endregion
diff --git a/butterflow-ui/butterflow-ui.csproj b/butterflow-ui/butterflow-ui.csproj
index c35472f..efb304f 100644
--- a/butterflow-ui/butterflow-ui.csproj
+++ b/butterflow-ui/butterflow-ui.csproj
@@ -74,6 +74,7 @@
Code
+
True
True
@@ -267,4 +268,7 @@
+
+ XCOPY "$(SolutionDir)\ThirdPartyCompiled" "$(TargetDir)\ThirdPartyCompiled\" /S /Y
+
\ No newline at end of file