video-frames
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVideo-Frames Skill
Video-Frames 技能
Production-grade video frame extraction with comprehensive quality control, progress tracking, and safety limits.
具备全面质量控制、进度追踪和安全限制的生产级视频帧提取工具。
When to Use
适用场景
✅ USE this skill when:
- Extracting specific frames from videos at timestamps
- Creating thumbnail grids/contact sheets for video overview
- Generating animated GIFs from video segments
- Batch extracting frames at intervals (e.g., every N seconds)
- Creating video previews or storyboards
- Needing pixel-perfect frame access by index
- Extracting frames at specific quality levels
❌ DON'T use this skill when:
- Simple format conversion → Use ffmpeg-tools
- Video editing (effects) → Use video editor
- Real-time frame capture → Use streaming tools
- Video capture from camera → Use camsnap
- Image generation → Use image-gen
✅ 适用场景:
- 从视频中按时间戳提取特定帧
- 为视频概览创建缩略图网格/联络表
- 从视频片段生成动画GIF
- 按固定间隔批量提取帧(例如:每N秒一帧)
- 创建视频预览或故事板
- 需要按索引精确访问某一帧
- 按特定质量等级提取帧
❌ 不适用场景:
- 简单格式转换 → 使用ffmpeg-tools
- 视频编辑(添加特效)→ 使用视频编辑器
- 实时帧捕获 → 使用流媒体工具
- 从摄像头捕获视频 → 使用camsnap
- 图像生成 → 使用image-gen
Prerequisites
前置要求
bash
undefinedbash
undefinedInstall FFmpeg
安装 FFmpeg
brew install ffmpeg # macOS
sudo apt install ffmpeg # Ubuntu/Debian
brew install ffmpeg # macOS
sudo apt install ffmpeg # Ubuntu/Debian
Optional: Install ImageMagick for better grid generation
可选:安装 ImageMagick 以获得更好的网格生成效果
brew install imagemagick # macOS
sudo apt install imagemagick # Ubuntu
brew install imagemagick # macOS
sudo apt install imagemagick # Ubuntu
Verify installation
验证安装
ffmpeg -version
ffprobe -version
undefinedffmpeg -version
ffprobe -version
undefinedCommands
命令说明
1. Extract Single Frame
1. 提取单帧
Extract a single frame at a specific time or by frame index.
bash
undefined按特定时间或帧索引提取单帧。
bash
undefinedExtract frame at timestamp
按时间戳提取帧
{baseDir}/video-frames.js frame video.mp4 --time 30 --out frame.jpg
{baseDir}/video-frames.js frame video.mp4 --time 00:02:30 --out frame.jpg
{baseDir}/video-frames.js frame video.mp4 --time 150.5 --out frame.jpg
{baseDir}/video-frames.js frame video.mp4 --time 30 --out frame.jpg
{baseDir}/video-frames.js frame video.mp4 --time 00:02:30 --out frame.jpg
{baseDir}/video-frames.js frame video.mp4 --time 150.5 --out frame.jpg
Extract by frame index
按帧索引提取
{baseDir}/video-frames.js frame video.mp4 --index 0 --out first-frame.jpg
{baseDir}/video-frames.js frame video.mp4 --index 1000 --out frame-1000.jpg
{baseDir}/video-frames.js frame video.mp4 --index 0 --out first-frame.jpg
{baseDir}/video-frames.js frame video.mp4 --index 1000 --out frame-1000.jpg
With quality settings
带质量设置
{baseDir}/video-frames.js frame video.mp4 --time 30 --format png --out high-quality.png
{baseDir}/video-frames.js frame video.mp4 --time 30 --quality 1 --out best-quality.jpg
{baseDir}/video-frames.js frame video.mp4 --time 30 --format jpg --quality 2
**Time Formats:**
| Format | Example | Description |
|--------|---------|-------------|
| Seconds | `30` | Simple seconds |
| MM:SS | `2:30` | Minutes:Seconds |
| HH:MM:SS | `00:02:30` | Full timecode |
| Decimal | `90.5` | Millisecond precision |
**Quality Settings (JPEG):**
| Value | Quality | File Size | Use Case |
|-------|---------|-----------|----------|
| `1` | Best | Large | Archival, quality preservation |
| `2-3` | High | Medium | Default, good balance |
| `5` | Medium | Small | Web, quick preview |
| `10+` | Low | Very small | Draft, thumbnail |
**Supported Formats:**
- `jpg/jpeg` - Web optimized, compression
- `png` - Lossless, transparency, best quality
- `bmp` - Uncompressed raw
- `tiff` - Professional formats
- `webp` - Next-gen web format{baseDir}/video-frames.js frame video.mp4 --time 30 --format png --out high-quality.png
{baseDir}/video-frames.js frame video.mp4 --time 30 --quality 1 --out best-quality.jpg
{baseDir}/video-frames.js frame video.mp4 --time 30 --format jpg --quality 2
**时间格式:**
| 格式 | 示例 | 说明 |
|--------|---------|-------------|
| 秒 | `30` | 简单秒数 |
| 分:秒 | `2:30` | 分钟:秒数 |
| 时:分:秒 | `00:02:30` | 完整时间码 |
| 十进制 | `90.5` | 毫秒精度 |
**JPEG 质量设置:**
| 数值 | 质量 | 文件大小 | 适用场景 |
|-------|---------|-----------|----------|
| `1` | 最佳 | 大 | 归档、画质保留 |
| `2-3` | 高 | 中等 | 默认选项,平衡画质与大小 |
| `5` | 中等 | 小 | 网页使用、快速预览 |
| `10+` | 低 | 极小 | 草稿、缩略图 |
**支持的输出格式:**
- `jpg/jpeg` - 网页优化格式,带压缩
- `png` - 无损格式,支持透明,画质最佳
- `bmp` - 无压缩原始格式
- `tiff` - 专业格式
- `webp` - 下一代网页格式2. Extract Multiple Frames
2. 提取多帧
Batch extract frames at regular intervals.
bash
undefined按固定间隔批量提取帧。
bash
undefinedExtract 1 frame per second
每秒提取1帧
{baseDir}/video-frames.js frames video.mp4 --fps 1
{baseDir}/video-frames.js frames video.mp4 --fps 1
Extract specific segment
提取特定片段
{baseDir}/video-frames.js frames video.mp4 --fps 1 --start 00:01:00 --duration 60
{baseDir}/video-frames.js frames video.mp4 --fps 5 --start 30 --duration 120
{baseDir}/video-frames.js frames video.mp4 --fps 1 --start 00:01:00 --duration 60
{baseDir}/video-frames.js frames video.mp4 --fps 5 --start 30 --duration 120
高质量提取
{baseDir}/video-frames.js frames video.mp4 --fps 1 --quality 1 --prefix keyframe
Higher quality extraction
提取时调整尺寸
{baseDir}/video-frames.js frames video.mp4 --fps 1 --quality 1 --prefix keyframe
{baseDir}/video-frames.js frames video.mp4 --fps 1 --width 1920 --quality 1
**帧率选项:**
| 帧率 | 说明 | 适用场景 |
|------|-------------|----------|
| `--fps 1` | 每秒1帧 | 时间轴提取 |
| `--fps 5` | 每秒5帧 | 细节分析 |
| `--fps 0.1` | 每10秒1帧 | 概览、故事板 |
| `--fps 0.5` | 每2秒1帧 | 中等细节需求 |
**输出结构:**/tmp/frames_1234567890/
├── frame_00001.jpg
├── frame_00002.jpg
├── frame_00003.jpg
└── ...
undefinedResize during extraction
3. 生成缩略图网格(联络表)
{baseDir}/video-frames.js frames video.mp4 --fps 1 --width 1920 --quality 1
**Frame Rate Options:**
| Rate | Description | Use Case |
|------|-------------|----------|
| `--fps 1` | 1 frame/second | Timeline extraction |
| `--fps 5` | 5 frames/second | Detailed analysis |
| `--fps 0.1` | Every 10 seconds | Overview, storyboard |
| `--fps 0.5` | Every 2 seconds | Moderate detail |
**Output:**/tmp/frames_1234567890/
├── frame_00001.jpg
├── frame_00002.jpg
├── frame_00003.jpg
└── ...
undefined创建视频概览用的缩略图网格。
bash
undefined3. Generate Thumbnail Grid (Contact Sheet)
基础网格
Create a grid of thumbnails for video overview.
bash
undefined{baseDir}/video-frames.js grid video.mp4 --output grid.jpg
Basic grid
自定义尺寸与布局
{baseDir}/video-frames.js grid video.mp4 --output grid.jpg
{baseDir}/video-frames.js grid video.mp4 --count 16 --columns 4 --width 480 --out grid.jpg
Custom size and layout
紧凑预览
{baseDir}/video-frames.js grid video.mp4 --count 16 --columns 4 --width 480 --out grid.jpg
{baseDir}/video-frames.js grid video.mp4 --count 20 --columns 5 --width 320 --out overview.jpg
Compact preview
高分辨率网格
{baseDir}/video-frames.js grid video.mp4 --count 20 --columns 5 --width 320 --out overview.jpg
{baseDir}/video-frames.js grid video.mp4 --count 9 --columns 3 --width 640 --format png --out detailed.png
**网格布局示例:**
| 缩略图数量 | 列数 | 行数 | 最佳用途 |
|-------|---------|------|----------|
| 4 | 2 | 2 | 快速预览 |
| 9 | 3 | 3 | 标准概览 |
| 12 | 4 | 3 | 详细时间轴 |
| 16 | 4 | 4 | 全面故事板 |
| 20 | 5 | 4 | 长视频 |
**输出格式示意:**+---+---+---+---+
| 1 | 2 | 3 | 4 | <- 视频第5秒
+---+---+---+---+
| 5 | 6 | 7 | 8 | <- 视频第25秒
+---+---+---+---+
| 9 |10 |11 |12 | <- 视频第45秒
+---+---+---+---+
undefinedHigh resolution grid
4. 创建动画GIF
{baseDir}/video-frames.js grid video.mp4 --count 9 --columns 3 --width 640 --format png --out detailed.png
**Grid Layout Examples:**
| Count | Columns | Rows | Best For |
|-------|---------|------|----------|
| 4 | 2 | 2 | Quick preview |
| 9 | 3 | 3 | Standard overview |
| 12 | 4 | 3 | Detailed timeline |
| 16 | 4 | 4 | Comprehensive storyboard |
| 20 | 5 | 4 | Long videos |
**Output Format:**+---+---+---+---+
| 1 | 2 | 3 | 4 | <- 5 seconds into video
+---+---+---+---+
| 5 | 6 | 7 | 8 | <- 25 seconds into video
+---+---+---+---+
| 9 |10 |11 |12 | <- 45 seconds into video
+---+---+---+---+
undefined将视频片段提取为动画GIF。
bash
undefined4. Create Animated GIF
基础GIF(从开始提取5秒)
Extract video segment as animated GIF.
bash
undefined{baseDir}/video-frames.js gif video.mp4 --output clip.gif
Basic GIF (5 seconds from start)
指定时间与时长
{baseDir}/video-frames.js gif video.mp4 --output clip.gif
{baseDir}/video-frames.js gif video.mp4 --start 00:01:30 --duration 5 --out highlight.gif
{baseDir}/video-frames.js gif video.mp4 --start 30 --duration 10 --out segment.gif
Specific time and duration
质量预设
{baseDir}/video-frames.js gif video.mp4 --start 00:01:30 --duration 5 --out highlight.gif
{baseDir}/video-frames.js gif video.mp4 --start 30 --duration 10 --out segment.gif
{baseDir}/video-frames.js gif video.mp4 --start 60 --duration 3 --preset fast --out quick.gif
{baseDir}/video-frames.js gif video.mp4 --start 60 --duration 3 --preset quality --out smooth.gif
{baseDir}/video-frames.js gif video.mp4 --start 60 --duration 3 --preset cinematic --out cinema.gif
Quality presets
自定义参数
{baseDir}/video-frames.js gif video.mp4 --start 60 --duration 3 --preset fast --out quick.gif
{baseDir}/video-frames.js gif video.mp4 --start 60 --duration 3 --preset quality --out smooth.gif
{baseDir}/video-frames.js gif video.mp4 --start 60 --duration 3 --preset cinematic --out cinema.gif
{baseDir}/video-frames.js gif video.mp4 --start 30 --duration 5 --fps 30 --width 720 --out preview.gif
**GIF预设参数:**
| 预设 | 帧率 | 宽度 | 颜色数 | 文件大小 | 最佳用途 |
|--------|-----|-------|--------|------|----------|
| `fast` | 15 | 480px | 128 | 小 | 快速生成 |
| `balanced` | 20 | 640px | 256 | 中等 | 默认选项 |
| `quality` | 24 | 720px | 512 | 大 | 流畅动效 |
| `cinematic` | 30 | 1080px | 1024 | 极大 | 最高画质 |
**最大限制:** 300帧(30fps下约10秒)Custom parameters
5. 获取视频信息
{baseDir}/video-frames.js gif video.mp4 --start 30 --duration 5 --fps 30 --width 720 --out preview.gif
**GIF Presets:**
| Preset | FPS | Width | Colors | Size | Best For |
|--------|-----|-------|--------|------|----------|
| `fast` | 15 | 480px | 128 | Small | Quick generation |
| `balanced` | 20 | 640px | 256 | Medium | Default |
| `quality` | 24 | 720px | 512 | Large | Smooth motion |
| `cinematic` | 30 | 1080px | 1024 | Very large | Maximum quality |
**Max Duration:** 300 frames (~10 seconds at 30fps)显示详细的视频元数据。
bash
{baseDir}/video-frames.js info video.mp4输出示例:
json
{
"stats": { "size": 1234567890, "mtime": "..." },
"duration": 3665,
"width": 1920,
"height": 1080,
"fps": 29.97,
"totalFrames": 109785,
"info": { ... } // 完整ffprobe输出
}5. Get Video Information
进度追踪
Display detailed video metadata.
bash
{baseDir}/video-frames.js info video.mp4Output:
json
{
"stats": { "size": 1234567890, "mtime": "..." },
"duration": 3665,
"width": 1920,
"height": 1080,
"fps": 29.97,
"totalFrames": 109785,
"info": { ... } // Full ffprobe output
}操作过程中会显示实时进度:
⏳ 提取帧:15/30 (50.0%) | 已耗时:12.3s
⏳ 生成缩略图:8/12 (66.7%) | 已耗时:5.2sProgress Tracking
安全特性
—
限制参数
Operations display real-time progress:
⏳ Extracting frames: 15/30 (50.0%) | Elapsed: 12.3s
⏳ Generating thumbnails: 8/12 (66.7%) | Elapsed: 5.2s| 限制项 | 数值 | 说明 |
|---|---|---|
| 最大视频文件大小 | 50 GB | 输入文件大小限制 |
| 最大视频时长 | 4小时 | 视频长度限制 |
| 最大批量提取帧数 | 1000 | 批量帧提取上限 |
| 最大网格缩略图数量 | 60 | 联络表限制 |
| 最大GIF帧数 | 300 | 动画GIF限制 |
| 超时时间 | 30分钟 | 默认操作超时时间 |
Safety Features
视频验证
Limits
—
| Limit | Value | Description |
|---|---|---|
| Max Video Size | 50 GB | Input file size limit |
| Max Duration | 4 hours | Video length limit |
| Max Frames | 1,000 | Batch frame extraction |
| Max Grid Size | 60 thumbnails | Contact sheet limit |
| Max GIF Frames | 300 | Animated GIF limit |
| Timeout | 30 minutes | Default operation timeout |
处理前,工具会自动验证:
- 文件存在且可读取
- 文件大小在限制内
- 视频格式有效
- 时长在限制内
- 包含视频流
- 文件未损坏
Video Validation
错误处理
—
错误码
Before processing, the skill validates:
- File exists and is readable
- File size within limits
- Valid video format
- Duration within limits
- Contains video stream
- Not corrupted
| 代码 | 名称 | 说明 |
|---|---|---|
| 0 | SUCCESS | 操作完成 |
| 1 | INVALID_INPUT | 参数缺失或无效 |
| 2 | FILE_NOT_FOUND | 视频文件未找到 |
| 3 | INVALID_FORMAT | 不支持的格式 |
| 4 | INVALID_TIME_RANGE | 时间戳无效 |
| 5 | FFMPEG_ERROR | FFmpeg执行失败 |
| 6 | OUT_OF_MEMORY | 内存超限 |
| 7 | TIMEOUT | 操作超时 |
| 8 | INTERRUPTED | 用户中断操作 |
| 9 | PERMISSION_DENIED | 读写权限不足 |
| 10 | VALIDATION_FAILED | 视频验证未通过 |
| 99 | UNKNOWN | 未知错误 |
Error Handling
常见错误场景
Error Codes
—
| Code | Name | Description |
|---|---|---|
| 0 | SUCCESS | Operation completed |
| 1 | INVALID_INPUT | Missing/invalid parameters |
| 2 | FILE_NOT_FOUND | Video not found |
| 3 | INVALID_FORMAT | Unsupported format |
| 4 | INVALID_TIME_RANGE | Invalid timestamp |
| 5 | FFMPEG_ERROR | FFmpeg execution failed |
| 6 | OUT_OF_MEMORY | Memory limit exceeded |
| 7 | TIMEOUT | Operation timed out |
| 8 | INTERRUPTED | User interrupted |
| 9 | PERMISSION_DENIED | Cannot read/write |
| 10 | VALIDATION_FAILED | Video validation failed |
| 99 | UNKNOWN | Unexpected error |
帧索引超出范围:
bash
{baseDir}/video-frames.js frame video.mp4 --index 999999Common Scenarios
❌ 错误:帧索引999999超出范围(0-109784)
Frame Index Out of Range:
bash
{baseDir}/video-frames.js frame video.mp4 --index 999999
**时间戳超出视频时长:**
```bash
{baseDir}/video-frames.js frame video.mp4 --time 10000❌ ERROR: Frame index 999999 out of range (0-109784)
❌ 错误:时间戳02:46:40超出范围(0-01:01:05)
**Timestamp Beyond Video:**
```bash
{baseDir}/video-frames.js frame video.mp4 --time 10000
**请求帧数过多:**
```bash
{baseDir}/video-frames.js frames video.mp4 --fps 100❌ ERROR: Timestamp 02:46:40 out of range (0-01:01:05)
❌ 错误:请求帧数过多:366500(上限:1000)
**Too Many Frames:**
```bash
{baseDir}/video-frames.js frames video.mp4 --fps 100
**GIF请求过长:**
```bash
{baseDir}/video-frames.js gif video.mp4 --duration 60 --fps 60❌ ERROR: Too many frames requested: 366500 (max: 1000)
❌ 错误:GIF过长:3600帧(上限:300)
**Large GIF Request:**
```bash
{baseDir}/video-frames.js gif video.mp4 --duration 60 --fps 60undefined❌ ERROR: GIF too long: 3600 frames (max: 300)
技术细节
—
帧提取方式
undefined-
片段定位 (在
-ss之前)-i- 快速帧访问
- 用于 选项
--time - 开头部分精度略有损失
-
帧选择 ()
-vf select- 精确按索引提取帧
- 速度较慢但帧精度高
- 用于 选项
--index
-
间隔提取 (过滤器)
fps- 高效批量提取
- 支持帧率转换
- 用于批量操作
Technical Details
质量设置细节
Frame Extraction Methods
—
-
Segment Seek (before
-ss)-i- Fast frame access
- Use for option
--time - Slight accuracy trade-off at start
-
Frame Selection ()
-vf select- Precise frame index extraction
- Slower but frame-accurate
- Use for option
--index
-
Extract at Interval (filter)
fps- Efficient batch extraction
- Frame-rate conversion
- Use for batch operations
JPEG 质量(CRF - 恒定速率因子):
-q:v 1 -> 100%画质(最佳,文件最大)
-q:v 2 -> ~95%画质(默认)
-q:v 5 -> ~85%画质(网页使用)
-q:v 10 -> ~70%画质(低画质)
-q:v 31 -> ~10%画质(最低)PNG 输出:
- 始终无损
- 文件体积较大
- 适合归档
- 支持透明背景
缩放(Lanczos 算法):
-vf scale=320:-2:flags=lanczos- Lanczos 重采样算法保证最佳画质
- 确保尺寸为偶数(编码要求)
-2 - 保持原视频宽高比
Quality Settings
GIF 优化
JPEG Quality (CRF - Constant Rate Factor):
-q:v 1 -> 100% quality (best, largest)
-q:v 2 -> ~95% quality (default)
-q:v 5 -> ~85% quality (web)
-q:v 10 -> ~70% quality (low)
-q:v 31 -> ~10% quality (minimum)PNG Output:
- Always lossless
- Larger file sizes
- Best for archival
- Transparent backgrounds supported
Scaling (Lanczos):
-vf scale=320:-2:flags=lanczos- Lanczos resampling for best quality
- ensures even dimensions (encoding requirement)
-2 - Maintains aspect ratio
调色板生成:
- 解析视频片段
- 生成最优256色调色板
- 将调色板应用到所有帧
- 抖动处理实现平滑渐变
文件体积优化:
- 固定帧率
- 限制颜色数量
- 编码前调整尺寸
- 优化编码设置
GIF Optimization
使用示例
—
视频故事板创建
Palette Generation:
- Parse video segment
- Generate optimal 256-color palette
- Apply palette to all frames
- Dithering for smooth gradients
File Size Optimization:
- Fixed frame rate
- Limited color palette
- Resizing before encoding
- Optimized encoding settings
bash
#!/bin/bash
VIDEO="movie.mp4"
OUTDIR="storyboard"
mkdir -p $OUTDIRExamples
创建概览网格
Video Storyboard Creation
—
bash
#!/bin/bash
VIDEO="movie.mp4"
OUTDIR="storyboard"
mkdir -p $OUTDIRecho "创建概览网格..."
{baseDir}/video-frames.js grid "$VIDEO" --count 20 --columns 5 --width 480 --out "$OUTDIR/overview.jpg"
Create overview grid
每分钟提取关键帧
echo "Creating overview grid..."
{baseDir}/video-frames.js grid "$VIDEO" --count 20 --columns 5 --width 480 --out "$OUTDIR/overview.jpg"
echo "提取关键帧..."
{baseDir}/video-frames.js frames "$VIDEO" --fps 0.0167 --prefix key --out "$OUTDIR/"
Extract key frames every minute
创建章节缩略图
echo "Extracting key frames..."
{baseDir}/video-frames.js frames "$VIDEO" --fps 0.0167 --prefix key --out "$OUTDIR/"
echo "创建章节缩略图..."
for time in 0:00 10:00 20:00 30:00; do
{baseDir}/video-frames.js frame "$VIDEO" --time $time --quality 1 --out "$OUTDIR/chapter_${time//:/}.png"
done
echo "故事板已生成在 $OUTDIR/"
undefinedCreate chapter thumbnails
视频预览图库
echo "Creating chapter thumbnails..."
for time in 0:00 10:00 20:00 30:00; do
{baseDir}/video-frames.js frame "$VIDEO" --time $time --quality 1 --out "$OUTDIR/chapter_${time//:/}.png"
done
echo "Storyboard complete in $OUTDIR/"
undefinedbash
#!/bin/bash
for video in *.mp4; do
echo "处理中:$video"
# 创建3x3网格
{baseDir}/video-frames.js grid "$video" --count 9 --columns 3 --width 640 --out "${video%.*}-grid.jpg"
# 创建5秒预览GIF
{baseDir}/video-frames.js gif "$video" --start 30 --duration 5 --preset balanced --out "${video%.*}-preview.gif"
doneVideo Preview Gallery
每N秒提取一帧
bash
#!/bin/bash
for video in *.mp4; do
echo "Processing: $video"
# Create 3x3 grid
{baseDir}/video-frames.js grid "$video" --count 9 --columns 3 --width 640 --out "${video%.*}-grid.jpg"
# Create 5-second preview GIF
{baseDir}/video-frames.js gif "$video" --start 30 --duration 5 --preset balanced --out "${video%.*}-preview.gif"
donebash
undefinedExtract Frames Every N Seconds
每分钟开头提取一帧
bash
undefinedfor i in {0..60}; do
{baseDir}/video-frames.js frame video.mp4 --time $((i*60)) --out "frames/minute_${i}.jpg"
done
Extract frame at beginning of every minute
批量提取的Shell脚本
for i in {0..60}; do
{baseDir}/video-frames.js frame video.mp4 --time $((i*60)) --out "frames/minute_${i}.jpg"
done
extract_frames() {
local video="$1"
local interval="${2:-10}" # 默认10秒间隔
local duration
duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$video")
for ((t=0; t<duration; t+=interval)); do
{baseDir}/video-frames.js frame "$video" --time $t --out "frames/frame_${t}.jpg"
done
}
undefinedShell script for batch extraction
高质量缩略图生成
extract_frames() {
local video="$1"
local interval="${2:-10}" # default 10 seconds
local duration
duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$video")
for ((t=0; t<duration; t+=interval)); do
{baseDir}/video-frames.js frame "$video" --time $t --out "frames/frame_${t}.jpg"
done
}
undefinedbash
undefinedHigh-Quality Thumbnail Generation
最佳画质单帧
bash
undefined{baseDir}/video-frames.js frame video.mp4
--time 10
--format png
--width 1920
--out thumbnail.png
--time 10
--format png
--width 1920
--out thumbnail.png
Best quality single frame
最佳画质网格
{baseDir}/video-frames.js frame video.mp4
--time 10
--format png
--width 1920
--out thumbnail.png
--time 10
--format png
--width 1920
--out thumbnail.png
{baseDir}/video-frames.js grid video.mp4
--count 9
--columns 3
--width 640
--format png
--out grid.png
--count 9
--columns 3
--width 640
--format png
--out grid.png
undefinedBest quality grid
性能优化建议
—
1. 使用JPEG提升速度
{baseDir}/video-frames.js grid video.mp4
--count 9
--columns 3
--width 640
--format png
--out grid.png
--count 9
--columns 3
--width 640
--format png
--out grid.png
undefinedJPEG编码比PNG更快:
bash
{baseDir}/video-frames.js frame video.mp4 --format jpg # 更快
{baseDir}/video-frames.js frame video.mp4 --format png # 画质更好,但速度慢Performance Tips
2. 草稿使用低画质
1. Use JPEG for Speed
—
JPEG encoding is faster than PNG:
bash
{baseDir}/video-frames.js frame video.mp4 --format jpg # Faster
{baseDir}/video-frames.js frame video.mp4 --format png # Better quality, slowerbash
undefined2. Lower Quality for Drafts
快速预览
bash
undefined{baseDir}/video-frames.js grid video.mp4 --count 9 --width 320 # 文件小,速度快
Quick preview
最终画质
{baseDir}/video-frames.js grid video.mp4 --count 9 --width 320 # Small, fast
{baseDir}/video-frames.js grid video.mp4 --count 16 --width 640 # 细节更丰富
undefinedFinal quality
3. 并行处理
{baseDir}/video-frames.js grid video.mp4 --count 16 --width 640 # Higher detail
undefinedbash
undefined3. Parallel Processing
并行处理多个视频
bash
undefined{baseDir}/video-frames.js grid video1.mp4 --out g1.jpg &
{baseDir}/video-frames.js grid video2.mp4 --out g2.jpg &
{baseDir}/video-frames.js grid video3.mp4 --out g3.jpg &
wait
undefinedProcess multiple videos in parallel
4. 提取时调整尺寸
{baseDir}/video-frames.js grid video1.mp4 --out g1.jpg &
{baseDir}/video-frames.js grid video2.mp4 --out g2.jpg &
{baseDir}/video-frames.js grid video3.mp4 --out g3.jpg &
wait
undefined比提取全尺寸后再缩放更高效:
bash
undefined4. Resize During Extraction
推荐方式
Better than extracting full size then scaling:
bash
undefined{baseDir}/video-frames.js frame video.mp4 --width 320 --out thumb.jpg
Good
低效方式
{baseDir}/video-frames.js frame video.mp4 --width 320 --out thumb.jpg
{baseDir}/video-frames.js frame video.mp4 --out full.jpg
Less efficient
再通过外部工具缩放
{baseDir}/video-frames.js frame video.mp4 --out full.jpg
undefinedThen resize externally
注意事项
undefined- 当ImageMagick可用时,网格生成会使用它(画质更好),否则使用FFmpeg的tile过滤器
- 帧索引0始终是视频的第一帧
- 时间戳会根据视频FPS四舍五入到最近的帧
- GIF使用256色调色板平衡画质与文件大小
- PNG透明背景会被保留(适合叠加使用)
- 所有操作会自动清理临时文件
- JSON输出支持程序化集成
- 网格缩略图会按视频时间间隔分布
Notes
—
- Grid generation uses ImageMagick when available (better quality), FFmpeg tile filter otherwise
- Frame index 0 is always the first frame of the video
- Timestamps are rounded to nearest frame based on video FPS
- GIFs are optimized with 256-color palette for balance of quality and size
- PNG transparency is preserved (useful for overlays)
- All operations clean up temporary files automatically
- JSON output enables programmatic integration
- Grid thumbnails include timestamps at video intervals
—