多媒体科技音视频开发集锦

FFmpeg CENC加密mp4文件

2019-05-06  本文已影响15人  smallest_one

目录

  1. 参考
  2. 概述
  3. CENC加密的mp4文件
  4. libav CENC加密、解密mp4文件

1. 参考

2. 概述

FFmpeg提供了cenc的方式来加密保护mp4文件。

ffmpeg -h muxer=mp4能看到mp4封装器提供的选项,加密相关的选项如下所示。

  -encryption_scheme <string>     E....... Configures the encryption scheme, allowed values are none, cenc-aes-ctr
  -encryption_key    <binary>     E....... The media encryption key (hex)
  -encryption_kid    <binary>     E....... The media encryption key identifier (hex)

ffmpeg命令行工具对已有mp4进行CENC加密示例:

ffmpeg -i julin_5s.mp4 -c:v copy -c:a copy -encryption_scheme cenc-aes-ctr -encryption_key 76a6c65c5ea762046bd749a2e632ccbb -encryption_kid a7e61c373e219033c21091fa607bf3b8 julin_5s_cenc.mp4

ffplay播放CENC加密的mp4文件的示例:

ffplay julin_5s_cenc.mp4 -decryption_key 76a6c65c5ea762046bd749a2e632ccbb

3. mp4的CENC加密文件

image.png

查看CENC加密后的mp4文件,相比原有文件在stbl下增加了3个box:

  1. senc:sample specific encryption data,特定加密数据样本。
  2. saio:sample auxiliary information offsets,样本辅助信息偏移量。
  3. saiz:sample auxiliary information sizes,样本辅助信息大小。

4. libav CENC加密、解密mp4文件

加密

AVDictionary *opts = NULL;
av_dict_set(&format_opts, "encryption_scheme", "cenc-aes-ctr", 0);

av_dict_set(&format_opts, "encryption_key", "76a6c65c5ea762046bd749a2e632ccbb", 0);
av_dict_set(&format_opts, "encryption_kid", "a7e61c373e219033c21091fa607bf3b8", 0);
ret = avformat_write_header(ofmt_ctx, &format_opts);

解密

av_dict_set(&format_opts, "decryption_key", "76a6c65c5ea762046bd749a2e632ccbb", 0);

ret = avformat_open_input(&ifmt_ctx, is->filename, is->iformat, &format_opts);
上一篇 下一篇

猜你喜欢

热点阅读