From a5830533794915610784da80e578baf5be122493 Mon Sep 17 00:00:00 2001 From: Tichau Date: Thu, 18 Feb 2016 18:51:24 +0100 Subject: [PATCH 01/49] Fixed: Clamp to power of 2 option now clamp to the nearest po2 size --- .../FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs index 81f86c4..204dd5e 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_ImageMagick.cs @@ -60,7 +60,7 @@ namespace FileConverter.ConversionJobs { int referenceSize = System.Math.Min(image.Width, image.Height); int size = 2; - while (size * 2 < referenceSize) + while (size * 2 <= referenceSize) { size *= 2; } From a51d07a893e671cab70b222a151a609d1daa0353 Mon Sep 17 00:00:00 2001 From: Tichau Date: Thu, 18 Feb 2016 19:19:00 +0100 Subject: [PATCH 02/49] Handle session terminating for windows certification purpose. --- Application/FileConverter/Application.xaml.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index 2fe59f6..3e4c33f 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -41,6 +41,7 @@ namespace FileConverter private bool needToRunConversionThread; private bool cancelAutoExit; + private bool isSessionEnding; private UpgradeVersionDescription upgradeVersionDescription = null; public Application() @@ -48,6 +49,14 @@ namespace FileConverter this.ConvertionJobs = this.conversionJobs.AsReadOnly(); } + protected override void OnSessionEnding(SessionEndingCancelEventArgs e) + { + base.OnSessionEnding(e); + + this.isSessionEnding = true; + this.Shutdown(); + } + public static Version ApplicationVersion { get @@ -109,8 +118,8 @@ namespace FileConverter base.OnExit(e); Debug.Log("Exit application."); - - if (this.upgradeVersionDescription != null && this.upgradeVersionDescription.NeedToUpgrade) + + if (!this.isSessionEnding && this.upgradeVersionDescription != null && this.upgradeVersionDescription.NeedToUpgrade) { Debug.Log("A new version of file converter has been found: {0}.", this.upgradeVersionDescription.LatestVersion); From bf724d0dd398600bb30ecd4c07968aa479a2de40 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Fri, 19 Feb 2016 14:09:21 +0100 Subject: [PATCH 03/49] Stylecop --- Application/FileConverter/Application.xaml.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index 3e4c33f..3d9e23a 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -49,14 +49,6 @@ namespace FileConverter this.ConvertionJobs = this.conversionJobs.AsReadOnly(); } - protected override void OnSessionEnding(SessionEndingCancelEventArgs e) - { - base.OnSessionEnding(e); - - this.isSessionEnding = true; - this.Shutdown(); - } - public static Version ApplicationVersion { get @@ -163,6 +155,14 @@ namespace FileConverter Debug.Release(); } + protected override void OnSessionEnding(SessionEndingCancelEventArgs e) + { + base.OnSessionEnding(e); + + this.isSessionEnding = true; + this.Shutdown(); + } + private void Initialize() { Diagnostics.Debug.Log("File Converter v" + ApplicationVersion.ToString()); From 95d141dd690418350c6df44ab52513c1861236f7 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Fri, 19 Feb 2016 15:31:56 +0100 Subject: [PATCH 04/49] Add INSTALLLOCATION registry key (for windows certification purpose) --- Installer/Product.wxs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Installer/Product.wxs b/Installer/Product.wxs index 344007e..353378e 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -17,7 +17,8 @@ - + + @@ -40,7 +41,7 @@ - + From 9d648d79758527ba7323cf41f3a7794a569292d5 Mon Sep 17 00:00:00 2001 From: Tichau Date: Fri, 19 Feb 2016 18:28:33 +0100 Subject: [PATCH 05/49] Add Webm output format --- .../ConversionJob_FFMPEG.Converters.cs | 75 ++++++++++ .../ConversionJobs/ConversionJob_FFMPEG.cs | 141 ++++-------------- .../ConversionPreset/ConversionPreset.cs | 19 +++ Application/FileConverter/OutputType.cs | 1 + Application/FileConverter/PathHelpers.cs | 1 + .../ConversionSettingsTemplateSelector.cs | 9 ++ .../FileConverter/Windows/SettingsWindow.xaml | 65 +++++++- .../Windows/SettingsWindow.xaml.cs | 1 + 8 files changed, 198 insertions(+), 114 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs index 7adca67..2d0738b 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs @@ -5,9 +5,72 @@ namespace FileConverter.ConversionJobs using System; using FileConverter.Controls; + using System.Globalization; public partial class ConversionJob_FFMPEG { + private static string ComputeTransformArgs(ConversionPreset conversionPreset) + { + float scaleFactor = conversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale); + string scaleArgs = string.Empty; + if (Math.Abs(scaleFactor - 1f) >= 0.005f) + { + scaleArgs = string.Format("scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); + } + + float rotationAngleInDegrees = conversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoRotation); + string rotationArgs = string.Empty; + if (Math.Abs(rotationAngleInDegrees - 0f) >= 0.05f) + { + // Transpose: + // 0: 90 CounterClockwise and vertical flip + // 1: 90 Clockwise + // 2: 90 CounterClockwise + // 3: 90 Clockwise and vertical flip + if (Math.Abs(rotationAngleInDegrees - 90f) <= 0.05f) + { + rotationArgs = "transpose=2"; + } + else if (Math.Abs(rotationAngleInDegrees - 180f) <= 0.05f) + { + rotationArgs = "vflip,hflip"; + } + else if (Math.Abs(rotationAngleInDegrees - 270f) <= 0.05f) + { + rotationArgs = "transpose=1"; + } + else + { + Diagnostics.Debug.LogError("Unsupported rotation: {0}°", rotationAngleInDegrees); + } + } + + // Build vf args (-vf "scale=..., transpose=...") + string transformArgs = string.Empty; + if (!string.IsNullOrEmpty(scaleArgs) || !string.IsNullOrEmpty(rotationArgs)) + { + transformArgs = "-vf \""; + if (!string.IsNullOrEmpty(scaleArgs)) + { + transformArgs += scaleArgs; + } + + if (!string.IsNullOrEmpty(rotationArgs)) + { + if (!string.IsNullOrEmpty(scaleArgs)) + { + transformArgs += ","; + } + + transformArgs += rotationArgs; + } + + transformArgs += "\""; + } + + return transformArgs; + } + /// /// Convert bitrate in mp3 encoder quality index. /// @@ -263,5 +326,17 @@ namespace FileConverter.ConversionJobs throw new Exception("Unknown VBR bitrate."); } + + /// + /// Convert video quality index to H264 constant rate factor. + /// + /// The quality index. + /// Returns the H264 constant rate factor. + /// The range of the quantizer scale is 0-63: lower values mean better quality. + /// https://trac.ffmpeg.org/wiki/Encode/VP9 + private int WebmQualityToCRF(int quality) + { + return 63 - quality; + } } } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index be5b200..fe8a48d 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -82,62 +82,7 @@ namespace FileConverter.ConversionJobs int videoEncodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality); int audioEncodingBitrate = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); - float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale); - string scaleArgs = string.Empty; - if (Math.Abs(scaleFactor - 1f) >= 0.005f) - { - scaleArgs = string.Format("scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); - } - - float rotationAngleInDegrees = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoRotation); - string rotationArgs = string.Empty; - if (Math.Abs(rotationAngleInDegrees - 0f) >= 0.05f) - { - // Transpose: - // 0: 90 CounterClockwise and vertical flip - // 1: 90 Clockwise - // 2: 90 CounterClockwise - // 3: 90 Clockwise and vertical flip - if (Math.Abs(rotationAngleInDegrees - 90f) <= 0.05f) - { - rotationArgs = "transpose=2"; - } - else if (Math.Abs(rotationAngleInDegrees - 180f) <= 0.05f) - { - rotationArgs = "vflip,hflip"; - } - else if (Math.Abs(rotationAngleInDegrees - 270f) <= 0.05f) - { - rotationArgs = "transpose=1"; - } - else - { - Diagnostics.Debug.LogError("Unsupported rotation: {0}°", rotationAngleInDegrees); - } - } - - // Build vf args (-vf "scale=..., transpose=...") - string transformArgs = string.Empty; - if (!string.IsNullOrEmpty(scaleArgs) || !string.IsNullOrEmpty(rotationArgs)) - { - transformArgs = "-vf \""; - if (!string.IsNullOrEmpty(scaleArgs)) - { - transformArgs += scaleArgs; - } - - if (!string.IsNullOrEmpty(rotationArgs)) - { - if (!string.IsNullOrEmpty(scaleArgs)) - { - transformArgs += ","; - } - - transformArgs += rotationArgs; - } - - transformArgs += "\""; - } + string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); // Compute final arguments. string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} {2}", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), transformArgs); @@ -214,62 +159,7 @@ namespace FileConverter.ConversionJobs string videoEncodingSpeed = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed); int audioEncodingBitrate = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); - float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale); - string scaleArgs = string.Empty; - if (Math.Abs(scaleFactor - 1f) >= 0.005f) - { - scaleArgs = string.Format("scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); - } - - float rotationAngleInDegrees = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoRotation); - string rotationArgs = string.Empty; - if (Math.Abs(rotationAngleInDegrees - 0f) >= 0.05f) - { - // Transpose: - // 0: 90 CounterClockwise and vertical flip - // 1: 90 Clockwise - // 2: 90 CounterClockwise - // 3: 90 Clockwise and vertical flip - if (Math.Abs(rotationAngleInDegrees - 90f) <= 0.05f) - { - rotationArgs = "transpose=2"; - } - else if (Math.Abs(rotationAngleInDegrees - 180f) <= 0.05f) - { - rotationArgs = "vflip,hflip"; - } - else if (Math.Abs(rotationAngleInDegrees - 270f) <= 0.05f) - { - rotationArgs = "transpose=1"; - } - else - { - Diagnostics.Debug.LogError("Unsupported rotation: {0}°", rotationAngleInDegrees); - } - } - - // Build vf args (-vf "scale=..., transpose=...") - string transformArgs = string.Empty; - if (!string.IsNullOrEmpty(scaleArgs) || !string.IsNullOrEmpty(rotationArgs)) - { - transformArgs = "-vf \""; - if (!string.IsNullOrEmpty(scaleArgs)) - { - transformArgs += scaleArgs; - } - - if (!string.IsNullOrEmpty(rotationArgs)) - { - if (!string.IsNullOrEmpty(scaleArgs)) - { - transformArgs += ","; - } - - transformArgs += rotationArgs; - } - - transformArgs += "\""; - } + string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); string encoderArgs = string.Format("-c:v libx264 -preset {0} -crf {1} -c:a aac -q:a {2} {3}", this.H264EncodingSpeedToPreset(videoEncodingSpeed), this.H264QualityToCRF(videoEncodingQuality), this.AACBitrateToQualityIndex(audioEncodingBitrate), transformArgs); arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); @@ -312,6 +202,31 @@ namespace FileConverter.ConversionJobs break; + case OutputType.Webm: + { + // https://trac.ffmpeg.org/wiki/Encode/VP9 + int videoEncodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality); + int encodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); + + string encodingArgs = string.Empty; + if (videoEncodingQuality == 63) + { + // Replace maximum quality settings by lossless compression. + encodingArgs = "-lossless 1"; + } + else + { + encodingArgs = string.Format("-crf {0} -b:v 0", this.WebmQualityToCRF(videoEncodingQuality)); + } + + string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); + + string encoderArgs = string.Format("-c:v libvpx-vp9 {0} -c:a libvorbis -q:a {1} {2}", encodingArgs, this.OGGVBRBitrateToQualityIndex(encodingQuality), transformArgs); + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + } + + break; + default: throw new NotImplementedException("Converter not implemented for output file type " + this.ConversionPreset.OutputType); } @@ -385,7 +300,7 @@ namespace FileConverter.ConversionJobs int hours = int.Parse(match.Groups[2].Value); int minutes = int.Parse(match.Groups[3].Value); int seconds = int.Parse(match.Groups[4].Value); - int milliseconds = int.Parse(match.Groups[5].Value); + int milliseconds = int.Parse(match.Groups[5].Value) * 10; float bitrate = 0f; float.TryParse(match.Groups[6].Value, out bitrate); diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 2c65a7b..0d07340 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -502,6 +502,18 @@ namespace FileConverter break; + case OutputType.Webm: + switch (settingsKey) + { + case ConversionPreset.ConversionSettingKeys.AudioBitrate: + case ConversionPreset.ConversionSettingKeys.VideoQuality: + case ConversionPreset.ConversionSettingKeys.VideoScale: + case ConversionPreset.ConversionSettingKeys.VideoRotation: + return true; + } + + break; + default: Debug.LogError("Relevant settings '{1}' are not define for output type {0}.", this.OutputType, settingsKey); break; @@ -573,6 +585,13 @@ namespace FileConverter this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.AudioEncodingMode, EncodingMode.Wav16.ToString(), true); break; + case OutputType.Webm: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate, "160"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality, "40"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, "1"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoRotation, "0"); + break; + default: throw new System.Exception("Missing default settings for type " + outputType); } diff --git a/Application/FileConverter/OutputType.cs b/Application/FileConverter/OutputType.cs index fbca11a..feebbc0 100644 --- a/Application/FileConverter/OutputType.cs +++ b/Application/FileConverter/OutputType.cs @@ -17,5 +17,6 @@ namespace FileConverter Ogg, Png, Wav, + Webm, } } \ No newline at end of file diff --git a/Application/FileConverter/PathHelpers.cs b/Application/FileConverter/PathHelpers.cs index 7720bf4..4ef603f 100644 --- a/Application/FileConverter/PathHelpers.cs +++ b/Application/FileConverter/PathHelpers.cs @@ -137,6 +137,7 @@ namespace FileConverter case OutputType.Avi: case OutputType.Mkv: case OutputType.Mp4: + case OutputType.Webm: return category == InputCategoryNames.Video; case OutputType.Ico: diff --git a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs index f5cff62..510eb71 100644 --- a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs +++ b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs @@ -67,6 +67,12 @@ namespace FileConverter.Windows set; } + public DataTemplate WebmSettingsDataTemplate + { + get; + set; + } + public override DataTemplate SelectTemplate(object item, DependencyObject container) { if (item == null) @@ -104,6 +110,9 @@ namespace FileConverter.Windows case OutputType.Wav: return this.WavSettingsDataTemplate; + + case OutputType.Webm: + return this.WebmSettingsDataTemplate; } return this.DefaultDataTemplate; diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 1407b55..1ab0363 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -247,6 +247,68 @@ + + + + + + + + + + + + + + + + + + + + + @@ -349,7 +411,8 @@ Mp4SettingsDataTemplate="{StaticResource MkvSettingsDataTemplate}" OggSettingsDataTemplate="{StaticResource OggSettingsDataTemplate}" PngSettingsDataTemplate="{StaticResource PngSettingsDataTemplate}" - WavSettingsDataTemplate="{StaticResource WavSettingsDataTemplate}" /> + WavSettingsDataTemplate="{StaticResource WavSettingsDataTemplate}" + WebmSettingsDataTemplate="{StaticResource WebmSettingsDataTemplate}" /> diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml.cs b/Application/FileConverter/Windows/SettingsWindow.xaml.cs index e1c7ba4..c5dddad 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml.cs +++ b/Application/FileConverter/Windows/SettingsWindow.xaml.cs @@ -42,6 +42,7 @@ namespace FileConverter OutputType.Wav, OutputType.Mkv, OutputType.Mp4, + OutputType.Webm, OutputType.Avi, OutputType.Ico, OutputType.Jpg, From 6f06f2943bb30bb9e52924fd491778b84bbd4222 Mon Sep 17 00:00:00 2001 From: Tichau Date: Tue, 23 Feb 2016 10:44:29 +0100 Subject: [PATCH 06/49] Add gif output type --- .../ConversionJobs/ConversionJobFactory.cs | 5 + .../ConversionJob_FFMPEG.Converters.cs | 26 +-- .../ConversionJobs/ConversionJob_FFMPEG.cs | 191 ++++++++++++++---- .../ConversionJobs/ConversionJob_Gif.cs | 123 +++++++++++ .../ConversionPreset/ConversionPreset.cs | 18 ++ .../FileConverter/FileConverter.csproj | 1 + Application/FileConverter/OutputType.cs | 1 + Application/FileConverter/PathHelpers.cs | 16 +- .../ConversionSettingsTemplateSelector.cs | 9 + .../FileConverter/Windows/SettingsWindow.xaml | 47 +++++ .../Windows/SettingsWindow.xaml.cs | 1 + 11 files changed, 379 insertions(+), 59 deletions(-) create mode 100644 Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs diff --git a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs index 6487167..da1f4ea 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJobFactory.cs @@ -18,6 +18,11 @@ namespace FileConverter.ConversionJobs return new ConversionJob_Ico(conversionPreset); } + if (conversionPreset.OutputType == OutputType.Gif) + { + return new ConversionJob_Gif(conversionPreset); + } + if (PathHelpers.GetExtensionCategory(extension) == PathHelpers.InputCategoryNames.Image) { return new ConversionJob_ImageMagick(conversionPreset); diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs index 2d0738b..c4d94b1 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs @@ -45,27 +45,21 @@ namespace FileConverter.ConversionJobs } } - // Build vf args (-vf "scale=..., transpose=...") + // Build vf args content (scale=..., transpose=...) string transformArgs = string.Empty; - if (!string.IsNullOrEmpty(scaleArgs) || !string.IsNullOrEmpty(rotationArgs)) + if (!string.IsNullOrEmpty(scaleArgs)) { - transformArgs = "-vf \""; - if (!string.IsNullOrEmpty(scaleArgs)) + transformArgs += scaleArgs; + } + + if (!string.IsNullOrEmpty(rotationArgs)) + { + if (!string.IsNullOrEmpty(transformArgs)) { - transformArgs += scaleArgs; + transformArgs += ","; } - if (!string.IsNullOrEmpty(rotationArgs)) - { - if (!string.IsNullOrEmpty(scaleArgs)) - { - transformArgs += ","; - } - - transformArgs += rotationArgs; - } - - transformArgs += "\""; + transformArgs += rotationArgs; } return transformArgs; diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index fe8a48d..4b07dc8 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -3,6 +3,7 @@ namespace FileConverter.ConversionJobs { using System; + using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; @@ -20,6 +21,8 @@ namespace FileConverter.ConversionJobs private ProcessStartInfo ffmpegProcessStartInfo; + private List ffmpegArgumentStringByPass = new List(); + public ConversionJob_FFMPEG() : base() { } @@ -63,7 +66,11 @@ namespace FileConverter.ConversionJobs this.ffmpegProcessStartInfo.RedirectStandardOutput = true; this.ffmpegProcessStartInfo.RedirectStandardError = true; - string arguments = string.Empty; + this.FillFFMpegArgumentsList(); + } + + protected virtual void FillFFMpegArgumentsList() + { switch (this.ConversionPreset.OutputType) { case OutputType.Aac: @@ -71,7 +78,9 @@ namespace FileConverter.ConversionJobs // https://trac.ffmpeg.org/wiki/Encode/AAC int audioEncodingBitrate = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); string encoderArgs = string.Format("-c:a aac -q:a {0}", this.AACBitrateToQualityIndex(audioEncodingBitrate)); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -85,8 +94,10 @@ namespace FileConverter.ConversionJobs string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); // Compute final arguments. - string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} {2}", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), transformArgs); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} -vf \"{2}\"", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), transformArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -95,7 +106,40 @@ namespace FileConverter.ConversionJobs { // http://taer-naguur.blogspot.fr/2013/11/flac-audio-encoding-with-ffmpeg.html string encoderArgs = string.Format("-compression_level 12"); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); + } + + break; + + case OutputType.Gif: + { + // http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html + string fileName = Path.GetFileName(this.InputFilePath); + string tempPath = Path.GetTempPath(); + string paletteFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + " - palette.png"); + + string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); + + // fps. + int framesPerSecond = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoFramesPerSecond); + if (!string.IsNullOrEmpty(transformArgs)) + { + transformArgs += ","; + } + + transformArgs += string.Format("fps={0}", framesPerSecond); + + // Generate palette. + string encoderArgs = string.Format("-vf \"{0},palettegen\"", transformArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, paletteFilePath, encoderArgs); + this.ffmpegArgumentStringByPass.Add(new FFMpegPass("Indexing colors", arguments, paletteFilePath)); + + // Create gif. + encoderArgs = string.Format("-i \"{0}\" -lavfi \"{1},paletteuse\"", paletteFilePath, transformArgs); arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -103,7 +147,9 @@ namespace FileConverter.ConversionJobs case OutputType.Ico: { string encoderArgs = string.Empty; - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -116,12 +162,15 @@ namespace FileConverter.ConversionJobs string scaleArgs = string.Empty; if (Math.Abs(scaleFactor - 1f) >= 0.005f) { - scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); + scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", + scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); } string encoderArgs = string.Format("-q:v {0} {1}", this.JPGQualityToQualityIndex(encodingQuality), scaleArgs); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -145,10 +194,12 @@ namespace FileConverter.ConversionJobs break; } - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } - break; + break; case OutputType.Mkv: case OutputType.Mp4: @@ -161,8 +212,12 @@ namespace FileConverter.ConversionJobs string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); - string encoderArgs = string.Format("-c:v libx264 -preset {0} -crf {1} -c:a aac -q:a {2} {3}", this.H264EncodingSpeedToPreset(videoEncodingSpeed), this.H264QualityToCRF(videoEncodingQuality), this.AACBitrateToQualityIndex(audioEncodingBitrate), transformArgs); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string encoderArgs = string.Format("-c:v libx264 -preset {0} -crf {1} -c:a aac -q:a {2} -vf\"{3}\"", + this.H264EncodingSpeedToPreset(videoEncodingSpeed), this.H264QualityToCRF(videoEncodingQuality), + this.AACBitrateToQualityIndex(audioEncodingBitrate), transformArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -171,7 +226,9 @@ namespace FileConverter.ConversionJobs { int encodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); string encoderArgs = string.Format("-codec:a libvorbis -qscale:a {0}", this.OGGVBRBitrateToQualityIndex(encodingQuality)); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -188,7 +245,9 @@ namespace FileConverter.ConversionJobs // http://www.howtogeek.com/203979/is-the-png-format-lossless-since-it-has-a-compression-parameter/ string encoderArgs = string.Format("-compression_level 100 {0}", scaleArgs); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -197,7 +256,9 @@ namespace FileConverter.ConversionJobs { EncodingMode encodingMode = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioEncodingMode); string encoderArgs = string.Format("-acodec {0}", this.WAVEncodingToCodecArgument(encodingMode)); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; @@ -221,22 +282,32 @@ namespace FileConverter.ConversionJobs string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); - string encoderArgs = string.Format("-c:v libvpx-vp9 {0} -c:a libvorbis -q:a {1} {2}", encodingArgs, this.OGGVBRBitrateToQualityIndex(encodingQuality), transformArgs); - arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + string encoderArgs = string.Format("-c:v libvpx-vp9 {0} -c:a libvorbis -q:a {1} -vf \"{2}\"", encodingArgs, + this.OGGVBRBitrateToQualityIndex(encodingQuality), transformArgs); + string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); + + this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); } break; default: - throw new NotImplementedException("Converter not implemented for output file type " + this.ConversionPreset.OutputType); + throw new NotImplementedException("Converter not implemented for output file type " + + this.ConversionPreset.OutputType); } - if (string.IsNullOrEmpty(arguments)) + if (this.ffmpegArgumentStringByPass.Count == 0) { - throw new Exception("Invalid ffmpeg process arguments."); + throw new Exception("No ffmpeg arguments generated."); } - this.ffmpegProcessStartInfo.Arguments = arguments; + for (int index = 0; index < this.ffmpegArgumentStringByPass.Count; index++) + { + if (string.IsNullOrEmpty(this.ffmpegArgumentStringByPass[index].Arguments)) + { + throw new Exception("Invalid ffmpeg process arguments."); + } + } } protected override void Convert() @@ -246,37 +317,58 @@ namespace FileConverter.ConversionJobs throw new Exception("The conversion preset must be valid."); } - this.UserState = "Conversion"; - - Diagnostics.Debug.Log("Execute command: {0} {1}.", this.ffmpegProcessStartInfo.FileName, this.ffmpegProcessStartInfo.Arguments); - Diagnostics.Debug.Log(string.Empty); - - try + for (int index = 0; index < this.ffmpegArgumentStringByPass.Count; index++) { - using (Process exeProcess = Process.Start(this.ffmpegProcessStartInfo)) + FFMpegPass currentPass = this.ffmpegArgumentStringByPass[index]; + + this.UserState = currentPass.Name; + this.ffmpegProcessStartInfo.Arguments = currentPass.Arguments; + + Diagnostics.Debug.Log("Execute command: {0} {1}.", this.ffmpegProcessStartInfo.FileName, this.ffmpegProcessStartInfo.Arguments); + Diagnostics.Debug.Log(string.Empty); + + try { - using (StreamReader reader = exeProcess.StandardError) + using (Process exeProcess = Process.Start(this.ffmpegProcessStartInfo)) { - while (!reader.EndOfStream) + using (StreamReader reader = exeProcess.StandardError) { - string result = reader.ReadLine(); + while (!reader.EndOfStream) + { + string result = reader.ReadLine(); - this.ParseFFMPEGOutput(result); + this.ParseFFMPEGOutput(result); - Diagnostics.Debug.Log("ffmpeg output: {0}", result); + Diagnostics.Debug.Log("ffmpeg output: {0}", result); + } } - } - exeProcess.WaitForExit(); + exeProcess.WaitForExit(); + } + } + catch + { + this.ConversionFailed("Failed to launch FFMPEG process."); + throw; } } - catch - { - this.ConversionFailed("Failed to launch FFMPEG process."); - throw; - } Diagnostics.Debug.Log(string.Empty); + + // Clean intermediate files. + for (int index = 0; index < this.ffmpegArgumentStringByPass.Count; index++) + { + FFMpegPass currentPass = this.ffmpegArgumentStringByPass[index]; + + if (string.IsNullOrEmpty(currentPass.FileToDelete)) + { + continue; + } + + Diagnostics.Debug.Log("Delete intermediate file {0}.", currentPass.FileToDelete); + + File.Delete(currentPass.FileToDelete); + } } private void ParseFFMPEGOutput(string input) @@ -315,5 +407,26 @@ namespace FileConverter.ConversionJobs this.ConversionFailed(input); } } + + private struct FFMpegPass + { + public string Name; + public string Arguments; + public string FileToDelete; + + public FFMpegPass(string name, string arguments, string fileToDelete) + { + this.Name = name; + this.Arguments = arguments; + this.FileToDelete = fileToDelete; + } + + public FFMpegPass(string arguments) + { + this.Name = "Conversion"; + this.Arguments = arguments; + this.FileToDelete = string.Empty; + } + } } } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs new file mode 100644 index 0000000..560e398 --- /dev/null +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs @@ -0,0 +1,123 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +using System.Threading.Tasks; + +namespace FileConverter.ConversionJobs +{ + using System; + using System.IO; + + public class ConversionJob_Gif : ConversionJob + { + private string intermediateFilePath = string.Empty; + private ConversionJob pngConversionJob = null; + private ConversionJob gifConversionJob = null; + + public ConversionJob_Gif(ConversionPreset conversionPreset) : base(conversionPreset) + { + } + + protected override void Initialize() + { + base.Initialize(); + + if (this.ConversionPreset == null) + { + throw new Exception("The conversion preset must be valid."); + } + + string extension = System.IO.Path.GetExtension(this.InputFilePath); + extension = extension.ToLowerInvariant().Substring(1, extension.Length - 1); + + string inputFilePath = string.Empty; + + // If the output is an image start to convert it into png before send it to ffmpeg. + if (PathHelpers.GetExtensionCategory(extension) == PathHelpers.InputCategoryNames.Image && extension != "png") + { + // Generate intermediate file path. + string fileName = Path.GetFileName(this.OutputFilePath); + string tempPath = Path.GetTempPath(); + this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".png"); + + // Convert input in png file to send it to ffmpeg for the gif conversion. + ConversionPreset intermediatePreset = new ConversionPreset("To compatible image", OutputType.Png, this.ConversionPreset.InputTypes.ToArray()); + this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath); + this.pngConversionJob.PrepareConversion(this.InputFilePath, this.intermediateFilePath); + + inputFilePath = this.intermediateFilePath; + } + else + { + inputFilePath = this.InputFilePath; + } + + // Convert png file into ico. + this.gifConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset); + this.gifConversionJob.PrepareConversion(inputFilePath, this.OutputFilePath); + } + + protected override void Convert() + { + if (this.ConversionPreset == null) + { + throw new Exception("The conversion preset must be valid."); + } + + Task updateProgress = this.UpdateProgress(); + + if (this.pngConversionJob != null) + { + this.UserState = "Read input image"; + + Diagnostics.Debug.Log(string.Empty); + Diagnostics.Debug.Log("Convert image to PNG (intermediate format)."); + this.pngConversionJob.StartConvertion(); + + if (this.pngConversionJob.State != ConversionState.Done) + { + this.ConversionFailed(this.pngConversionJob.ErrorMessage); + return; + } + } + + Diagnostics.Debug.Log(string.Empty); + Diagnostics.Debug.Log("Convert png intermediate image to gif."); + this.gifConversionJob.StartConvertion(); + + if (this.gifConversionJob.State != ConversionState.Done) + { + this.ConversionFailed(this.gifConversionJob.ErrorMessage); + return; + } + + if (!string.IsNullOrEmpty(this.intermediateFilePath)) + { + Diagnostics.Debug.Log("Delete intermediate file {0}.", this.intermediateFilePath); + + File.Delete(this.intermediateFilePath); + } + + updateProgress.Wait(); + } + + private async Task UpdateProgress() + { + while (this.gifConversionJob.State != ConversionState.Done && + this.gifConversionJob.State != ConversionState.Failed) + { + if (this.pngConversionJob != null && this.pngConversionJob.State == ConversionState.InProgress) + { + this.Progress = this.pngConversionJob.Progress; + } + + if (this.gifConversionJob != null && this.gifConversionJob.State == ConversionState.InProgress) + { + this.Progress = this.gifConversionJob.Progress; + this.UserState = this.gifConversionJob.UserState; + } + + await Task.Delay(40); + } + } + } +} diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 0d07340..7652be2 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -424,6 +424,17 @@ namespace FileConverter case OutputType.Ico: break; + case OutputType.Gif: + switch (settingsKey) + { + case ConversionPreset.ConversionSettingKeys.VideoScale: + case ConversionPreset.ConversionSettingKeys.VideoRotation: + case ConversionPreset.ConversionSettingKeys.VideoFramesPerSecond: + return true; + } + + break; + case OutputType.Jpg: switch (settingsKey) { @@ -534,6 +545,12 @@ namespace FileConverter case OutputType.Flac: break; + case OutputType.Gif: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, "1"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoRotation, "0"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoFramesPerSecond, "15"); + break; + case OutputType.Png: this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale, "1"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageRotation, "0"); @@ -753,6 +770,7 @@ namespace FileConverter public const string VideoEncodingSpeed = "VideoEncodingSpeed"; public const string VideoScale = "VideoScale"; public const string VideoRotation = "VideoRotation"; + public const string VideoFramesPerSecond = "VideoFramesPerSecond"; } } } diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index d24f7ec..a734fb9 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -95,6 +95,7 @@ + diff --git a/Application/FileConverter/OutputType.cs b/Application/FileConverter/OutputType.cs index feebbc0..e383e1b 100644 --- a/Application/FileConverter/OutputType.cs +++ b/Application/FileConverter/OutputType.cs @@ -9,6 +9,7 @@ namespace FileConverter Aac, Avi, Flac, + Gif, Ico, Jpg, Mkv, diff --git a/Application/FileConverter/PathHelpers.cs b/Application/FileConverter/PathHelpers.cs index 4ef603f..4b98225 100644 --- a/Application/FileConverter/PathHelpers.cs +++ b/Application/FileConverter/PathHelpers.cs @@ -88,9 +88,9 @@ namespace FileConverter case "wma": return InputCategoryNames.Audio; + case "3gp": case "avi": case "bik": - case "3gp": case "flv": case "m4v": case "mp4": @@ -112,6 +112,9 @@ namespace FileConverter case "svg": case "xcf": return InputCategoryNames.Image; + + case "gif": + return InputCategoryNames.AnimatedImage; } return InputCategoryNames.Misc; @@ -138,13 +141,16 @@ namespace FileConverter case OutputType.Mkv: case OutputType.Mp4: case OutputType.Webm: - return category == InputCategoryNames.Video; - + return category == InputCategoryNames.Video || category == InputCategoryNames.AnimatedImage; + case OutputType.Ico: - case OutputType.Png: case OutputType.Jpg: + case OutputType.Png: return category == InputCategoryNames.Image; + case OutputType.Gif: + return category == InputCategoryNames.Image || category == InputCategoryNames.Video || category == InputCategoryNames.AnimatedImage; + default: return false; } @@ -168,6 +174,8 @@ namespace FileConverter public const string Audio = "Audio"; public const string Video = "Video"; public const string Image = "Image"; + public const string AnimatedImage = "Animated Image"; + public const string Misc = "Misc"; } } diff --git a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs index 510eb71..ed05e92 100644 --- a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs +++ b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs @@ -49,6 +49,12 @@ namespace FileConverter.Windows set; } + public DataTemplate GifSettingsDataTemplate + { + get; + set; + } + public DataTemplate JpgSettingsDataTemplate { get; @@ -90,6 +96,9 @@ namespace FileConverter.Windows case OutputType.Avi: return this.AviSettingsDataTemplate; + case OutputType.Gif: + return this.GifSettingsDataTemplate; + case OutputType.Jpg: return this.JpgSettingsDataTemplate; diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 1ab0363..1ab26ee 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -109,6 +109,52 @@ + + + + + + + + + + + + + + + + @@ -405,6 +451,7 @@ DefaultDataTemplate="{StaticResource EmptyDataTemplate}" AacSettingsDataTemplate="{StaticResource AacSettingsDataTemplate}" AviSettingsDataTemplate="{StaticResource AviSettingsDataTemplate}" + GifSettingsDataTemplate="{StaticResource GifSettingsDataTemplate}" JpgSettingsDataTemplate="{StaticResource JpgSettingsDataTemplate}" MkvSettingsDataTemplate="{StaticResource MkvSettingsDataTemplate}" Mp3SettingsDataTemplate="{StaticResource Mp3SettingsDataTemplate}" diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml.cs b/Application/FileConverter/Windows/SettingsWindow.xaml.cs index c5dddad..7944ca5 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml.cs +++ b/Application/FileConverter/Windows/SettingsWindow.xaml.cs @@ -47,6 +47,7 @@ namespace FileConverter OutputType.Ico, OutputType.Jpg, OutputType.Png, + OutputType.Gif, }; this.OutputFormats.ItemsSource = outputTypes; From 35fa417695b242f1d98b5bfa42f626a8404f0bdd Mon Sep 17 00:00:00 2001 From: Tichau Date: Tue, 23 Feb 2016 10:44:57 +0100 Subject: [PATCH 07/49] Add gif input type --- Installer/Product.wxs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Installer/Product.wxs b/Installer/Product.wxs index 353378e..7b383dc 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -112,7 +112,7 @@ - + From 780ca19ae3b460fdd07cb6ee0f10f1b58d3fe027 Mon Sep 17 00:00:00 2001 From: Adrien Allard Date: Tue, 23 Feb 2016 11:41:13 +0100 Subject: [PATCH 08/49] Fixed: scale and rotate videos. --- .../ConversionJob_FFMPEG.Converters.cs | 10 +++++++ .../ConversionJobs/ConversionJob_FFMPEG.cs | 26 +++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs index c4d94b1..fcc6674 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.Converters.cs @@ -9,6 +9,16 @@ namespace FileConverter.ConversionJobs public partial class ConversionJob_FFMPEG { + private static string Encapsulate(string optionName, string args) + { + if (string.IsNullOrEmpty(args)) + { + return string.Empty; + } + + return string.Format("{0} \"{1}\"", optionName, args); + } + private static string ComputeTransformArgs(ConversionPreset conversionPreset) { float scaleFactor = conversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale); diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 4b07dc8..89166d3 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -94,7 +94,8 @@ namespace FileConverter.ConversionJobs string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); // Compute final arguments. - string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} -vf \"{2}\"", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), transformArgs); + string videoFilteringArgs = ConversionJob_FFMPEG.Encapsulate("-vf", transformArgs); + string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} {2}", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), videoFilteringArgs); string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); @@ -162,8 +163,7 @@ namespace FileConverter.ConversionJobs string scaleArgs = string.Empty; if (Math.Abs(scaleFactor - 1f) >= 0.005f) { - scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", - scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); + scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); } string encoderArgs = string.Format("-q:v {0} {1}", this.JPGQualityToQualityIndex(encodingQuality), scaleArgs); @@ -211,10 +211,15 @@ namespace FileConverter.ConversionJobs int audioEncodingBitrate = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); + string videoFilteringArgs = ConversionJob_FFMPEG.Encapsulate("-vf", transformArgs); + + string encoderArgs = string.Format( + "-c:v libx264 -preset {0} -crf {1} -c:a aac -q:a {2} {3}", + this.H264EncodingSpeedToPreset(videoEncodingSpeed), + this.H264QualityToCRF(videoEncodingQuality), + this.AACBitrateToQualityIndex(audioEncodingBitrate), + videoFilteringArgs); - string encoderArgs = string.Format("-c:v libx264 -preset {0} -crf {1} -c:a aac -q:a {2} -vf\"{3}\"", - this.H264EncodingSpeedToPreset(videoEncodingSpeed), this.H264QualityToCRF(videoEncodingQuality), - this.AACBitrateToQualityIndex(audioEncodingBitrate), transformArgs); string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); @@ -281,9 +286,14 @@ namespace FileConverter.ConversionJobs } string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); + string videoFilteringArgs = ConversionJob_FFMPEG.Encapsulate("-vf", transformArgs); + + string encoderArgs = string.Format( + "-c:v libvpx-vp9 {0} -c:a libvorbis -q:a {1} {2}", + encodingArgs, + this.OGGVBRBitrateToQualityIndex(encodingQuality), + videoFilteringArgs); - string encoderArgs = string.Format("-c:v libvpx-vp9 {0} -c:a libvorbis -q:a {1} -vf \"{2}\"", encodingArgs, - this.OGGVBRBitrateToQualityIndex(encodingQuality), transformArgs); string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); From 73ae27644d395c9705d8bce63635b8cceaf6626b Mon Sep 17 00:00:00 2001 From: Tichau Date: Tue, 23 Feb 2016 19:02:03 +0100 Subject: [PATCH 09/49] Ignore ffmpeg progress parsing if no duration has been found. --- .../ConversionJobs/ConversionJob_FFMPEG.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 89166d3..6cf6e08 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -395,21 +395,24 @@ namespace FileConverter.ConversionJobs return; } - match = this.progressRegex.Match(input); - if (match.Success && match.Groups.Count >= 7) + if (this.fileDuration.Ticks > 0) { - int size = int.Parse(match.Groups[1].Value); - int hours = int.Parse(match.Groups[2].Value); - int minutes = int.Parse(match.Groups[3].Value); - int seconds = int.Parse(match.Groups[4].Value); - int milliseconds = int.Parse(match.Groups[5].Value) * 10; - float bitrate = 0f; - float.TryParse(match.Groups[6].Value, out bitrate); + match = this.progressRegex.Match(input); + if (match.Success && match.Groups.Count >= 7) + { + int size = int.Parse(match.Groups[1].Value); + int hours = int.Parse(match.Groups[2].Value); + int minutes = int.Parse(match.Groups[3].Value); + int seconds = int.Parse(match.Groups[4].Value); + int milliseconds = int.Parse(match.Groups[5].Value) * 10; + float bitrate = 0f; + float.TryParse(match.Groups[6].Value, out bitrate); - this.actualConvertedDuration = new TimeSpan(0, hours, minutes, seconds, milliseconds); + this.actualConvertedDuration = new TimeSpan(0, hours, minutes, seconds, milliseconds); - this.Progress = this.actualConvertedDuration.Ticks / (float)this.fileDuration.Ticks; - return; + this.Progress = this.actualConvertedDuration.Ticks / (float)this.fileDuration.Ticks; + return; + } } if (input.Contains("Exiting.") || input.Contains("Error") || input.Contains("Unsupported dimensions") || input.Contains("No such file or directory")) From 569d4198edf66f2bd50bd9cb8b9e2310f485b5e2 Mon Sep 17 00:00:00 2001 From: Tichau Date: Wed, 24 Feb 2016 08:09:11 +0100 Subject: [PATCH 10/49] Add enable audio option for avi output format --- .../ConversionJobs/ConversionJob_FFMPEG.cs | 8 +++++++- .../ConversionPreset/ConversionPreset.cs | 5 +++++ .../FileConverter/Windows/SettingsWindow.xaml | 13 +++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 6cf6e08..88b0ccc 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -93,9 +93,15 @@ namespace FileConverter.ConversionJobs string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); + string audioArgs = "-an"; + if (this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.EnableAudio)) + { + audioArgs = string.Format("-c:a libmp3lame -qscale:a {0}", this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate)); + } + // Compute final arguments. string videoFilteringArgs = ConversionJob_FFMPEG.Encapsulate("-vf", transformArgs); - string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} -c:a libmp3lame -qscale:a {1} {2}", this.MPEG4QualityToQualityIndex(videoEncodingQuality), this.MP3VBRBitrateToQualityIndex(audioEncodingBitrate), videoFilteringArgs); + string encoderArgs = string.Format("-c:v mpeg4 -vtag xvid -qscale:v {0} {1} {2}", this.MPEG4QualityToQualityIndex(videoEncodingQuality), audioArgs, videoFilteringArgs); string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); this.ffmpegArgumentStringByPass.Add(new FFMpegPass(arguments)); diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 7652be2..5246c1a 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -411,6 +411,7 @@ namespace FileConverter case OutputType.Avi: switch (settingsKey) { + case ConversionPreset.ConversionSettingKeys.EnableAudio: case ConversionPreset.ConversionSettingKeys.AudioBitrate: case ConversionPreset.ConversionSettingKeys.VideoQuality: case ConversionPreset.ConversionSettingKeys.VideoScale: @@ -567,6 +568,7 @@ namespace FileConverter break; case OutputType.Avi: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.EnableAudio, "True"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality, "20"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, "1"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoRotation, "0"); @@ -771,6 +773,9 @@ namespace FileConverter public const string VideoScale = "VideoScale"; public const string VideoRotation = "VideoRotation"; public const string VideoFramesPerSecond = "VideoFramesPerSecond"; + + public const string EnableAudio = "EnableAudio"; + public const string EnableVideo = "EnableVideo"; } } } diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 1ab26ee..4dc28b5 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -172,7 +172,7 @@ - @@ -207,13 +207,14 @@ - - From 8e1f73f745ee61db6a7306790db48300c7c55753 Mon Sep 17 00:00:00 2001 From: Tichau Date: Wed, 24 Feb 2016 08:09:25 +0100 Subject: [PATCH 11/49] Update resharper settings --- FileConverter.sln.DotSettings | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/FileConverter.sln.DotSettings b/FileConverter.sln.DotSettings index 876a5e5..e3c157d 100644 --- a/FileConverter.sln.DotSettings +++ b/FileConverter.sln.DotSettings @@ -10,6 +10,7 @@ False False False + False UseExplicitType UseExplicitType UseExplicitType @@ -20,6 +21,41 @@ <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> True True False \ No newline at end of file From 666af8a37b44b07a57dfdf17b7edc6e0d0a4550e Mon Sep 17 00:00:00 2001 From: Tichau Date: Wed, 24 Feb 2016 08:21:30 +0100 Subject: [PATCH 12/49] Refactor conversion preset settings definition to avoid duplicate. --- .../ConversionPreset/ConversionPreset.cs | 138 +----------------- 1 file changed, 3 insertions(+), 135 deletions(-) diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 5246c1a..0e45380 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -397,145 +397,13 @@ namespace FileConverter private bool IsRelevantSetting(string settingsKey) { - switch (this.OutputType) - { - case OutputType.Aac: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.AudioBitrate: - return true; - } - - break; - - case OutputType.Avi: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.EnableAudio: - case ConversionPreset.ConversionSettingKeys.AudioBitrate: - case ConversionPreset.ConversionSettingKeys.VideoQuality: - case ConversionPreset.ConversionSettingKeys.VideoScale: - case ConversionPreset.ConversionSettingKeys.VideoRotation: - return true; - } - - break; - - case OutputType.Flac: - case OutputType.Ico: - break; - - case OutputType.Gif: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.VideoScale: - case ConversionPreset.ConversionSettingKeys.VideoRotation: - case ConversionPreset.ConversionSettingKeys.VideoFramesPerSecond: - return true; - } - - break; - - case OutputType.Jpg: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.ImageQuality: - case ConversionPreset.ConversionSettingKeys.ImageScale: - case ConversionPreset.ConversionSettingKeys.ImageRotation: - case ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2: - return true; - } - - break; - - case OutputType.Mkv: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.AudioBitrate: - case ConversionPreset.ConversionSettingKeys.VideoQuality: - case ConversionPreset.ConversionSettingKeys.VideoScale: - case ConversionPreset.ConversionSettingKeys.VideoRotation: - case ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed: - return true; - } - - break; - - case OutputType.Mp3: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.AudioEncodingMode: - case ConversionPreset.ConversionSettingKeys.AudioBitrate: - return true; - } - - break; - - case OutputType.Mp4: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.AudioBitrate: - case ConversionPreset.ConversionSettingKeys.VideoQuality: - case ConversionPreset.ConversionSettingKeys.VideoScale: - case ConversionPreset.ConversionSettingKeys.VideoRotation: - case ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed: - return true; - } - - break; - - case OutputType.Ogg: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.AudioBitrate: - return true; - } - - break; - - case OutputType.Png: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.ImageScale: - case ConversionPreset.ConversionSettingKeys.ImageRotation: - case ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2: - case ConversionPreset.ConversionSettingKeys.ImageMaximumSize: - return true; - } - - break; - - case OutputType.Wav: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.AudioEncodingMode: - return true; - } - - break; - - case OutputType.Webm: - switch (settingsKey) - { - case ConversionPreset.ConversionSettingKeys.AudioBitrate: - case ConversionPreset.ConversionSettingKeys.VideoQuality: - case ConversionPreset.ConversionSettingKeys.VideoScale: - case ConversionPreset.ConversionSettingKeys.VideoRotation: - return true; - } - - break; - - default: - Debug.LogError("Relevant settings '{1}' are not define for output type {0}.", this.OutputType, settingsKey); - break; - } - - return false; + return this.Settings.ContainsKey(settingsKey); } private void InitializeDefaultSettings(OutputType outputType) { + this.settings.Clear(); + switch (outputType) { case OutputType.Aac: From df7834dec87bb0a8cce21735fb71149c85ecd7d5 Mon Sep 17 00:00:00 2001 From: Tichau Date: Tue, 1 Mar 2016 08:26:57 +0100 Subject: [PATCH 13/49] Update change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ee8e1..a729164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Version 0.6.1 +- New: Possibility to encode videos using VP9 video codec and Ogg vorbis audio codec in a webm container. +- Fixed: Issue where "Clamp to power of 2 size" option didn't work well with image that already have a power of 2 size. +- Fixed: Issue where conversion progress was not updated correctly (for converters based on ffmpeg). + ## Version 0.6 - New: Possibility to encode videos using H.264 video codec and AAC audio codec in a mp4 container (more portable than mkv). - New: Support new image input file formats: psd, tga, svg and exr. From 3ae020866d1f3cd100a24e1fb2cc173c19935853 Mon Sep 17 00:00:00 2001 From: Tichau Date: Fri, 8 Apr 2016 08:41:03 +0200 Subject: [PATCH 14/49] Add enable audio option for mkv, mp4 and webm formats. --- .../ConversionJobs/ConversionJob_FFMPEG.cs | 22 ++++++++++++---- .../ConversionPreset/ConversionPreset.cs | 3 +++ .../FileConverter/Windows/SettingsWindow.xaml | 26 ++++++++++--------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 88b0ccc..e2e90f8 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -219,11 +219,17 @@ namespace FileConverter.ConversionJobs string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); string videoFilteringArgs = ConversionJob_FFMPEG.Encapsulate("-vf", transformArgs); + string audioArgs = "-an"; + if (this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.EnableAudio)) + { + audioArgs = string.Format("-c:a aac -qscale:a {0}", this.AACBitrateToQualityIndex(audioEncodingBitrate)); + } + string encoderArgs = string.Format( - "-c:v libx264 -preset {0} -crf {1} -c:a aac -q:a {2} {3}", + "-c:v libx264 -preset {0} -crf {1} {2} {3}", this.H264EncodingSpeedToPreset(videoEncodingSpeed), this.H264QualityToCRF(videoEncodingQuality), - this.AACBitrateToQualityIndex(audioEncodingBitrate), + audioArgs, videoFilteringArgs); string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); @@ -278,7 +284,7 @@ namespace FileConverter.ConversionJobs { // https://trac.ffmpeg.org/wiki/Encode/VP9 int videoEncodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality); - int encodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); + int audioEncodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate); string encodingArgs = string.Empty; if (videoEncodingQuality == 63) @@ -294,10 +300,16 @@ namespace FileConverter.ConversionJobs string transformArgs = ConversionJob_FFMPEG.ComputeTransformArgs(this.ConversionPreset); string videoFilteringArgs = ConversionJob_FFMPEG.Encapsulate("-vf", transformArgs); + string audioArgs = "-an"; + if (this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.EnableAudio)) + { + audioArgs = string.Format("-c:a libvorbis -qscale:a {0}", this.OGGVBRBitrateToQualityIndex(audioEncodingQuality)); + } + string encoderArgs = string.Format( - "-c:v libvpx-vp9 {0} -c:a libvorbis -q:a {1} {2}", + "-c:v libvpx-vp9 {0} {1} {2}", encodingArgs, - this.OGGVBRBitrateToQualityIndex(encodingQuality), + audioArgs, videoFilteringArgs); string arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 0e45380..2b3657a 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -444,6 +444,7 @@ namespace FileConverter break; case OutputType.Mkv: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.EnableAudio, "True"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality, "28"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, "Medium"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, "1"); @@ -457,6 +458,7 @@ namespace FileConverter break; case OutputType.Mp4: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.EnableAudio, "True"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality, "28"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, "Medium"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, "1"); @@ -473,6 +475,7 @@ namespace FileConverter break; case OutputType.Webm: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.EnableAudio, "True"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate, "160"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoQuality, "40"); this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.VideoScale, "1"); diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 4dc28b5..d19272a 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -236,7 +236,7 @@ - @@ -283,13 +283,14 @@ - -