Download - Multimedia on the web - HTML5 video and audio

Transcript
Page 1: Multimedia on the web - HTML5 video and audio

Multimedia on the web.HTML5 Audio and Video

Christian Heilmann, MIT Boston, January 2012

Page 2: Multimedia on the web - HTML5 video and audio

I’m Chris.

Page 3: Multimedia on the web - HTML5 video and audio

What we will cover:★ Quick history of Multimedia on the web★ Annoyances with Flash★ HTML5 audio and video★ Painful stuff – codecs and conversion★ Embedding★ Controlling★ Transforming★ Realtime changes★ Awesome audio stuff

Page 4: Multimedia on the web - HTML5 video and audio

Quick history of Multimedia on the web

Page 5: Multimedia on the web - HTML5 video and audio

First, there were images.

JPG, GIF, PNG (later), WBMP, ICO

Page 6: Multimedia on the web - HTML5 video and audio

Connections were bad.

Progressive JPG, interlaced GIF, <img src=”foo.jpg” lowsrc=”foogrey.gif” alt=”a foo, what else?”>

Page 7: Multimedia on the web - HTML5 video and audio

Animation was done with animated GIFs or with JavaScript animation.

Page 8: Multimedia on the web - HTML5 video and audio

Audio was mostly Midi background music.

(and if you think about using that today I will hit you!)

Page 9: Multimedia on the web - HTML5 video and audio

Other things we did were Java Applets.

Page 10: Multimedia on the web - HTML5 video and audio

And then we gotRealPlayer.

Page 11: Multimedia on the web - HTML5 video and audio

And many others...

★ Quicktime / Quicktime VR★ Microsoft Media Player★ Shockwave★ Acrobat had some image

editing features.★ iPix / VRML and many other

forgotten ones...

Page 12: Multimedia on the web - HTML5 video and audio

They all had the same issues.★ End users must install a

plugin.★ You need to upgrade the

plugin constantly.★ There is limited interaction

with the rest of the page.

Page 13: Multimedia on the web - HTML5 video and audio

Another big issue is and was security – plugins are one of main attack vectors for malware.

Page 14: Multimedia on the web - HTML5 video and audio

In the end, one plugin prevailed over all the others: Flash.

Page 15: Multimedia on the web - HTML5 video and audio

With aggressive marketing, clever partnerships and a rich dev environment Flash became the multimedia choice for the web.

Page 16: Multimedia on the web - HTML5 video and audio

And there is the DRM stuff...

Page 17: Multimedia on the web - HTML5 video and audio

Annoyances with Flash

Page 18: Multimedia on the web - HTML5 video and audio

+

=

Apple and Flash movies means a lot of times your fan will start up.

Page 19: Multimedia on the web - HTML5 video and audio

Why would I want yet another editor to build web content?

Page 20: Multimedia on the web - HTML5 video and audio

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/SJixW2u4IvQ?fs=1&amp;hl=en_US" /><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><embed src="http://www.youtube.com/v/SJixW2u4IvQ?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385" /></object>

WTF is all this?

Page 21: Multimedia on the web - HTML5 video and audio

Flash is a black box inside a document.

Alien

Page 22: Multimedia on the web - HTML5 video and audio

Therefore it is also an accessibility problem.★ Other browsers than IE don’t allow you

to access Flash with a keyboard.★ You are at the mercy of the developers

to make their movies keyboard accessible.

★ Which is bad, as audio and video can help a lot of people to understand things.

Page 23: Multimedia on the web - HTML5 video and audio

Flash can talk to JavaScript via APIs.

Page 25: Multimedia on the web - HTML5 video and audio

You are at the mercy of the API developers though – what they don’t make public, you can’t reach.

Page 26: Multimedia on the web - HTML5 video and audio

HTML5 audio and video

Page 27: Multimedia on the web - HTML5 video and audio

HTML5 audio and video make things much simpler:★ Better accessibility★ Doing one thing well★ Much simpler API★ Allows for styling and overlays★ View-source “hackable”

Page 28: Multimedia on the web - HTML5 video and audio

Screencast of Oprah’s web site

http://www.oprah.com/own

Page 29: Multimedia on the web - HTML5 video and audio

Painful stuff – Codecs and conversion

Page 30: Multimedia on the web - HTML5 video and audio

So, we understood that there is a need for an open high-fidelity technology if we really want the web to be a media.

Page 31: Multimedia on the web - HTML5 video and audio

What we didn’t quite consider yet is something that both accelerated and hindered innovation for a long time.

Page 32: Multimedia on the web - HTML5 video and audio

Copyright

Page 33: Multimedia on the web - HTML5 video and audio

Videos on the web are encoded to make them smaller – there is no such things as an “AVI File”...

Page 34: Multimedia on the web - HTML5 video and audio

They are containers for video in a certain compression and audio in another.

Page 35: Multimedia on the web - HTML5 video and audio

The issue was that all these compression formats had their own copyright and didn’t work with open technology like HTML5.

Page 36: Multimedia on the web - HTML5 video and audio

Therefore we needed new formats:

★ H.264 “MP4”★ OGG/Vorbis★ VP8 / WebM

Page 37: Multimedia on the web - HTML5 video and audio

Our job is now to convert the videos we record to these open formats – which can be annoying.

Page 38: Multimedia on the web - HTML5 video and audio

The main annoyance is that different browsers support different formats, which means we need to provide several versions :(

Page 39: Multimedia on the web - HTML5 video and audio

Audacity: http://audacity.sourceforge.net/

WebM tools: http://www.webmproject.org/tools/

Evom: http://thelittleappfactory.com/evom/

VLC: http://www.videolan.org/vlc/

Ogg convert: http://oggconvert.tristanb.net/

Firefogg: http://firefogg.org/

TinyOgg: http://tinyogg.com/

ffmpeg:http://ffmpeg.org/

Page 40: Multimedia on the web - HTML5 video and audio

http://www.mirovideoconverter.com/

Page 41: Multimedia on the web - HTML5 video and audio

http://www.archive.org

Page 42: Multimedia on the web - HTML5 video and audio

Embedding

Page 43: Multimedia on the web - HTML5 video and audio

Embedding audio and video in an HTML5 document is easy:<audio src=”foo.ogg”> If your browser didn’t suck, you’d have audio here.

</audio><video src=”foo.ogv”> If your browser didn’t suck, you’d have video here.

</video>

Page 44: Multimedia on the web - HTML5 video and audio

That doesn’t do anything yet<video src=”foo.ogv” controls> If your browser didn’t suck, you’d have video here.

</video>

★ Controls appear on mouse hover or tabbing

★ Keyboard enabled controls

★ Video can be styled in any way.

Page 45: Multimedia on the web - HTML5 video and audio

Controls differ from browser to browser...

Firefox

Opera

Safari

Chrome

Full Screen

Page 46: Multimedia on the web - HTML5 video and audio

So to give it to all browsers... <video controls> <source src="http://www.archive.org/{...}_512kb.mp4" type="video/mp4"></source> <source src="http://www.archive.org/{...}nsters.ogv" type="video/ogg"></source> <p>Your browser doesn't like HTML5 video, watch the movie on <a href="http://www.archive.org/{...}_monsters"> archive.org</a>. </p> </video>

Page 47: Multimedia on the web - HTML5 video and audio

Things to consider:

★ Use MP4 always as the first option to support iOS devices (iPads, iPhone and so on...)

★ If you omit the type attribute, the browser loads the meta data of each source!

Page 49: Multimedia on the web - HTML5 video and audio

Other attributes:

★ poster – define a picture to show before loading.

★ height/width – oh, well...★ loop – automatically restart★ preload (auto/none/

metadata)

Page 50: Multimedia on the web - HTML5 video and audio

But what if you don’t like the controls?

Page 51: Multimedia on the web - HTML5 video and audio

Controlling

Page 52: Multimedia on the web - HTML5 video and audio

HTML5’s Media API gives you control:

★ load() – load a new media.★ canPlayType(type) – returns probably,

maybe and “” (really!)★ play() – play the movie★ pause() – pause the movie.★ addTrack(label,kind,language) -for

subtitles

Page 53: Multimedia on the web - HTML5 video and audio

Video details:width / height / videoWidth / videoHeight / poster

Controls:controls / volume / muted

Tracks:tracks

Network state:src / currentSrc / networkState / preload / buffered

Ready statereadyState / seeking

Playback statecurrentTime / startTime / duration / paused / defaultPlayBackRate / playbackRate / played / seekable / ended / autoplay / loop

Page 54: Multimedia on the web - HTML5 video and audio

Writing a play button is simple:var audio = document.getElementsByTagName('audio')[0];var play = document.getElementsByClassName('play')[0];play.addEventListener('click',function(e){ var t = e.target; if(audio.paused){ audio.play(); t.innerHTML = 'pause'; } else { audio.pause(); t.innerHTML = 'play'; } e.preventDefault();});

Page 55: Multimedia on the web - HTML5 video and audio

However, simply checking properties is not safe!

Page 56: Multimedia on the web - HTML5 video and audio

Any JS use gets much safer by listening to events.

Page 57: Multimedia on the web - HTML5 video and audio

HTML5 video events:loadstart / progress / suspend / abort / error / emptied / stalled / play / pause / loadedmetadata / loadeddate / waiting / playing / canplay / canplaythrough / seeking / seeked / timeupdate / ended / ratechange

Page 58: Multimedia on the web - HTML5 video and audio

video.addEventListener('play', playEvent, false);video.addEventListener('pause', pausedEvent, false);video.addEventListener('ended', function () { this.pause();}, false);function playEvent() { play.innerHTML = 'pause';}function pausedEvent() { play.innerHTML = 'play';}play.onclick = function () { if (video.ended) { video.currentTime = 0; } if (video.paused){ video.play(); }else{ video.pause(); }};

Page 60: Multimedia on the web - HTML5 video and audio

You can use these events to sync animation or trigger changes with audio and video.

Page 62: Multimedia on the web - HTML5 video and audio
Page 63: Multimedia on the web - HTML5 video and audio
Page 64: Multimedia on the web - HTML5 video and audio
Page 65: Multimedia on the web - HTML5 video and audio
Page 66: Multimedia on the web - HTML5 video and audio
Page 67: Multimedia on the web - HTML5 video and audio

Transforming

http://www.flickr.com/photos/jiazi/1061447777

Page 68: Multimedia on the web - HTML5 video and audio

I am a film buff and I like to find easter eggs in movies. Every pixar movie for example has A113 in it – the room in the uni a lot of pixar employees had their animation lectures in. To find things like that I sometimes zoom the screen and scan around.

I thought this should be possible in HTML5.

Page 70: Multimedia on the web - HTML5 video and audio

Using SVG and other technologies you can change the look and feel of videos even more.

Page 71: Multimedia on the web - HTML5 video and audio

http://people.mozilla.com/~prouget/demos/round/index.xhtml

Page 73: Multimedia on the web - HTML5 video and audio

Realtime changes

Page 79: Multimedia on the web - HTML5 video and audio

Awesome audio stuff

Page 80: Multimedia on the web - HTML5 video and audio

https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension

Page 84: Multimedia on the web - HTML5 video and audio
Page 85: Multimedia on the web - HTML5 video and audio

Thanks!

Chris Heilmann@codepo8http://icant.co.uk