用 ffmpeg 把视频片段转换为 GIF 动图

palettegen/paletteuse 两趟调色板滤镜生成的 GIF 色彩准确,不会出现常见的色带。

Windows视频FFmpegGIF低风险
用 -vf 指定 fps、scale 以及 split/palettegen/paletteuse 滤镜链,把截取的片段转为高质量 GIF。

01命令

命令
$ ffmpeg -i input.mp4 -ss 5 -t 3 -vf "fps=12,scale=480:-1:flags=lanczos,split[a][b];[a]palettegen[p];[b][p]paletteuse" output.gif

02作用说明

GIF 只支持 256 色,ffmpeg 默认转换会出现明显色带;palettegen 会根据帧内容生成最优调色板,paletteuse 再应用它,滤镜链中的 split 就是为了让同一批帧同时供两个滤镜使用。fps=12 和 scale=480 可以控制文件体积——30fps 全分辨率的 GIF 会大得离谱。用 -ss 和 -t 选择片段,追求极致准确时也可以分两趟对同一批帧单独生成调色板。

03风险

风险低风险
使用条件ffmpeg must be installed (winget install Gyan.FFmpeg)

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • FFmpeg Wiki: Seeking
    FFmpeg · technical · 2026-09-17
    依据: Explains input seeking (-ss) and duration limiting (-t) used to select the segment that becomes the GIF.
  • FFmpeg Documentation
    FFmpeg · vendor-doc · 2026-09-17
    依据: Documents the -vf filterchain, fps and scale filters, and the palettegen/paletteuse filters for GIF palette optimization.

最后验证: 2026-09-17 · 分类: 媒体