我有一个使用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(版本E 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!
有人可以帮助我吗?我绝望。
谢谢
您的密钥应该是字节的数组;您的行new Uint8Array([0x279926496a7f5d25da69f2b3b2799a7f])
错误地创建了一个单成员数组。相反,您应该将其写为new Uint8Array([0x27, 0x99, 0x26, 0x49, 0x6a, 0x7f, 0x5d, 0x25, 0xda, 0x69, 0xf2, 0xb3, 0xb2, 0x79, 0x9a, 0x7f])
。然后,它仍然需要编码为base64格式,然后在JSONWEBKEY中使用。
另外,您永远不会与密钥生成许可证。如果尚未,请参阅此示例页面的源,以获取与ClearKey设置视频的正确方法。将其generateLicense()
功能集成到您的代码中(您还需要其toBase64()
功能将密钥转换为正确的格式)。实际上,我建议在编写自己的版本之前将该代码在自己的机器上使用。请注意,它需要在安全上下文(例如https)上运行,如果您想使用他们的视频文件,则需要它与应用程序相同(即。您自己的服务器)。
编辑:另外," domexception:均不支持所请求的配置。"表示您可能错误地编写了config
(或环境不支持的指定功能)。不幸的是,我无能为力,因为这里的规范在这里不确定,我本人正在努力。同样,我建议让最低的工作示例首先运行。