-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.xaml.cs
104 lines (95 loc) · 2.97 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Input;
namespace BatchEncoder
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
var ver = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
Window.Title += $" - {ver.ProductVersion}";
MainWindow_OnOptionChanged(null, null);
Application.Current.Exit += OnExit;
}
void MainWindow_OnOptionChanged(object sender, EventArgs eventArgs)
{
var settings = new EncodeSettings
{
input = "input.mp4",
videoCodec = VideoCodec.Text,
videoBitrate = VideoBitrate.Text,
videoMaxrate = VideoMaxBitrate.Text,
framerate = Framerate.Text,
videoSize = (string.IsNullOrEmpty(VideoWidth.Text) || string.IsNullOrEmpty(VideoHeight.Text)) ? "" : $"{VideoWidth.Text}x{VideoHeight.Text}",
yuv420p = YUV420P.IsChecked == true,
simultaneously = Simultaneously.IsChecked == true,
audioCodec = AudioCodec.Text,
audioBitrate = AudioBitrate.Text,
startSec = StartSec.Text,
duration = Duration.Text,
concatenate = Concatenate.IsChecked == true,
output = "output.mp4"
};
var arguments = MovieEncoder.CreateArguments(settings);
CommandPreview.Text = "ffmpeg " + arguments;
}
void MainWindow_OnDragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effects = DragDropEffects.All;
}
else
{
e.Effects = DragDropEffects.None;
}
}
void MainWindow_OnDrop(object sender, DragEventArgs e)
{
var files = (string[]) e.Data.GetData(DataFormats.FileDrop, false);
var queue = new Queue<EncodeSettings>();
foreach (var file in files)
{
if (ExtensionChecker.IsUnsupportedExtension(file)) continue;
var settings = new EncodeSettings
{
input = file,
videoCodec = VideoCodec.Text,
videoBitrate = VideoBitrate.Text,
videoMaxrate = VideoMaxBitrate.Text,
framerate = Framerate.Text,
videoSize = (string.IsNullOrEmpty(VideoWidth.Text) || string.IsNullOrEmpty(VideoHeight.Text)) ? "" : $"{VideoWidth.Text}x{VideoHeight.Text}",
yuv420p = YUV420P.IsChecked == true,
simultaneously = Simultaneously.IsChecked == true,
audioCodec = AudioCodec.Text,
audioBitrate = AudioBitrate.Text,
startSec = StartSec.Text,
duration = Duration.Text,
concatenate = Concatenate.IsChecked == true,
output = file
};
queue.Enqueue(settings);
}
MovieEncoder.AddQueue(queue, Concatenate.IsChecked == true);
}
void CheckTextContainsNumber(object sender, TextCompositionEventArgs e)
{
var regex = new Regex("[^0-9.-]+");
e.Handled = regex.IsMatch(StartSec.Text + e.Text);
}
void OnExit(object sender, ExitEventArgs e)
{
MovieEncoder.RemoveConcatFile();
Application.Current.Exit -= OnExit;
}
}
}