How to convert a video to a high-quality GIF with a smaller file size using FFmpeg

Опубликовано: 05 Октябрь 2024
на канале: Sensei
33
3

How to convert a video to a high-quality GIF with a smaller file size using ffmpeg ?

Steps:
1.Install FFMPEG(   • How To Install FFMPEG on Windows 11  )
2.Follow below command instructions

Start with ffmpeg in command line
{-ss 30}: Specifies the start time offset in the input video.
{-t 3}: Specifies the duration of the output video.
{-i input.mp4}: Specifies the input video file.
{-vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"}: This part of the command is a filter graph.
Let's break it down further:
{fps=10}: Sets the frame rate of the output GIF
{scale=320:-1:flags=lanczos}: Scales the video to a width of 320 pixels while maintaining the aspect ratio. The {flags=lanczos} option helps to improve the quality of the scaled image.
{split[s0][s1]}: Splits the video into two streams named s0 and s1.
{[s0]palettegen[p]}: Generates a palette for the GIF from the first stream (s0).
{[s1][p]paletteuse}: Applies the palette generated by palettegen to the second stream (s1), creating the final GIF.
{-loop 0}: Specifies that the GIF should loop indefinitely.
{output.gif}: Specifies the output GIF file.

This command creates a GIF with a custom palette generated from the input video, which often results in better quality and smaller file sizes compared to using the default palette. Adjust the parameters (fps, scale, ss, t) according to your preferences and the characteristics of your input video.

Music:
"Sappheiros - Embrace" is under a Creative Commons license (CC BY 3.0)
Music promoted by BreakingCopyright: https://bit.ly/embrace-song