Skip to content

Commit

Permalink
v0.9-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoDePasquale committed Apr 9, 2020
1 parent a0c187d commit dca89a1
Show file tree
Hide file tree
Showing 21 changed files with 1,236 additions and 455 deletions.
95 changes: 90 additions & 5 deletions FF Video Converter/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Threading.Tasks;


namespace FFVideoConverter
{
public static class ClassExtensions
Expand Down Expand Up @@ -80,7 +81,7 @@ public static void Resume(this Process process)
#region HttpClient

//Asynchroniously downloads a remote file into a stream, with progress reporting
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destination, IProgress<(float, long, long)> progress)
public static async Task DownloadAsync(this HttpClient client, string requestUri, Stream destinationStream, IProgress<(float, long, long)> progress)
{
using (HttpResponseMessage response = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
{
Expand All @@ -93,7 +94,8 @@ public static async Task DownloadAsync(this HttpClient client, string requestUri
using (Stream downloadStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
var relativeProgress = new Progress<long>(currentBytes => progress.Report(((float)currentBytes / totalBytes, currentBytes, totalBytes)));
await downloadStream.CopyToAsync(destination, relativeProgress).ConfigureAwait(false);
await downloadStream.CopyToAsync(destinationStream, relativeProgress).ConfigureAwait(false);
destinationStream.Close(); //Necessary to allow the updater to extract the archive
progress.Report((1f, totalBytes, totalBytes));
}
}
Expand All @@ -102,17 +104,17 @@ public static async Task DownloadAsync(this HttpClient client, string requestUri
//Asynchroniously copies a stream into another, with progress reporting
public static async Task CopyToAsync(this Stream source, Stream destination, IProgress<long> progress)
{
var buffer = new byte[40960];
var buffer = new byte[8192];
long totalBytesRead = 0;
int bytesRead;
Stopwatch sw = new Stopwatch(); //Used to report progress every 200 milliseconds
Stopwatch sw = new Stopwatch();

sw.Start();
while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) != 0)
{
await destination.WriteAsync(buffer, 0, bytesRead).ConfigureAwait(false);
totalBytesRead += bytesRead;
if (sw.ElapsedMilliseconds > 500)
if (sw.ElapsedMilliseconds > 500) //Reports progress only every 500 milliseconds
{
sw.Restart();
progress.Report(totalBytesRead);
Expand All @@ -122,5 +124,88 @@ public static async Task CopyToAsync(this Stream source, Stream destination, IPr
}

#endregion

#region ToString

public static string ToBytesString(this long l)
{
string suffix;
double readable;

if (l >= 0x10000000000) // Terabyte
{
suffix = "TB";
readable = l >> 30;
}
else if (l >= 0x40000000) // Gigabyte
{
suffix = "GB";
readable = l >> 20;
}
else if (l >= 0x100000) // Megabyte
{
suffix = "MB";
readable = l >> 10;
}
else if (l >= 0x400) // Kilobyte
{
suffix = "KB";
readable = l;
}
else
{
return l.ToString("0 B"); // Byte
}
// Divide by 1024 to get fractional value
readable = (readable / 1024);
// Return formatted number with suffix
return readable.ToString("0.## ") + suffix;
}

public static string GetName(this Quality quality)
{
switch (quality)
{
case Quality.Best:
return "Best";
case Quality.VeryGood:
return "Very good";
case Quality.Good:
return "Good";
case Quality.Medium:
return "Medium";
case Quality.Low:
return "Low";
case Quality.VeryLow:
return "Very low";
default:
return "";
}
}

public static string GetName(this Preset preset)
{
switch (preset)
{
case Preset.VerySlow:
return "Very slow";
case Preset.Slower:
return "Slower";
case Preset.Slow:
return "Slow";
case Preset.Medium:
return "Medium";
case Preset.Fast:
return "Fast";
case Preset.Faster:
return "Faster";
case Preset.VeryFast:
return "Very fast";
default:
return "";
}
}

#endregion
}
}
29 changes: 16 additions & 13 deletions FF Video Converter/ComparisonWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FFVideoConverter"
xmlns:ffme="clr-namespace:Unosquare.FFME;assembly=ffme.win"
Title="Quality comparison" Height="1005" Width="1600" WindowStartupLocation="CenterScreen" Style="{StaticResource BlurWindowStyle}">
Title="Quality comparison" Height="1005" Width="1600" WindowStartupLocation="CenterScreen" Style="{StaticResource BlurWindowStyle}" Loaded="Window_Loaded">

<Window.Resources>
<Storyboard x:Key="ProgressAnimationIn">
Expand All @@ -14,10 +14,13 @@
<SplineThicknessKeyFrame KeyTime="00:00:00.3" Value="0, -25, 0, 25" />
</ThicknessAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="progressBarPreview" BeginTime="00:00:00">
<SplineThicknessKeyFrame KeyTime="00:00:00.3" Value="225,12,0,0" />
<SplineThicknessKeyFrame KeyTime="00:00:00.3" Value="225,12,150,0" />
</ThicknessAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="textBlockPreviewBuildProgress" BeginTime="00:00:00">
<SplineThicknessKeyFrame KeyTime="00:00:00.3" Value="76,0,0,14" />
</ThicknessAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="textBlockPreviewTimespan" BeginTime="00:00:00">
<SplineThicknessKeyFrame KeyTime="00:00:00" Value="76,0,0,14" />
<SplineThicknessKeyFrame KeyTime="00:00:00.3" Value="0,0,150,-29" />
</ThicknessAnimationUsingKeyFrames>
</Storyboard>

Expand All @@ -31,7 +34,7 @@
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="progressBarPreview" BeginTime="00:00:00">
<SplineThicknessKeyFrame KeyTime="00:00:00.3" Value="225,49,0,-29" />
</ThicknessAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="textBlockPreviewTimespan" BeginTime="00:00:00">
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="textBlockPreviewBuildProgress" BeginTime="00:00:00">
<SplineThicknessKeyFrame KeyTime="00:00:00" Value="87,0,0,14" />
</ThicknessAnimationUsingKeyFrames>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="comboBoxQuality" BeginTime="00:00:00">
Expand All @@ -48,12 +51,11 @@

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="900"/>
<RowDefinition Height="900*"/>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<Grid x:Name="gridTitlebar" Grid.Row="1" Background="#7F060606" MouseDown="Grid_MouseDown">
<Grid x:Name="gridTitlebar" Grid.Row="0" Background="#7F060606" MouseDown="Grid_MouseDown">
<Button x:Name="buttonClose" Content="_X" Height="30" VerticalAlignment="Top" Click="ButtonClose_Click" FontWeight="Bold" FontSize="15" Style="{StaticResource TitleBarButton}" HorizontalAlignment="Right" Width="30" Foreground="#FFC12222"/>
<Label x:Name="labelTitle" Content="Encoding quality comparison" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FFCBCBCB" Background="{x:Null}" FontSize="16" FontWeight="DemiBold" Height="32"/>
<Label x:Name="labelLoading" Content="Generating previews " Margin="0,25,0,-25" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FFCBCBCB" Background="{x:Null}" FontSize="16" FontWeight="DemiBold" Height="32">
Expand All @@ -73,7 +75,7 @@
</Label.Triggers>
</Label>
</Grid>
<Grid x:Name="gridComparison" Grid.Row="2" Margin="0,0,0,1">
<Grid x:Name="gridComparison" Grid.Row="1" Margin="0,0,0,1">
<Grid.Effect>
<BlurEffect x:Name="blurEffect" RenderingBias="Performance" Radius="0"/>
</Grid.Effect>
Expand All @@ -90,16 +92,17 @@
<TextBlock x:Name="textBlockConverted" Visibility="Hidden" HorizontalAlignment="Right" TextWrapping="Wrap" Text="Converted" VerticalAlignment="Top" Background="#99000000" Height="30" Width="85" Padding="6"/>
<Slider x:Name="sliderComparison" Visibility="Hidden" Maximum="1" SmallChange="0.01" TickFrequency="0.01" Style="{StaticResource ComparisonSlider}" Value="0.5" Height="{Binding ActualHeight, ElementName=gridComparison, Mode=OneWay}"/>
</Grid>
<Grid x:Name="gridControls" Grid.Row="3">
<Grid x:Name="gridControls" Grid.Row="2">
<ComboBox MaxDropDownHeight="600" x:Name="comboBoxQuality" HorizontalAlignment="Left" Height="24" Margin="142,49,0,-28" VerticalAlignment="Top" Width="167" SelectionChanged="ComboBoxQuality_SelectionChanged" ToolTipService.ShowDuration="20000" ToolTip="A lower value gives higher quality but with a larger file size.&#x0a;The progress is exponential, so increasing this value by 6 results in roughly half the file size.&#x0a;&#x0a;Choose the highest CRF value that still provides an acceptable quality:&#x0a;if the output looks good try a higher value, if it looks bad, choose a lower value."/>
<Slider x:Name="sliderPreview" Margin="54,0,388,7" Minimum="0" Height="25" VerticalAlignment="Bottom" IsMoveToPointEnabled="True" ValueChanged="SliderPreview_ValueChanged" Thumb.DragStarted="SliderPreview_DragStarted" Thumb.DragCompleted="SliderPreview_DragCompleted"/>
<CheckBox x:Name="checkBoxZoom" Content="Fit to window" VerticalAlignment="Top" Margin="0,48,18,-29" Checked="CheckBoxZoom_Checked" Unchecked="CheckBoxZoom_Unchecked" IsChecked="True" HorizontalAlignment="Right" Width="110"/>
<Button x:Name="buttonCreatePreview" Content="Create preview" Height="30" Margin="0,0,10,8" VerticalAlignment="Bottom" Click="ButtonCreatePreview_Click" HorizontalAlignment="Right" Width="128"/>
<TextBlock x:Name="textBlockPreviewTimespan" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Preview timespan: 00:00:00 - 00:00:00" VerticalAlignment="Bottom" Margin="1220,0,0,14" Width="223" IsHitTestVisible="False"/>
<ProgressBar x:Name="progressBarPreview" Margin="225,49,0,-29" Height="25" VerticalAlignment="Top" HorizontalAlignment="Left" Width="1218"/>
<TextBlock x:Name="textBlockPreviewTimespan" HorizontalAlignment="Right" TextWrapping="Wrap" Text="Preview timespan: 00:00:00 - 00:00:00" VerticalAlignment="Bottom" Margin="0,0,151,14" Width="223" IsHitTestVisible="False"/>
<TextBlock x:Name="textBlockPreviewBuildProgress" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Bottom" Margin="76,0,0,-25" Width="223" IsHitTestVisible="False"/>
<ProgressBar x:Name="progressBarPreview" Margin="225,49,150,-29" Height="25" VerticalAlignment="Top"/>
<Button x:Name="buttonPlayPause" Content=" ▶️" FontSize="16" HorizontalAlignment="Left" Style="{StaticResource RoundedButton}" Margin="10,0,0,4" Width="34" Click="ButtonPlayPause_Click" Padding="0,0,2,1" Height="35" VerticalAlignment="Bottom"/>
<Button x:Name="buttonNextFrame" Content="Next frame" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="128" Margin="0,0,469,-37" Click="ButtonNextFrame_Click"/>
<Button x:Name="buttonPreviousFrame" Content="Previous frame" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="128" Margin="0,0,946,-37" Click="ButtonPreviousFrame_Click"/>
<Button x:Name="buttonNextFrame" Content="Next frame" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="128" Margin="0,0,646,-59" Click="ButtonNextFrame_Click"/>
<Button x:Name="buttonPreviousFrame" Content="Previous frame" Height="30" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="128" Margin="0,0,921,-59" Click="ButtonPreviousFrame_Click"/>
</Grid>
</Grid>
</Window>
Loading

0 comments on commit dca89a1

Please sign in to comment.