Media Processing Skill
Process video, audio, and images using FFmpeg and ImageMagick command-line tools for conversion, optimization, streaming, and manipulation tasks.
When to Use This Skill
Use when:
- 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
- Optimizing file sizes and quality
- Applying filters and effects
- Creating composite images or videos
Tool Selection Guide
FFmpeg: Video/Audio Processing
Use FFmpeg for:
- Video encoding, conversion, transcoding
- Audio extraction, conversion, mixing
- Live streaming (RTMP, HLS, DASH)
- Video filters (scale, crop, rotate, overlay)
- Hardware-accelerated encoding
- Media file inspection (ffprobe)
- Frame extraction, concatenation
- Codec selection and optimization
ImageMagick: Image Processing
Use ImageMagick for:
- Image format conversion (PNG, JPEG, WebP, GIF)
- Resizing, cropping, transformations
- Batch image processing (mogrify)
- Visual effects (blur, sharpen, sepia)
- Text overlays and watermarks
- Image composition and montages
- Color adjustments, filters
- Thumbnail generation
Decision Matrix
| Task |
Tool |
Why |
| Video encoding |
FFmpeg |
Native video codec support |
| Audio extraction |
FFmpeg |
Direct stream manipulation |
| Image resize |
ImageMagick |
Optimized for still images |
| Batch images |
ImageMagick |
mogrify for in-place edits |
| Video thumbnails |
FFmpeg |
Frame extraction built-in |
| GIF creation |
FFmpeg or ImageMagick |
FFmpeg for video source, ImageMagick for images |
| Streaming |
FFmpeg |
Live streaming protocols |
| Image effects |
ImageMagick |
Rich filter library |
Installation
macOS
brew install ffmpeg imagemagick
Ubuntu/Debian
sudo apt-get install ffmpeg imagemagick
Windows
# Using winget
winget install ffmpeg
winget install ImageMagick.ImageMagick
# Or download binaries
# FFmpeg: https://ffmpeg.org/download.html
# ImageMagick: https://imagemagick.org/script/download.php
Verify Installation
ffmpeg -version
ffprobe -version
magick -version
# or
convert -version
Quick Start Examples
Video Conversion
# Convert format (copy streams, 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
Audio Extraction
# Extract audio (no re-encoding)
ffmpeg -i video.mp4 -vn -c:a copy audio.m4a
# Convert to MP3
ffmpeg -i video.mp4 -vn -q:a 0 audio.mp3
Image Processing
# Convert format
magick input.png output.jpg
# Resize maintaining aspect ratio
magick input.jpg -resize 800x600 output.jpg
# Create square thumbnail
magick input.jpg -resize 200x200^ -gravity center -extent 200x200 thumb.jpg
Batch Image Resize
# Resize all JPEGs to 800px width
mogrify -resize 800x -quality 85 *.jpg
# Output to separate directory
mogrify -path ./output -resize 800x600 *.jpg
Video Thumbnail
# Extract frame at 5 seconds
ffmpeg -ss 00:00:05 -i video.mp4 -vframes 1 -vf scale=320:-1 thumb.jpg
HLS Streaming
# Generate HLS playlist
ffmpeg -i input.mp4 \
-c:v libx264 -preset fast -crf 22 -g 48 \
-c:a aac -b:a 128k \
-f hls -hls_time 6 -hls_playlist_type vod \
playlist.m3u8
Image Watermark
# Add watermark to corner
magick input.jpg watermark.png -gravity southeast \
-geometry +10+10 -composite output.jpg
Common Workflows
Optimize Video for Web
# H.264 with good compression
ffmpeg -i input.mp4 \
-c:v libx264 -preset slow -crf 23 \
-c:a aac -b:a 128k \
-movflags +faststart \
output.mp4
Create Responsive Images
# Generate multiple sizes
for size in 320 640 1024 1920; do
magick input.jpg -resize ${size}x -quality 85 "output-${size}w.jpg"
done
Extract Video Segment
# From 1:30 to 3:00 (re-encode for precision)
ffmpeg -i input.mp4 -ss 00:01:30 -to 00:03:00 \
-c:v libx264 -c:a aac output.mp4
Batch Image Optimization
# Convert PNG to optimized JPEG
mogrify -path ./optimized -format jpg -quality 85 -strip *.png
Video GIF Creation
# High quality GIF with palette
ffmpeg -i input.mp4 -vf "fps=15,scale=640:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
Image Blur Effect
# Gaussian blur
magick input.jpg -gaussian-blur 0x8 output.jpg
Advanced Techniques
Multi-Pass Video Encoding
# Pass 1 (analysis)
ffmpeg -y -i input.mkv -c:v libx264 -b:v 2600k -pass 1 -an -f null /dev/null
# Pass 2 (encoding)
ffmpeg -i input.mkv -c:v libx264 -b:v 2600k -pass 2 -c:a aac output.mp4
Hardware-Accelerated Encoding
# NVIDIA NVENC
ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc -preset fast -crf 22 output.mp4
# Intel QuickSync
ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v h264_qsv output.mp4
Complex Image Pipeline
# Resize, crop, border, adjust
magick input.jpg \
-resize 1000x1000^ \
-gravity center \
-crop 1000x1000+0+0 +repage \
-bordercolor black -border 5x5 \
-brightness-contrast 5x10 \
-quality 90 \
output.jpg
Video Filter Chains
# Scale, denoise, watermark
ffmpeg -i video.mp4 -i logo.png \
-filter_complex "[0:v]scale=1280:720,hqdn3d[v];[v][1:v]overlay=10:10" \
-c:a copy output.mp4
Animated GIF from Images
# Create with delay
magick -delay 100 -loop 0 frame*.png animated.gif
# Optimize size
magick animated.gif -fuzz 5% -layers Optimize optimized.gif
Media Analysis
Inspect Video Properties
# Detailed JSON output
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4
# Get resolution
ffprobe -v error -select_streams v:0 \
-show_entries stream=width,height \
-of csv=s=x:p=0 input.mp4
Image Information
# Basic info
identify image.jpg
# Detailed format
identify -verbose image.jpg
# Custom format
identify -format "%f: %wx%h %b\n" image.jpg
Performance Tips
- Use CRF for quality control - Better than bitrate for video
- Copy streams when possible - Avoid re-encoding with
-c copy
- Hardware acceleration - GPU encoding 5-10x faster
- Appropriate presets - Balance speed vs compression
- Batch with mogrify - In-place image processing
- Strip metadata - Reduce file size with
-strip
- Progressive JPEG - Better web loading with
-interlace Plane
- Limit memory - Prevent crashes on large batches
- Test on samples - Verify settings before batch
- Parallel processing - Use GNU Parallel for multiple files
Reference Documentation
Detailed guides in references/:
- ffmpeg-encoding.md - Video/audio codecs, quality optimization, hardware acceleration
- ffmpeg-streaming.md - HLS/DASH, live streaming, adaptive bitrate
- ffmpeg-filters.md - Video/audio filters, complex filtergraphs
- imagemagick-editing.md - Format conversion, effects, transformations
- imagemagick-batch.md - Batch processing, mogrify, parallel operations
- format-compatibility.md - Format support, codec recommendations
Common 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 size
800x600^ - Fill (may crop)
800x - Width only
x600 - Height only
50% - Scale percentage
Troubleshooting
FFmpeg "Unknown encoder"
# Check available encoders
ffmpeg -encoders | grep h264
# Install codec libraries
sudo apt-get install libx264-dev libx265-dev
ImageMagick "not authorized"
# Edit policy file
sudo nano /etc/ImageMagick-7/policy.xml
# Change <policy domain="coder" rights="none" pattern="PDF" />
# to <policy domain="coder" rights="read|write" pattern="PDF" />
Memory errors
# Limit memory usage
ffmpeg -threads 4 input.mp4 output.mp4
magick -limit memory 2GB -limit map 4GB input.jpg output.jpg
Resources
1---2name: media-processing3description: Video/audio/image processing with FFmpeg and ImageMagick. Tools: FFmpeg (video/audio), ImageMagick (images). Capabilities: format conversion, encoding (H.264/H.265/VP9/AV1), streaming (HLS/DASH), filters, effects, thumbnails, watermarks, batch processing, hardware acceleration (NVENC/QSV). Actions: convert, encode, resize, crop, compress, extract, merge, stream, transcode media. Keywords: FFmpeg, ImageMagick, video encoding, audio extraction, image resize, thumbnail, watermark, HLS, DASH, H.264, H.265, VP9, AV1, codec, bitrate, framerate, resolution, aspect ratio, filter, overlay, concat, trim, fade, batch processing. Use when: converting video/audio formats, encoding with specific codecs, generating thumbnails, creating streaming manifests, extracting audio from video, batch processing images, adding watermarks, optimizing file sizes.4license: MIT5---6
7# Media Processing Skill
8
9Process video, audio, and images using FFmpeg and ImageMagick command-line tools for conversion, optimization, streaming, and manipulation tasks.
10
11## When to Use This Skill
12
13Use when:
14- Converting media formats (video, audio, images)
15- Encoding video with codecs (H.264, H.265, VP9, AV1)
16- Processing images (resize, crop, effects, watermarks)
17- Extracting audio from video
18- Creating streaming manifests (HLS/DASH)
19- Generating thumbnails and previews
20- Batch processing media files
21- Optimizing file sizes and quality
22- Applying filters and effects
23- Creating composite images or videos
24
25## Tool Selection Guide
26
27### FFmpeg: Video/Audio Processing
28Use FFmpeg for:
29- Video encoding, conversion, transcoding
30- Audio extraction, conversion, mixing
31- Live streaming (RTMP, HLS, DASH)
32- Video filters (scale, crop, rotate, overlay)
33- Hardware-accelerated encoding
34- Media file inspection (ffprobe)
35- Frame extraction, concatenation
36- Codec selection and optimization
37
38### ImageMagick: Image Processing
39Use ImageMagick for:
40- Image format conversion (PNG, JPEG, WebP, GIF)
41- Resizing, cropping, transformations
42- Batch image processing (mogrify)
43- Visual effects (blur, sharpen, sepia)
44- Text overlays and watermarks
45- Image composition and montages
46- Color adjustments, filters
47- Thumbnail generation
48
49### Decision Matrix
50
51| Task | Tool | Why |
52|------|------|-----|
53| Video encoding | FFmpeg | Native video codec support |
54| Audio extraction | FFmpeg | Direct stream manipulation |
55| Image resize | ImageMagick | Optimized for still images |
56| Batch images | ImageMagick | mogrify for in-place edits |
57| Video thumbnails | FFmpeg | Frame extraction built-in |
58| GIF creation | FFmpeg or ImageMagick | FFmpeg for video source, ImageMagick for images |
59| Streaming | FFmpeg | Live streaming protocols |
60| Image effects | ImageMagick | Rich filter library |
61
62## Installation
63
64### macOS
65```bash
66brew install ffmpeg imagemagick
67```
68
69### Ubuntu/Debian
70```bash
71sudo apt-get install ffmpeg imagemagick
72```
73
74### Windows
75```bash
76# Using winget
77winget install ffmpeg
78winget install ImageMagick.ImageMagick
79
80# Or download binaries
81# FFmpeg: https://ffmpeg.org/download.html
82# ImageMagick: https://imagemagick.org/script/download.php
83```
84
85### Verify Installation
86```bash
87ffmpeg -version
88ffprobe -version
89magick -version
90# or
91convert -version
92```
93
94## Quick Start Examples
95
96### Video Conversion
97```bash
98# Convert format (copy streams, fast)
99ffmpeg -i input.mkv -c copy output.mp4
100
101# Re-encode with H.264
102ffmpeg -i input.avi -c:v libx264 -crf 22 -c:a aac output.mp4
103
104# Resize video to 720p
105ffmpeg -i input.mp4 -vf scale=-1:720 -c:a copy output.mp4
106```
107
108### Audio Extraction
109```bash
110# Extract audio (no re-encoding)
111ffmpeg -i video.mp4 -vn -c:a copy audio.m4a
112
113# Convert to MP3
114ffmpeg -i video.mp4 -vn -q:a 0 audio.mp3
115```
116
117### Image Processing
118```bash
119# Convert format
120magick input.png output.jpg
121
122# Resize maintaining aspect ratio
123magick input.jpg -resize 800x600 output.jpg
124
125# Create square thumbnail
126magick input.jpg -resize 200x200^ -gravity center -extent 200x200 thumb.jpg
127```
128
129### Batch Image Resize
130```bash
131# Resize all JPEGs to 800px width
132mogrify -resize 800x -quality 85 *.jpg
133
134# Output to separate directory
135mogrify -path ./output -resize 800x600 *.jpg
136```
137
138### Video Thumbnail
139```bash
140# Extract frame at 5 seconds
141ffmpeg -ss 00:00:05 -i video.mp4 -vframes 1 -vf scale=320:-1 thumb.jpg
142```
143
144### HLS Streaming
145```bash
146# Generate HLS playlist
147ffmpeg -i input.mp4 \
148 -c:v libx264 -preset fast -crf 22 -g 48 \
149 -c:a aac -b:a 128k \
150 -f hls -hls_time 6 -hls_playlist_type vod \
151 playlist.m3u8
152```
153
154### Image Watermark
155```bash
156# Add watermark to corner
157magick input.jpg watermark.png -gravity southeast \
158 -geometry +10+10 -composite output.jpg
159```
160
161## Common Workflows
162
163### Optimize Video for Web
164```bash
165# H.264 with good compression
166ffmpeg -i input.mp4 \
167 -c:v libx264 -preset slow -crf 23 \
168 -c:a aac -b:a 128k \
169 -movflags +faststart \
170 output.mp4
171```
172
173### Create Responsive Images
174```bash
175# Generate multiple sizes
176for size in 320 640 1024 1920; do
177 magick input.jpg -resize ${size}x -quality 85 "output-${size}w.jpg"
178done
179```
180
181### Extract Video Segment
182```bash
183# From 1:30 to 3:00 (re-encode for precision)
184ffmpeg -i input.mp4 -ss 00:01:30 -to 00:03:00 \
185 -c:v libx264 -c:a aac output.mp4
186```
187
188### Batch Image Optimization
189```bash
190# Convert PNG to optimized JPEG
191mogrify -path ./optimized -format jpg -quality 85 -strip *.png
192```
193
194### Video GIF Creation
195```bash
196# High quality GIF with palette
197ffmpeg -i input.mp4 -vf "fps=15,scale=640:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" output.gif
198```
199
200### Image Blur Effect
201```bash
202# Gaussian blur
203magick input.jpg -gaussian-blur 0x8 output.jpg
204```
205
206## Advanced Techniques
207
208### Multi-Pass Video Encoding
209```bash
210# Pass 1 (analysis)
211ffmpeg -y -i input.mkv -c:v libx264 -b:v 2600k -pass 1 -an -f null /dev/null
212
213# Pass 2 (encoding)
214ffmpeg -i input.mkv -c:v libx264 -b:v 2600k -pass 2 -c:a aac output.mp4
215```
216
217### Hardware-Accelerated Encoding
218```bash
219# NVIDIA NVENC
220ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc -preset fast -crf 22 output.mp4
221
222# Intel QuickSync
223ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v h264_qsv output.mp4
224```
225
226### Complex Image Pipeline
227```bash
228# Resize, crop, border, adjust
229magick input.jpg \
230 -resize 1000x1000^ \
231 -gravity center \
232 -crop 1000x1000+0+0 +repage \
233 -bordercolor black -border 5x5 \
234 -brightness-contrast 5x10 \
235 -quality 90 \
236 output.jpg
237```
238
239### Video Filter Chains
240```bash
241# Scale, denoise, watermark
242ffmpeg -i video.mp4 -i logo.png \
243 -filter_complex "[0:v]scale=1280:720,hqdn3d[v];[v][1:v]overlay=10:10" \
244 -c:a copy output.mp4
245```
246
247### Animated GIF from Images
248```bash
249# Create with delay
250magick -delay 100 -loop 0 frame*.png animated.gif
251
252# Optimize size
253magick animated.gif -fuzz 5% -layers Optimize optimized.gif
254```
255
256## Media Analysis
257
258### Inspect Video Properties
259```bash
260# Detailed JSON output
261ffprobe -v quiet -print_format json -show_format -show_streams input.mp4
262
263# Get resolution
264ffprobe -v error -select_streams v:0 \
265 -show_entries stream=width,height \
266 -of csv=s=x:p=0 input.mp4
267```
268
269### Image Information
270```bash
271# Basic info
272identify image.jpg
273
274# Detailed format
275identify -verbose image.jpg
276
277# Custom format
278identify -format "%f: %wx%h %b\n" image.jpg
279```
280
281## Performance Tips
282
2831. **Use CRF for quality control** - Better than bitrate for video
2842. **Copy streams when possible** - Avoid re-encoding with `-c copy`
2853. **Hardware acceleration** - GPU encoding 5-10x faster
2864. **Appropriate presets** - Balance speed vs compression
2875. **Batch with mogrify** - In-place image processing
2886. **Strip metadata** - Reduce file size with `-strip`
2897. **Progressive JPEG** - Better web loading with `-interlace Plane`
2908. **Limit memory** - Prevent crashes on large batches
2919. **Test on samples** - Verify settings before batch
29210. **Parallel processing** - Use GNU Parallel for multiple files
293
294## Reference Documentation
295
296Detailed guides in `references/`:
297
298- **ffmpeg-encoding.md** - Video/audio codecs, quality optimization, hardware acceleration
299- **ffmpeg-streaming.md** - HLS/DASH, live streaming, adaptive bitrate
300- **ffmpeg-filters.md** - Video/audio filters, complex filtergraphs
301- **imagemagick-editing.md** - Format conversion, effects, transformations
302- **imagemagick-batch.md** - Batch processing, mogrify, parallel operations
303- **format-compatibility.md** - Format support, codec recommendations
304
305## Common Parameters
306
307### FFmpeg Video
308- `-c:v` - Video codec (libx264, libx265, libvpx-vp9)
309- `-crf` - Quality (0-51, lower=better, 23=default)
310- `-preset` - Speed/compression (ultrafast to veryslow)
311- `-b:v` - Video bitrate (e.g., 2M, 2500k)
312- `-vf` - Video filters
313
314### FFmpeg Audio
315- `-c:a` - Audio codec (aac, mp3, opus)
316- `-b:a` - Audio bitrate (e.g., 128k, 192k)
317- `-ar` - Sample rate (44100, 48000)
318
319### ImageMagick Geometry
320- `800x600` - Fit within (maintains aspect)
321- `800x600!` - Force exact size
322- `800x600^` - Fill (may crop)
323- `800x` - Width only
324- `x600` - Height only
325- `50%` - Scale percentage
326
327## Troubleshooting
328
329**FFmpeg "Unknown encoder"**
330```bash
331# Check available encoders
332ffmpeg -encoders | grep h264
333
334# Install codec libraries
335sudo apt-get install libx264-dev libx265-dev
336```
337
338**ImageMagick "not authorized"**
339```bash
340# Edit policy file
341sudo nano /etc/ImageMagick-7/policy.xml
342# Change <policy domain="coder" rights="none" pattern="PDF" />
343# to <policy domain="coder" rights="read|write" pattern="PDF" />
344```
345
346**Memory errors**
347```bash
348# Limit memory usage
349ffmpeg -threads 4 input.mp4 output.mp4
350magick -limit memory 2GB -limit map 4GB input.jpg output.jpg
351```
352
353## Resources
354
355- FFmpeg: https://ffmpeg.org/documentation.html
356- FFmpeg Wiki: https://trac.ffmpeg.org/
357- ImageMagick: https://imagemagick.org/
358- ImageMagick Usage: https://imagemagick.org/Usage/