linyqh/speclip-skills/ffmpeg-best-practice
Claude Code and agent skill by linyqh/speclip-skills
- community
Checking that the SKILL.md file is still in the repository.
Lean FFmpeg playbook for reliable video compression, WeChat-compatible MP4 export, clip stitching, audio mixing, subtitle handling, and quick fallback decisions. Use for requests like “压缩视频”, “微信上传”, “体积太大”, “导出更小但别糊”, “多段素材拼接”, “字幕烧录”, and “ffmpeg 报错”.
Install
npx vskill@latest install linyqh/speclip-skills/ffmpeg-best-practiceSKILL.md
The same SKILL.md was published earlier as neversight/learn-skills.dev/ffmpeg-best-practice.
FFmpeg Best Practice
Use this skill when the task requires direct FFmpeg work and the answer should be stable, compatible, and easy to adapt.
Scope
- Compression for smaller files without obvious quality loss
- WeChat/mobile/web-safe MP4 output
- Concat, trim, normalize, subtitle burn-in or muxing
- Audio mixing and missing-audio handling
- Hardware encode with software fallback
Core Workflow
- Probe input files with
ffprobebefore writing commands. - Check encoder availability once per machine/session.
- Decide whether the job is stream-copy or re-encode.
- For compression, default to
MP4 + H.264 + AAC + yuv420p + +faststart. - Prefer capped CRF first; use 2-pass only for a hard file-size target.
- Use
-map 0:a?for optional audio and do not write[0:a?]insidefilter_complex. - If hardware encode fails or produces oversized output, fall back to
libx264. - For subtitle burn-in, first collect subtitle style/settings parameters, then convert subtitles to
.ass, and only then run burn-in. - Return the command, output path, chosen profile, and key flag rationale.
Probe First
Run for each input:
Check once per machine/session:
Minimum checks:
- Video/audio presence
- Resolution, fps, duration, rotation
- Whether target is compatibility-first or strict-size-first
- Available H.264 hardware encoders on this machine
Compression Rules
When the goal is “尽量小,但别太糊”:
- Do not copy streams. Re-encode.
- Keep
MP4 + H.264 + AAC + yuv420p + +faststartas the default delivery target. - Prefer
CRF + maxrate + bufsizeover pure fixed bitrate. - Downscale before crushing bitrate.
- Clamp fps to
24/25/30unless higher fps is genuinely needed. - Use
AAC 64k~96kfor speech-heavy output,96k~128kfor general content. - Never upscale just to match a target profile.
WeChat-Compatible Core Method
Treat “微信压缩” as a compatibility-first export target, not a claim of exact parity with WeChat’s private pipeline.
- Container:
mp4 - Video:
H.264,yuv420p - Audio:
AAC-LC, stereo,44.1kHzor48kHz - Delivery:
-movflags +faststart - Frame rate:
24,25, or30 - Avoid 10-bit, unusual pixel formats, and fragile containers
Use this ladder as the default starting point:
Selection:
- Short side
<= 540: keep at most540p - Short side
<= 720: keep at most720p - Short side
> 720: default to720p; keep1080ponly if detail matters - Hard upload limit: switch to 2-pass bitrate budgeting
Command Patterns
Replace placeholders like IN, OUT, W, H, FPS, CRF, and bitrate values before running.
1) Fast remux, no compression
2) Web-safe baseline export
3) Recommended WeChat-style compression
Default to 720p / 25fps / CRF 22 / maxrate 1800k / bufsize 3600k / AAC 96k unless the source or budget says otherwise.
4) Hard file-size target with 2-pass H.264
On Windows, replace /dev/null with NUL.
5) Concat and normalize mixed clips
- Matching streams: use concat demuxer +
-c copy - Mixed sources: re-encode with concat filter after normalizing resolution/fps/audio
- If any clip lacks audio, generate silence first
6) Subtitle handling
Burn in (required order: get subtitle settings -> convert to ASS -> burn in):
Before any burn-in command, you must first obtain subtitle settings parameters such as:
- font family
- font size
- primary color
- outline/border color and width
- shadow
- alignment/position
- margins / safe area
If subtitle masking is enabled in the current workspace, you must also obtain:
- the exact subtitle mask filter snippet
- the intended visual style of the mask (translucent glass-like blur, not a black rectangle)
Do not burn subtitles directly from raw .srt or other plain subtitle sources. Always convert to .ass first so style and layout are explicit and reproducible.
Required mask-aware burn-in workflow
When the workspace enables subtitle masking, the only correct workflow is:
- Call
subtitle_settingswithvideo_path - Read the returned
subtitleMaskFilter - Convert subtitles to
.ass - Apply the returned mask filter before the
.asssubtitle filter
Rules:
- Use the
subtitle_settingsmask filter snippet verbatim - Do not replace it with
drawbox, a black rectangle, or a custom gray overlay - The expected look is a translucent glass-like blur that keeps the background visible while making the source subtitle unreadable
- If the user mentions the preview mask style, treat that preview style as the target appearance
- If the burn-in result visually diverges from the preview, revise the FFmpeg parameters instead of falling back to a dark overlay
Step 1: convert subtitle source to ASS:
Step 2: burn in from the generated ASS file:
Mask-aware burn in (preferred when masking is enabled):
Notes:
- Replace
SUBTITLE_MASK_FILTERwith the exact filter string returned bysubtitle_settings(video_path=...) - Do not hand-rewrite that filter unless the user is explicitly debugging the mask effect
- Keep the mask filter and subtitle filter in a single
-filter_complexpipeline - If audio exists and no audio edit is requested, prefer
-c:a copy
Soft subtitle mux:
Quick Fallbacks
matches no streams: replace-map 0:awith-map 0:a?- Audio labels fail in
filter_complex: do not use optional audio labels; pre-create silence concatparameter mismatch: pre-normalize clips to the same resolution/fps/audio layout- Hardware encoder unavailable or output too large: fall back to
libx264 - Output still too large: reduce to
720pbefore increasingCRF - VFR sync drift: normalize to CFR before audio mixing or concat
Encoder Defaults
- macOS:
h264_videotoolbox, fallbacklibx264 - Windows:
h264_nvenc, thenh264_qsv, thenh264_amf, thenlibx264 - Best compression efficiency:
libx264 -preset slow - Best compatibility:
-pix_fmt yuv420p -movflags +faststart
Output Contract
Always return:
- Exact command used
- Output path
- Chosen profile (
copy,web,540p,720p,1080p, or2-pass) - Why key flags were chosen
- Any fallback applied
Safety
- Never overwrite source media in place
- Prefer absolute output paths
- Probe first when stream topology is uncertain
- Do not claim “exactly WeChat internal compression”; call it compatibility-aligned
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingffmpeg-best-practice/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/linyqh/speclip-skills/ffmpeg-best-practice)