Decrypting And Combining .ts Audio Files with .m3u8

后端 未结 3 1280
甜味超标
甜味超标 2020-12-24 03:44

I have a few thousand .ts AES-128 encrypted audio files with a .key and .m3u8 file.

The key file just contains a key comprised of 44 characters. The .m3ud files appe

3条回答
  •  旧时难觅i
    2020-12-24 04:23

    Recent versions of ffmpeg should be able to decrypt the AES-128 HLS streams. You don't need a webserver. If the m3u8 URIs/paths are wrong you can:

    • create a directory
    • copy the key to a key file, ie my.key, and place it in the dir. Note that keys can be rotated, if the playlist has multiple keys copy all of them to different files.
    • copy all .ts segments to the same dir
    • copy and edit the playlist.m3u8 and use just the filename(s) for the key(s) URI(s) and segments.
    • to obtain a single .ts file do:

      ffmpeg -i playlist.m3u8 -c copy output.ts
      
    • if you want just the audio stream without the .ts container you can extract it. Eg: assuming you have a single audio stream using the AAC codec run:

      ffmpeg -i playlist.m3u8 -map 0:a -c copy output.aac
      

    This will extract the AAC stream to a file without re-encoding. If you want a codec different than your source you will have to re-encode.

    If for some reason you have to use openssl to decrypt the segments keep in mind that if no IV is specified then the IV is equal to the segment's media sequence, ie. the first segment has IV=0, the second has IV=1 and so on. After decryption update the playlist to point the decrypted segments and remove the EXT-X-KEY line. If you go this route you don't even need ffmpeg to obtain a single .ts file as MPEG-TS is directly concatenable, ie. you can just use cat on the decrypted segments.

提交回复
热议问题