paazmaya.fi

The Website of Juga Paazmaya | Stories about Web Development, Japanese Martial Arts, Hardware prototyping and travelling

Media Encryption with MP4Box

The MP4Box application provided in the Gpac software package support media file (such as *.mp4) encryption as stated in their manual:

MP4Box can be used to encrypt or decrypt media streams in a more or less format-agnostic manner, according to the ISMA E&A and OMA DRM 2.0 specifications. An XML language is used by MP4Box to get/set the encryption parameters.

Command line to add the encryption data to an existing mp4 file could be like the following:

MP4Box -isma -crypt kobudo-rei-uto_ismacrypt.xml kobudo-rei-uto_isma.mp4

The XML file referred as “kobudo-rei-uto_ismacrypt.xml” has the following content:

<?xml version="1.0" encoding="UTF-8" ?>
<ISMACryp>
    <ISMACrypTrack
        trackID="1"
        key="0x180031a348c14d401143be02fe7708f5"
        salt="0xd0763edaa9d9bd2a"
        scheme_URI="urn:gpac:isma:encryption_scheme"
        kms_URI="self"
        selectiveType="5" />
</ISMACryp>

The resulting media file is attached.

Output of the command:

MP4Box -info 1 kobudo-rei-uto_isma.mp4

is the following:

Track # 1 Info - TrackID 1 - TimeScale 30000 - Duration 00:00:04.500
Media Info: Language "Undetermined" - Type "vide:encv" - 135 samples
Handler name: GPAC ISO Video Handler
MPEG-4 Config
    Visual Stream - ObjectTypeIndication 0x21
    AVC/H264 Video - Visual Size 784 x 320 - Profile High @ Level 4.1
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 - Indicated track size 784 x 320
    Decoding Buffer size 10863 - Average bitrate 873 kbps - Max Bitrate 968 kbps
    No stream dependencies for decoding
    StreamPriority 0

*Encrypted stream - ISMA scheme iAEC (version 1)
scheme location: urn:gpac:isma:encryption_scheme
KMS location: key in file
Selective Encryption: Yes
Initialization Vector size: 32 bits

Computed info from media:
    Total size 503484 bytes - Total samples duration 4500 ms
    Average rate 983 kbps - Max Rate 969 kbps

Also the output of the help items of the MP4Box executable is attached for easier viewing.