gif-generation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTable of Contents
目录
- Overview
- Required TodoWrite Items
- Process
- Step 1: Validate Input File
- Step 2: Check ffmpeg Installation
- Step 3: Execute Conversion
- Basic Conversion (Fast, Larger File)
- High Quality with Palette Generation (Recommended)
- Maximum Quality with Dithering
- Optimization Options
- Common Presets
- Step 4: Verify Output
- Exit Criteria
- Troubleshooting
- Large Output File
- Color Banding
- Slow Conversion
GIF Generation Skill
GIF生成技能
Post-process video files (webm/mp4) and generate optimized GIF output with configurable quality settings.
对视频文件(webm/mp4)进行后处理,支持配置质量参数生成优化的GIF输出。
When To Use
适用场景
- Converting recordings to animated GIF format
- Creating lightweight demo animations
- 将录屏转换为动图GIF格式
- 创建轻量级演示动图
When NOT To Use
不适用场景
- High-quality video output - use full recording tools
- Static image generation without animation needs
- 需要高质量视频输出:请使用完整的录屏工具
- 无动画需求的静态图片生成
Overview
概述
This skill handles the conversion of video recordings (typically from browser automation) to GIF format. It provides multiple quality presets and optimization options to balance file size with visual quality.
本技能可将视频录屏(通常来自浏览器自动化工具)转换为GIF格式,提供多种质量预设和优化选项,可在文件大小和视觉质量之间取得平衡。
Required TodoWrite Items
必填待办项
- Validate input video file exists
- Check ffmpeg installation
- Execute GIF conversion
- Verify output and report resultsVerification: Run the command with flag to verify availability.
--help- 校验输入视频文件存在
- 检查ffmpeg安装情况
- 执行GIF转换
- 校验输出并上报结果验证: 携带参数运行命令以确认可用性。
--helpProcess
处理流程
Step 1: Validate Input File
步骤1:校验输入文件
Confirm the source video file exists and is a supported format:
bash
undefined确认源视频文件存在且为支持的格式:
bash
undefinedCheck file exists and get info
检查文件存在并获取信息
if [[ -f "$INPUT_FILE" ]]; then
file "$INPUT_FILE"
ffprobe -v quiet -show_format -show_streams "$INPUT_FILE" 2>/dev/null | head -20
else
echo "Error: Input file not found: $INPUT_FILE"
exit 1
fi
**Verification:** Run the command with `--help` flag to verify availability.
Supported input formats: `.webm`, `.mp4`, `.mov`, `.avi`if [[ -f "$INPUT_FILE" ]]; then
file "$INPUT_FILE"
ffprobe -v quiet -show_format -show_streams "$INPUT_FILE" 2>/dev/null | head -20
else
echo "Error: Input file not found: $INPUT_FILE"
exit 1
fi
**验证:** 携带`--help`参数运行命令以确认可用性。
支持的输入格式:`.webm`、`.mp4`、`.mov`、`.avi`Step 2: Check ffmpeg Installation
步骤2:检查ffmpeg安装情况
Verify ffmpeg is available:
bash
if ! command -v ffmpeg &> /dev/null; then
echo "Error: ffmpeg is not installed"
echo "Install with: sudo apt install ffmpeg (Linux) or brew install ffmpeg (macOS)"
exit 1
fi
ffmpeg -version | head -1Verification: Run the command with flag to verify availability.
--help验证ffmpeg可用:
bash
if ! command -v ffmpeg &> /dev/null; then
echo "Error: ffmpeg is not installed"
echo "Install with: sudo apt install ffmpeg (Linux) or brew install ffmpeg (macOS)"
exit 1
fi
ffmpeg -version | head -1验证: 携带参数运行命令以确认可用性。
--helpStep 3: Execute Conversion
步骤3:执行转换
Choose the appropriate conversion command based on quality requirements:
根据质量要求选择合适的转换命令:
Basic Conversion (Fast, Larger File)
基础转换(速度快,文件更大)
bash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1" output.gifVerification: Run the command with flag to verify availability.
--helpbash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1" output.gif验证: 携带参数运行命令以确认可用性。
--helpHigh Quality with Palette Generation (Recommended)
生成调色板的高质量转换(推荐)
bash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gifVerification: Run the command with flag to verify availability.
--helpbash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif验证: 携带参数运行命令以确认可用性。
--helpMaximum Quality with Dithering
带抖动处理的最高质量转换
bash
ffmpeg -i input.webm -vf "fps=15,scale=1024:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256:stats_mode=single[p];[s1][p]paletteuse=dither=bayer:bayer_scale=5" output.gifVerification: Run the command with flag to verify availability.
--helpbash
ffmpeg -i input.webm -vf "fps=15,scale=1024:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256:stats_mode=single[p];[s1][p]paletteuse=dither=bayer:bayer_scale=5" output.gif验证: 携带参数运行命令以确认可用性。
--helpOptimization Options
优化选项
| Option | Description | Recommended Value |
|---|---|---|
| Frames per second | 10-15 for smooth, 5-8 for smaller files |
| Width in pixels (-1 maintains aspect ratio) | 800 for web, 480 for thumbnails |
| High-quality scaling algorithm | Always use for best quality |
| Generate optimized color palette | Use for quality-critical output |
| Dithering algorithm | |
| 选项 | 描述 | 推荐值 |
|---|---|---|
| 每秒帧率 | 追求流畅效果设为10-15,追求更小文件设为5-8 |
| 宽度像素值(-1表示保持宽高比) | 网页使用设为800,缩略图使用设为480 |
| 高质量缩放算法 | 追求最佳质量时始终使用 |
| 生成优化的调色板 | 对输出质量要求高时使用 |
| 抖动算法 | 需要图案效果用 |
Common Presets
常用预设
bash
undefinedbash
undefinedThumbnail (small, fast loading)
缩略图(文件小,加载快)
ffmpeg -i input.webm -vf "fps=8,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" thumbnail.gif
ffmpeg -i input.webm -vf "fps=8,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" thumbnail.gif
Documentation (balanced)
文档使用(平衡质量)
ffmpeg -i input.webm -vf "fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" docs.gif
ffmpeg -i input.webm -vf "fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" docs.gif
High-fidelity demo
高保真演示
ffmpeg -i input.webm -vf "fps=15,scale=1024:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256[p];[s1][p]paletteuse" demo.gif
**Verification:** Run the command with `--help` flag to verify availability.ffmpeg -i input.webm -vf "fps=15,scale=1024:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256[p];[s1][p]paletteuse" demo.gif
**验证:** 携带`--help`参数运行命令以确认可用性。Step 4: Verify Output
步骤4:校验输出文件
Confirm successful conversion and report metrics:
bash
if [[ -f "$OUTPUT_FILE" ]]; then
echo "GIF generated successfully: $OUTPUT_FILE"
# Report file size
SIZE=$(du -h "$OUTPUT_FILE" | cut -f1)
echo "File size: $SIZE"
# Get dimensions and frame count
ffprobe -v quiet -select_streams v:0 -show_entries stream=width,height,nb_frames -of csv=p=0 "$OUTPUT_FILE"
else
echo "Error: GIF generation failed"
exit 1
fiVerification: Run the command with flag to verify availability.
--help确认转换成功并上报指标:
bash
if [[ -f "$OUTPUT_FILE" ]]; then
echo "GIF generated successfully: $OUTPUT_FILE"
# 上报文件大小
SIZE=$(du -h "$OUTPUT_FILE" | cut -f1)
echo "File size: $SIZE"
# 获取尺寸和帧数
ffprobe -v quiet -select_streams v:0 -show_entries stream=width,height,nb_frames -of csv=p=0 "$OUTPUT_FILE"
else
echo "Error: GIF generation failed"
exit 1
fi验证: 携带参数运行命令以确认可用性。
--helpExit Criteria
退出标准
- Input file validated as existing video format
- ffmpeg confirmed available
- GIF file created at specified output path
- Output file size reported to user
- No ffmpeg errors during conversion
- 输入文件已校验为存在的视频格式
- 已确认ffmpeg可用
- 已在指定输出路径生成GIF文件
- 已向用户上报输出文件大小
- 转换过程中无ffmpeg错误
Troubleshooting
问题排查
Large Output File
输出文件过大
Reduce quality settings:
bash
undefined降低质量设置:
bash
undefinedLower fps and resolution
降低帧率和分辨率
ffmpeg -i input.webm -vf "fps=8,scale=640:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" smaller.gif
**Verification:** Run the command with `--help` flag to verify availability.ffmpeg -i input.webm -vf "fps=8,scale=640:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" smaller.gif
**验证:** 携带`--help`参数运行命令以确认可用性。Color Banding
色带问题
Use dithering:
bash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=floyd_steinberg" smooth.gifVerification: Run the command with flag to verify availability.
--help使用抖动处理:
bash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse=dither=floyd_steinberg" smooth.gif验证: 携带参数运行命令以确认可用性。
--helpSlow Conversion
转换速度慢
Use basic conversion without palette generation for speed:
bash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1" quick.gifVerification: Run the command with flag to verify availability.
--help使用无调色板生成的基础转换提升速度:
bash
ffmpeg -i input.webm -vf "fps=10,scale=800:-1" quick.gif验证: 携带参数运行命令以确认可用性。
--help