M

What I've learned about streaming video.

Last night we were watching some streaming video content, and I was just interested in how this content is stored on the servers. Here's some information that I found out; perhaps it will be of interest.

Some streaming video is stored in transport stream, or TS, format. These TS files usually contain a very short piece of video, something on the order of 10-12 seconds, so to start playing the video you want, your browser just needs to download a small file, instead of grabbing the entire video file. This also helps when you want to start playing a video in the middle somewhere; instead of downloading the entire file, your browser just downloads the appropriate TS file that covers your starting point.

These TS files are stored in a playlist format known as M3U8 (which might sound familiar, if you have encountered M3U playlist files before). These M3U8 files are the format used for common video streaming protocols, and are UTF-8 text files that are pretty much just lists of URLs for the TS files.

The makers of these videos are of course not going to leave these TS files unencrypted. They are usually encoded in OpenSSL format, using a key that is of course also stored with the video files. The URL for the key is usually found in the M3U8 file, which makes it very convenient for the decoding software in your browser.

Now if you are familiar with the Chrome or Firefox browsers you might also know about the developer tools window, which allows you to look at various statistics and pieces of information about the pages you're loading. In particular, you are able to get an overview of the files that your browser is loading up when it opens up a page. There are often dozens of files downloaded; anything from small images to background scripts may be loaded to make your page work.

So if one were interested in the M3U8 files in a specific video, you could open up the developer tools, look for any files with "m3u8" in the filename, and download those to your computer. This fil could then simply be passed to a downloading utility such as wget which would download all the TS files.

Once you have the pieces it's on to downloading the crypt key, which may be in the M3U8 file (look for a header line starting with "#EXT-X-KEY"). This key can then be used to decrypt each TS file using the openssl command.

Once you've decrypted, though, you still have just a bunch of 12-second video files, not a complete video. This is where ffmpeg comes in. The tool can be used to concatenate files to create a gapless video file from all of the individual pieces, and this whole file is the entire video, playable at your leisure.

Or at least, that's the theory.

This article is my 73rd oldest. It is 479 words long