[FFmpeg-user] How to decrypt .ts files into separate .ts files with ffmpeg without using a playlist?

Moritz Barsnick barsnick at gmx.net
Mon Feb 10 21:18:57 EET 2020

On Mon, Feb 10, 2020 at 13:40:59 +0000, Crazy Red Elephant via ffmpeg-user wrote:

> I have a number of .ts files, .m3u8 playlist and a key to decrypt
> them. The key is a file, not a hexadecimal string. My goal is to
> decrypt some of these .ts files to analyze them individually. I also
> obviously don't want to modify the actual video/audio streams in them
> in any way, just a decryption.

I had to google my way into this, but have a solution:

This AES encryption is on the outmost layer. In other words, no
demuxing has to be done before decrypting. You can just apply straight
AES decryption onto the input segments, without using ffmpeg.

You already figured out the key from the keyfile. As your m3u8 has no
"IV" section, I assumed your encryption uses no such initialization

I found that the openssl command line tool can do this decrption:

$ openssl aes-128-cbc -d -nosalt -K 5e5852fab5eedf7c6b7a367b1fc140a1 -iv 0 -in part0.ts -out part0.dec.ts

I did this for each segment (in a shell loop obviously), and got the
desired results. The decrypted segments now play exactly like your
encrypted playlist.

> So how to do this properly? The ffmpeg documentation wasn't helpful...

As far as I can tell, the HLS demuxer handles key files, but the
command line tool itself only takes actual decryption keys (and IVs),
not files. And I didn't manage to decrypt the individual segments with
ffmpeg, even with use of the key values on the command line.

> [Here](https://www.mediafire.com/file/twsn7mdew9aa8lx/test.zip/file)
> are the files I'm working with in a zip archive. I've included only
> three of the .ts files there, that should be enough for a test.

Appreciated. That was good for testing.

Hope this helps,

More information about the ffmpeg-user mailing list