Media Shaka
Context: $ARGUMENTS
Shaka Packager is Google's production DRM packager — the same tool used by YouTube, Netflix-style pipelines, and most commercial OTT stacks. It does NOT re-encode: inputs must already be encoded at the bitrates/resolutions you want to ship. It outputs encrypted CMAF (fMP4) segments plus DASH .mpd and HLS .m3u8 manifests that point at the SAME encrypted files.
Quick start
- Test encryption (no license server): ClearKey → Step 3 (CENC recipe)
- Production Widevine (Google/YouTube): Step 5 (license-server integration)
- Multi-DRM DASH+HLS for studio OTT:
cbcs+ Widevine + PlayReady → Step 4 - FairPlay (Apple HLS):
cbcs+ SAMPLE-AES → Step 6 - Inspect, validate, generate keys:
scripts/shaka.pysubcommands
When to use
- Packaging already-encoded renditions into encrypted DASH+HLS for a commercial OTT service.
- Integrating with a Widevine / PlayReady / FairPlay license server (EZDRM, PallyCon, Axinom, BuyDRM, DRMtoday, Irdeto, or Google's Widevine cloud).
- Building CMAF with common encryption so one set of
.m4sfiles plays on Android (Widevine), iOS/Safari (FairPlay), and Edge/Xbox (PlayReady). - Generating test ClearKey streams for development against Shaka Player or dash.js.
- You do NOT use Shaka Packager for: re-encoding, stabilization, filtering. Encode first with ffmpeg, then package.
Step 1 — Install
Pick one:
# macOS
brew install shaka-packager
# Verify
packager --version
# Docker (CI, reproducible)
docker run --rm -v "$PWD":/work -w /work google/shaka-packager \
packager --version
# Prebuilt binary (Linux / macOS / Windows)
# https://github.com/shaka-project/shaka-packager/releases
scripts/shaka.py check wraps the version probe.
Step 2 — Decide DRM scheme
| Scheme | Cipher | DASH | HLS | FairPlay | Notes |
|--------|--------|------|-----|----------|-------|
| cenc | AES-CTR full sample | Yes | Legacy | No | DASH default pre-2018, NOT FairPlay compatible |
| cens | AES-CTR pattern 1:9 | Yes | No | No | Rarely used |
| cbc1 | AES-CBC full sample | Yes | No | No | Legacy |
| cbcs | AES-CBC pattern 1:9 | Yes | Yes | Yes | Recommended for all new work |
Rule: use cbcs unless a specific device mandate forces cenc. Widevine 14.0+, PlayReady, and FairPlay all support cbcs, so one set of .m4s files plays on everything. This is the whole point of CMAF.
KIDs and keys are 32-char hex (16 bytes each). KID must be unique per content (use scripts/shaka.py gen-clearkey-keys).
Step 3 — Package ClearKey CENC (test / demo)
Encodes must already exist. Package a 1080p + 720p + audio ladder:
packager \
in=1080.mp4,stream=video,output=1080.mp4,drm_label=HD \
in=720.mp4,stream=video,output=720.mp4,drm_label=SD \
in=audio.m4a,stream=audio,output=audio.mp4 \
--enable_raw_key_encryption \
--keys label=HD:key_id=11223344556677889900aabbccddeeff:key=00112233445566778899aabbccddeeff,label=SD:key_id=aabbccddeeff00112233445566778899:key=ffeeddccbbaa99887766554433221100 \
--protection_scheme cbcs \
--segment_duration 4 \
--clear_lead 10 \
--mpd_output manifest.mpd \
--hls_master_playlist_output master.m3u8
--clear_lead 10leaves the first 10s unencrypted so the player can start before the license arrives.--segment_duration 4matches the CMAF norm (Apple / DASH-IF recommend 4–6 s).- Output is a DASH
.mpdand an HLS.m3u8master, both referencing the same encrypted fragmented-MP4 files.
Test playback: https://shaka-player-demo.appspot.com/ (paste ClearKey JSON).
Step 4 — Multi-DRM DASH+HLS (production)
Widevine + PlayReady on DASH, FairPlay on HLS, all cbcs, same segments:
packager \
in=1080.mp4,stream=video,output=1080.mp4,drm_label=HD \
in=720.mp4,stream=video,output=720.mp4,drm_label=SD \
in=audio.m4a,stream=audio,output=audio.mp4 \
--enable_widevine_encryption \
--key_server_url https://license.widevine.com/cenc/getcontentkey/YOUR_PROVIDER \
--signer "your-signer-name" \
--aes_signing_key YOUR_AES_SIGNING_KEY_HEX \
--aes_signing_iv YOUR_AES_SIGNING_IV_HEX \
--enable_playready_encryption \
--playready_key_server_url https://your-playready-license-server/rightsmanager.asmx \
--protection_scheme cbcs \
--segment_duration 4 \
--mpd_output manifest.mpd \
--hls_master_playlist_output master.m3u8
For vendor-managed DRM (EZDRM / PallyCon / Axinom), the vendor gives you the URL, signer, AES key, AES IV. You do NOT run your own Widevine license server unless you are a Google-certified integrator.
Step 5 — Widevine-only (Google cloud or private license server)
packager \
in=video.mp4,stream=video,output=video.mp4,drm_label=HD \
in=audio.m4a,stream=audio,output=audio.mp4 \
--enable_widevine_encryption \
--key_server_url https://license.widevine.com/cenc/getcontentkey/YOUR_PROVIDER \
--content_id $(printf 'my-content-42' | xxd -p) \
--signer "your-signer-name" \
--aes_signing_key KEY_HEX --aes_signing_iv IV_HEX \
--protection_scheme cbcs \
--mpd_output manifest.mpd
--content_id must be hex-encoded. PSSH is auto-inserted into the moov box — required for Widevine CDM to recognise the content.
Step 6 — FairPlay HLS only
packager \
in=video.mp4,stream=video,output=video.mp4 \
in=audio.m4a,stream=audio,output=audio.mp4 \
--enable_raw_key_encryption \
--keys label=:key_id=KID_HEX:key=KEY_HEX \
--protection_scheme cbcs \
--hls_master_playlist_output master.m3u8
FairPlay uses the Apple SAMPLE-AES scheme (which is cbcs at the cipher level). You still need a FairPlay Key Server for production: the client sends an SPC, the server returns a CKC. Shaka Packager does the bit-level work, NOT the SPC/CKC exchange.
Step 7 — Verify
# DASH
curl -s https://validator.dashif.org/validator/ -F "file=@manifest.mpd"
# HLS
mediastreamvalidator master.m3u8 # Apple tool
hlsreport.pl -s master.m3u8 # formatted report
# Probe PSSH boxes
MP4Box -info video.mp4 # GPAC
mp4dump --verbosity 2 video.mp4 # Bento4
Shaka Player demo page is the fastest end-to-end check.
Available scripts
scripts/shaka.py check— reportpackager --version.scripts/shaka.py gen-clearkey-keys— emit a random 16-byte KID + key pair (hex).scripts/shaka.py clearkey— package DASH+HLS with raw key encryption.scripts/shaka.py widevine— package with Widevine license-server integration.scripts/shaka.py multi-drm— Widevine + PlayReady combined.scripts/shaka.py fairplay-hls— HLS-only FairPlay (cbcs) output.
All commands accept --dry-run (print the packager invocation) and --verbose. Stdlib-only, non-interactive.
Workflow
# Generate a test key pair
uv run ${CLAUDE_SKILL_DIR}/scripts/shaka.py gen-clearkey-keys
# Package a test stream
uv run ${CLAUDE_SKILL_DIR}/scripts/shaka.py clearkey \
--inputs-video 1080.mp4 720.mp4 \
--input-audio audio.m4a \
--outdir out/ \
--scheme cbcs \
--keys "label=HD:kid=HEX:key=HEX" "label=SD:kid=HEX:key=HEX"
# Package against a Widevine license server
uv run ${CLAUDE_SKILL_DIR}/scripts/shaka.py widevine \
--inputs 1080.mp4 720.mp4 audio.m4a \
--key-server https://license.widevine.com/cenc/getcontentkey/PROVIDER \
--signer "signer-name" --aes-key HEX --aes-iv HEX \
--outdir out/