blob: a285e490b770b8db9182bee52fef1d1b44489dd4 (
plain)
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
105
106
107
108
109
110
111
112
113
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="VideoView.xaml.cs" company="HandBrake Project (http://handbrake.fr)">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// Interaction logic for VideoView.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Views
{
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Caliburn.Micro;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Utilities;
using HandBrake.Interop.Model.Encoding;
using HandBrakeWPF.ViewModels;
using HandBrakeWPF.ViewModels.Interfaces;
/// <summary>
/// Interaction logic for VideoView.xaml
/// </summary>
public partial class VideoView : UserControl
{
/// <summary>
/// Initializes a new instance of the <see cref="VideoView"/> class.
/// </summary>
public VideoView()
{
InitializeComponent();
}
private void qsv_preset_radiobutton(object sender, System.Windows.RoutedEventArgs e)
{
qsv_preset_ValueChanged(sender, null);
}
private void qsv_preset_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
VideoViewModel mvm = ((VideoViewModel)this.DataContext);
EncodeTask task = mvm.Task;
string addon = "";
if (SystemInfo.IsHswOrNewer)
{
if (task.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality)
{
if (task.QsvPreset == QsvPreset.Balanced ||
task.QsvPreset == QsvPreset.Speed)
addon = "num-ref-frame=1";
}
if (task.VideoEncodeRateType == VideoEncodeRateType.AverageBitrate)
{
if (task.QsvPreset == QsvPreset.Quality)
addon = "lookahead=1:gop-ref-dist=3";
else
if (task.QsvPreset == QsvPreset.Balanced)
{
addon = "num-ref-frame=1:gop-ref-dist=1";
}
else
if (task.QsvPreset == QsvPreset.Speed)
addon = "gop-ref-dist=1";
}
}
string full_string = addon + ":";
IDictionary<string, string> newOptions = new Dictionary<string, string>();
string[] existingSegments = full_string.Split(':');
foreach (string existingSegment in existingSegments)
{
string optionName = existingSegment;
string optionValue = string.Empty;
int equalsIndex = existingSegment.IndexOf('=');
if (equalsIndex >= 0)
{
optionName = existingSegment.Substring(
0, existingSegment.IndexOf("=", System.StringComparison.Ordinal));
optionValue = existingSegment.Substring(equalsIndex);
}
if (optionName != string.Empty)
{
if (newOptions.ContainsKey(optionName))
newOptions.Remove(optionName);
newOptions.Add(optionName, optionValue);
}
}
full_string = "";
foreach (KeyValuePair<string, string> entry in newOptions)
{
full_string += entry.Key;
if (entry.Value != string.Empty)
full_string += entry.Value;
full_string += ":";
}
full_string = full_string.TrimEnd(':');
task.AdvancedEncoderOptions = full_string;
task.NotifyOfPropertyChange(() => task.AdvancedEncoderOptions);
}
}
}
|