Skip to content

Commit

Permalink
v1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoDePasquale committed Jan 23, 2021
1 parent 2749438 commit 1bcbbab
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 29 deletions.
9 changes: 5 additions & 4 deletions FF Video Converter/FFmpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async void Convert(MediaInfo sourceInfo, string outputPath, ConversionOpt
progressData = new ProgressData();
previousProgressData = new ProgressData();

//Capture the Synchronization Context of the caller, in order to invoke the events on its original thread
//Capture the Synchronization Context of the caller, in order to invoke the events in its original thread
synchronizationContext = SynchronizationContext.Current;

//Duration
Expand Down Expand Up @@ -100,7 +100,7 @@ public async void Convert(MediaInfo sourceInfo, string outputPath, ConversionOpt
}
else if (conversionOptions.EncodeSections.Count == 1)
{
await RunConversionProcess(BuildArgumentsString(sourceInfo, outputPath, conversionOptions, conversionOptions.EncodeSections.ActualStart, conversionOptions.EncodeSections.ActualEnd, true, true)).ConfigureAwait(false);
await RunConversionProcess(BuildArgumentsString(sourceInfo, outputPath, conversionOptions, conversionOptions.EncodeSections.ActualStart, conversionOptions.EncodeSections.ActualEnd, conversionOptions.FadeEffect, conversionOptions.FadeEffect)).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -391,11 +391,12 @@ public void StopConversion()
{
try
{
if (convertProcess != null && !convertProcess.HasExited)
if (convertProcess != null)
{
stopped = true;
convertProcess.Kill();
convertProcess.CancelOutputRead();
convertProcess.CancelErrorRead();
convertProcess.Kill();
}
}
catch (Exception)
Expand Down
2 changes: 1 addition & 1 deletion FF Video Converter/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
<TextBlock HorizontalAlignment="Left" Text="Destination" VerticalAlignment="Top" Margin="10,4,0,0"/>
</Grid>

<TabControl HorizontalAlignment="Left" Height="211" Margin="10,304,0,0" Grid.Row="1" VerticalAlignment="Top" Width="827" >
<TabControl HorizontalAlignment="Left" Height="211" Margin="10,304,0,0" Grid.Row="1" VerticalAlignment="Top" Width="827" SelectionChanged="TabControl_SelectionChanged">
<TabItem Header="Encode">
<Grid x:Name="gridVideoSettings">
<TextBlock HorizontalAlignment="Left" Text="Encoder" Margin="12,11,0,0" Foreground="{StaticResource TextColorBlue}" FontSize="14" Height="19" VerticalAlignment="Top" />
Expand Down
48 changes: 39 additions & 9 deletions FF Video Converter/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private enum HitLocation
None, Body, UpperLeft, UpperRight, LowerRight, LowerLeft, Left, Right, Top, Bottom
};

static readonly string[] SUPPORTED_EXTENSIONS = { ".mkv", ".mp4", ".m4v", ".avi", ".webm" };
static readonly string[] SUPPORTED_EXTENSIONS = { ".mkv", ".mp4", ".m4v", ".avi", ".webm", ".gif"};
readonly FFmpegEngine ffmpegEngine;
readonly QueueWindow queueWindow;
readonly CompletedWindow completedWindow;
Expand Down Expand Up @@ -121,9 +121,10 @@ public MainWindow()
queueWindow.QueueStarted += () =>
{
//If there are no jobs running, start the next one
if ((runningJob == null || (runningJob.State != JobState.Running && runningJob.State == JobState.Paused)) && queuedJobs.Count > 0)
if ((runningJob == null || (runningJob.State != JobState.Running && runningJob.State != JobState.Paused)) && queuedJobs.Count > 0)
{
RunJob(queuedJobs[0]);
queueWindow.RunningJob = queuedJobs[0];
queuedJobs.RemoveAt(0);
}
};
Expand Down Expand Up @@ -197,15 +198,16 @@ private void OpenSource(string playerSource = null)
if (mediaInfo.IsLocal)
{
string extension = Path.GetExtension(sourcePath);
textBoxDestination.Text = sourcePath.Remove(sourcePath.LastIndexOf('.')) + " converted" + extension;
if (extension == ".mkv")
{
comboBoxFormat.SelectedIndex = 1;
}
else
{
extension = ".mp4";
comboBoxFormat.SelectedIndex = 0;
}
textBoxDestination.Text = sourcePath.Remove(sourcePath.LastIndexOf('.')) + " converted" + extension;
labelTitle.Content = Path.GetFileName(sourcePath);
}
else
Expand Down Expand Up @@ -707,6 +709,7 @@ private void ButtonConvert_Click(object sender, RoutedEventArgs e)
if (((Button)sender).Name == "buttonConvert" || (queueWindow.QueueActive && runningJob == null)) //If the queue is started but there are no conversion running, run this one directly instead of adding it to the queue
{
RunJob(job);
queueWindow.RunningJob = job;
}
else
{
Expand Down Expand Up @@ -761,7 +764,7 @@ private ConversionOptions GenerateConversionOptions(Encoder encoder)
{
conversionOptions.CropData = new CropData((short)integerTextBoxCropLeft.Value, (short)integerTextBoxCropTop.Value, (short)integerTextBoxCropRight.Value, (short)integerTextBoxCropBottom.Value);
}
else if (comboBoxResolution.SelectedIndex != 0)
if (comboBoxResolution.SelectedIndex != 0)
{
conversionOptions.Resolution = Resolution.FromString(comboBoxResolution.Text);
}
Expand Down Expand Up @@ -796,6 +799,7 @@ private ConversionOptions GenerateConversionOptions(Encoder encoder)

private async void RunJob(Job job)
{
job.State = JobState.Running;
runningJob = job;
ffmpegEngine.Convert(job.SourceInfo, job.Destination, job.ConversionOptions);

Expand Down Expand Up @@ -1053,20 +1057,24 @@ private void ButtonCancel_Click(object sender, RoutedEventArgs e)
runningJob.ConversionResults.Add(new ConversioResult("Resolution", runningJob.SourceInfo.Resolution.ToString()));
runningJob.ConversionResults.Add(new ConversioResult("Aspect ratio", runningJob.SourceInfo.Resolution.AspectRatio.ToString()));
runningJob.ConversionResults.Add(new ConversioResult("Size", runningJob.SourceInfo.Size.ToBytesString()));

completedJobs.Add(runningJob);

OnConversionEnded();
}
}

private void OnConversionEnded()
{
runningJob = null;
queueWindow.RunningJob = null;

if (queueWindow.QueueActive)
{
//Run next job, if present
if (queuedJobs.Count > 0)
{
RunJob(queuedJobs[0]);
queueWindow.RunningJob = queuedJobs[0];
queuedJobs.RemoveAt(0);
}
else
Expand Down Expand Up @@ -1701,11 +1709,33 @@ public enum EXECUTION_STATE : uint
#endregion

//CURRENTLY NOT USED
private void ButtonUpdateCommanLine_Click(object sender, RoutedEventArgs e)
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//string arguments = ffmpegEngine.BuildArgumentsString(mediaInfo, textBoxDestination.Text, conversionOptions);
//arguments = System.Text.RegularExpressions.Regex.Replace(arguments, " -(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", "\n-");
//textBoxCommandLine.Text = arguments;
/*if (tabItemAdvanced.IsSelected && mediaInfo != null)
{
Encoder encoder = (Encoder)comboBoxEncoder.SelectedItem;
encoder.Preset = (Preset)comboBoxPreset.SelectedIndex;
if (radioButtonBitrate.IsChecked == true)
{
int audioBitrate = 0;
foreach (var audioTrack in mediaInfo.AudioTracks)
{
if (audioTrack.Enabled) audioBitrate += audioTrack.Bitrate;
}
long desiredSize = (long)(mediaInfo.Size * sliderTargetSize.Value / 100);
int totalBitrate = (int)(desiredSize * 8 / mediaInfo.Duration.TotalSeconds);
encoder.Bitrate = (totalBitrate - audioBitrate) / 1000;
}
else
{
encoder.Quality = (Quality)comboBoxQuality.SelectedIndex;
}
ConversionOptions conversionOptions = GenerateConversionOptions(encoder);
string arguments = ffmpegEngine.BuildArgumentsString(mediaInfo, textBoxDestination.Text, conversionOptions);
arguments = System.Text.RegularExpressions.Regex.Replace(arguments, " -(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", "\n-");
textBoxCommandLine.Text = arguments;
}*/
}
}
}
22 changes: 13 additions & 9 deletions FF Video Converter/MediaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,21 @@ await Task.Run(() =>
if (audioStreamElements[i].TryGetProperty("sample_rate", out e))
sampleRate = Convert.ToInt32(e.GetString());
index = audioStreamElements[i].GetProperty("index").GetInt32();
JsonElement e2 = audioStreamElements[i].GetProperty("tags");
if (e2.TryGetProperty("language", out e))
language = e.GetString();
if (bitrate == 0)

if (audioStreamElements[i].TryGetProperty("tags", out JsonElement e2))
{
if (e2.TryGetProperty("BPS-eng", out e))
bitrate = Convert.ToInt32(e.GetString()); ;
if (e2.TryGetProperty("language", out e))
language = e.GetString();
if (bitrate == 0)
{
if (e2.TryGetProperty("BPS-eng", out e))
bitrate = Convert.ToInt32(e.GetString()); ;
}
e2 = audioStreamElements[i].GetProperty("disposition");
if (e2.TryGetProperty("default", out e))
defaultTrack = Convert.ToBoolean(e.GetByte());
}
e2 = audioStreamElements[i].GetProperty("disposition");
if (e2.TryGetProperty("default", out e))
defaultTrack = Convert.ToBoolean(e.GetByte());

audioTracks[i] = new AudioTrack(codec, bitrate, sampleRate, totalSeconds, index, language, defaultTrack);
Bitrate -= bitrate / 1000;
}
Expand Down
4 changes: 2 additions & 2 deletions FF Video Converter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// usando l'asterisco '*' come illustrato di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]
5 changes: 4 additions & 1 deletion FF Video Converter/QueueWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
<Rectangle Fill="{StaticResource ButtonBackgroundColor}" Grid.Column="1" Margin="0,4" />
</Grid>

<ListView x:Name="listViewQueuedJobs" Grid.Row="1" Background="Transparent" BorderBrush="Transparent" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="ListViewJobs_SelectionChanged" MouseMove="ListViewJobs_MouseMove" PreviewMouseLeftButtonDown="ListViewJobs_PreviewMouseLeftButtonDown" AllowDrop="True" DragEnter="ListViewJobs_DragEnter" DragOver="ListViewJobs_DragOver" Drop="ListViewJobs_Drop" />
<TextBlock Grid.Row="1" Text="Running:" Foreground="{StaticResource TextColorBlue}" Margin="5,5,0,239" />
<ListView x:Name="listViewRunningJob" Grid.Row="1" Background="Transparent" BorderBrush="Transparent" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionChanged="ListViewJobs_SelectionChanged" Margin="0,23,0,213" />
<TextBlock Grid.Row="1" Text="Queued:" Foreground="{StaticResource TextColorBlue}" Margin="5,53,0,194" />
<ListView x:Name="listViewQueuedJobs" Grid.Row="1" Background="Transparent" BorderBrush="Transparent" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="ListViewJobs_SelectionChanged" MouseMove="ListViewJobs_MouseMove" PreviewMouseLeftButtonDown="ListViewJobs_PreviewMouseLeftButtonDown" AllowDrop="True" DragEnter="ListViewJobs_DragEnter" DragOver="ListViewJobs_DragOver" Drop="ListViewJobs_Drop" Margin="0,72,0,0" />

<Button x:Name="buttonEdit" Content="Edit" Margin="10,10,0,0" HorizontalAlignment="Left" Width="105" Height="30" VerticalAlignment="Top" Click="ButtonEdit_Click" Grid.Column="1" Grid.Row="1" Visibility="Hidden"/>
<Button x:Name="buttonRemove" Content="Remove" Margin="124,10,0,0" HorizontalAlignment="Left" Width="105" Height="30" VerticalAlignment="Top" Click="ButtonRemove_Click" Grid.Column="1" Grid.Row="1" Visibility="Hidden"/>
Expand Down
33 changes: 30 additions & 3 deletions FF Video Converter/QueueWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public bool QueueActive
get => buttonStartStopQueue.Content.ToString() == "Stop queue";
set => buttonStartStopQueue.Content = value ? "Stop queue" : "Start queue";
}
public Job RunningJob
{
get => (Job)listViewRunningJob.Items[0];
set
{
listViewRunningJob.Items.Clear();
if (value != null) listViewRunningJob.Items.Add(value);
}
}
public QueueCompletedAction QueueCompletedAction { get => (QueueCompletedAction)comboBoxShutdown.SelectedIndex; }
public event Action QueueStarted;

Expand Down Expand Up @@ -97,8 +106,9 @@ private void ButtonStartStopQueue_Click(object sender, RoutedEventArgs e)

private void ListViewJobs_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedJob = (Job)listViewQueuedJobs.SelectedItem;
if (listViewQueuedJobs.SelectedIndex == -1)
ListView listView = (ListView)sender;
selectedJob = (Job)listView.SelectedItem;
if (listView.SelectedIndex == -1)
{
stackPanelContent.Visibility = Visibility.Hidden;
stackPanelLabel.Visibility = Visibility.Hidden;
Expand Down Expand Up @@ -200,6 +210,23 @@ private void ListViewJobs_SelectionChanged(object sender, SelectionChangedEventA
textBlockEnd.Visibility = Visibility.Collapsed;
textBlockEndLabel.Visibility = Visibility.Collapsed;
}

if (listView == listViewQueuedJobs)
{
buttonEdit.IsEnabled = true;
buttonRemove.IsEnabled = true;
listViewRunningJob.SelectionChanged -= ListViewJobs_SelectionChanged;
listViewRunningJob.SelectedIndex = -1;
listViewRunningJob.SelectionChanged += ListViewJobs_SelectionChanged;
}
else
{
buttonEdit.IsEnabled = false;
buttonRemove.IsEnabled = false;
listViewQueuedJobs.SelectionChanged -= ListViewJobs_SelectionChanged;
listViewQueuedJobs.SelectedIndex = -1;
listViewQueuedJobs.SelectionChanged += ListViewJobs_SelectionChanged;
}
}
}

Expand Down Expand Up @@ -303,7 +330,7 @@ private void ListViewJobs_DragOver(object sender, DragEventArgs e)
{
mousePosition = e.GetPosition(draggedOverItem);
dropAfter = mousePosition.Y > draggedOverItem.RenderSize.Height / 2;
Point draggedOverPosition = draggedOverItem.TransformToAncestor(listViewQueuedJobs).Transform(new Point(0, 0));
Point draggedOverPosition = draggedOverItem.TransformToAncestor(listViewQueuedJobs).Transform(new Point(0, listViewQueuedJobs.Margin.Top));
double verticalPosition = draggedOverPosition.Y - 5;
if (dropAfter) verticalPosition += draggedOverItem.RenderSize.Height;
insertionLine.Margin = new Thickness(0, verticalPosition, 0, 0);
Expand Down

0 comments on commit 1bcbbab

Please sign in to comment.