Friday, January 18, 2013

YouTube adds supports for HLS for iPhones

I recently stumbled upon some Youtube changes while browsing the new Youtube app on IOS 6.0.1, iPhone 4 device. It seems like Youtube is starting to support HTTP Live Streaming for some of its videos. Not all videos seems to available in this format. So far it seems like longer videos > 10min are getting delivered using HLS. For those not familiar with HLS, here is the link.
I guess even for Android this should available, I haven't done any testing on that though.

I am using a transparent proxy setup to capture all traffic from iphone over wifi. Basically, setup a linux box as a router in between your wifi router and the internet, The iphone can then connect to the wifi and you can capture all traffic on the linux box. I have a proxy server setup on the linux box with an iptables rules to redirect traffic to the proxy.


iptables -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-port 8080 -t nat

You can also setup a wifi proxy on the iPhone itself.


Here are the relevant access log entry from the proxy server:

GET /api/manifest/hls_variant/source/youtube/id/f05679e8c2cdb67b/playlist_type/DVR/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/source,id,playlist_type,ip,ipbits,expire/signature/DAB9EC312CEE95417A5461FBCD623092E4849B6E.2197D3CCB5EFE63BEB3A0C65F399380ED0DE12D5/key/yta1/file/index.m3u8?dnc=1&ibw=701401 HTTP/1.1" 200 3667 "AppleCoreMedia/1.0.0.10A523 (iPhone; U; CPU OS 6_0_1 like Mac OS X; en_us)" "www.youtube.com" "application/vnd.apple.mpegurl"
GET /api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/94/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/46413816/lmt/1351106299100627/playlist_type/DVR/dnc/1/upn/91U2G9_nEVg/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/7F867A0CAA588BB5DBDB1E285230523F20930E66.6335FFF172E4233FBA59A5A7805DE1C7274E9779/key/dg_yt0/file/index.m3u8  

The first url is for the master/main playlist file which have a set of playlists for different quality. Here is the master playlist file:


#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=574855,CODECS="avc1.4d001f,mp4a.40.2",RESOLUTION=854x480
http://www.youtube.com/api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/94/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/46413816/lmt/1351106299100627/playlist_type/DVR/dnc/1/upn/lSlHW_byIf8/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/4C76FF059DB63CFD497CD95927CE938309A94BE8.16261EC4A02FD3AD409D464F58F67F4F2A5428CB/key/dg_yt0/file/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=258129,CODECS="avc1.4d0015,mp4a.40.2",RESOLUTION=426x240
http://www.youtube.com/api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/92/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/18636628/lmt/1351106309380657/playlist_type/DVR/dnc/1/upn/lSlHW_byIf8/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/8F806261C4B67A557A7D7C257F3FC11965EC467E.32DEA199436459A8C8A82BD22266B40E432AEBCB/key/dg_yt0/file/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=513854,CODECS="avc1.4d001e,mp4a.40.2",RESOLUTION=640x360
http://www.youtube.com/api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/93/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/39397656/lmt/1351106301230978/playlist_type/DVR/dnc/1/upn/lSlHW_byIf8/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/246A094D3416CC1E6F9967C807833FC078FCC276.0DFC45978BB745CA4E50607683ED20FD313F5FDE/key/dg_yt0/file/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1546069,CODECS="avc1.4d001f,mp4a.40.2",RESOLUTION=1280x720
http://www.youtube.com/api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/95/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/95870036/lmt/1351106319097925/playlist_type/DVR/dnc/1/upn/lSlHW_byIf8/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/97D54E76CD28F4E5D9626E086095A6C9C948E6BB.96DC338814F375B81AAFEE65A67880AAB52A5DD1/key/dg_yt0/file/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1974882,CODECS="avc1.640028,mp4a.40.2",RESOLUTION=1920x1080
http://www.youtube.com/api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/96/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/139150456/lmt/1351106335845761/playlist_type/DVR/dnc/1/upn/lSlHW_byIf8/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/46B5396DD6AABA1E35531A90416EDD4B27578D91.71B5D6DEEBE5AE76918E0A6A58B781941F57B1CB/key/dg_yt0/file/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=255424,CODECS="avc1.420015,mp4a.40.2",RESOLUTION=426x240
http://www.youtube.com/api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/132/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/25629664/lmt/1351106311307068/playlist_type/DVR/dnc/1/upn/lSlHW_byIf8/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/0DFEA8F14E8B1F902604EE0D0C06A87228C4B1C5.66C30A2C672E7E4B54893733AC72FAC7CB5CD076/key/dg_yt0/file/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=50483,CODECS="avc1.42000B,mp4a.40.2",RESOLUTION=128x72
http://www.youtube.com/api/manifest/hls_playlist/id/f05679e8c2cdb67b/itag/151/source/youtube/ratebypass/yes/pbr/yes/gir/yes/clen/4852280/lmt/1351106296882221/playlist_type/DVR/dnc/1/upn/lSlHW_byIf8/ip/0.0.0.0/ipbits/0/expire/1358566855/sparams/ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type/signature/7AADB2B1630EAE160A025F379B3350FCE2D208EF.040FDB0523382E45294BEF587C6FDE2FFCD9C987/key/dg_yt0/file/index.m3u8


Based on the above playlist, there are about 7 different qualities available ranging from 1920x1080 to 128x72 resolution:

Here are the itags and the corresponding resolutions:
 92 ->    426x240
 93 ->    640x360
 94 ->    854x480
 95 ->  1280x720
 96 ->  1920x1080
151 ->  128x72

So now in addition to the various itags listed on wikipedia  (about 23) that YouTube already support, here are a few other. So it seems like for every video uploaded there are about 30 formats that Youtube maintains, pretty amazing ! Not sure if they have some in line transcoding available to converts the video on-the-fly into various formats.

The playlist file that follows are obviously pointing to the actual video files. The interesting thing there is that the duration is about 5 secs and not the assumed default of 10sec for HLS. I guess YouTube wants to be a bit aggressive in adapting to the network conditions. Also, in the path there are byte ranges for the video, not sure what those are for ?

Here are the first few lines for the video playlist file: 


#EXTM3U
#EXT-X-VERSION:3
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:7
#EXTINF:5.005000,
http://redirector.c.youtube.com/videoplayback/id/f05679e8c2cdb67b/itag/94/source/youtube/range/0-359643/file/seg.ts?ratebypass=yes&pbr=yes&gir=yes&clen=46413816&lmt=1351106299100627&playlist_type=DVR&dnc=1&upn=lSlHW_byIf8&ip=0.0.0.0&ipbits=0&expire=1358566855&sparams=ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type&signature=4C76FF059DB63CFD497CD95927CE938309A94BE8.16261EC4A02FD3AD409D464F58F67F4F2A5428CB&key=dg_yt0&dur=5.005
#EXTINF:5.005000,
http://redirector.c.youtube.com/videoplayback/id/f05679e8c2cdb67b/itag/94/source/youtube/range/359644-640139/file/seg.ts?ratebypass=yes&pbr=yes&gir=yes&clen=46413816&lmt=1351106299100627&playlist_type=DVR&dnc=1&upn=lSlHW_byIf8&ip=0.0.0.0&ipbits=0&expire=1358566855&sparams=ip,ipbits,expire,id,itag,source,ratebypass,pbr,gir,clen,lmt,playlist_type&signature=4C76FF059DB63CFD497CD95927CE938309A94BE8.16261EC4A02FD3AD409D464F58F67F4F2A5428CB&key=dg_yt0&dur=5.005


The videos are regular mpegts format with H264 and AAC as video and audio codecs, so nothing surprising there. Here is the ffmpeg output for one of the videos of itag=94.


Input #0, mpegts, from 'yt-hls-94.ts':
  Duration: 00:00:04.99, start: 11.384589, bitrate: 700 kb/s
  Program 1
    Metadata:
      service_name    : Google
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 854x480, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, s16, 118 kb/s


2 comments:

Unknown said...

Can you provide the link to the Youtube M3u Playlist you tested.

Thanks

Unknown said...

Can you provide the link to the Youtube M3U (hls_variant) playlist you used for testing.

Thanks