mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 18:15:44 +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>
|
/// <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)
|
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);
|
var source = FFProbe.Analyse(input);
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace FFMpegCore
|
||||||
/// <returns>Bitmap with the requested snapshot.</returns>
|
/// <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)
|
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);
|
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
|
||||||
|
|
||||||
|
|
@ -47,52 +47,47 @@ namespace FFMpegCore
|
||||||
.ProcessAsynchronously();
|
.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)
|
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)
|
CheckSnapshotOutputExtension(output, [FileExtension.Gif]);
|
||||||
{
|
|
||||||
throw new ArgumentException(
|
|
||||||
$"Invalid snapshot output extension: {output}, needed: {FileExtension.Gif}");
|
|
||||||
}
|
|
||||||
|
|
||||||
var source = FFProbe.Analyse(input);
|
var source = FFProbe.Analyse(input);
|
||||||
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex);
|
|
||||||
|
|
||||||
return arguments
|
return GifSnapshotProcess(input, output, source, size, captureTime, duration, streamIndex)
|
||||||
.OutputToFile(output, true, outputOptions)
|
|
||||||
.ProcessSynchronously();
|
.ProcessSynchronously();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<bool> GifSnapshotAsync(string input, string output, Size? size = null, TimeSpan? captureTime = null, TimeSpan? duration = null, int? streamIndex = null)
|
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)
|
CheckSnapshotOutputExtension(output, [FileExtension.Gif]);
|
||||||
{
|
|
||||||
output = Path.Combine(Path.GetDirectoryName(output), Path.GetFileNameWithoutExtension(output) + FileExtension.Gif);
|
|
||||||
}
|
|
||||||
|
|
||||||
var source = await FFProbe.AnalyseAsync(input).ConfigureAwait(false);
|
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);
|
var (arguments, outputOptions) = SnapshotArgumentBuilder.BuildGifSnapshotArguments(input, source, size, captureTime, duration, streamIndex);
|
||||||
|
|
||||||
return await arguments
|
return arguments.OutputToFile(output, true, outputOptions);
|
||||||
.OutputToFile(output, true, outputOptions)
|
}
|
||||||
.ProcessAsynchronously();
|
|
||||||
|
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>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue