mediafilesegmenter是否支持Sample Encryption采样加密?
Great question! Let's break this down clearly:
mediafilesegmenter does NOT natively support Sample-AES encryption — here's why that's happening and how you can achieve your desired workflow:
What's going on with your current command
When you run:
$ mediafilesegmenter -k -r myMovie.mp4
The -k flag triggers AES-128 whole-segment encryption, where entire HLS media segments are encrypted as a single block. This is fundamentally different from Sample-AES, which encrypts individual media samples (like video frames or audio samples) rather than entire segments.
How to get Sample-AES encrypted HLS streams
Since mediafilesegmenter can't handle sample-level encryption on its own, you'll need a two-step workflow using additional tools. A common, reliable approach uses the open-source Bento4 toolset:
First, encrypt your MP4 with Sample-AES using
mp4encrypt
This tool lets you apply MPEG-CENC (Common Encryption) with Sample-AES mode. A sample command looks like:mp4encrypt \ --method MPEG-CENC \ --key 1:abcdef1234567890abcdef1234567890:abcdef1234567890abcdef1234567890 \ --property 1:KID:12345678-1234-1234-1234-123456789012 \ --sample-aes \ myMovie.mp4 \ encrypted_sample_aes.mp4Adjust the key and KID values to match your specific encryption requirements.
Then segment the encrypted MP4 with mediafilesegmenter
Now you can use mediafilesegmenter to split the Sample-AES encrypted file into HLS segments:mediafilesegmenter -r encrypted_sample_aes.mp4This will generate HLS segments that retain the Sample-AES encryption metadata and sample-level protection.
Quick note
Sample-AES is often paired with DRM systems like Apple FairPlay Streaming, so you'll also need to ensure your HLS manifest includes the appropriate DRM metadata (such as the content key URL) to enable playback on supported devices.
内容的提问来源于stack exchange,提问作者Kwan

