axiomatic-systems / Bento4

Full-featured MP4 format, MPEG DASH, HLS, CMAF SDK and tools
http://www.bento4.com
2.04k stars 485 forks source link

mp4hls ignoring DRM signaling #543

Open qchroman opened 4 years ago

qchroman commented 4 years ago

Hello all,

I have noticed that if you run the following command

python.exe ./mp4-hls.py -f ^
--... ^
--widevine ^
--fairplay ^
--output-dir=./output/hls-fp-wv ^
./input/sintel_trailer-480p.frag.mp4 ./input/sintel_trailer-720p.frag.mp4

To add FP and WV to the HLS output, the output is missing the WV signaling inside the iframe.m3u8 manifest

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-I-FRAMES-ONLY
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://0fda16c25ae198873dd948cdacc5b01c",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXTINF:27.416667,
#EXT-X-BYTERANGE:1128@376
segment-0.ts
#EXTINF:24.541667,
#EXT-X-BYTERANGE:16920@376
segment-1.ts
#EXT-X-ENDLIST

And the stream.m3u8 is missing the FP signaling

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,CAESEFrhmIc9xxxlIzazFsP2hbCAcKgJIRA==",KEYFORMAT="com.widevine",KEYFORMATVERSIONS="1",IV=0x5AE198873DD948CDACC5B0FDA16C201C
#EXTINF:27.416667,
segment-0.ts
#EXTINF:24.541667,
segment-1.ts
#EXT-X-ENDLIST

Tested with 1.6.0-637 version of Bento.

barbibulle commented 4 years ago

Indeed, the iframes playlist is missing the KEY entry for Widevine. But in a simple test on my system, I can verify that the stream.m3u8 playlist does contain both KEY lines. Ex:

mp4hls -f "--widevine=#CAESEFrhmIc9xxxlIzazFsP2hbCAcKgJIRA==" --fairplay=uri:skd://0fda16c25ae198873dd948cdacc5b01c --encryption-key=00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f video.mp4

Gives:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://0fda16c25ae198873dd948cdacc5b01c",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,CAESEFrhmIc9xxxlIzazFsP2hbCAcKgJIRA==",KEYFORMAT="com.widevine",KEYFORMATVERSIONS="1",IV=0x000102030405060708090A0B0C0D0E0F
#EXTINF:6.000000,
segment-0.ts
...
qchroman commented 4 years ago

I apologize for not using the command right in my initial report, I completely ignored the widevine header value and the fairplay URI value.

Here are my latest tests

python ./1.6.0.637/utils/mp4-hls.py -f ^
--widevine=#CAESEKHfoShqOEkwkq6uVMR7B2MaC2J1eWRybWtleW9zIhCh36EoajhJMJKurlTEewdjKgJIRA== ^
--fairplay=uri:skd://a1dfa1286a38493092aeae54c47b0763 ^
--encryption-key=682860eb2d3ba52245d951d845536b43a1dfa1286a38493092aeae54c47b0763 ^
--output-dir=./output/dash-hls-wv-issue ^
./input/sintel_trailer-480p.frag.mp4 ./input/sintel_trailer-720p.frag.mp4

results in the following:

stream:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://a1dfa1286a38493092aeae54c47b0763",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,CAESEKHfoShqOEkwkq6uVMR7B2MaC3NvbWVwcm92aWRlciIQod+hKGo4STCSrq5UxHsHYyoCSEQ=",KEYFORMAT="com.widevine",KEYFORMATVERSIONS="1",IV=0xA1DF092AEAE54C47B0763A1286A38493
#EXTINF:27.416667,
segment-0.ts
#EXTINF:24.541667,
segment-1.ts
#EXT-X-ENDLIST

iframes:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-I-FRAMES-ONLY
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="key.bin",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXTINF:27.416667,
#EXT-X-BYTERANGE:1128@376
segment-0.ts
#EXTINF:24.541667,
#EXT-X-BYTERANGE:16920@376
segment-1.ts
#EXT-X-ENDLIST

Notice the key.bin instead of the actual URL defined by me.

python ./1.6.0.637/utils/mp4-hls.py -f ^
--encryption-key=45d951d682860eb2d3ba522845536b43a1df092aeae54c47b0763a1286a38493 ^
--encryption-iv=a1dfa1286a38493092aeae54c47b0763 ^
--encryption-iv-mode=fps ^
--encryption-key-uri=skd://a1dfa1286a38493092aeae54c47b0763 ^
--encryption-key-format=com.apple.streamingkeydelivery ^
--encryption-key-format-versions=1 ^
--encryption-mode=SAMPLE-AES ^
--output-dir=./output/dash-hls-wv-issue ^
./input/sintel_trailer-480p.frag.mp4 ./input/sintel_trailer-720p.frag.mp4

Results in valid manifests:

stream:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://a1dfa1286a38493092aeae54c47b0763",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXTINF:27.416667,
segment-0.ts
#EXTINF:24.541667,
segment-1.ts
#EXT-X-ENDLIST

iframes:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-I-FRAMES-ONLY
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://a1dfa1286a38493092aeae54c47b0763",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXTINF:27.416667,
#EXT-X-BYTERANGE:1128@376
segment-0.ts
#EXTINF:24.541667,
#EXT-X-BYTERANGE:16920@376
segment-1.ts
#EXT-X-ENDLIST

And the last one

python ./1.6.0.637/utils/mp4-hls.py -f ^
--widevine=#CAESEKHfoShqOEkwkq6uVMR7B2MaC3NvbWVwcm92aWRlciIQod+hKGo4STCSrq5UxHsHYyoCSEQ= ^
--encryption-key=45d951d682860eb2d3ba522845536b43a1df092aeae54c47b0763a1286a38493 ^
--encryption-iv=a1dfa1286a38493092aeae54c47b0763 ^
--encryption-iv-mode=fps ^
--encryption-key-uri=skd://a1dfa1286a38493092aeae54c47b0763 ^
--encryption-key-format=com.apple.streamingkeydelivery ^
--encryption-key-format-versions=1 ^
--encryption-mode=SAMPLE-AES ^
--output-dir=./output/dash-hls-wv-issue ^
./input/sintel_trailer-480p.frag.mp4 ./input/sintel_trailer-720p.frag.mp4

Results in stream manifest missing the fairplay signaling:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,CAESEKHfoShqOEkwkq6uVMR7B2MaC3NvbWVwcm92aWRlciIQod+hKGo4STCSrq5UxHsHYyoCSEQ=",KEYFORMAT="com.widevine",KEYFORMATVERSIONS="1",IV=0xA1DF092AEAE54C47B0763A1286A38493
#EXTINF:27.416667,
segment-0.ts
#EXTINF:24.541667,
segment-1.ts
#EXT-X-ENDLIST

And the iframs manifest missing the widevine signaling:

#EXTM3U
#EXT-X-VERSION:5
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-I-FRAMES-ONLY
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:27
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://a1dfa1286a38493092aeae54c47b0763",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXTINF:27.416667,
#EXT-X-BYTERANGE:1128@376
segment-0.ts
#EXTINF:24.541667,
#EXT-X-BYTERANGE:16920@376
segment-1.ts
#EXT-X-ENDLIST