我有一个使用 MP4Box 加密的纯音频 mp4 文件,使用命令MP4BOx -crypt drm.xml audio-only.mp4 -out audio-only-enc.mp4
这是 drm.xml:
<GPACDRM type="CENC AES-CTR">
<DRMInfo type="pssh" version="0">
<BS ID128="9A04F07998404286AB92E65BE0885F95"/>
<BS data="application/data;base64:ACE125"/>
<BS sourceFile="cenc_blob.bin"/>
</DRMInfo> <DRMInfo type="pssh" version="1" cypherOffset="9" cypherKey="0x6770616363656E6364726D746F6F6C31" cypherIV="0x00000000000000000000000000000001">
<BS ID128="6770616363656E6364726D746F6F6C31"/>
<BS value="2" bits="32"/>
<BS ID128="0x279926496a7f5d25da69f2b3b2799a7f"/>
<BS ID128="0x676cb88f302d10227992649885984045"/>
<BS bits="8" string="CID=Toto"/>
<BS ID128="0xccc0f2b3b279926496a7f5d25da692f6"/>
<BS ID128="0xccc0f2b3b279926496a7f5d25da692d6"/>
</DRMInfo>
<CrypTrack trackID="2" IsEncrypted="1" IV_size="16" first_IV="0x0a610676cb88f302d10ac8bc66e039ed" saiSavedBox="senc">
<key KID="0x279926496a7f5d25da69f2b3b2799a7f" value="0xccc0f2b3b279926496a7f5d25da692f6"/>
</CrypTrack>
</GPACDRM>
Well, now i would to decrypt that file with mpeg-dash.
In first, i've created .mpd and segmentated that mp4 file.
.Mpd file looks like following:
<?xml version="1.0"?>
<!-- MPD file Generated with GPAC version 0.6.2-DEV-rev1147-g47f9373-master at 2016-12-03T10:37:20.403Z-->
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500S" type="static" mediaPresentationDuration="PT0H4M30.118S" maxSegmentDuration="PT0H0M3.994S" profiles="urn:mpeg:dash:profile:full:2011" xmlns:cenc="urn:mpeg:cenc:2013">
<ProgramInformation moreInformationURL="http://gpac.io">
<Title>audio-enc.mpd generated by GPAC</Title>
</ProgramInformation>
<Period duration="PT0H4M30.118S">
<AdaptationSet segmentAlignment="true" lang="und">
<ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" cenc:default_KID="27992649-6a7f-5d25-da69-f2b3b2799a7f"/>
<Representation id="1" mimeType="audio/mp4" codecs="mp4a.40.2" audioSamplingRate="44100" startWithSAP="1" bandwidth="103460">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentList timescale="44100" duration="176400">
<Initialization sourceURL="segment_audioinit.mp4"/>
<SegmentURL media="segment_audio1.m4s"/>
<SegmentURL media="segment_audio2.m4s"/>
....
<SegmentURL media="segment_audio67.m4s"/>
<SegmentURL media="segment_audio68.m4s"/>
</SegmentList>
</Representation>
</AdaptationSet>
</Period>
</MPD>
现在,这是我页面的 html:
<!doctype html>
<html>
<head>
<title>Dash.js Rocks</title>
<style>
video {
width: 640px;
height: 360px;
}
</style>
</head>
<body>
<div>
<video id="videoPlayer" controls></video>
</div>
<script src="http://cdn.dashjs.org/latest/dash.all.min.js"></script>
<script src="js/main.js"></script>
<script>
(function(){
var url = "http://localhost:8080/prova-enc/audio-enc.mpd";
var player = dashjs.MediaPlayer().create();
player.initialize(document.querySelector("#videoPlayer"), url, true);
})();
</script>
</body>
</html>
这是“main.js”:
'use strict';
var KEY = new Uint8Array([
0x279926496a7f5d25da69f2b3b2799a7f
]);
var config = [{
initDataTypes: ['mp4'],
videoCapabilities: [{
contentType: 'video/mp4; codecs="mp4a.40.2"'
}]
}];
var video = document.querySelector('videoPlayer');
if(video) {
video.addEventListener('encrypted', handleEncrypted, false);
}
navigator.requestMediaKeySystemAccess('org.w3.clearkey', config).then(
function(keySystemAccess) {
return keySystemAccess.createMediaKeys();
}
).then(
function(createdMediaKeys) {
return video.setMediaKeys(createdMediaKeys);
}
).catch(
function(error) {
console.error('Failed to set up MediaKeys', error);
}
);
function handleEncrypted(event) {
console.log('encrypted event:', event);
var session = video.mediaKeys.createSession();
session.addEventListener('message', handleMessage, false);
session.generateRequest(event.initDataType, event.initData).catch(
function(error) {
console.error('Failed to generate a license request', error);
}
);
}
当我从 Chrome(版本 55.0.2883.75(64 位))转到我的服务器上的页面时,这是控制台的输出:
main.js:29 Failed to set up MediaKeys DOMException: None of the requested configurations were supported.
(anonymous) @ main.js:29
Debug.js:108 [23] EME detected on this user agent! (ProtectionModel_21Jan2015)
Debug.js:108 [29] Playback Initialized
Debug.js:108 [49] [dash.js 2.3.0] MediaPlayer has been initialized
XHRLoader.js:223 XHR finished loading: GET "http://localhost:8080/prova-enc/audio-enc.mpd".
c @ XHRLoader.js:223
d @ XHRLoader.js:256
d @ ManifestLoader.js:83
Q @ StreamController.js:663
Pb @ MediaPlayer.js:1928
Fb @ MediaPlayer.js:1772
Db @ MediaPlayer.js:1736
b @ MediaPlayer.js:169
(anonymous) @ dash1.html:23
(anonymous) @ dash1.html:24
Debug.js:108 [70] Parsing complete: ( xml2json: 10.3ms, objectiron: 4.63ms, total: 0.0150s)
Debug.js:108 [72] Manifest has been refreshed at Sat Dec 03 2016 16:16:33 GMT+0100 (CET)[1480778193.925]
Debug.js:108 [82] SegmentTimeline detected using calculated Live Edge Time
Debug.js:108 [89] MediaSource attached to element. Waiting on open...
Debug.js:108 [95] MediaSource is open!
Debug.js:108 [96] Duration successfully set to: 270.118
Debug.js:108 [98] Added 0 inline events
Debug.js:108 [98] No video data.
Debug.js:108 [99] audio codec: audio/mp4;codecs="mp4a.40.2"
Debug.js:108 [110] Schedule controller stopping for audio
Debug.js:108 [115] No text data.
Debug.js:108 [115] No fragmentedText data.
Debug.js:108 [116] No embeddedText data.
Debug.js:108 [116] No muxed data.
Debug.js:108 [117] Start Event Controller
Debug.js:108 [120] Schedule controller starting for audio
Debug.js:108 [122] Native video element event: play
XHRLoader.js:223 XHR finished loading: GET "http://localhost:8080/prova-enc/segment_audioinit.mp4".
c @ XHRLoader.js:223
d @ XHRLoader.js:256
d @ FragmentLoader.js:96
n @ FragmentModel.js:159
l @ FragmentModel.js:150
o @ ScheduleController.js:260
d @ ScheduleController.js:168
y @ ScheduleController.js:303
(anonymous) @ EventBus.js:87
c @ EventBus.js:87
R @ Stream.js:457
Q @ Stream.js:437
d @ Stream.js:124
b @ StreamController.js:427
Debug.js:108 [128] Init fragment finished loading saving to audio's init cache
Debug.js:108 [136] DRM: onNeedKey
Debug.js:108 [136] DRM: initData: /psshy@B«æ[à_
[148] DRM: KeySystem Access Denied! -- Key system access denied!
有人可以帮助我吗?我很绝望。
不管怎么说,还是要谢谢你