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;