mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-01-18 12:36:44 +00:00
Add "BuildGifSnapshotArguments" method
This commit is contained in:
parent
19c177a248
commit
d14ef2268f
1 changed files with 25 additions and 0 deletions
|
@ -31,6 +31,31 @@ public static (FFMpegArguments, Action<FFMpegArgumentOptions> outputOptions) Bui
|
|||
.Resize(size));
|
||||
}
|
||||
|
||||
public static (FFMpegArguments, Action<FFMpegArgumentOptions> outputOptions) BuildGifSnapshotArguments(
|
||||
string input,
|
||||
IMediaAnalysis source,
|
||||
Size? size = null,
|
||||
TimeSpan? captureTime = null,
|
||||
TimeSpan? duration = null,
|
||||
int? streamIndex = null,
|
||||
int fps = 12)
|
||||
{
|
||||
var defaultGifOutputSize = new Size(480, -1);
|
||||
|
||||
captureTime ??= TimeSpan.FromSeconds(source.Duration.TotalSeconds / 3);
|
||||
size = PrepareSnapshotSize(source, size) ?? defaultGifOutputSize;
|
||||
streamIndex ??= source.PrimaryVideoStream?.Index
|
||||
?? source.VideoStreams.FirstOrDefault()?.Index
|
||||
?? 0;
|
||||
|
||||
return (FFMpegArguments
|
||||
.FromFileInput(input, false, options => options
|
||||
.Seek(captureTime)
|
||||
.WithDuration(duration)),
|
||||
options => options
|
||||
.WithGifPalettArgument((int)streamIndex, size, fps));
|
||||
}
|
||||
|
||||
private static Size? PrepareSnapshotSize(IMediaAnalysis source, Size? wantedSize)
|
||||
{
|
||||
if (wantedSize == null || (wantedSize.Value.Height <= 0 && wantedSize.Value.Width <= 0) || source.PrimaryVideoStream == null)
|
||||
|
|
Loading…
Reference in a new issue