This post is archived and may contain outdated information. It has been set to 'noindex' and should stop showing up in search results.
How YouTube Streams Video & Audio
Nov 20, 2014Web and InternetComments (15)
This is a technical post on how the YouTube player works, including the kinds of http requests it makes and how it streams video and audio. This information was researched with the modern HTML5 player. It will likely differ from the discontinued legacy Flash player that YouTube used to use.

Get YouTube Video Info

When the YouTube video player is started, either on a page or an embed, it first sends a request to with about 13 query string parameters. These parameters contain information such as the video ID, the player width/height, and what host is requesting the video.

get_video_info then returns a large JSON string with information about the video and each video/audio file associated with it. get_video_info may also return an error if it determines the requestor shouldn't have access in the given environment (restricted in a certain country, not embeddable, etc).

Some YouTube videos have content restrictions, depending on where the video is being accessed from. For example, a VEVO video will probably not work if you try to access the embed URL directly, but will work fine inside its iframe embed or on the YouTube website.

get_video_info can also be accessed directly to obtain information about YouTube video and audio, as well as download links to them (for any public and unrestricted video). Since the information is returned in a JSON string, it can be hard to read it. You can access this information in a friendly interface using this YouTube video info utility that I created.

Chunks Of Video

The YouTube player does not play one large video/audio file for users. It instead constantly sends requests for small chunks of video or audio as the player is playing. You can see this if you look at the network traffic while watching a video:

YouTube videoplayback requests

These requests are made to and have a long subdomain with many query string parameters. The query string parameters tell information about the file it should return to the YouTube player. This includes what type of file (video or audio and the format), what part of the file to return, when the request should expire, the ip address of the requestor, and other information.

In order for YouTube to constantly pull small chunks of the video or audio and be able to piece them together in the player, it uses the range parameter to tell the starting and ending bytes that should be returned for each chunk. Here is a sample http request showing just the range parameter:

The above is an example of the YouTube video player requesting the part of the file that is from 262778 bytes to 341069 bytes. The returned file will be the 78291 byte size chunk.

Security And Speed

The reason YouTube makes requests for small chunks may be to improve performance. It doesn't know when a user might simply close the window, and by only sending small chunks this could potentially save a lot of bandwidth. Also, if the user changes the video quality in the middle of the video, YouTube will only have to change the video stream (it keeps playing the exact same audio).

The more important reason I suspect is security when it comes to restricted content videos. By streaming videos in chunks, users can't simply open up the page source or developer tools and download the complete video directly from a URL. The YouTube player is piecing together each chunk of video and audio on the fly, so you would need a program that does the same thing in order to acquire a complete video with audio.

YouTube does make unrestricted and public videos available for download in a couple different pre-made sizes (usually 720p and 360p). You can use the same YouTube Video Info utility to get links to these downloads (under the "Stream Maps"). Keep in mind that videos with restrictions by YouTube will not work with this utility.

Audio Bitrate

To determine what audio bitrate YouTube is actually playing, you can download the audio file (or all of the chunks individually and add their size together), and compare the total file size of the audio against the length of the video. With a few calculations you can arrive at the kbps (or average kbps if it's VBR).

For example, one of my test videos is 21.1 seconds long. I downloaded the full audio stream by copying the YouTube http request and modifying it so that the range encompassed the entire audio. The audio file ended up being 341070 bytes. Dividing by the length (21.1 seconds) gives 16164.5 bytes per second, which equals 129315.6 bits per second or 126.3 kbps audio (k/bits per second).

In my test video, I had originally uploaded it with 320 kbps audio and a video resolutions of 3840x2160 (4k). So it was quite surprising to find that YouTube was streaming just 126 kbps audio. In their defense, their compression is very good. I can't tell the difference between their 126 kbps and the 192 kbps AAC version of the audio, even when creating a JavaScript audio player that seamlessly switches between the two streams on the fly.
Comments (15)
Add a Comment
Tony   Oct 16, 2019
Part 2. On its main site it seems to use exclusively some form of DASH segmented files similar to YouTube and no-one seems to know how to download them. They are easy to download from the mobile site but this is limited to 480p. Is there any chance of you extending your info tool to deal with I am only guessing, but it might not be too difficult. Thanks.
Tony   Oct 16, 2019
Hello Nick. Part 1. A few things about your info tool and VLC first. Sometimes the tool finds links to separate segmented video and audio files as well as a link to a one-piece multiplexed video/audio file, usually at 360p, but VLC can't play any of them. Trying to play them with VLC, the error boils down to 403 forbidden. But VLC can find a link to the same YouTube multiplexed video/audio file at 360p, which it can play. Any idea why? I also note that although VLC can't play YouTube segmented videos, it can assemble and play segmented videos controlled by a .m3u8 playlist, such as those on Dailymotion. The main thing I wanted to ask though is about This site has thousands of films, many at 720p or 1080p.
Burt   Dec 05, 2018
(Continued from Dec 04, 2018): rsion is actually on higher average bitrate. What do you know! You can see the math on my previous post if you're interested. %clen=the proportion; a chunk of certain bitrate, where 1=100% of the audio file in its entirety. With that percentage you can count how many seconds are played on which bitrate and from that you can get the amount of bytes played on each bitrate. Add 'em all up and devide with the file's duration in seconds and hey presto!
Burt   Dec 04, 2018
YouTube just changed all of a sudden the quality of my uploaded music videos from 1080p to 144p since somewhere from the middle of August 2018. So I conducted a little test deriving the data using your tool page thanks! File uploaded earlier in 2018: plays at 1080p, duration 693 s. clen tot.=7552475 bitrate 9718, clen 355748 -> %clen=0,0471-> 32,64 s -> 317222,00 B bitrate 21966, clen 956753 -> %clen=0,1268 -> 87,79 s -> 1928389,46 B bitrate 130183 (44100 Hz), clen 6239974 -> %clen=0,8262 -> 572,57 s -> 74538559,20 B tot.=76784170,67 B 110799,679 B/s=108,20 kBps * * * Same file loaded in December 2018: plays at 144p, 693 s. bitrate 130714 (44100 Hz) clen 6362118 Tot.=90584802 B 127,65 kBps So, it seems that the later 144p ve
webment   Nov 02, 2018
nice. your blog is very informative. Thanks a lot for sharing with us. I want to use it my website.
Dan Dube   Aug 29, 2016
Nick Vogt Still not working. I think it might be because you're using a newer HTTPS version (not sure what it's called, TPB uses it too, it's the one that doesn't work on XP)
Nick Vogt   Aug 29, 2016
I don't have a Blackberry to test it on unfortunately. I realized I was missing the viewport meta tag though, so added that in. Maybe it will work better for you now.
Dan Dube   Aug 28, 2016
Nick, first of all, thanks for your site. However, I want to use it on my BlackBerry smartphone, and it doesn't work for some weird reason. Would you be interested in fixing it? Thanks!
John Grant   Nov 30, 2015
Hi, possible to receive the PHP script ? thanks in advance
Shahid Khan   Aug 13, 2015
please share this scripts( thanks
Syed Alish Raza Naqvi   Aug 04, 2015
Dear Owner of h3xed please i need this script please share
Phng o   May 04, 2015
Thank you Nick Vogt . But i think can do it, you can check it at
Nick Vogt   May 04, 2015
The video owner must not allow that feature. It could be copyright protected.
Phng o   May 03, 2015
i tried with video id ncGcwqESXP8, the stream not work. Do you have a idea for it? Thanks
Niammuddin M Z   Feb 26, 2015
please share this script, i want to learn