diff --git a/FF Video Converter/FFmpeg.cs b/FF Video Converter/FFmpeg.cs index fd0c8b8..53ab0c8 100644 --- a/FF Video Converter/FFmpeg.cs +++ b/FF Video Converter/FFmpeg.cs @@ -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 @@ -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 { @@ -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) diff --git a/FF Video Converter/MainWindow.xaml b/FF Video Converter/MainWindow.xaml index daa0edd..75342d1 100644 --- a/FF Video Converter/MainWindow.xaml +++ b/FF Video Converter/MainWindow.xaml @@ -300,7 +300,7 @@ - + diff --git a/FF Video Converter/MainWindow.xaml.cs b/FF Video Converter/MainWindow.xaml.cs index 6e298c9..159e2c8 100644 --- a/FF Video Converter/MainWindow.xaml.cs +++ b/FF Video Converter/MainWindow.xaml.cs @@ -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; @@ -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); } }; @@ -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 @@ -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 { @@ -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); } @@ -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); @@ -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 @@ -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; + }*/ } } } \ No newline at end of file diff --git a/FF Video Converter/MediaInfo.cs b/FF Video Converter/MediaInfo.cs index 4e6ecc3..ecc9b20 100644 --- a/FF Video Converter/MediaInfo.cs +++ b/FF Video Converter/MediaInfo.cs @@ -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; } diff --git a/FF Video Converter/Properties/AssemblyInfo.cs b/FF Video Converter/Properties/AssemblyInfo.cs index f48e3e3..b1420f0 100644 --- a/FF Video Converter/Properties/AssemblyInfo.cs +++ b/FF Video Converter/Properties/AssemblyInfo.cs @@ -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")] diff --git a/FF Video Converter/QueueWindow.xaml b/FF Video Converter/QueueWindow.xaml index cd603a1..b614467 100644 --- a/FF Video Converter/QueueWindow.xaml +++ b/FF Video Converter/QueueWindow.xaml @@ -57,7 +57,10 @@ - + + + +