5

Following this post, I usually download transport stream (.ts) files by using the browser's developer console to find the URLs of the .ts files and then I use wget to download them. After that I use the ffmpeg -f concat method to combine them into an mp4 file.

Recently I come across a site that streams videos and I used the same method to download all the .ts files. The site is here. After I downloaded all the individual .ts files, I use ffmprobe to check the file format but realized the .ts files cannot be understood by ffmpeg/ffmprobe. While the site uses http (not https) I thought the streams are not encrypted so I tried to open the .ts file in an hex editor but I don't know what format it is (but they don't look like zip/gz). My question is: are the transport steams encrypted? If yes, is there a way to decrypt them? If not? Can anyone point me to the right direction such that I can make ffmpeg understand them?

An example transport stream (first & second) are here and here but the link might expire in a bit. In that case you will need to open the site in developer console to find the updated link to the .ts files.

The site uses JW Player 8.0.0

albertma789
  • 353
  • 2
  • 3
  • 11
  • 1
    Stackoverflow is for *programming questions*. Questions about general computing hardware and software are off-topic for Stack Overflow unless they directly involve tools used primarily for programming. You may be able to get help on [Super User](https://superuser.com/tour). – President James K. Polk Dec 24 '17 at 05:07

1 Answers1

2

Your ts sample link cannot be successfully accessed, but I suspect that the ts has been encrypted using DRM, normally it's a AES 128 encryption. In this case, you will need the key to decrypt the stream, then you can concat or do whatever post production you need.

You can follow info from the following pages: https://developer.bitmovin.com/hc/en-us/articles/115001084734-What-is-HLS-AES-Encryption-,

HLS with AES 128 encryption on Android (Ice Cream Sandwich)

https://www.wowza.com/docs/how-to-secure-apple-hls-streaming-using-drm-encryption

etc.

JasonYang
  • 686
  • 7
  • 14
  • In such sense does it mean I cannot decrypt the stream? I am the receiver of the stream and my browser can play the stream so I am sure the key is also somehow passed along. I just don't know how to locate it. – albertma789 Dec 26 '17 at 03:44
  • You can try locate the m3u8 file, which keeps all the ts addresses, the key is normally distributed there. No DRM is perfect, it’s just a matter of how difficult to decrypt the stream. – JasonYang Dec 26 '17 at 03:47
  • Great! Indeed I found in the m3u8 file a link for a key like this `#EXT-X-KEY:METHOD=AES-128,URI="https://path.to.keyfile.key"`. I downloaded and it is a 16 byte file so it matches the AES-128. Now then I use the following to try to decrypt it `openssl enc -d -aes128 -in input.ts -out output.ts -K $(hexdump -v -e '/1 "%02X"' < keyfile.key)` but the system complained of `iv undefined` . Is there a way to find the iv or create one? – albertma789 Dec 26 '17 at 08:30
  • 1
    The iv for each segment should be noted in the m3u8 file. If not exist, you can try use 0 to set initial vector. After all, like you said, everything you need is in the page already. – JasonYang Dec 26 '17 at 09:23
  • 4
    Just a quick update. I managed to decode the stream after using 0 as the iv. That is `openssl enc -d -aes128 -in input.ts -out output.ts -K $(hexdump -v -e '/1 "%02X"' < keyfile.key) -iv 0` – albertma789 Feb 07 '18 at 05:05
  • I am also trying to download a protected/encrypted video stream. Please tell me the steps to do that, like softwares/libraries which I need and commands and other steps. Please help. Seperate answer would be really helpful. – IamVISH May 11 '20 at 19:51
  • 1
    @IamVISH I hope this is not too late. There are several ways to do it but the simplest way is to make use of ffmpeg. Turn on the debugger mode of your browser, go to the "network" tab. Go to the page where the video loads, or if you are already at the page, reload the page. Then search for a file with the extension .m3u8 from the debugger network tab. Once you locate the full path of the .m3u8 file, open a terminal and type `ffmpeg -i "path/to/m3u8" output.mp4` ffmpeg will automatically decrypt the segments for you and concatenate them if the key is also specified in the m3u8 file. – albertma789 Nov 02 '20 at 06:17
  • @albertma789 - Am getting "Server returned 401 Unauthorized (authorization failed)"... how do we pass authentication information in ffmpeg command? – Pavithran Ravichandiran Jan 19 '21 at 16:49
  • @jinxer-albatross you can use the `-headers` and `-user-agent` tags. Details here: https://stackoverflow.com/questions/33718810/ffmpeg-how-to-pass-http-headers I believe you can even add cookies using the `-headers` option – albertma789 Jan 21 '21 at 03:05