mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-21 10:01:58 +01:00
Add gif output type
This commit is contained in:
1 parent
9d648d7975
commit
6f06f2943b
11 files changed
+379
-59
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<FFMpegPass> ffmpegArgumentStringByPass = new List<FFMpegPass>();
|
||||
|
||||
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<int>(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<int>(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<int>(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<EncodingMode>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// <copyright file="ConversionJob_Ico.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,7 @@
|
||||
<Compile Include="ConversionJobs\ConversionJobFactory.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.Converters.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_FFMPEG.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_Gif.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_Ico.cs" />
|
||||
<Compile Include="ConversionJobs\ConversionJob_ImageMagick.cs" />
|
||||
<Compile Include="ConversionPreset\ConversionSettingsOverride.cs" />
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace FileConverter
|
||||
Aac,
|
||||
Avi,
|
||||
Flac,
|
||||
Gif,
|
||||
Ico,
|
||||
Jpg,
|
||||
Mkv,
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -109,6 +109,52 @@
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="GifSettingsDataTemplate">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Content="Frames per second :" Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Right"/>
|
||||
<Slider x:Name="QualitySlider" Grid.Row="0" Grid.Column="1" Value="{Binding SelectedPreset.Settings, ConverterParameter=VideoFramesPerSecond|System.Int32, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay}"
|
||||
Margin="0,2,0,0" VerticalAlignment="Top" AutoToolTipPlacement="TopLeft" IsSnapToTickEnabled="True" IsSelectionRangeEnabled="True" SelectionStart="10" SelectionEnd="20" Minimum="1" Maximum="30" TickPlacement="BottomRight" SmallChange="1" LargeChange="4" TickFrequency="1" Foreground="#004B82" />
|
||||
|
||||
<!-- Scale -->
|
||||
<Label Content="Scale :" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right"/>
|
||||
<Grid Grid.Row="1" Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="60"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Slider x:Name="ScaleSlider" Grid.Column="0" Value="{Binding SelectedPreset.Settings, ConverterParameter=VideoScale|System.Double, Converter={StaticResource ConversionSettingsToValueType}, ElementName=window, Mode=TwoWay}" Margin="0,2,0,0" VerticalAlignment="Top" IsSnapToTickEnabled="True" Minimum="0.075" Maximum="2" SmallChange="0.075" LargeChange="0.25" TickPlacement="BottomRight" Ticks="0.075 0.125 0.25 0.5 0.75 1 1.25 1.5 1.75 2" Foreground="#004B82"/>
|
||||
<Label Grid.Column="1">
|
||||
<Label.Content>
|
||||
<MultiBinding Converter="{StaticResource FormatStringConverter}" Mode="OneWay">
|
||||
<MultiBinding.ConverterParameter>{0:P0}</MultiBinding.ConverterParameter>
|
||||
<Binding ElementName="ScaleSlider" Path="Value" Mode="OneWay"/>
|
||||
</MultiBinding>
|
||||
</Label.Content>
|
||||
</Label>
|
||||
</Grid>
|
||||
|
||||
<!--Rotate-->
|
||||
<Label Content="Rotate :" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right"/>
|
||||
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
|
||||
<RadioButton Content="None" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter=VideoRotation|0, Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=TwoWay}" ToolTip="{x:Static project:Resources.ZeroDegreesRotationTooltip}" Margin="0,7,7,7"/>
|
||||
<RadioButton Content="90°" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter=VideoRotation|90, Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=TwoWay}" ToolTip="{x:Static project:Resources.NinetyDegreesRotationTooltip}" Margin="7"/>
|
||||
<RadioButton Content="180°" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter=VideoRotation|180, Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=TwoWay}" ToolTip="{x:Static project:Resources.OneEightyDegreesRotationTooltip}" Margin="7"/>
|
||||
<RadioButton Content="270°" IsChecked="{Binding SelectedPreset.Settings, ConverterParameter=VideoRotation|270, Converter={StaticResource ConversionSettingsEquals}, ElementName=window, Mode=TwoWay}" ToolTip="{x:Static project:Resources.TwoSeventyDegreesRotationTooltip}" Margin="7"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="AviSettingsDataTemplate">
|
||||
<Grid>
|
||||
@@ -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}"
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace FileConverter
|
||||
OutputType.Ico,
|
||||
OutputType.Jpg,
|
||||
OutputType.Png,
|
||||
OutputType.Gif,
|
||||
};
|
||||
|
||||
this.OutputFormats.ItemsSource = outputTypes;
|
||||
|
||||
Reference in new issue
Block a user