Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube's HD Video Streaming Server Technology?

Lately I've been researching different methods for streaming MP4s to the browser. Flash Media Server is an obvious choice here (using Cloudfront), and most solutions I've seen use the RTMP protocol.

However, I spent some time on YouTube with Firebug and Chrome debugger figuring out how their streaming worked and I discovered some interesting differences between some of their videos and quality rates.

My two sample videos are A and B. A is available up to 480p and B is available up to 1080p. For both videos, all rates up to 480p are served in an FLV container with H.264 video and AAC audio, over HTTP. What's interesting here is that if you have not yet downloaded (cached) the entire video, and you try to skip forward to an uncached part of the video, a new request will be made with a 'begin' parameter equal to the target offset in milliseconds. Example from Video A at 480p:

http://v11.lscache8.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor%2Coc%3AU0dWTldQVF9FSkNNNl9PSlhJ&fexp=904806%2C902906%2C903711&algorithm=throttle-factor&itag=35&ipbits=0&burst=40&sver=3&expire=1279756800&key=yt1&signature=D2D704D63C242CF187CAA5B5D5BAFB8DFACAC5FF.39180C01559C976717B651A7EB1D0C6249231EB7&factor=1.25&id=8568eb3135971f6f&begin=111863

Response Headers:
Cache-Control:public,max-age=23472
Connection:close
Content-Length:14320637
Content-Type:video/x-flv
Date:Wed, 21 Jul 2010 17:23:48 GMT
Expires:Wed, 21 Jul 2010 23:55:00 GMT
Last-Modified:Wed, 19 May 2010 12:31:41 GMT
Server:gvs 1.0
X-Content-Type-Options:nosniff

The file returned by this URL is a fully valid FLV containing only the portion of the video after the requested offset.

I did the same kind of test on the higher resolution versions of Video B. At 720p and 1080p, YouTube will return a video in an MP4 container, also with H.264 video and AAC audio. What's impressive to me is that their server takes the same type of offset for an MP4 video (via the 'begin' parameter) and returns a valid, streamable MP4 (moov atom at the front of the file with correct offsets) that also only includes the requested portion of the video.

So, how does YouTube do this? How do they generate the FLV or MP4 container on the fly with the correct headers and only the desired segment of the requested video? I know this can be accomplished using FFMPEG to seek to the desired start point and the qt-faststart script to reposition the moov atom to the front of the stream, but it seems like this would be too slow to handle on-demand for millions of YouTube viewers.

Ideas?

Thanks in advance!

Footnote: I am not allowed to include more than 1 link at this point, so here is Video A's URL: http:// www.youtube .com/watch?v=hWjrMTWXH28 "Video available up to 480p"

like image 550
bgentry Avatar asked Jul 21 '10 18:07

bgentry


1 Answers

A simular question has been asked at this forum. http://www.flashforum.de/forum/video/flv-ab-beliebiger-position-streamen-248483.html

There are two solutions avaiable:

  1. Use a streaming server
  2. Use a file-wrapper written in a programming-language of your choice (example is written in php)

In both solutions you need to modify all your videos f.e. using flvmid to add the key-frame-informations to the flv-video.

In the second solution you php-script recives the request you've posted above and parses the flv-video until it reaches the position given by the parameter begin. After that it starts to push the video-content to the page-visitor. Read the thread to get more informations and a php-code-examples.

The original thread is written in german but you can use http://translate.google.com to get a bad english :)

The HTTP-Response you've posted contains the following line:

Server:gvs

Maybe gvs means something like "Google Video Server". I've searched for gvs but I could not find anything of value.

like image 128
SimonSimCity Avatar answered Oct 13 '22 06:10

SimonSimCity