1

我有一个使用 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!

有人可以帮助我吗?我很绝望。

不管怎么说,还是要谢谢你

4

1 回答 1

0

您的密钥应该是一个字节数组;您的行new Uint8Array([0x279926496a7f5d25da69f2b3b2799a7f])错误地创建了一个单成员数组。相反,您应该将其写为new Uint8Array([0x27, 0x99, 0x26, 0x49, 0x6a, 0x7f, 0x5d, 0x25, 0xda, 0x69, 0xf2, 0xb3, 0xb2, 0x79, 0x9a, 0x7f]). 然后在JsonWebKey中使用之前仍需要将其编码为 base64 格式。

此外,您永远不会使用密钥生成许可证。如果您还没有,请参阅此示例页面的源代码,了解使用 ClearKey 设置视频的正确方法。将它的generateLicense()功能集成到您的代码中(您还需要它的toBase64()功能来将您的密钥转换为正确的格式)。事实上,我建议在编写您自己的版本之前让该代码在您自己的机器上按原样运行。请注意,它需要在安全上下文(例如 HTTPS)上运行,如果您想使用他们的视频文件,您需要它与应用程序位于同一来源(即您需要将其托管在你自己的服务器)。

编辑:另外,“DOMException:不支持任何请求的配置。” 表示您可能写错了config(或指定了您的环境不支持的功能)。不幸的是,我对此无能为力,因为这里的规范非常未定义,我自己也在为此苦苦挣扎。同样,我建议首先运行该最小工作示例。

于 2017-05-22T16:06:04.123 回答