From d14ef2268f6b5ae9b9027d181db85dd1d08fe4ba Mon Sep 17 00:00:00 2001 From: Rafael Carvalho Date: Tue, 7 Mar 2023 16:31:45 +1300 Subject: [PATCH] Add "BuildGifSnapshotArguments" method --- FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs index 4456837..2645867 100644 --- a/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs +++ b/FFMpegCore/FFMpeg/SnapshotArgumentBuilder.cs @@ -31,6 +31,31 @@ public static (FFMpegArguments, Action outputOptions) Bui .Resize(size)); } + public static (FFMpegArguments, Action 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)