diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs
index beb815c..cc9f94a 100644
--- a/FFMpegCore/FFMpeg/FFMpeg.cs
+++ b/FFMpegCore/FFMpeg/FFMpeg.cs
@@ -20,7 +20,7 @@ namespace FFMpegCore
/// Bitmap with the requested snapshot.
public static bool Snapshot(string input, string output, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
{
- CheckSnapshotOutputExtension(ref output);
+ CheckSnapshotOutputExtension(output, FileExtension.Image.All);
var source = FFProbe.Analyse(input);
@@ -39,7 +39,7 @@ namespace FFMpegCore
/// Bitmap with the requested snapshot.
public static async Task SnapshotAsync(string input, string output, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
{
- CheckSnapshotOutputExtension(ref output);
+ CheckSnapshotOutputExtension(output, FileExtension.Image.All);
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
@@ -47,52 +47,47 @@ namespace FFMpegCore
.ProcessAsynchronously();
}
- private static FFMpegArgumentProcessor SnapshotProcess(string input, string output, IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
- {
- var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildSnapshotArguments(input, output, source, size, captureTime, streamIndex, inputFileIndex);
-
- return arguments
- .OutputToFile(output, true, outputOptions);
- }
-
- private static void CheckSnapshotOutputExtension(ref string output)
- {
- if (!FileExtension.Image.All.Contains(Path.GetExtension(output).ToLower()))
- {
- throw new ArgumentException(
- $"Invalid snapshot output extension: {output}, needed: {string.Join(",", FileExtension.Image.All)}");
- }
- }
-
public static bool GifSnapshot(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null)
{
- if (Path.GetExtension(output)?.ToLower() != FileExtension.Gif)
- {
- throw new ArgumentException(
- $"Invalid snapshot output extension: {output}, needed: {FileExtension.Gif}");
- }
+ CheckSnapshotOutputExtension(output, [FileExtension.Gif]);
var source = FFProbe.Analyse(input);
- var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex);
- return arguments
- .OutputToFile(output, true, outputOptions)
+ return GifSnapshotProcess(input, output, source, size, captureTime, duration, streamIndex)
.ProcessSynchronously();
}
public static async Task GifSnapshotAsync(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null)
{
- if (Path.GetExtension(output)?.ToLower() != FileExtension.Gif)
- {
- output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Gif);
- }
+ CheckSnapshotOutputExtension(output, [FileExtension.Gif]);
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
+
+ return await GifSnapshotProcess(input, output, source, size, captureTime, duration, streamIndex)
+ .ProcessAsynchronously();
+ }
+
+ private static FFMpegArgumentProcessor SnapshotProcess(string input, string output, IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, int? streamIndex = null, int inputFileIndex = 0)
+ {
+ var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildSnapshotArguments(input, output, source, size, captureTime, streamIndex, inputFileIndex);
+
+ return arguments.OutputToFile(output, true, outputOptions);
+ }
+
+ private static FFMpegArgumentProcessor GifSnapshotProcess(string input, string output, IMediaAnalysis source, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null)
+ {
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex);
- return await arguments
- .OutputToFile(output, true, outputOptions)
- .ProcessAsynchronously();
+ return arguments.OutputToFile(output, true, outputOptions);
+ }
+
+ private static void CheckSnapshotOutputExtension(string output, List extensions)
+ {
+ if (!extensions.Contains(Path.GetExtension(output).ToLower()))
+ {
+ throw new ArgumentException(
+ $"Invalid snapshot output extension: {output}, needed: {string.Join(",", FileExtension.Image.All)}");
+ }
}
///