mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 01:55:45 +00:00
FIX: small moments
This commit is contained in:
parent
aa1051b268
commit
4025b82fbf
1 changed files with 29 additions and 34 deletions
|
|
@ -20,7 +20,7 @@ namespace FFMpegCore
|
|||
/// <returns>Bitmap with the requested snapshot.</returns>
|
||||
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
|
|||
/// <returns>Bitmap with the requested snapshot.</returns>
|
||||
public static async Task<bool> 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<bool> 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<string> extensions)
|
||||
{
|
||||
if (!extensions.Contains(Path.GetExtension(output).ToLower()))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Invalid snapshot output extension: {output}, needed: {string.Join(",", FileExtension.Image.All)}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue