YouTube is a social video-sharing website hosting millions of videos, with advanced features like subtitles and annotations, video commenting and more.
Video Formats[edit | edit source]
Videos are usually available in multiple formats, as specified by a numeric format id (fmt).
|Format Name:||Standard (360p)||Medium||High||HD (720p)||HD (1080p)||Mobile|
|Video||Codec||MPEG-4 AVC (H.264)||MPEG-4 Part 2|
|Aspect Ratio||4:3 or 16:9||4:3||16:9||16:9||16:9||11:9|
|Average Bitrate (kbit/s)||500||512||900-1200||2000||3500||58|
|Frame Rate (fps)||Unknown||50||25||23.96||11.24|
|Sampling Rate (Hz)||44100||22050|
|Average Bitrate (kbit/s)||Unknown||128||232||90||20|
Downloading a video[edit | edit source]
There are multiple methods used to gather the video's download URL. Most methods contain tokens which are tied to a specific IP address and expire after a short amount of time.
Method 1[edit | edit source]
- Get the VIDEO ID
- Navigate to http://www.youtube.com/watch?v= and your VIDEO ID.
- View the source code and extact the "t" value from inside SWF_ARGS
- Copy that t value (without quotes) and paste after http://www.youtube.com/get_video?video_id=VIDEO_ID&t=
Method 2[edit | edit source]
- Get the VIDEO ID
- Navigate to http://www.youtube.com/get_video_info?video_id and your VIDEO ID.
- Split the & key = value string up to find "fmt_url_map", then deocode the URL escaped characters.
- Split the string by commas, then find the format you like (the first two numbers in each of the results).
- Split by the | character and use the second returned string as the video URL.
Video Annotations[edit | edit source]
YouTube recently introduced annotations, allowing users to create 'links' and other pop-up text in the flash YouTube player. Unfortunatley, as they rely on the flash player you cannot see them when you download it.
But, in any case, the syntax for viewing the XML file where the flash player gets the info of what annotations to put where and when is stored at:
where obviously you must replace "<your_video_id>" with the actual video id.
Just a note of warning to those trying to do stuff with it, the server may return it in a gzip compressed format, so watch out if so.
I personally don't know much about the format of the files, so if anyone would like to contribute that, it would be appreciated.
Video Subtitles[edit | edit source]
YouTube finally released support for subtitles, and of course, they did it in a nice way for us to use... not really.
Firstly, we have to get the list of subtitles to determine what language the subtitles are in, and what they called them. So open up the url:
where you put in your video id. The ts value, i'm not quite sure how to get it or what it does - but you can safely leave it empty for now.
This URL should return an XML file with <transcript_list docid="some-number"> as the root element and all the languages YouTube supports. In this file, all subtitle tracks have a self-closing <track> tag with the attributes:
- id - the subtitle track id
- name - the name of the subtitle track
- lang_code - the language ISO 639-21 code of the track
- lang_original - the name of the language in that language (WARNING! many languages will contain non-ascii text)
- lang_translated - the name of the language in your language (NOTE: your language is set by the hl parameter in the url. Changing this will translate these to that language and change the default language returned)
- cantran - true/false - if the track can be translated by the automatic translation engine or not
Using these attributes of your selected track, you can get the subtitles in TimedText XML format by going now to the url:
where name and lang_code are url escaped versions of the attributes above.
To translate the subtitles to another language, add "&tlang=" and the ISO code of the language to be translated to.
More[edit | edit source]
See http://adamswiki.wik.is/YouTube for more... (this will eventually be copied over here)