axiomatic-systems / Bento4

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

Encrypted MP4DASH --hls content does not play back #259

Open wmucheru opened 6 years ago

wmucheru commented 6 years ago

I'm using Bento4 and ExpressPlay to package content and Shaka Player / VideoJS to play back content. I want to have both DASH and HLS playlists for multi-device support. Here is the script I'm using:

DASH + HLS with DRM

KID=18E93B2068ACAECBF142EF0266A23383
KEY=FF434A8474BD63EC1456E812F18424B7
CID=01af1718424ae08b

mp4fragment video.mp4 video_frag.mp4

mp4dash \
    --force \
    --subtitles \
    --use-segment-timeline \
    --profiles='on-demand' \
    --marlin \
    --widevine \
    --widevine-header=provider:intertrust#content_id:${CID}#kid:${KID} \
    --encryption-key=${KID}:${KEY} \
    --encryption-cenc-scheme=cbcs \
    --hls \
    --hls-master-playlist-name=pl.m3u8 \
    video_frag.mp4

DASH with DRM

mp4dash \
    --force \
    --subtitles \
    --profiles='on-demand' \
    --marlin \
    --widevine \
    --widevine-header=provider:intertrust#content_id:${CID}#kid:${KID} \
    --encryption-key=${KID}:${KEY} \
    --eme-signaling=pssh-v1 \
    --use-segment-timeline \
    video_frag.mp4

The results:

Am I missing something @barbibulle ? I'm using Bento4-SDK-1-5-1-622 on MacOS

wmucheru commented 6 years ago

Is there a fix for this?

adamhewitt627 commented 6 years ago

I'm hitting either the same or a similar issue. I've been able to do HLS + DRM with mp4hls but not with mp4dash --hls. (I have also succeeded with mp4dash -hls w/o DRM, but the point is to get DRM working)

Output of mp4hls --encryption-key ...

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128,URI="..."
#EXTINF:6.013968,
#EXT-X-BYTERANGE:99904@0
media.aac
#EXTINF:6.013968,
#EXT-X-BYTERANGE:98576@99904
media.aac
#EXTINF:6.013968,
#EXT-X-BYTERANGE:97968@198480
media.aac
...

Output of mp4dash --hls --encryption-key ...

#EXTM3U
# Created with Bento4 mp4-dash.py, VERSION=1.8.0-622
#
#EXT-X-VERSION:6
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-MAP:URI="media.m4s",BYTERANGE="764@0"
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="...",IV=0x49ee35c94efe88b9910c8f973879648d
#EXTINF:1.996916,
#EXT-X-BYTERANGE:34155@764
media.m4s
#EXTINF:1.996916,
#EXT-X-BYTERANGE:32694@34919
media.m4s
#EXTINF:1.996916,
#EXT-X-BYTERANGE:32091@67613
media.m4s
...
adamhewitt627 commented 6 years ago

With one caveat, I am able to create HLS w/DRM file with this command:

mp4dash media.m4s -o media_folder `
    --force --no-split --use-segment-list `
    --encryption-key "<kid>:<key>" --encryption-cenc-scheme=cbcs `
    --hls

The Problem

Regardless of DRM included - iOS & Safari don't seem to understand the master.m3u8. Edge can play it just fine. If I overwrite its output to match the mp4hls result, the stream will play.

mp4Dash -- hls

#EXTM3U
# Created with Bento4 mp4-dash.py, VERSION=1.8.0-622
#
#EXT-X-VERSION:6

# Media Playlists

# Audio
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio/mp4a",LANGUAGE="und",NAME="Unknown",AUTOSELECT=YES,DEFAULT=YES,URI="audio-und-mp4a.m3u8"

# Video

# I-Frame Playlists

mp4hls

#EXTM3U
# Created with Bento4 mp4-hls.py version 1.1.0r622

#EXT-X-VERSION:4

# Media Playlists
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=131166,BANDWIDTH=134300,CODECS="mp4a.40.2"
media-1/stream.m3u8
barbibulle commented 6 years ago

Sorry about the late reply here. I'll take a look at this shortly and comment.

wmucheru commented 6 years ago

@adamhewitt627 So for the above playlists, if you have over a 100 videos to package, would you have to update all the master.m3u8 files so that you could enable playback?

barbibulle commented 6 years ago

Hi William,

thanks for the analysis. Can you confirm that you're only having this problem with audio-only streams? It looks like mp4-dash.py isn't fully compatible with audio-only streams, which should be fixed.

On Thu, Apr 5, 2018 at 7:35 AM, Adam Hewitt notifications@github.com wrote:

With one caveat, I am able to create HLS w/DRM file with this command:

mp4dash media.m4s -o media_folder --force --no-split --use-segment-list --encryption-key ":" --encryption-cenc-scheme=cbcs ` --hls

The Problem

Regardless of DRM included - iOS & Safari don't seem to understand the master.m3u8. Edge can play it just fine. If I overwrite its output to match the mp4hls result, the stream will play. mp4Dash -- hls

EXTM3U# Created with Bento4 mp4-dash.py, VERSION=1.8.0-622##EXT-X-VERSION:6

Media Playlists

Audio#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio/mp4a",LANGUAGE="und",NAME="Unknown",AUTOSELECT=YES,DEFAULT=YES,URI="audio-und-mp4a.m3u8"

Video

I-Frame Playlists

mp4hls

EXTM3U# Created with Bento4 mp4-hls.py version 1.1.0r622

EXT-X-VERSION:4

Media Playlists#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=131166,BANDWIDTH=134300,CODECS="mp4a.40.2"

media-1/stream.m3u8

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/axiomatic-systems/Bento4/issues/259#issuecomment-378957978, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWJjfdZfHrUvPSfiiDRuWcUNeANHCAAks5tliuogaJpZM4SxwX7 .

wmucheru commented 6 years ago

This problem also occurs with video streams as well, which was our use case

wmucheru commented 6 years ago

Any luck on this?

barbibulle commented 6 years ago

Sorry for not looking at this thread sooner. If I understand correctly your issue, you're having trouble playing back the stream when --encryption-cenc-scheme=cbcs is specified. Is is possible that the player you're using doesn't support the CBCS encryption mode? This mode is fairly new (it used to only be supported by FairPlay), so it is very possible that your player (or browser if you're playing in a browser) doesn't support it. Note that when playing DRM-protected content in a browser, the actual decryption is done by DRM-specific modules, so even if the content works with one DRM in your browser (say, for example, FairPlay in Safari), it doesn't guarantee that it will work with another DRM.

Can you confirm that it works with you leave all options as-is except for --encryption-cenc-scheme=cbcs, and that this option is indeed the one that causes the video not to play?

On Wed, Jul 4, 2018 at 2:28 PM, William Mucheru notifications@github.com wrote:

Any luck on this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/axiomatic-systems/Bento4/issues/259#issuecomment-402561723, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWJjaqfTpwFFqC2oAZ5q_g-Jn_GM5y1ks5uDTOKgaJpZM4SxwX7 .

wmucheru commented 4 years ago

Changing the option in --encryption-cenc-scheme=cbcs to --encryption-cenc-scheme=cenc did enable playback finally, and also removing the --hls option. I had to re-encode the HLS streams separately with Fairplay which although means taking up more storage but fixes the issue.

I am sure someone else would have a better way of packaging a multi-DRM stream

barbibulle commented 4 years ago

Hi @wmucheru, by now, most players should support CBCS. If you can tell me which version of what player you're using, I can try and reproduce the issue and see if this is something that can be fixed. In general, supporting a single presentation that can be played with HLS and DASH, by using the --hls option of the mp4dash tool is well supported and used by many.

ashutoshsingh0223 commented 3 years ago

Having the same issue. HLS manifest doesn't have Key URL information. When generated with mp4dash --hls cbcs is not a problem but when using clearkey --hls doesn't add key url to manifest. Is it mandatory to use fairplay with --hls?

EDIT: My BAD Having the same issue. HLS manifest doesn't have Key URL information - This is fine