The YouTube Flash Video (FLV) secret

I’m sorry for the hyperbole in the title, but it really is something YouTube is very hush-hush about. In spite of that, direct access to the Flash Video file of YouTube movies gives you a very powerful tool. You have total control over: when, how and where you play the video.

A recap of the ActionScript 3.0 YouTube player series:

Before we get started, I would like to make clear that, strictly speaking you may be violating the YouTube terms of use. I suggest that you make sure that you have a linkback somewhere to the original YouTube page of any video you play this way. As long as it’s not intended for commercial use, I don’t think YouTube will mind. This also means that evrything in this post could break at any moment. YouTube has no obligation to keep things working the way they are. Use at your own risk and make sure you have a backup plan.

How does YouTube work:

  1. Lets take for instance the video at this url :
  2. In the URL above, you can see the YouTube video ID, visibly tlkd45W4TWU.
  3. If you load that page and analyze it, the definition of the embedded Flash player is particularly interesting. You can get to it using, for instance, Firebug
  4. The flashvars and more specifically the “t=” part are especially interesting (lets call it the T-parameter) <pre lang="html"></pre>

  5. If you take a look at the network traffic (again Firebug is brilliant for this) you will notice a new request:
  6. This URI uses both the video id and T-parameter and is the one that returns the actual FLV file.

So what we need to do, is obtain the video_id, use that to request the page, extract the T-parameter and, finally, request the FLV. Because of Flash’s security policies, we cannot execute this request to the YouTube page from within the Flash applet. The easiest solution is to deploy a small server side script. Again the work has already been done for you:

I’ve deployed this PHP script on my random YouTube player. And for the example above, this is the result.


This part was a pretty technical overview of how YouTube deals with its video id’s and how the Flash Video file is requested from the server. A simple script can be deployed to perform the task of extracting this FLV. With the FLV URI, we now have complete control over the YouTube stream. This will be shown in the next installments of the series.

Image source