Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

decrypt AES-128 encrypted .m3u8 playlist and .TS files with ffmpeg

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
like image 523
Mohammad Olfatmiri Avatar asked Dec 16 '17 09:12

Mohammad Olfatmiri


1 Answers

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.

like image 58
John Avatar answered Oct 13 '22 06:10

John