FFmpeg - Convert MP4 video to GIF
FFmpeg command to convert an MP4 video to a GIF file:
ffmpeg -i input.mp4 \
-filter_complex \
"[0:v] fps=10,scale=320:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse" \
output.gif
This will create a GIF with a maximum width of 320 pixels and a maximum height proportional to the input aspect ratio, with a frame rate of 10 frames per second.
-i input.mp4
: Specifies the input video file.-filter_complex
: For using complex filtergraphs to modify the video stream."[0:v] fps=10,scale=320:-1,split [a][b];[a] palettegen [p];[b][p] paletteuse"
: This filtergraph does the following:[0:v]
: Specifies the video stream from the input file.fps=10
: Sets the output frame rate to 10 frames per second.scale=320:-1
: Resizes the video to a maximum width of 320 pixels, while preserving the aspect ratio.split [a][b]
: Splits the video stream into two copies, named [a] and [b].[a] palettegen [p]
: Generates a color palette for the GIF based on the frames in [a], and saves it to a temporary file named [p].[b][p] paletteuse
: Applies the color palette generated in - [p] to the frames in [b], and outputs the final GIF frames.
output.gif
: output file.
09. May 2023