diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs index 870e8c8..f0b89f8 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs @@ -4,6 +4,7 @@ namespace FileConverter.ConversionJobs { using System; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Text.RegularExpressions; @@ -132,8 +133,16 @@ namespace FileConverter.ConversionJobs case OutputType.Png: { + float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale); + string scaleArgs = string.Empty; + if (Math.Abs(scaleFactor - 1f) >= 0.005f) + { + scaleArgs = string.Format("-vf scale=iw*{0}:ih*{0}", scaleFactor.ToString("#.##", CultureInfo.InvariantCulture)); + } + // http://www.howtogeek.com/203979/is-the-png-format-lossless-since-it-has-a-compression-parameter/ - string encoderArgs = string.Format("-compression_level 100"); + string encoderArgs = string.Format("-compression_level 100 {0}", scaleArgs); + arguments = string.Format("-n -stats -i \"{0}\" {2} \"{1}\"", this.InputFilePath, this.OutputFilePath, encoderArgs); } @@ -142,7 +151,16 @@ namespace FileConverter.ConversionJobs case OutputType.Jpg: { int encodingQuality = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageQuality); - string encoderArgs = string.Format("-q:v {0}", this.JPGQualityToQualityIndex(encodingQuality)); + + float scaleFactor = this.ConversionPreset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale); + string scaleArgs = string.Empty; + if (Math.Abs(scaleFactor - 1f) >= 0.005f) + { + 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); } diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 835b80f..ae5eb29 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -436,6 +436,16 @@ namespace FileConverter switch (settingsKey) { case ConversionPreset.ConversionSettingKeys.ImageQuality: + case ConversionPreset.ConversionSettingKeys.ImageScale: + return true; + } + + break; + + case OutputType.Png: + switch (settingsKey) + { + case ConversionPreset.ConversionSettingKeys.ImageScale: return true; } @@ -453,13 +463,17 @@ namespace FileConverter this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.AudioBitrate, "128"); break; - case OutputType.Flac: case OutputType.Ico: + case OutputType.Flac: + break; + case OutputType.Png: + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale, "1"); break; case OutputType.Jpg: this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageQuality, "25"); + this.InitializeSettingsValue(ConversionPreset.ConversionSettingKeys.ImageScale, "1"); break; case OutputType.Mkv: @@ -634,6 +648,7 @@ namespace FileConverter public const string AudioEncodingMode = "AudioEncodingMode"; public const string AudioBitrate = "AudioBitrate"; public const string ImageQuality = "ImageQuality"; + public const string ImageScale = "ImageScale"; public const string VideoQuality = "VideoQuality"; public const string VideoEncodingSpeed = "VideoEncodingSpeed"; } diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 027162a..c00014b 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -117,6 +117,7 @@ + diff --git a/Application/FileConverter/ValueConverters/Generic/FormatStringConverter.cs b/Application/FileConverter/ValueConverters/Generic/FormatStringConverter.cs new file mode 100644 index 0000000..020814c --- /dev/null +++ b/Application/FileConverter/ValueConverters/Generic/FormatStringConverter.cs @@ -0,0 +1,32 @@ +// License: http://www.gnu.org/licenses/gpl.html GPL version 3. + +namespace FileConverter.ValueConverters.Generic +{ + using System; + using System.Globalization; + using System.Windows.Data; + + public class FormatStringConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values == null) + { + throw new ArgumentException("The values must not be null."); + } + + string format = parameter as string; + if (format == null) + { + return string.Empty; + } + + return string.Format(format, values); + } + + public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs index 90cf3e2..116b2a2 100644 --- a/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs +++ b/Application/FileConverter/Windows/ConversionSettingsTemplateSelector.cs @@ -42,6 +42,12 @@ namespace FileConverter.Windows get; set; } + + public DataTemplate PngSettingsDataTemplate + { + get; + set; + } public DataTemplate MkvSettingsDataTemplate { @@ -77,6 +83,9 @@ namespace FileConverter.Windows case OutputType.Jpg: return this.JpgSettingsDataTemplate; + + case OutputType.Png: + return this.PngSettingsDataTemplate; } return this.DefaultDataTemplate; diff --git a/Application/FileConverter/Windows/SettingsWindow.xaml b/Application/FileConverter/Windows/SettingsWindow.xaml index 9e4d1bf..c6bd9ee 100644 --- a/Application/FileConverter/Windows/SettingsWindow.xaml +++ b/Application/FileConverter/Windows/SettingsWindow.xaml @@ -17,6 +17,7 @@ + @@ -151,13 +152,66 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + JpgSettingsDataTemplate="{StaticResource JpgSettingsDataTemplate}" + PngSettingsDataTemplate="{StaticResource PngSettingsDataTemplate}" /> @@ -354,6 +409,5 @@