A command-line tool for decrypting HLS sample-encrypted MPEG-TS files.
Implements the Apple HLS Sample Encryption specification (SAMPLE-AES), where encryption is applied selectively at the elementary stream level rather than to the entire transport stream.
| Stream type | Encrypted byte | Standard byte |
|---|---|---|
| H.264 (AVC) | 0xDB |
0x1B |
| AAC (ADTS) | 0xCF |
0x0F |
| AC-3 | 0xC1 |
0x81 |
- Parses PAT/PMT to identify encrypted elementary stream PIDs
- For each encrypted PID, concatenates all ES data across PES boundaries
- Decrypts the full ES using stream-type-specific rules:
- H.264: NAL types 1 and 5 only, EPB removal, 1:9 pattern (16 bytes encrypted, 144 skipped), IV resets per NAL
- AAC: Per ADTS frame, skip header + 16 leader bytes, decrypt remaining complete 16-byte blocks
- AC-3: Per syncframe, skip 16 leader bytes, decrypt remaining complete 16-byte blocks
- Re-splits decrypted ES back into PES packets matching original boundaries
- Patches PMT to restore standard stream type bytes
- Writes the decrypted transport stream
All decryption uses AES-128-CBC with no padding.
cargo install --path .
Or build from source:
cargo build --release
decrypt-mpegts --input <file.ts> --output <decrypted.ts> --key <hex> [--iv <hex>] [-y]
| Argument | Description |
|---|---|
-i, --input |
Input MPEG-TS file |
-o, --output |
Output MPEG-TS file |
-k, --key |
AES-128 key (32 hex characters) |
--iv |
AES-128 IV (32 hex characters, defaults to all zeros) |
-y, --yes |
Overwrite output file without prompting |
decrypt-mpegts \
--input encrypted.ts \
--output decrypted.ts \
--key 00112233445566778899aabbccddeeff \
--iv 0fedcba9876543210fedcba987654321
Set RUST_LOG for detailed output:
RUST_LOG=info decrypt-mpegts --input in.ts --output out.ts --key ...