Yes, you can do it with ffmpeg . You need to write the key from the database to a file, say video.key .
You need a second file, name it key_info , which is the key information file. It has the following format:
key URI key file path IV (optional)
For instance:
http:
You tell ffmpeg use it to encrypt your segments with the hls_key_info argument:
ffmpeg -i input.mp4 -c copy -bsf:v h264_mp4toannexb -hls_time 10 -hls_key_info_file key_info playlist.m3u8
This will encrypt your segments with AES-128 in CBC mode and add the appropriate tags to your playlist:
#EXT-X-KEY:METHOD=AES-128,URI="http://example.com/video.key"
You can also manually encrypt segments if you want using openssl . Here is an example script where each IV is equal to the segment index:
source share