加密
hls的加密采用aes-128-cbc, 关于aes-128-cbc, 请参考前文使用openssl命令加解密 aes-128-cbc的简单示例.
- 获取加密用16字节key, 并查看其值.
openssl rand 16 > enc.key
xxd enc.key
00000000: 598b a998 f204 f30c b900 4de6 7060 0b33 Y…M.p`.3
- 获取加密用iv并查看其值.
openssl rand -hex 16 >enc.iv.txt
xxd enc.iv.txt
00000000: 6139 6238 3031 3366 3830 3966 3334 6330 a9b8013f809f34c0
00000010: 3330 3839 3932 3066 6633 3461 6566 3765 3089920ff34aef7e
00000020: 0a .
cat enc.iv.txt
a9b8013f809f34c03089920ff34aef7e
- 生成hls_key_info_file. 其内容形式如下:
Key URI
Path to key file
IV (optional)
vim enc.keyinfo
https://me.test.com/get_dk
enc.key
a9b8013f809f34c03089920ff34aef7e
- 使用ffmpeg生成加密hls视频
ffmpeg -y
-i mp4_sample.mp4
-hls_key_info_file enc.keyinfo
-hls_playlist_type vod
-hls_segment_filename "fileSequence%d.ts"
prog_index.m3u8
解密
- 选择 fileSequence0.ts 来解密
ls -a fileSequence*
- 使用openssl 解密ts视频. 这里的iv, K都是加密时设定的.
openssl aes-128-cbc -d -in fileSequence0.ts -out fileSequence0_decrypto.ts -nosalt -iv a9b8013f809f34c03089920ff34aef7e -K 598ba998f204f30cb9004de670600b33
得到的fileSequence0_decrypto.ts
即是解密视频.
参考列表:
http://hlsbook.net/how-to-encrypt-hls-video-with-ffmpeg/
https://blog.csdn.net/nizhengjia888/article/details/78041945