video-to-gif

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill: Video to GIF

Skill:视频转GIF

Convert a video file into multiple GIF variants with different parameters, so the user can visually compare and pick the best one.
Prerequisite: FFmpeg must be installed. gifsicle is optional (enables lossy compression variants).

将视频文件转换为具有不同参数的多种GIF变体,方便用户直观对比并选择最佳版本。
前置要求:必须安装FFmpeg。gifsicle为可选组件(启用有损压缩变体)。

When to Use

使用场景

The user wants to create a GIF from a video clip but isn't sure about the right parameters. GIF quality involves tradeoffs between:
  • File size — smaller is better for sharing/embedding
  • Color accuracy — fewer colors = smaller but may cause banding
  • Smoothness — higher FPS = smoother but larger
  • Resolution — wider = sharper detail but larger
Rather than guessing, this skill generates multiple variants and lets the user decide.

用户想要从视频片段创建GIF,但不确定合适的参数。GIF的画质需要在以下方面进行权衡:
  • 文件大小 — 越小越利于分享/嵌入
  • 色彩准确度 — 颜色数量越少=文件越小,但可能出现色带
  • 流畅度 — FPS越高=越流畅,但文件越大
  • 分辨率 — 宽度越大=细节越清晰,但文件越大
无需猜测参数,该Skill会生成多种变体,让用户自行决定。

Default Workflow

默认工作流程

When the user provides a video file:
bash
python /path/to/skills/video-to-gif/scripts/video_to_gif.py <input.mp4>
This generates GIFs in
<input>_gifs/
directory with the full preset (18 variants):
  • 3 FPS options: 10, 15, 20
  • 3 widths: 480px, 640px, 800px
  • 2 color counts: 128, 256
Output includes a sorted comparison table showing file size, FPS, width, and colors for each variant.

当用户提供视频文件时:
bash
python /path/to/skills/video-to-gif/scripts/video_to_gif.py <input.mp4>
此命令会在
<input>_gifs/
目录下生成采用full预设的GIF(共18种变体):
  • 3种FPS选项:10、15、20
  • 3种宽度:480px、640px、800px
  • 2种颜色数量:128、256
输出内容包含一个排序后的对比表格,展示每个变体的文件大小、FPS、宽度和颜色数量。

Presets

预设配置

PresetVariantsBest For
full
~18General use — broad exploration of the parameter space
minimal
~4Quick comparison — just a few key tradeoff points
lossy
~12Smallest files — includes gifsicle lossy compression levels
quality
~12Best visuals — higher res, includes bayer dithering
bash
undefined
预设变体数量适用场景
full
~18通用场景 — 全面探索参数空间
minimal
~4快速对比 — 仅包含几个关键权衡点
lossy
~12最小文件体积 — 包含gifsicle有损压缩级别
quality
~12最佳视觉效果 — 更高分辨率,包含拜耳抖动
bash
undefined

Quick comparison with fewer variants

使用更少变体进行快速对比

python .../video_to_gif.py input.mp4 --presets minimal
python .../video_to_gif.py input.mp4 --presets minimal

Include lossy compression (requires gifsicle)

启用有损压缩(需要gifsicle)

python .../video_to_gif.py input.mp4 --presets lossy
python .../video_to_gif.py input.mp4 --presets lossy

Higher quality focus

侧重更高画质

python .../video_to_gif.py input.mp4 --presets quality

---
python .../video_to_gif.py input.mp4 --presets quality

---

Common Options

常用选项

FlagDefaultDescription
-o
,
--output-dir
<input>_gifs/
Output directory for all GIF variants
--start
noneStart time in seconds (trim source)
--end
noneEnd time in seconds (trim source)
--presets
full
Preset config: full, minimal, lossy, quality
--fps
presetOverride FPS values (e.g.,
--fps 10 15 20
)
--width
presetOverride width values (e.g.,
--width 480 640
)
--colors
presetOverride color counts (e.g.,
--colors 128 256
)
--lossy
presetGifsicle lossy levels (e.g.,
--lossy 0 30 80
)

标识默认值说明
-o
,
--output-dir
<input>_gifs/
所有GIF变体的输出目录
--start
起始时间(秒,用于裁剪源视频)
--end
结束时间(秒,用于裁剪源视频)
--presets
full
预设配置:full、minimal、lossy、quality
--fps
预设值覆盖FPS值(例如:
--fps 10 15 20
--width
预设值覆盖宽度值(例如:
--width 480 640
--colors
预设值覆盖颜色数量(例如:
--colors 128 256
--lossy
预设值Gifsicle有损压缩级别(例如:
--lossy 0 30 80

Examples

示例

bash
undefined
bash
undefined

Convert first 10 seconds of a video

转换视频的前10秒

python .../video_to_gif.py demo.mp4 --end 10
python .../video_to_gif.py demo.mp4 --end 10

Extract a specific segment

提取特定片段

python .../video_to_gif.py demo.mp4 --start 5 --end 15
python .../video_to_gif.py demo.mp4 --start 5 --end 15

Custom parameter sweep

自定义参数扫描

python .../video_to_gif.py demo.mp4 --fps 12 15 --width 480 800 --colors 256
python .../video_to_gif.py demo.mp4 --fps 12 15 --width 480 800 --colors 256

Lossy compression comparison (needs gifsicle)

有损压缩对比(需要gifsicle)

python .../video_to_gif.py demo.mp4 --lossy 0 30 60 100

---
python .../video_to_gif.py demo.mp4 --lossy 0 30 60 100

---

How to Choose

选择技巧

After running, open the output directory and compare:
  1. Start with the smallest files — check if quality is acceptable
  2. Look for color banding — if visible, try 256 colors or bayer dithering (quality preset)
  3. Check smoothness — if too choppy, go up to 15 or 20 FPS
  4. Check clarity — if text is unreadable, go up to 640 or 800px width
The sweet spot for most screen recordings is usually around 640px, 15fps, 256 colors.

运行完成后,打开输出目录进行对比:
  1. 先看最小的文件 — 检查画质是否可接受
  2. 查看是否有色带 — 如果存在,尝试256色或拜耳抖动(quality预设)
  3. 检查流畅度 — 如果过于卡顿,将FPS提升至15或20
  4. 检查清晰度 — 如果文字无法辨认,将宽度提升至640或800px
对于大多数屏幕录制内容,最佳平衡点通常是640px、15fps、256色

Important Notes

重要说明

  • Widths larger than the source video resolution are automatically skipped.
  • The script uses FFmpeg's two-pass palette generation for optimal GIF quality (much better than single-pass).
  • Lossy compression via gifsicle can reduce file size by 30-70% with minimal visual impact at level 30-60.
  • For very long clips, consider trimming with
    --start
    /
    --end
    first — GIFs over 10 seconds can get very large.
  • 大于源视频分辨率的宽度会自动跳过。
  • 脚本使用FFmpeg的两次调色板生成技术,以获得最佳GIF画质(远优于单次生成)。
  • 通过gifsicle进行的有损压缩在30-60级别时,可减少30-70%的文件大小,且视觉影响极小。
  • 对于超长片段,建议先使用
    --start
    /
    --end
    进行裁剪 — 超过10秒的GIF文件可能会非常大。