9

I'm trying to decrypt a .m3u8 playlist, I followed these steps :

  • 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.

and using this command to decrypt the playlist

ffmpeg -i playlist.m3u8 -c copy output.ts

but I got this error : Invalid data found when processing input

here is my m3u8 :

#EXTM3U
#EXT-X-TARGETDURATION:12
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-KEY:METHOD=AES-128,URI="my.key"
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:6.000,
s-1-v1-a1.ts
#EXTINF:6.000,
s-2-v1-a1.ts
#EXTINF:6.000,
s-3-v1-a1.ts
#EXTINF:12.000,
s-4-v1-a1.ts
#EXTINF:12.000,
s-5-v1-a1.ts
#EXTINF:6.000,
s-6-v1-a1.ts
#EXT-X-ENDLIST
  • whats wrong with my command ?
  • how to not convert playlist to one .TS file? I want to decrypt files separtly
0

1 Answer 1

10

Try specifying the full local path in your manifest so make the KEY like:

#EXT-X-KEY:METHOD=AES-128,URI="file://path/to/local/my.key"

and the TS chunks all like:

file://path/to/local/s-6-v1-a1.ts

If that doesn't work then ffmpeg could need the input for a m3u8 to be served over HTTP. So put your m3u8 file and the key and all your chunks on some web dir and rerun your ffmpeg command using the URL for the m3u8 so it'd be like:

ffmpeg -i http://mytestwebserver.com/playlist.m3u8 -c copy output.ts

If you don't have access to a webserver you can install some local and free like MAMP. I have had no issues using the above command to copy a HLS stream locally when the input is a HLS URL.

2
  • 1
    This method worked for me. I end up downloading and substituting all the ts-chunks and the encryption key with their local paths using the following script gist.github.com/grwlf/e1876f5d78cb6e66791809771d7bf36b Note it is very playlist-dependant.
    – Grwlf
    Commented Oct 25, 2019 at 20:54
  • 1
    Does the key file have some specific format for data inside it? I got the decryption key but not from URI provided in M3U8 file, now I don't know how to use that key! Already tried to save a sample.key file and put the key inside it, didn't work. Commented Dec 12, 2021 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.