title: Creating playable DASH video encrypted with Clear Key encryption
body: <p>I am attempting to transcode and DASH (with Clear Key encryption) a <a href="http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov" rel="noreferrer">sample H.264</a> file for the <a href="https://github.com/google/shaka-player" rel="noreferrer">Google Shaka player</a>. Every set of steps I've been able to piece together online results in a playable version if unencrypted, then breaks down when I attempt to layer in encryption.</p>
  
  <h3>Unencrypted</h3>
  
  <p>Here are the steps I follow for the working unencrypted version:</p>
  
  <ol>
  <li><p>Separate video from audio</p>
  
  <pre><code>ffmpeg -i input.mp4 -an -c copy video_only.mp4
  ffmpeg -i input.mp4 -map 0:2 -c copy audio_only.m4a
  </code></pre></li>
  <li><p>Transcode the video into a working variant (only 1 for now)</p>
  
  <pre><code>ffmpeg -i video_only.mp4 -an -vcodec libx264 -s 1280x720 -c:v libx264 -b:v 384k -bf 2 -g 90 -sc_threshold 0 -an -strict experimental video_only_384kbps.mp4
  </code></pre></li>
  </ol>
  
  <p>3a. Create the mpd</p>
  
  <pre><code>    MP4Box -dash 5000 -segment-name 'outputseg-%s' -url-template -bs-switching no \
          -out output.mpd -rap \
          audio_only.m4a \
          video_only_384kbps.mp4
  </code></pre>
  
  <p>4a. Load the video into Osmo4 or Google Shaka
  It plays.</p>
  
  <h3>With Encryption</h3>
  
  <p>Now, I attempt to layer in encryption. Starting from after step 2 above:</p>
  
  <p>3b. Encrypt the variants with Clear Key</p>
  
  <pre><code>    MP4Box -crypt drm.xml audio_only.m4a -out audio_only_encrypted.m4a
      MP4Box -crypt drm.xml video_only_384kbps.mp4 -out video_only_384kbps_encrypted.mp4
  </code></pre>
  
  <p>where drm.xml contains a sample derived straight from the <a href="https://gpac.wp.mines-telecom.fr/mp4box/encryption/common-encryption/" rel="noreferrer">MP4Box/GPAC site</a>:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;GPACDRM type="CENC AES-CTR"&gt;
        &lt;!-- example for GPAC - keys are listed after the content and UL follows --&gt;
        &lt;DRMInfo cypherIV="0x00000000000000000000000000000001" cypherKey="0x6770616363656E6364726D746F6F6C31" cypherOffset="9" type="pssh" version="1"&gt;
          &lt;BS ID128="6770616363656E6364726D746F6F6C31"/&gt;
          &lt;BS bits="32" value="2"/&gt;
          &lt;BS ID128="0x279926496a7f5d25da69f2b3b2799a7f"/&gt;
          &lt;BS ID128="0x676cb88f302d10227992649885984045"/&gt;
          &lt;BS bits="8" string="CID=Toto"/&gt;
          &lt;BS ID128="0xccc0f2b3b279926496a7f5d25da692f6"/&gt;
          &lt;BS ID128="0xccc0f2b3b279926496a7f5d25da692d6"/&gt;
        &lt;/DRMInfo&gt;
        &lt;CrypTrack IV_size="16" IsEncrypted="1" first_IV="0x0a610676cb88f302d10ac8bc66e039ed" saiSavedBox="senc" trackID="1"&gt;
          &lt;key KID="0x279926496a7f5d25da69f2b3b2799a7f" value="0xccc0f2b3b279926496a7f5d25da692f6"/&gt;
        &lt;/CrypTrack&gt;
      &lt;/GPACDRM&gt;
  </code></pre>
  
  <p>4b. Create the mpd</p>
  
  <pre><code>MP4Box -dash 5000 -segment-name 'outputseg-%s' -url-template -bs-switching no \
      -out output.mpd -rap \
      audio_only_encrypted.m4a \
      video_only_384kbps_encrypted.mp4
  </code></pre>
  
  <p>5b. Load the video into Osmo4 or Google Shaka.
  * On Osmo4, no errors are found but the player just hangs until I kill it
  * On Google Shaka, I consistently receive a player error: 
  "CustomEvent {detail: Error: No DrmInfo exists!
      at shaka.media.EmeManager.buildKeySystemQueries_ (<a href="http://localhost:808" rel="noreferrer">http://localhost:808</a>…, srcElement: null, target: s…a.p…r.Player, currentTarget: s…a.p…r.Player} </p>
  
  <p>The output.mpd after 5b looks like this:</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
      &lt;!-- MPD file Generated with GPAC version 0.5.2-DEV-rev566-g4c06d0f-master  at 2015-09-03T19:17:57.544Z--&gt;
      &lt;MPD xmlns="urn:mpeg:dash:schema:mpd:2011" minBufferTime="PT1.500S" type="static" mediaPresentationDuration="PT0H0M54.424S" maxSegmentDuration="PT0H0M4.992S" profiles="urn:mpeg:dash:profile:full:2011" xmlns:cenc="urn:mpeg:cenc:2013"&gt;
       &lt;ProgramInformation moreInformationURL="http://gpac.sourceforge.net"&gt;
        &lt;Title&gt;output.mpd generated by GPAC&lt;/Title&gt;
       &lt;/ProgramInformation&gt;
  
       &lt;Period duration="PT0H0M54.424S"&gt;
        &lt;AdaptationSet segmentAlignment="true" lang="eng"&gt;
         &lt;Representation id="1" mimeType="audio/mp4" codecs="mp4a.40.2" audioSamplingRate="48000" startWithSAP="1" bandwidth="140631"&gt;
          &lt;AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/&gt;
          &lt;ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" cenc:default_KID="27992649-6a7f-5d25-da69-f2b3b2799a7f"/&gt;
          &lt;SegmentTemplate timescale="48000" media="outputseg-audio_only_encrypted$Number$.m4s" startNumber="1" duration="239616" initialization="outputseg-audio_only_encryptedinit.mp4"/&gt;
         &lt;/Representation&gt;
        &lt;/AdaptationSet&gt;
        &lt;AdaptationSet segmentAlignment="true" maxWidth="1280" maxHeight="720" maxFrameRate="24" par="16:9" lang="eng"&gt;
         &lt;Representation id="2" mimeType="video/mp4" codecs="avc1.64001f" width="1280" height="720" frameRate="24" sar="1:1" startWithSAP="1" bandwidth="375052"&gt;
          &lt;ContentProtection schemeIdUri="urn:mpeg:dash:mp4protection:2011" value="cenc" cenc:default_KID="27992649-6a7f-5d25-da69-f2b3b2799a7f"/&gt;
          &lt;SegmentTemplate timescale="12288" media="outputseg-video_only_384kbps_encrypted$Number$.m4s" startNumber="1" duration="46080" initialization="outputseg-video_only_384kbps_encryptedinit.mp4"/&gt;
         &lt;/Representation&gt;
        &lt;/AdaptationSet&gt;
       &lt;/Period&gt;
      &lt;/MPD&gt;
  </code></pre>
  
  <p>Software versions:</p>
  
  <ul>
  <li>MP4Box: GPAC version 0.5.2-DEV-rev566-g4c06d0f-master</li>
  <li>FFMPEG: ffmpeg version 2.6.3 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)</li>
  </ul>
  
  <p>Does anyone have any suggestions on how to proceed?</p>