Your transcode is done, the ladder looks right, and the files still stutter on a Fire TV. Nine times out of ten the problem is not the encoder — it is the packaging step: the stage that cuts a mezzanine file into CMAF segments, aligns audio and video timelines, and writes the manifests a player actually reads.

Three open-source tools dominate this layer: Google’s Shaka Packager, Axiomatic’s Bento4, and Telecom Paris’ GPAC (the MP4Box toolkit). They overlap just enough that teams pick one by accident, then discover six months later that the tool cannot do low-latency chunked CMAF, or that it silently wrote a playlist that Safari refuses to play.

Here is the practical breakdown, with the exact commands and the settings that matter.

TL;DR: Quick Verdict

  • Shaka Packager — best default for VOD and live HLS + DASH from one command. Clean CMAF output, Widevine/PlayReady/FairPlay signalling, actively maintained by Google. Use it unless you have a specific reason not to.
  • Bento4 — the forensic toolbox. mp4dump, mp4info, mp4edit and mp4fragment will tell you exactly what is wrong with a file, and mp4dash produces very clean DASH + HLS. Best when you must inspect or repair media, not just package it.
  • GPAC / MP4Box — the swiss army knife with a filter graph. Unmatched for unusual pipelines (subtitles, thumbnails, per-scene packaging, arbitrary filter chains). Steeper learning curve, LGPL, no vendor lock-in.

If you are still choosing the streaming server that will serve these segments, our low-latency streaming server comparison of ZLMediaKit, SRS and Ant Media covers the delivery half of the problem.

Head-to-Head Comparison

DimensionShaka PackagerBento4GPAC / MP4Box
GitHub stars2,6742,5313,332
Last release activity2026-11-042026-11-222026-11-30
LicenseBSD-3-Clause (Google)GPL-2.0 for tools, commercial option — no LICENSE file in repo, verify before shippingLGPL-2.1
DASH outputYes (static + live)Yes (mp4dash)Yes (-dash)
HLS outputYes (TS or fMP4)Yes (--hls)Yes via -dash + HLS profile
CMAF / chunked outputYes (--chunk_duration)Partial (fragmented MP4)Yes (-frag, -dash-live)
DRM encryptionWidevine, PlayReady, FairPlay, CENCCENC (mp4encrypt)CENC (MP4Box -crypt)
Filter graphNoNoYes — the main differentiator
Inspection / repairMinimalExcellent (mp4dump, mp4info)Good (-info, -diso)
Official Docker imageYes (google/shaka-packager)No (build from source)Package or build from source
Best fitPrimary packagerDebugging + DASH/HLS packagingComplex pipelines, subtitles, forensics

Which Tool for Which Job?

Use caseRecommendationWhy
Standard VOD ladder → HLS + DASHShaka PackagerOne command, two manifests, correct CMAF
Live with 2–6s latencyShaka (LL-DASH) or GPACBoth support chunked CMAF; Shaka’s flags are simpler
“This file plays in Chrome but not Safari”Bento4mp4dump shows the actual box structure and sample flags
Adding subtitles or multiple audio tracks at scaleGPACFilter graph handles track routing without scripting
Encrypting for Widevine + FairPlayShakaKey and --protection_systems handling is the cleanest
Repairing a broken MP4 before packagingBento4mp4edit can rewrite boxes in place
Somebody else’s CI pipeline you must matchMatch theirsSegment boundaries must be identical across the ladder

Shaka Packager: The Modern Default

Shaka Packager takes inputs, segments them, and emits HLS playlists and a DASH manifest in one pass. It is the least surprising tool of the three.

1
2
3
4
5
6
7
8
docker run --rm -v "$PWD:/media" google/shaka-packager \
  packager \
  'in=/media/master_1080p.mp4,stream=video,init_segment=/media/out/v1080/init.mp4,segment_template=/media/out/v1080/$Number$.m4s' \
  'in=/media/master_1080p.mp4,stream=audio,init_segment=/media/out/a128/init.mp4,segment_template=/media/out/a128/$Number$.m4s' \
  'in=/media/master_720p.mp4,stream=video,init_segment=/media/out/v720/init.mp4,segment_template=/media/out/v720/$Number$.m4s' \
  --segment_duration 4 \
  --hls_master_playlist_output /media/out/master.m3u8 \
  --mpd_output /media/out/manifest.mpd

Four flags carry most of the risk:

  • --segment_duration 4 — keyframe-aligned segments. If your encoder’s GOP is 2s, segments land on 2s boundaries regardless, and your manifest will not match the ladder.
  • --hls_master_playlist_output — writes #EXT-X-STREAM-INF entries with bandwidth and codec attributes. Missing CODECS= is the single most common cause of Safari refusing a stream.
  • --generate_static_live_mpd — for live playback of a static archive; useful for event replays.
  • --chunk_duration — with --low_latency_dash_mode, produces chunked CMAF for LL-DASH. Do not enable it for VOD: it multiplies object count on your CDN.

Encryption is where Shaka earns its place. Raw key encryption with CENC, signalled to both Widevine and FairPlay:

1
2
3
4
5
6
7
8
9
packager \
  'in=master.mp4,stream=video,output=v.mp4' \
  'in=master.mp4,stream=audio,output=a.mp4' \
  --enable_raw_key_encryption \
  --keys 'label=video:key_id=11112222333344445555666677778888:key=00112233445566778899aabbccddeeff' \
  --keys 'label=audio:key_id=99998888777766665555444433332222:key=ffeeddccbbaa99887766554433221100' \
  --protection_systems Widevine,PlayReady,FairPlay \
  --hls_master_playlist_output master.m3u8 \
  --mpd_output manifest.mpd

Note the separate audio and video keys. Rotating a single key shared by all renditions is the shortcut that later forces a full library re-package when a studio asks for per-track keys.

Bento4: Inspect First, Package Second

Shaka Packager — official project banner

Bento4’s packaging command is short, but its real value is the inspection tools that ship beside it. When a file misbehaves, mp4info and mp4dump answer questions no manifest will:

1
2
3
4
5
# What is actually in this file?
mp4info master_1080p.mp4 | head -40

# Where are the samples, and are they sync samples?
mp4dump --verbosity 2 master_1080p.mp4 | grep -A3 '"type": "stss"' | head -20

Packaging is a two-step process: fragment, then dash.

1
2
3
4
5
6
7
# Fragment at 4s, aligned to keyframes present in the file
mp4fragment --fragment-duration 4000 master_1080p.mp4 fragmented_1080p.mp4

# Build DASH + HLS from the fragmented inputs
mp4dash --hls --use-segment-timeline \
  -o out/ \
  fragmented_1080p.mp4 fragmented_720p.mp4 audio_128k.mp4

mp4fragment refuses to invent keyframes. If your master has a 10s GOP, your 4s fragment request becomes 10s fragments — which is Bento4 telling you the truth that Shaka will also honour but less loudly. That is why Bento4 is the tool to reach for when “the segments are the wrong size” and nobody believes the encoder is at fault.

Two caveats. There is no LICENSE file at the repository root, and the tools have historically been GPL-2.0 with a paid commercial option from Axiomatic Systems — confirm the terms before shipping it inside a proprietary product. And there is no official Docker image, so you build from source with CMake, which means pinning a commit rather than a tag.

GPAC / MP4Box: The Filter Graph

GPAC models media processing as a directed graph: inputs are sources, filters transform, outputs write. Most of the time you never touch the graph directly, because MP4Box wraps the common cases:

1
2
3
4
5
6
7
# Package a ladder into DASH with 4s segments, on-demand profile
MP4Box -dash 4000 -profile onDemand -out out/manifest.mpd \
  v1080.mp4 v720.mp4 v480.mp4 a128.mp4

# Live-style packaging with fragments, keeping audio and video aligned
MP4Box -dash 4000 -frag 4000 -rap -bs-switching no \
  -out out/live.mpd v1080.mp4 a128.mp4

The -rap flag is doing more work than it looks: it forces segment boundaries onto random access points, which is the difference between a manifest that seeks correctly and one that shows a black frame for half a second on every seek.

Where GPAC pulls ahead is anything multi-track or multi-format. Adding WebVTT subtitles and a thumbnail track in the same package is a filter graph, not a shell script:

1
2
gpac -i v1080.mp4 -i a128.mp4 -i subtitles.vtt \
  -o out/manifest.mpd:dash=1:segdur=4:template='$RepresentationID$/$Number$'

GPAC is LGPL-2.1, which is friendlier for embedding than Bento4’s GPL, and it is the only one of the three that will happily ingest odd containers and rewrite them. The cost is documentation: flags are numerous, historically under-explained, and version-dependent. Pin your GPAC version in CI.

The Part That Actually Breaks: Keyframe Alignment

Whatever tool you pick, packaging inherits the encoder’s GOP structure. If your ladder is not keyframe-aligned, adaptive switching stalls — the player jumps to a rendition whose next segment starts 1.5s later than expected.

Encode with forced keyframes that line up with your segment duration:

1
2
3
4
5
6
# 2-second GOP for a 4-second segment duration
ffmpeg -i master.mov \
  -vf "scale=-2:1080" -c:v libx264 -preset slow -crf 20 \
  -g 48 -keyint_min 48 -sc_threshold 0 -force_key_frames "expr:gte(t,n_forced*2)" \
  -c:a aac -b:a 128k -ar 48000 \
  v1080.mp4

-sc_threshold 0 disables scene-change keyframes so the GOP is strictly periodic; -force_key_frames guarantees a keyframe at every 2s boundary even when the encoder would prefer otherwise. Do this for every rendition and the packaging step becomes deterministic.

Also normalise audio: 48 kHz, stereo or explicit channel layout, and consistent AAC profile across renditions. Mixed audio parameters produce a ladder where switching renditions changes loudness — a complaint that always gets blamed on the packager.

Common Traps

Trap 1 — Segment duration shorter than the GOP. The packager cannot split inside a GOP. Your 2s request silently becomes 6s. Fix the encoder, not the flag.

Trap 2 — Missing CODECS in the HLS master playlist. Safari and iOS are strict. If you hand-write or post-process the master playlist, keep the codec string accurate (avc1.640028,mp4a.40.2), or let the packager write it.

Trap 3 — Encrypting audio and video with the same key. It works, and it will pass QA. It also blocks per-track licence policies later.

Trap 4 — Packaging the same asset twice with different tools. Segment boundaries will differ by a frame, and your CDN cache will hold both. Standardise on one packager per library.

Trap 5 — Forgetting init.mp4 in fMP4 HLS. Players request /v1080/init.mp4 before the first segment. A missing init segment produces a stream that works in one player and fails in another.

Trap 6 — No #EXT-X-INDEPENDENT-SEGMENTS. Without it, players may assume segments are not independently decodable and refuse to switch renditions mid-stream.

If your pipeline feeds a live server rather than a VOD library, the self-hosted live streaming guide covering Owncast, MediaMTX and nginx-rtmp explains how packaged output maps onto ingest protocols — and the Node.js transcoding comparison of fluent-ffmpeg, ffmpeg-wasm and Remotion covers the encoding stage that produces your mezzanine files in the first place.

FAQ

Is Shaka Packager still maintained? Yes. It ships regular releases, tracks CMAF and low-latency DASH changes, and is the packaging tool referenced by Google’s own streaming documentation.

Can Bento4 produce HLS? Yes — mp4dash --hls writes both DASH and HLS from fragmented inputs. It is less feature-rich than Shaka for HLS-specific tags, but the output is standards-compliant.

Which tool handles DRM best? Shaka Packager. Its --protection_systems flag generates the correct signalling for Widevine, PlayReady and FairPlay in one pass, including the HLS #EXT-X-KEY entries FairPlay requires.

Do I need CMAF? For VOD, CMAF gives you one set of segments for both HLS and DASH, which halves storage and CDN cost. For low-latency live, chunked CMAF is effectively required.

GPAC is LGPL — can I use it commercially? Yes, LGPL-2.1 permits commercial use, including dynamic linking into proprietary applications. Static linking carries additional obligations; check with counsel if you redistribute binaries.

Can I skip packaging and serve progressive MP4? For short clips, yes. For anything adaptive, no — you lose rendition switching, CDN segment caching, and DRM.

Which one should a small team start with? Shaka Packager in Docker. It handles both manifests in one command, and when something breaks you can hand the same file to Bento4’s mp4dump to find out why.


💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com