Menu

MP4Box encyption of HEVC encoded video

Help
2015-04-27
2015-06-30
  • Urs-Viktor Marti

    Hi,

    My goal is to encrypt a video encoded in HEVC (using x265) by using MP4Box. For this I have use the following installation:
    OS: Windows 7

    The MP4Box version output looks like:

    MP4Box - GPAC version 0.5.2-DEV-rev322-gf6fed6c-master
    GPAC Copyright (c) Telecom ParisTech 2000-2012
    GPAC Configuration: (static configuration file)
    Features: GPAC_64_BITS GPAC_HAS_SSL GPAC_HAS_SPIDERMONKEY GPAC_HAS_JPEG GPAC_HAS_PNG
    

    As Sample drm-file.xml I use (according to http://gpac.wp.mines-telecom.fr/mp4box/encryption/common-encryption/):

    <?xml version="1.0" encoding="UTF-8"?>
    <GPACDRM type="CENC AES-CTR">
    <!-- example for playReady - data contains the cyphered key & co -->
    <DRMInfo type="pssh" version="0">
    <BS ID128="9A04F07998404286AB92E65BE0885F95"/>
    <BS data="application/data;base64:ACE125"/>
    <BS sourceFile="cenc_blob.bin"/>
    </DRMInfo>
    <!-- example for GPAC - keys are listed after the content and UL follows -->
    <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="1" IsEncrypted="1" IV_size="16" first_IV="0x0a610676cb88f302d10ac8bc66e039ed" saiSavedBox="senc">
    <key KID="0x279926496a7f5d25da69f2b3b2799a7f" value="0xccc0f2b3b279926496a7f5d25da692f6"/>
    </CrypTrack>
    </GPACDRM>
    

    The video is encoded with the following command line:

    >x265-64bit-latest.exe --threads 3 --input sample.yuv --input-depth 8 --input-res 1280x720 --input-csp i420 --fps 25 --bitrate 4700 --output sample-hevc.265
    

    And then I use to package the encoded video by using MP4Box with the command:

    >mp4box -add sample-hevc.265 -new sample-hevc.mp4
    

    Now I encrypt and decrypt the video file with the following command lines:

    >MP4Box -crypt drm_file.xml sample-hevc.mp4 -out sample-hevc-enc.mp4
    >MP4Box -decrypt drm_file.xml sample-hevc-enc.mp4 -out sample-hevc-dec.mp4
    

    Now, when I play the decrypted video by using VLC sample-hevc-dec.mp4 (2.1.5 Rincewind) or mp4client sample-hevc-dec.mp4 (version 0.5.2-DEV-rev322-gf6fed6c-master), the video looks "incomplete" - it seem that only the delta between frames is shown, but not the initial frame.

    Do you know what I did wrong? How can I play the complete video and be sure that the video is correctly encrypted and also decrypted?

     
  • Viet-Thanh-Trung NGUYEN

    Hello,
    Does your original file sample-hevc.mp4 play well with VLC or MP4Client ? If yes, could you please upload it somewhere and we will check it