使用ffmpeg创建aes加密的hls视频码流

1. 生成秘钥
命令行下执行
>openssl rand -out file.key 16

2. 编辑aes key信息文件file.keyinfo,文件内容如下
http://www.flashavconverter.com/downloads/file.key
file.key

第一行是用来嵌入到生成的m3u8文件的key的下载地址,步骤1生成的file.key需要上传到webserver,可以通过http://xxx.xxx.xxx/file.key下载
第二行指向步骤1生成的本地文件file.key。
3. 使用下面ffmpeg命令生成aes加密的hls码流
ffmpeg -i 1.flv -hls_time 100 -hls_key_info_file file.keyinfo -hls_list_size 100 aes.m3u8

上面1.flv是输入的要加密的视频文件名 hls_time 100表示生成的视频片段是100秒间隔的,hls_key_info_file指向步骤2创建的key信息文件,hls_list_size指定最大的hls片段数,可以设置比较大的数目,否则生成的m3u8里面会缺少文件,默认值好像只有3吧。

4. 上传生成好的文件到你的webserver下面,设置允许外部读取的权限
5. 创建用于播放的html页面

  1. <link media="all" rel="stylesheet" href="https://unpkg.com/video.js@7.1.0/dist/video-js.css">
  2. <script src="https://unpkg.com/video.js@7.1.0/dist/video.js"></script>
  3.  
  4. <video-js id="player">
  5. <source src="http://www.flashavconverter.com/downloads/aes.m3u8" type="application/x-mpegURL" />
  6. </video-js>
  7. <script>
  8. videojs("player");
  9. </script>

这里使用video.js来播放,video source要指定为你的webserver的m3u8的地址,比如http://www.flashavconverter.com/downloads/aes.m3u8
6. 上传生成号的html到webserver,用firefox或者chrome打开http://www.flashavconverter.com/downloads/aes.html即可播放

附件大小
aes.zip15.46 KB