天天看點

hls二次加密 m3u8_HLS 視訊加密小記

我是在ubuntu中,安裝好了 ffmpeg

加密用的 key(生成一個encrypt2.key檔案)

openssl rand 16 > encrypt2.key

另一個是 iv(生成一段字元串,記下來)

openssl rand -hex 16

建立一個檔案 encrypt2.keyinfo 内容格式如下:

Key URI # encrypt2.key的路徑,使用http形式

Path to key file # encrypt2.key檔案路徑

IV # 上面生成的iv

如:

http://localhost/test/encrypt2.key

./encrypt2.key

88c674428c1e719751565ad00fe24243

最後使用 ffmpeg 指令,将一個mp4檔案 轉換成 m3u8格式

ffmpeg -y -i test.mp4 -hls_time 60 -hls_key_info_file encrypt2.keyinfo -hls_segment_filename "file%d.ts" playlist.m3u8

以上參數說明:

-hls_time 每段檔案的時間長度(機關:秒)

-hls_segment_filename 每個小段的檔案名生成規則

最後會生成一個 playlist.m3u8 和 一個或多個的 file 開頭 ts結尾的 ts檔案。

使用 video标簽 播放 m3u8,如:

以上的内容都是抄 參考的第3篇的博文,執行的指令隻是為了友善自己,不用再次連結到其它Blog上再細看

Reference