Search code examples
ffmpeghttp-live-streamingm3u8

How to decrypt segmented parts .ts files which are encrypted with ffmpeg?


I use ffmpeg to generate encrypted m3u8 playlists, both generation and playing work perfectly.

The statement I use to generate m3u8:

ffmpg -i "source.mp4"  -c:v h264_nvenc 
 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 10 -hls_playlist_type vod
 -hls_key_info_file "d:\enc.keyinfo" -hls_segment_filename "output_$03d.ts" "output.m3u8";

Content of d:\enc.keyinfo:

/enc.key
d:\enc.key
261daad184c6acf4a3a21393ds232e1a

Now I need to decrypt one or more generated .ts segments (not the whole m3u8 playlist), what should I do?


Solution

  • If you just want to do it manually you can just use openssl

    openssl aes-128-cbc -d -in encrypted.ts -out decrypted.ts -nosalt -K 261daad184c6acf4a3a21393ds232e1a -iv <iv>
    

    To do so you also need to get the IV from your output.m3u8 playlist file. It is a property on the #EXT-X-KEY tag in there. If it is not explicitly specified on that tag, then it is implicitly 0 for the first segment, 1 for the second, and so on.