Transcript
Page 1: GDD HTML5, Flash, and the Battle for Faster Cat Videos

HTML5, Flash and the Battle for Faster Cat VideosBy YouTube's Greg Schechter, Phil Harnish and Matt Ward

Page 2: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Greg SchechterThe Web Warrior

[email protected]

[email protected]

Matt WardSeek Bar Engineer

[email protected]

Phil HarnishSr. Play Button

Eng

Page 3: GDD HTML5, Flash, and the Battle for Faster Cat Videos
Page 4: GDD HTML5, Flash, and the Battle for Faster Cat Videos

HTML + JS + CSS + Awesomeness

Page 5: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Offline File Access Multimedia Performance Presentation Graphics Storage

HTML5

Page 6: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Offline File Access Multimedia Performance Presentation Graphics Storage

HTML5

Page 7: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Translation

Page 8: GDD HTML5, Flash, and the Battle for Faster Cat Videos

HTML5 ~=

By geishaboy500http://www.flickr.com/photos/geishaboy500/3183872667/

Page 9: GDD HTML5, Flash, and the Battle for Faster Cat Videos

99% connected desktop penetration?http://www.adobe.com/products/player_census/flashplayer/

Page 10: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?

Page 11: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Features Accessibility "Device-ability"Security Embeds API

HTML5 vs Flash

Page 12: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Round 1: Features

http://www.flickr.com/photos/zipckr/4624150058/

Page 13: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection

Page 14: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

Page 15: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access

Page 16: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access● Adaptive & Live Streaming

Page 17: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access● Adaptive & Live Streaming● Fullscreen video

Page 18: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access● Adaptive & Live Streaming● Fullscreen video

○ Hardware accelerated HD cat videos!○ **API available in webkit and gecko

Page 19: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Mozilla Fullscreen API

var elem = document.getElementById("my-element");document.onmozfullscreenchange = function() {// The fullscreen element:// document.mozFullScreenElement;console.log ("We went fullscreen!");};elem.mozRequestFullScreen();

Page 20: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access● Adaptive & Live Streaming● Fullscreen video

○ HD, hardware accelerated cat videos!○ **API available in webkit and gecko

Page 21: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access● Adaptive & Live Streaming ● Fullscreen video

○ HD, hardware accelerated cat videos!○ **API available in webkit and gecko

● Consistent format support

Page 22: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access● Adaptive & Live Streaming● Fullscreen video

○ HD, hardware accelerated cat videos!○ **API available in webkit and gecko

● Consistent format support○ HTML5 needs to support both H.264 and WebM

Page 23: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why Flash?Features missing in HTML5

● Content protection○ RTMPE protocol / Flash Access

● Camera & Microphone Access● Adaptive & Live Streaming● Fullscreen video

○ HD, hardware accelerated cat videos!○ **API available in webkit and gecko

● Consistent format support○ HTML5 needs to support both H.264 and WebM

● Cross platform consistency****

Page 24: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?<video> Expectations

● Open source technology

○ Browser / Player / Codec

Page 25: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?<video> Expectations

● Open source technology

○ Browser / Player / Codec● Lower latency

○ No plug-in instantiation

Page 26: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?<video> Expectations

● Open source technology

○ Browser / Player / Codec● Lower latency

○ No plug-in instantiation● Better performance and fidelity

Page 27: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?<video> Expectations

● Open source technology

○ Browser / Player / Codec● Lower latency

○ No plug-in instantiation● Better performance and fidelity● Accessibility

Page 28: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?<video> Expectations

http://imgs.xkcd.com/comics/in_ur_reality.png

Page 29: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?<video> Expectations

● Open source technology

○ Browser / Player / Codec● Lower latency

○ No plug-in instantiation● Better performance and fidelity● Accessibility

○ User agents can have special video handling

Page 30: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Please put on your3D Glasses

Page 31: GDD HTML5, Flash, and the Battle for Faster Cat Videos

By jmettrauxhttp://www.flickr.com/photos/jmettraux/4959258811/

Page 32: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?3D

● Flash

○ Build for graphics

○ Tools for easy video manipulation

■ HTML5 would require WebGL or Canvas

● HTML5○ Easy integration with browser and

devices○ Open Standard○ Allows for innovations by the browser

vendors as well as YouTube

Page 33: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Round 2: Device-ability

By dakinyhttp://www.flickr.com/photos/dakiny/4430765149/

Page 34: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?HTML5 Capable Browsers (~60%)

Page 35: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?Flash Support vs. HTML5 Support

Page 36: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?YouTube Data API Usage for Flash vs. HTML5 Devices

Page 37: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why HTML5?

Page 38: GDD HTML5, Flash, and the Battle for Faster Cat Videos

When HTML5?

Page 39: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Primary Goal:Recover playbacks that would

be lost without flash

Page 40: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Our Solution

Page 41: GDD HTML5, Flash, and the Battle for Faster Cat Videos

<iframe type="text/html" width="640" height="385" frameborder="0" src="http://www.youtube.com/embed/VIDEO_ID" allowfullscreen></iframe>

Page 42: GDD HTML5, Flash, and the Battle for Faster Cat Videos

When HTML5?<iframe> Embed

● Give the user HTML5 or Flash based on device and user preferences.

● Allows for better mobile support.

● Offers an "it just works" experience.

Page 43: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Why an iframe?Other embedding methods

● <script>

○ We need our content to be sandboxed

○ More than just a video tag

● <object>

○ Can load content with the data attribute

○ But no way to interact with it

Page 44: GDD HTML5, Flash, and the Battle for Faster Cat Videos

When HTML5?When does the user get HTML5?

Page 45: GDD HTML5, Flash, and the Battle for Faster Cat Videos

When HTML5?Detecting HTML5

var videoElement = document.createElement('video');if (videoElement && videoElement.canPlayType && (videoElement.canPlayType('video/mp4; codecs="avc1.42001E, mp4a.40.2"') || videoElement.canPlayType('video/webm; codecs="vp8.0, vorbis"'))) { // Sweet, we can use HTML5!}

Page 46: GDD HTML5, Flash, and the Battle for Faster Cat Videos

When HTML5?When does the user get HTML5?

Page 47: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Round 3: Performance

By Two Hawk's Eyehttp://www.flickr.com/photos/mycoolpics/92033686/

Page 48: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Player Start Time

TODO(schechter): Add csi screen captures

500ms

(Up from 200ms in Jan 2011)

Flash

HTML5

Page 49: GDD HTML5, Flash, and the Battle for Faster Cat Videos

iframe Embed Time Till Thumbnail Visible

Flash - 5.1s

HTML5 - 1.4s

*Collected data shows faster load times than this control environment, but the comparison is actuate.

Page 50: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Get Video Time

Page 51: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Get Video Time

● HTML5:

○ Opera is Awesome

■ 200ms ahead of the pack

● Flash: IE9 and Opera are the leaders

○ 300ms faster● HTML5 is almost always faster than Flash

○ 300ms - 400ms faster○ IE9 is an exception

■ IE9 Flash is slightly faster than IE9 HTML5

Page 52: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Video Start Time

HTML5

Flash 2.5s

Page 53: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Video Start Time

HTML5

Flash 2.5s

● Firefox closest to catching Flash

○ HTML5 ~1.0s slower than Flash

Page 54: GDD HTML5, Flash, and the Battle for Faster Cat Videos

So why is Flash so fast?

Page 55: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Make Assumptions

Page 56: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Making Assumptions

● Most users have a recent version of flash

● Thus we can optimistically embed the most common case and do version checking and updating after a script loads

● 250ms improvement to flash start time

Page 57: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Preload Video Connection

Page 58: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Preload Video Connection

● Resolves DNS while page is rendering● Maintains an open connection● 200ms improvement

<head> <script> var img = new Image(); img.src = videoConnectionUrl; </script></head>

Page 59: GDD HTML5, Flash, and the Battle for Faster Cat Videos

What about embeds?

Page 60: GDD HTML5, Flash, and the Battle for Faster Cat Videos

#1 cache

Page 61: GDD HTML5, Flash, and the Battle for Faster Cat Videos

1. youtube.com/v/di5I49yg7bY 302 redirect2. s.ytimg.com/swf/l.swf?args&swf=swf2-hash_url.swf3. s.ytimg.com/swf/swf2-hash_url.swf ~150kb

Page 62: GDD HTML5, Flash, and the Battle for Faster Cat Videos

1. youtube.com/v/di5I49yg7bY 3022. s.ytimg.com/swf/l.swf?args&swf=swf2-hash_url.swf3. s.ytimg.com/swf/swf2-hash_url.swf

1. youtube.com/v/di5I49yg7bY application/x-shockwave-flash2. s.ytimg.com/swf/swf2-hash_url.swf

Better

Page 63: GDD HTML5, Flash, and the Battle for Faster Cat Videos

1. youtube.com/v/di5I49yg7bY 3022. s.ytimg.com/swf/l.swf?args&swf=swf2-hash_url.swf3. s.ytimg.com/swf/swf2-hash_url.swf

1. youtube.com/v/di5I49yg7bY application/x-shockwave-flash2. s.ytimg.com/swf/swf2-hash_url.swf

1. youtube.com/embed/di5I49yg7bY text/html2. s.ytimg.com/swf/swf2-hash_url.swf

Best

Page 64: GDD HTML5, Flash, and the Battle for Faster Cat Videos

#2 lazy load

Page 65: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Most embeds are never played.

Page 66: GDD HTML5, Flash, and the Battle for Faster Cat Videos

● Delay expensive queries.● Use cache for most videos.● Delay loading... flash?

Page 67: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Demo:http://gregthebusker.com/iframedemo.html

Page 68: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Player API

http://code.google.com/apis/youtube/getting_started.html#player_apis

Page 69: GDD HTML5, Flash, and the Battle for Faster Cat Videos

The JavaScript APICommunication

Page 70: GDD HTML5, Flash, and the Battle for Faster Cat Videos

The JavaScript APICommunication

● Poll the URL fragment? http://youtube.com/embed/video_id#fragment

Page 71: GDD HTML5, Flash, and the Battle for Faster Cat Videos

The JavaScript APICommunication

● Poll the URL fragment?http://youtube.com/embed/video_id#fragment

● Messages are one dimensional.

● Polling eats up CPU and is not instant.

● Both directions of communication use the same fragment.

Page 72: GDD HTML5, Flash, and the Battle for Faster Cat Videos

The JavaScript APICommunication

● Better idea: PostMessage API.someWindow.postMessage(message, targetOrigin);

Page 73: GDD HTML5, Flash, and the Battle for Faster Cat Videos

The JavaScript APICommunication

● Better idea: PostMessage API.someWindow.postMessage(message, targetOrigin);

● Uses JSON for native encoding and decoding of data.● No polling.● Native event listeners.● Communications are sandboxed per-window.● Calls are asynchronous.

Page 74: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Conclusion

● Flash is still preferred in most places○ More critical features○ Deeper reach

● HTML5 is awesome○ Improves every day○ Greater mobile reach○ People want it

Page 75: GDD HTML5, Flash, and the Battle for Faster Cat Videos

Questions?

[email protected]@[email protected]

can haz question?By cloudzilla http://www.flickr.com/photos/cloudzilla/378829651/