4

I am developing application which is recording video using MediaCodec and converting it into Mp4(h.264+aac) using MediaMuxer. I want to keep that mp4 encrypted but i am not able to find anyway to encrypt video while recording .So currently I have to encrypt video once video is created. Since MediaCrypto is used while decoding is there any other way ?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
ʌɐɥqıɐʌ
  • 137
  • 16

1 Answers1

0

I just did a lot of research trying to find a solution to this question.

Short answer is that the API does not support encryption according to standard (CENC) and also it is not possible to use the MediaMuxer to achieve such video encryption.

The reason is that CENC encryption (or others that are supported by MediaCrypto for decryption) require certain boxes to be written at the beginning of the MPEG-file, in particular the 'schm' and 'saiz' boxes which lie in a deeper level in the 'stbl' box. (See this figure for an overview of the structure of these boxes.) When starting a track with the MediaMuxer all the track header ('tkhd') boxes are fully written and finalized though and it is not possible to squeeze content into them. (you can kind of see this happening here)

An option that should work is to use ffmpeg, which should work if you use C/C++.

Johuber
  • 1
  • 2