Media Gpac
Context: $ARGUMENTS
Quick start
- Inspect a broken MP4: → Step 2 (
info/diso) - Package DASH/CMAF: → Step 3 (
dashsubcommand) - Fragment for fMP4: → Step 3 (
fragment) - Extract a raw track (h264/aac ES): → Step 3 (
extract-track) - CENC encrypt for ClearKey testing: → Step 3 (
encrypt) - Hand commercial DRM to Shaka instead: →
media-shakaskill
When to use
- Doing ISO-BMFF surgery ffmpeg can't (box-level edits, precise track IDs, edit-list fixes).
- Packaging CMAF/DASH where fragment timing must be accurate (MP4Box beats ffmpeg's dash muxer).
- Dumping the full box tree to XML for diagnostics (
-diso). - Repairing broken moov/moof boxes, rewriting sidx, or setting language/default flags in-place.
- Authoring ClearKey-encrypted CENC content for pipeline testing.
Step 1 — Install
# macOS
brew install gpac
# Debian/Ubuntu
sudo apt install gpac
# Fedora/RHEL
sudo dnf install gpac
# Verify
MP4Box -version
gpac -version
MP4Box is the legacy (stable, widely documented) CLI for ISOBMFF surgery. gpac is the newer filter-graph CLI (similar philosophy to ffmpeg filters). Prefer MP4Box for most tasks — it's documented everywhere.
Step 2 — Pick the operation
| Task | Tool |
|------|------|
| Human-readable summary | MP4Box -info in.mp4 |
| Full box tree as XML | MP4Box -diso in.mp4 (writes in_info.xml) |
| Extract track as raw ES | MP4Box -raw TID in.mp4 |
| Fragment for fMP4 | MP4Box -frag 2000 in.mp4 |
| DASH / CMAF package | MP4Box -dash 4000 -frag 4000 -rap … |
| Inject sidx | MP4Box -add-sidx 4000 in.mp4 |
| CENC encrypt | MP4Box -crypt drm.xml -out o.mp4 in.mp4 |
| CENC decrypt | MP4Box -decrypt drm.xml -out o.mp4 in.mp4 |
| Remove track | MP4Box -rem TID in.mp4 |
| Set language | MP4Box -lang TID=jpn in.mp4 |
| Enable/disable | MP4Box -enable TID -disable TID in.mp4 |
| Split by time | MP4Box -splitx T1:T2 in.mp4 |
| Edit list | MP4Box -elst '0,N,1' in.mp4 |
| Add tracks | MP4Box -add a.h264 -add a.aac out.mp4 |
Always pass -out when you want a new file — MP4Box edits in-place otherwise. Back up first.
Step 3 — Run via the helper script
The scripts/gpac.py wrapper gives an argparse interface over these operations. Stdlib-only, non-interactive, --dry-run prints the command.
# Inspect
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py info --input in.mp4
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py diso --input in.mp4 --output boxes.xml
# Extract raw track 1 (ES)
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py extract-track --input in.mp4 --track 1 --output track1.h264
# Fragment (2-second fragments, in-place copy with -out)
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py fragment --input in.mp4 --output frag.mp4 --fragment-ms 2000
# DASH/CMAF (live profile)
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py dash --input in.mp4 --outdir dashout --segment-ms 4000 --profile live
# CENC ClearKey encrypt
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py encrypt \
--input in.mp4 --output enc.mp4 \
--key-id 0123456789abcdef0123456789abcdef \
--key fedcba9876543210fedcba9876543210
# Remove track 2 (usually audio #2)
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py remove-track --input in.mp4 --output stripped.mp4 --track 2
# Set language on track 2
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py set-lang --input in.mp4 --track 2 --lang jpn
# Split by time
uv run ${CLAUDE_SKILL_DIR}/scripts/gpac.py split-time --input in.mp4 --output-pattern seg --start 00:00:10 --end 00:00:30
Add --dry-run to print the MP4Box command without executing. Add --verbose to echo the command before running.
Step 4 — Verify
After any authoring step, confirm result with:
MP4Box -info out.mp4
For DASH, validate the manifest:
xmllint --noout manifest.mpd
ls -la dashout/ # should contain init.mp4 + seg_*.m4s (live) OR one onDemand file
For CENC: play with ffplay -decryption_key KEY enc.mp4 or a Shaka-Player ClearKey page. For fragmented MP4: MP4Box -info shows Fragmented: yes and lists moof count.
Available scripts
scripts/gpac.py— argparse wrapper for MP4Box:check,info,diso,extract-track,fragment,dash,encrypt,decrypt,remove-track,set-lang,split-time. Generates DRM XML for CENC ops in a temp file.