Skip to content

Commit 9c70d3e

Browse files
author
RandomEngy
committed
Fix logging threading issue, implement two-pass encoding, fix x264 options string getting fried before it could be used by the encode process.
1 parent 9efe840 commit 9c70d3e

6 files changed

Lines changed: 101 additions & 3 deletions

File tree

Lib/HandBrakeInterop.dll

1 KB
Binary file not shown.

Lib/HandBrakeInterop.pdb

0 Bytes
Binary file not shown.

VidCoder/Model/Logger.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public string LogText
3636
{
3737
get
3838
{
39-
return logBuilder.ToString();
39+
lock (this.logLock)
40+
{
41+
return logBuilder.ToString();
42+
}
4043
}
4144
}
4245

VidCoder/View/EncodingWindow.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@
486486
Text="{Binding QualitySliderLeftText}"/>
487487
<TextBlock Height="21" HorizontalAlignment="Right" Margin="0,149,6,0" VerticalAlignment="Top" Width="93" TextAlignment="Right"
488488
Text="{Binding QualitySliderRightText}"/>
489+
<CheckBox
490+
Content="2-pass Encoding"
491+
Height="16" HorizontalAlignment="Left" Margin="124,112,0,0" VerticalAlignment="Top"
492+
IsChecked="{Binding TwoPassEncoding}"
493+
IsEnabled="{Binding TwoPassEncodingEnabled}"/>
494+
<CheckBox
495+
Content="Turbo first Pass"
496+
Height="16" HorizontalAlignment="Left" Margin="145,135,0,0" VerticalAlignment="Top"
497+
IsChecked="{Binding TurboFirstPass}"
498+
IsEnabled="{Binding TurboFirstPassEnabled}"/>
489499
</Grid>
490500
</TabItem>
491501
<TabItem Header="Audio">

VidCoder/ViewModel/EncodingViewModel.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,59 @@ public double SelectedFramerate
14171417
}
14181418
}
14191419

1420+
public bool TwoPassEncoding
1421+
{
1422+
get
1423+
{
1424+
return this.profile.TwoPass;
1425+
}
1426+
1427+
set
1428+
{
1429+
this.profile.TwoPass = value;
1430+
this.NotifyPropertyChanged("TwoPassEncoding");
1431+
this.NotifyPropertyChanged("TurboFirstPass");
1432+
this.NotifyPropertyChanged("TurboFirstPassEnabled");
1433+
this.IsModified = true;
1434+
}
1435+
}
1436+
1437+
public bool TwoPassEncodingEnabled
1438+
{
1439+
get
1440+
{
1441+
return this.VideoEncodeRateType != VideoEncodeRateType.ConstantQuality;
1442+
}
1443+
}
1444+
1445+
public bool TurboFirstPass
1446+
{
1447+
get
1448+
{
1449+
if (!this.TwoPassEncoding)
1450+
{
1451+
return false;
1452+
}
1453+
1454+
return profile.TurboFirstPass;
1455+
}
1456+
1457+
set
1458+
{
1459+
this.profile.TurboFirstPass = value;
1460+
this.NotifyPropertyChanged("TurboFirstPass");
1461+
this.IsModified = true;
1462+
}
1463+
}
1464+
1465+
public bool TurboFirstPassEnabled
1466+
{
1467+
get
1468+
{
1469+
return this.VideoEncodeRateType != VideoEncodeRateType.ConstantQuality && this.TwoPassEncoding;
1470+
}
1471+
}
1472+
14201473
public VideoEncodeRateType VideoEncodeRateType
14211474
{
14221475
get
@@ -1447,8 +1500,18 @@ public VideoEncodeRateType VideoEncodeRateType
14471500
default:
14481501
break;
14491502
}
1503+
1504+
// Disable two-pass options
1505+
1506+
this.profile.TwoPass = false;
1507+
this.profile.TurboFirstPass = false;
1508+
this.NotifyPropertyChanged("TwoPassEncoding");
1509+
this.NotifyPropertyChanged("TurboFirstPass");
14501510
}
14511511

1512+
this.NotifyPropertyChanged("TwoPassEncodingEnabled");
1513+
this.NotifyPropertyChanged("TurboFirstPassEnabled");
1514+
14521515
if (value == VideoEncodeRateType.AverageBitrate)
14531516
{
14541517
this.VideoBitrate = 1200;
@@ -2459,6 +2522,10 @@ private void NotifyAllChanged()
24592522
this.NotifyPropertyChanged("DeblockText");
24602523
this.NotifyPropertyChanged("Grayscale");
24612524
this.NotifyPropertyChanged("SelectedFramerate");
2525+
this.NotifyPropertyChanged("TwoPassEncoding");
2526+
this.NotifyPropertyChanged("TurboFirstPass");
2527+
this.NotifyPropertyChanged("TwoPassEncodingEnabled");
2528+
this.NotifyPropertyChanged("TurboFirstPassEnabled");
24622529
this.NotifyPropertyChanged("VideoEncodeRateType");
24632530
this.NotifyPropertyChanged("TargetSize");
24642531
this.NotifyPropertyChanged("VideoBitrate");

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public MainViewModel()
102102

103103
this.logger = new Logger();
104104

105-
this.updateService.HandlePendingUpdate();
106105
this.updateService = ServiceFactory.UpdateService;
106+
this.updateService.HandlePendingUpdate();
107107
this.updateService.CheckUpdates();
108108

109109
List<Preset> presets = new List<Preset>();
@@ -1661,6 +1661,12 @@ public void StartEncodeQueue()
16611661
foreach (EncodeJobViewModel jobVM in this.EncodeQueue)
16621662
{
16631663
this.totalQueueTime += jobVM.Job.Length;
1664+
1665+
// Add the job length twice for two-pass encoding.
1666+
if (jobVM.Job.EncodingProfile.TwoPass)
1667+
{
1668+
this.totalQueueTime += jobVM.Job.Length;
1669+
}
16641670
}
16651671

16661672
this.OverallEncodeProgressFraction = 0;
@@ -1715,7 +1721,14 @@ private void OnEncodeProgress(object sender, EncodeProgressEventArgs e)
17151721
return;
17161722
}
17171723

1718-
double completedSeconds = this.completedQueueTime.TotalSeconds + this.EncodeQueue[0].Job.Length.TotalSeconds * e.FractionComplete;
1724+
double currentJobLengthSeconds = this.EncodeQueue[0].Job.Length.TotalSeconds;
1725+
1726+
double completedSeconds = this.completedQueueTime.TotalSeconds + currentJobLengthSeconds * e.FractionComplete;
1727+
if (e.Pass == 2)
1728+
{
1729+
completedSeconds += currentJobLengthSeconds;
1730+
}
1731+
17191732
this.OverallEncodeProgressFraction = completedSeconds / this.totalQueueTime.TotalSeconds;
17201733

17211734
this.EncodeQueue[0].PercentComplete = (int)(e.FractionComplete * 100);
@@ -1756,6 +1769,11 @@ private void OnEncodeCompleted(object sender, EventArgs e)
17561769
{
17571770
// If the encode completed successfully
17581771
this.completedQueueTime += this.EncodeQueue[0].Job.Length;
1772+
if (this.EncodeQueue[0].Job.EncodingProfile.TwoPass)
1773+
{
1774+
this.completedQueueTime += this.EncodeQueue[0].Job.Length;
1775+
}
1776+
17591777
HandBrakeInstance finishedInstance = this.EncodeQueue[0].HandBrakeInstance;
17601778
this.EncodeQueue.RemoveAt(0);
17611779

0 commit comments

Comments
 (0)