FFmpeg 与 ImageMagick 媒体处理
media-processing
FFmpeg + ImageMagick 媒体处理。当进行视频/音频转码、图像缩放/裁剪、HLS/DASH、缩略图生成、批量操作或硬件加速处理管道时应使用此技能。
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- media-processing
- license
- MIT
- description
- FFmpeg + ImageMagick media processing. This skill should be used when transcoding video/audio, resizing/cropping images, HLS/DASH, thumbnails, batch ops, or hardware-accelerated pipelines.
02 资源文件 23
- 参考文档references/ffmpeg/encoding-codecs.md2.6 KB
- 参考文档references/ffmpeg/encoding-hardware.md2.2 KB
- 参考文档references/ffmpeg/encoding-quality.md2.9 KB
- 参考文档references/ffmpeg/filters-audio-advanced.md3.9 KB
- 参考文档references/ffmpeg/filters-video.md4.0 KB
- 参考文档references/ffmpeg/streaming-hls-dash.md2.6 KB
- 参考文档references/ffmpeg/streaming-live.md3.5 KB
- 参考文档references/ffmpeg/streaming-thumbnails.md2.0 KB
- 参考文档references/format-compatibility/conversions.md2.8 KB
- 参考文档references/format-compatibility/formats.md2.6 KB
- 参考文档references/imagemagick/batch-advanced.md3.6 KB
- 参考文档references/imagemagick/batch-basic.md2.8 KB
- 参考文档references/imagemagick/editing-basics.md2.8 KB
- 参考文档references/imagemagick/editing-effects.md3.6 KB
- 脚本scripts/batch_resize.py10.0 KB
- 脚本scripts/media_convert.py8.3 KB
- 脚本scripts/requirements.txt558 B
- 脚本scripts/tests/.coverage52.0 KB
- 脚本scripts/tests/requirements.txt32 B
- 脚本scripts/tests/test_batch_resize.py10.5 KB
- 脚本scripts/tests/test_media_convert.py7.2 KB
- 脚本scripts/tests/test_video_optimize.py11.5 KB
- 脚本scripts/video_optimize.py13.0 KB
03 SKILL.md 正文
Media Processing Skill
Process video, audio, and images using FFmpeg and ImageMagick for conversion, optimization, streaming, and manipulation.
When to Use This Skill
- Converting media formats (video, audio, images)
- Encoding video with codecs (H.264, H.265, VP9, AV1)
- Processing images (resize, crop, effects, watermarks)
- Extracting audio from video
- Creating streaming manifests (HLS/DASH)
- Generating thumbnails and previews
- Batch processing media files
- Hardware-accelerated encoding
Tool Selection Guide
| Task | Tool |
|---|---|
| Video encoding/transcoding | FFmpeg |
| Audio extraction/conversion | FFmpeg |
| Live streaming (RTMP/HLS/DASH) | FFmpeg |
| Image resize/crop/convert | ImageMagick |
| Batch image processing | ImageMagick (mogrify) |
| Video thumbnails | FFmpeg |
| Image effects/watermarks | ImageMagick |
Installation
# macOS
brew install ffmpeg imagemagick
# Ubuntu/Debian
sudo apt-get install ffmpeg imagemagick
# Windows
winget install ffmpeg
winget install ImageMagick.ImageMagick
# Verify
ffmpeg -version && ffprobe -version && magick -version
Quick Examples
# Convert format (stream copy, fast)
ffmpeg -i input.mkv -c copy output.mp4
# Re-encode with H.264
ffmpeg -i input.avi -c:v libx264 -crf 22 -c:a aac output.mp4
# Resize video to 720p
ffmpeg -i input.mp4 -vf scale=-1:720 -c:a copy output.mp4
# Extract audio
ffmpeg -i video.mp4 -vn -q:a 0 audio.mp3
# Image conversion
magick input.png -quality 85 -strip output.jpg
# Resize image
magick input.jpg -resize 800x output.jpg
# Square thumbnail
magick input.jpg -resize 200x200^ -gravity center -extent 200x200 thumb.jpg
# Batch resize
mogrify -path ./output -resize 800x -quality 85 *.jpg
# HLS stream
ffmpeg -i input.mp4 -c:v libx264 -preset fast -crf 22 \
-f hls -hls_time 6 -hls_playlist_type vod playlist.m3u8
# Video GIF
ffmpeg -i input.mp4 -vf "fps=15,scale=640:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
Key Parameters
FFmpeg Video
-c:v— Video codec (libx264, libx265, libvpx-vp9)-crf— Quality (0-51, lower=better, 23=default)-preset— Speed/compression (ultrafast to veryslow)-b:v— Video bitrate (e.g., 2M, 2500k)-vf— Video filters
FFmpeg Audio
-c:a— Audio codec (aac, mp3, opus)-b:a— Audio bitrate (e.g., 128k, 192k)-ar— Sample rate (44100, 48000)
ImageMagick Geometry
800x600— Fit within (maintains aspect)800x600!— Force exact size800x600^— Fill (may crop)800x/x600— Width or height only50%— Scale percentage
Troubleshooting
FFmpeg "Unknown encoder"
ffmpeg -encoders | grep h264
sudo apt-get install libx264-dev libx265-dev
ImageMagick "not authorized"
# Edit /etc/ImageMagick-7/policy.xml
# Change rights="none" to rights="read|write" for the format
Memory errors
ffmpeg -threads 4 input.mp4 output.mp4
magick -limit memory 2GB -limit map 4GB input.jpg output.jpg
References
FFmpeg:
ffmpeg/encoding-codecs.md— H.264, H.265, VP9, AV1, audio codecs, codec selectionffmpeg/encoding-quality.md— CRF, bitrate, presets, tune options, threadingffmpeg/encoding-hardware.md— NVIDIA NVENC, Intel QSV, AMD AMF, Apple VideoToolboxffmpeg/filters-video.md— Scale, crop, rotate, overlay, denoise, color, textffmpeg/filters-audio-advanced.md— Audio filters, complex filtergraphs, recipesffmpeg/streaming-hls-dash.md— HLS, multi-bitrate HLS, DASH, encryptionffmpeg/streaming-live.md— RTMP platforms, screen capture, UDP/RTP, loop streamsffmpeg/streaming-thumbnails.md— Frame extraction, sprite sheets, preview generation
ImageMagick:
imagemagick/editing-basics.md— Format conversion, resize, crop, thumbnails, rotationimagemagick/editing-effects.md— Blur, sharpen, color effects, borders, text, compositionimagemagick/batch-basic.md— Mogrify, resize loops, format conversion, optimizationimagemagick/batch-advanced.md— Parallel processing, watermarks, web pipelines, Python
Formats:
format-compatibility/formats.md— Supported formats, codecs, platform compatibility tablesformat-compatibility/conversions.md— Common conversion commands, migration strategies
Resources
- FFmpeg: https://ffmpeg.org/documentation.html
- ImageMagick: https://imagemagick.org/
04 同仓库更多 Skills
Three.js三维网页开发
threejs
使用 Three.js(WebGL/WebGPU)构建 3D Web 应用。适用于 3D 场景、动画、自定义着色器、PBR 材质、VR/XR 体验、游戏、数据可视化、产品配置器等场景。
AI 写作痕迹去除
humanizer
去除文本中 AI 生成的写作痕迹。在编辑或审阅文本时使用,使其听起来更自然、更像人工撰写。基于维基百科全面的“AI 写作迹象”指南。检测并修复以下模式:夸大的象征意义、宣传性语言、表面的 -ing 分析、模糊的归因、破折号过度使用、三段式法则、AI 词汇、被动语态、否定平行结构和填充短语。
CoreDNS 配置与 Go DNS 编程
coredns-golang-dns
CoreDNS 配置与 Go 语言 DNS 编程。适用于编写 Corefile 配置文件、在 Kubernetes 中修补 CoreDNS(kube-system ConfigMap、NodeHosts、重写规则、条件转发器)、提供静态 A/AAAA/CNAME/SRV 记录、使用 miekg/dns 构建 Go DNS 服务器/拦截器(分视图 DNS、条件转发、响应重写、透明代理)、通过 cert-manager Certificates 和 trust-manager Bundles 启用 DNS-over-TLS / DNS-over-HTTPS,或为 DoT/DoH 客户端分发 CA 信任。