<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>HTML5 Doctor &#187; video</title>
	<atom:link href="http://html5doctor.com/tag/video/feed/" rel="self" type="application/rss+xml" />
	<link>http://html5doctor.com</link>
	<description>helping you implement HTML5 today</description>
	<lastBuildDate>Wed, 16 May 2012 11:31:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>It&#8217;s Curtains for Marital Strife Thanks to getUserMedia</title>
		<link>http://html5doctor.com/getusermedia/</link>
		<comments>http://html5doctor.com/getusermedia/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 14:56:03 +0000</pubDate>
		<dc:creator>Bruce Lawson</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[JavaScript APIs]]></category>
		<category><![CDATA[multimedia]]></category>
		<category><![CDATA[getusermedia]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[webrtc]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=4335</guid>
		<description><![CDATA[<p>HTML5 (or now, the WebRTC spec) gives us getUserMedia, a way for JavaScript to access streams from a device's camera and microphone. Find out how to use it and normalise the syntax differences between Opera and Chrome with the gUMshield.</p>]]></description>
			<content:encoded><![CDATA[<p>True story: I was tasked by the lovely Mrs Lawson to buy some curtains that match our carpet during the January sales. I dutifully did so — and had to return to the shop straight away because they didn&#8217;t match at all. Mrs Lawson accompanied me, and with a withering glance at her incompetent mate, immediately found some correctly hued fabric, and all was well.</p>

<p>But what&#8217;s a middle-aged colour-blind bloke to do? I had early in the curtain procurement process decided against cutting a hole in the carpet in order that I may take a sample with me. (All other mistakes aside, this was a correct decision.)</p>

<p>So, in order to ensure that I would never again repeat the mistake, I set out to make an app that would allow me to capture the colour of an image straight from my camera. Of course, it had to be a web app rather than a native app, because we&#8217;re web angels, not proprietary devils.</p>

<section id="intro">
  <h2><code>getUserMedia</code> <a href="#intro" class="permalink">#</a></h2>

  <p><a href="http://dev.w3.org/2011/webrtc/editor/getusermedia.html"><code>getUserMedia</code></a> is an API that gives a web page access to a user&#8217;s camera and microphone via JavaScript. It&#8217;s supported in Opera Labs (<a href="http://dev.opera.com/articles/view/labs-more-fun-using-the-web-with-getusermedia-and-native-pages/">latest Android build</a>, <a href="http://dev.opera.com/articles/view/getusermedia-access-camera-privacy-ui/">latest desktop builds</a>) and WebKit in <a href="http://tools.google.com/dlpage/chromesxs?platform=win">Chrome Canary</a> builds (<a href="https://sites.google.com/site/webrtc/running-the-demos">instructions</a>).</p>

  <p>Like many other APIs, it&#8217;s not part of the &#8220;real&#8221; HTML5 spec. It started life as the HTML5 <code>&lt;device&gt;</code> element, then got moved into the W3C as part of the <a href="http://www.w3.org/TR/webrtc/">webRTC</a> specifications. But let&#8217;s not taxonomise when we could be having fun.</p>

  <p>The first thing we need to do when using super-cool new UIs is detect whether it&#8217;s supported:</p>

  <figure>
    <pre><code> if (navigator.getUserMedia) {
  // do something cool
} else {
  // fallback code
}</code></pre>
    <figcaption>Basic usage of <code>getUserMedia</code></figcaption>
  </figure>

  <p>For this article, our &#8220;do something cool&#8221; will be to grab the dominant colour of the current input stream from the camera. As a fallback, we have several options.</p>

  <p>One option, if we&#8217;re using the default Android browser, is to show a form that automatically starts the camera when focussed:</p>

  <figure>
    <pre><code>&lt;form enctype="multipart/form-data" method="post"&gt;
  &lt;input type="file" accept="video/*;capture=camera" /&gt;
&lt;/form&gt;</code></pre>
    <figcaption>Fallback code for Android</figcaption>
  </figure>

  <p>There&#8217;s also the <a href="http://www.w3.org/TR/2011/WD-html-media-capture-20110414/#captureparam"><code>capture</code> attribute</a>, a proposed extension from the <a href="http://www.w3.org/TR/html-media-capture/">W3C Device API Media Capture API</a> that tells a user agent where to get the input data. Android extends the <a href="http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#attr-input-accept"><code>accept</code> attribute</a>. See more in <a href="http://davidbcalhoun.com/2011/android-3-0-honeycomb-is-first-to-implement-the-device-api">David Calhoun&#8217;s Device API article</a>. Alternative capture arguments are <code>camcorder</code> (for video), <code>microphone</code>, and <code>filesystem</code>.</p>

  <p>Browsers that don&#8217;t understand the still-draft Media Capture API will simply ignore the <code>capture</code> attrbute and prompt the user to browse to a file on their file system for uploading.</p>

  <p>Users on iOS are out of luck, as their devices don&#8217;t allow access to the file system.</p>

  <section id="differences-from-media-capture">
    <h3>Differences Between the Media Capture API and <code>getUserMedia</code> <a href="#differences-from-media-capture" class="permalink">#</a></h3>

    <p>Robin Berjon, co-chair of the Device API (DAP) Working Group explains: The markup-only Media Capture API is a simpler, low-hanging-fruit version that can work easily for a lot of use cases. It also has a very simple security model (just a file upload).</p>

    <p>In fact, it works exactly like <code>&lt;input type=file&gt;</code>, except that it knows to allow the user to grab a pic from the camera by default instead of hitting the filesystem. But just like with <code>&lt;input type=file&gt;</code>, once a picture has been taken (i.e., a file selected), you can access it and read from it using the File API, which means you can stuff it in an <code>&lt;img&gt;</code> or a <code>&lt;canvas&gt;</code> and do nasty things to it without annoying any faraway server.</p>

    <p>But of course, if it&#8217;s part of a form and you submit it, it gets submitted just like a regular file upload.</p>

    <p>The thing is, though, it&#8217;s always a snapshot. Even if you use it to take a video (which you can), the page only gets it after you&#8217;ve finished shooting. With <code>getUserMedia</code> (<b>gUM</b>), you get the live stream, which you can modify, record, or stream elsewhere. The gUM approach is more powerful but more complex, and it has more severe security issues.</p>
  </section>
</section>

<section id="api">
  <h2><code>getUserMedia</code> API <a href="#api" class="permalink">#</a></h2>

  <p>Let&#8217;s assume (because we&#8217;re optimists) that your user has a <code>getUserMedia</code>-enabled device. The API is nice and simple, as all Web APIs should be.</p>

  <p><code>navigator.getUserMedia</code> accepts two required arguments and an optional third.</p>

  <p>The first argument tells the device <b>which media you require access to</b>, and it&#8217;s passed as a JavaScript object. So, if you only require access to the microphone, the first argument would be <code>{audio: true}</code>; for video-chatting, you would use <code>{audio: true, video: true}</code>.</p>

  <p>The device decides which camera to use: <q>User agents are encouraged to default to using the user&#8217;s primary or system default camera and/or microphone (as appropriate) to generate the media stream.</q></p>

  <p>A previous version of the specification allowed hints to user agents about which camera to use. The API could specify &#8220;user&#8221; (the front camera on a phone) or &#8220;environment&#8221; (the rear camera on a phone). Debate continues about whether to reinstate this (<a href="http://lists.w3.org/Archives/Public/public-media-capture/2012Jan/0014.html">read the ongoing conversation</a>). One argument against is that letting sites know what cameras a device has could help Dr Malice of Evil Corp. fingerprint users after luring them to his site (which I find to be overly-cautious). <a href="http://lists.w3.org/Archives/Public/public-media-capture/2012Jan/0018.html">Harald Alvestrand poses a conundrum</a>: <q>conferencing units may have a room camera, a document camera and a lectern camera, neither of which is attached to the physical box; which one of these is <q>front</q>?</q></p>

  <p>But let&#8217;s not worry at the moment. Devices with more than one camera generally have a mechanism that allow the user to choose which one is used, so this gives the user control. Note also that the spec says <q>User agents may allow users to use any media source, including pre-recorded media files.</q></p>

  <p>The second argument is the <b>success callback</b>, the function to be executed on success, assuming that the user allows access and the device supports your request.</p>

  <p>There is an optional third argument. This is the <b>failure callback</b>, the function to be executed if something went wrong. It&#8217;s optional, but only optional in the sense that washing your hands before you eat is optional: if you don&#8217;t do it, you leave yourself open to all sorts of bugs and your mum will shout at you.</p>

  <p>Of course, it&#8217;s important to do feature detection before making an API call to ensure that the browser and device are capable, but even if feature detection succeeds, there is still much that can cause failure. For example, the user could deny permission or turn off the camera via a hardware switch, or the device itself could disable the camera.</p>

  <p>So here&#8217;s how we recommend you use the API:</p>

  <figure>
    <pre><code>navigator.getUserMedia({audio: true, video: true}, success, error);

function success(stream) { 
  // ... use 'stream' ... 
} 

function error(){ 
  // display fallback content 
}</code></pre>
    <figcaption>Using the gUM API</figcaption>
  </figure>

  <p>To check whether it&#8217;s working correctly, we can attach the output of the camera&#8217;s stream to the input of an HTML5 video on the page, like this:</p>

  <figure>
    <pre><code>&lt;video autoplay&gt;&lt;/video&gt;
&lt;script&gt;
if (navigator.getUserMedia) {
  navigator.getUserMedia({audio: true, video: true}, success, error);
  function success(stream)
  { 
    // ... use 'stream' ...
    var video = document.getElementsByTagName('video')[0];
    video.src = stream; 
  }
  // ...
&lt;/script&gt;</code></pre>
    <figcaption>Streaming captured video to an HTML5 <code>&lt;video&gt;</code> element</figcaption>
  </figure>

  <section id="differences-between-webkit-and-opera">
    <h3>Differences Between Webkit and Opera <a href="#differences-between-webkit-and-opera" class="permalink">#</a></h3>

    <p>The two rendering engines that implement getUserMedia do so in two different ways. Hopefully, they&#8217;ll harmonise when the features reach the released browsers.</p>

    <p>The differences:</p>

    <ul>
      <li>WebKit uses a prefix — <code>navigator.webkitGetUserMedia</code> — while Opera doesn&#8217;t.</li>
      <li>
        WebKit implements the options according to an old version of the spec, in which audio and video were passed as strings:
        <pre><code>navigator.webkitGetUserMedia("video, audio", /* ... */)</code></pre>
        whereas Opera implements the most recent version of the specification which uses JavaScript objects:
        <pre><code>navigator.getUserMedia({video: true, audio: true}, /* ... */)</code></pre>
      </li>
      <li>
        WebKit attaches the resulting stream like this:
        <pre><code>video.src = window.webkitURL.createObjectURL(stream);</code></pre>
        which is according to the current version of the spec. Opera uses:
        <pre><code>video.src = stream;</code></pre>
        and has proposed simplifying the spec (but discussion continues).
      </li>
    </ul>

    <p>But this fragmentation, even though it&#8217;s only in experimental browser releases is, like, a total drag, man.</p>
  </section>

  <section id="gUM-shield">
    <h3>Introducing The gUM Shield <a href="#gUM-shield" class="permalink">#</a></h3>

    <p>Fortunately, we&#8217;ve got your back. Two of the finest minds I know — actually, two of the finest <em>Mikes</em>, Doctor <a href="http://twitter.com/akamike">Mike Robinson</a> and Opera&#8217;s <a href="http://twitter.com/miketaylr">Mike Taylor</a> — have created a snippet of script that you can copy to shield you from these annoying differences. We&#8217;ve named this <code>getUserMedia</code> syntax normalisation script snippet <a href="https://gist.github.com/f2ac64ed7fc467ccdfe3">The gUM Shield</a>.

    <p>It assumes that there&#8217;s a variable called <var>video</var> to which you&#8217;ve assigned a reference to the <code>&lt;video&gt;</code> element you&#8217;ll stream to. Do this with some mechanism like:</p>

    <pre><code>video = document.getElementById('video');</code></pre>

    <p>Simply <a href="https://gist.github.com/f2ac64ed7fc467ccdfe3">hit the &#8216;Hub</a>, download it, plug it into your script, and <a href="http://jsbin.com/avaxaq/edit#preview">check it out</a>!</p>

    <p>Note that it&#8217;s <em>experimental</em>. Who knows what&#8217;ll happen when Mozilla, Microsoft, and Apple implement it, but please, have a play. Fork it and improve it!</p>
  </section>
</section>

<sectino id="exciting">
  <h2>Doing Exciting Things with the Video Stream <a href="#exciting" class="permalink">#</a></h2>

  <p>So far, we&#8217;re only echoing the video stream. But, as you&#8217;ll know from Tab Atkins&#8217; guest article <a href="http://html5doctor.com/video-canvas-magic/">video + canvas = magic</a>, if we copy the video into a canvas, we can manipulate it:</p>

  <figure>
    <pre><code>var video = document.querySelector('video');
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');

ctx.drawImage(video, 0, 0, video.width, video.height,
  0, 0, canvas.width, canvas.height);</code></pre>
    <figcaption>Canvas and video magic</figcaption>
  </figure>

  <p>A common mistake is assuming that this somehow establishes a &#8220;live connection&#8221; between the video stream and the canvas. It doesn&#8217;t. It only grabs the current frame. So you need to grab the current frame repeatedly in order to replicate a video. The magical number is 15 times a second (or every 67 milliseconds), but a slower frame rate would probably be okay for this demo:</p>

  <figure>
    <pre><code>setInterval(function () { 
  ctx.drawImage(video, 0, 0, video.width, video.height,
  0, 0, canvas.width, canvas.height);
}, 1000 / 67);</code></pre>
    <figcaption>Live updating of <code>&lt;canvas&gt;</code> from a <code>&lt;video&gt;</code></figcaption>
  </figure>

  <p>See the <a href="http://jsbin.com/ahozok/edit#html,live">working demo</a>.</p>

  <p>What I want to do now is to grab the dominant colour from the canvas. I&#8217;m stealing <a href="http://experimenting.in/exp/real-life-color-picker/">a demo by Shwetank Dixit</a> (who borrowed from <a href="http://www.lokeshdhakar.com/">Lokesh Dhakar</a>&#8216;s <a href="http://www.lokeshdhakar.com/2011/11/03/color-thief/">Color Thief demo</a>). We won&#8217;t look at how it determines the dominant colour (because that&#8217;s nothing to do with getUserMedia).</p>

  <p><a href="http://html5doctor.com/demos/getusermedia/dominantcolor/">Try this in Opera Labs and Chrome Canary</a>!</p>

  <p>Unfortunately, this works splendidly in Opera but it occasionally fails in Chrome, and we&#8217;re not sure why. (We&#8217;ve emailed the Chrome team to ask them.) Apart from the rather anti-climactic end to an article, you shouldn&#8217;t be dismayed by this. <code>getUserMedia</code> is only available in experimental builds that have plenty of work to be done before they hit production.</p>

  <p>Back to our demo. Once you&#8217;ve got the dominant colour, you could prompt the user for a name for that colour (&#8220;carpet&#8221;, for example) and store that in local storage using its name as a key. Then, when you find a pair of curtains in the shop, you can find their dominant colour and easily compare it with that stored against &#8220;carpet&#8221; from earlier.</p>

  <p>And you can return home, confident of delighting the love of your life with your chromatically appropriate choice of soft furnishings. That&#8217;s HTML5: enriching marriages since 2004.</p>

  <img src="http://html5doctor.com/wp-content/uploads/2012/01/getUserMedia1.jpg" alt="woman says &#039;hey daddy-o, the curtains really razz my berries, ya dig?&#039;. Man replies &#039;Baby, I totally dig. Early night?&#039;. A thought bubble shows him thinking &#039;Thank you, getUserMedia&#039;" width="570" height="390" class="aligncenter size-full wp-image-4336" />
</section>

<section id="harshing-your-mellow">
  <h2>Harshing Your Mellow <a href="#harshing-your-mellow" class="permalink">#</a></h2>

  <p>Things need refining before web apps with <code>getUserMedia</code> are on a par with native applications. At the moment, there is no way of controlling which camera is to be used (and no agreement that a developer should be able to). The camera&#8217;s <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-July/032471.html">flash mechanism isn&#8217;t programmatically controllable</a>, which could harm the user experience. Most importantly are the privacy implications of web pages being able to access your camera. Opera has an <a href="http://dev.opera.com/articles/view/getusermedia-access-camera-privacy-ui/">experimental privacy UI</a>, but Chrome has no UI yet.</p>
</section>

<section id="demos">
  <h2>More Demos <a href="#demos" class="permalink">#</a></h2>

  <p>See Paul Neave&#8217;s <a href="http://neave.com/webcam/html5/">HTML5 Webcam Toy</a> and the links at the foot of my <a href="http://dev.opera.com/articles/view/getusermedia-access-camera-privacy-ui/">Opera Labs article</a>.</p>
</section>

<section id="thanks">
  <h2>Thanks <a href="#thanks" class="permalink">#</a></h2>

  <p>Thank for help and code are due to <a href="http://twitter.com/robinberjon">Robin Berjon</a>, <a href="http://twitter.com/shwetank">Shwetank Dixit</a>, <a href="http://twitter.com/ourmaninjapan">Daniel Davis</a>, <a href="http://www.lokeshdhakar.com/">Lokesh Dhakar</a>, <a href="http://twitter.com/miketaylr">Mike Taylor</a>, <a href="http://twitter.com/akamike">Mike Robinson</a>, and <a href="http://twitter.com/richtibbett">Rich Tibbett</a>.</p>
</section>
<section>
<h2>Addy Osmani&#8217;s Polyfill</h2>
<p>Added 13 March 2012: Addy Osmani has published a <a href="https://github.com/addyosmani/getUserMedia.js">getUserMedia polyfill</a> called getUserMedia.js, which uses Flash if gUM isn&#8217;t available. It&#8217;s not ready for production yet, as IE is still being tested. Forkers may hit the &#8216;hub.
</section><div id="crp_related"><h3>Related Posts:</h3><ul class="related"><li><a href="http://html5doctor.com/how-to-get-all-the-browsers-playing-ball/" rel="bookmark" class="crp_title">How to get all the browsers playing ball</a></li><li><a href="http://html5doctor.com/using-modernizr-to-detect-html5-features-and-provide-fallbacks/" rel="bookmark" class="crp_title">Using Modernizr to detect HTML5 features and provide fallbacks</a></li><li><a href="http://html5doctor.com/introducing-web-sql-databases/" rel="bookmark" class="crp_title">Introducing Web SQL Databases</a></li><li><a href="http://html5doctor.com/html5-briefing-notes-journalists-analysts/" rel="bookmark" class="crp_title">HTML5: briefing notes for journalists and analysts</a></li><li><a href="http://html5doctor.com/video-canvas-magic/" rel="bookmark" class="crp_title">video + canvas = magic</a></li></ul></div><p><a href="http://html5doctor.com/getusermedia/" rel="bookmark">It&#8217;s Curtains for Marital Strife Thanks to getUserMedia</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on February 7, 2012.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/getusermedia/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Video Subtitling and WebVTT</title>
		<link>http://html5doctor.com/video-subtitling-and-webvtt/</link>
		<comments>http://html5doctor.com/video-subtitling-and-webvtt/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 15:33:59 +0000</pubDate>
		<dc:creator>Tom Leadbetter</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[multimedia]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[subtitles]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[webvtt]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=4084</guid>
		<description><![CDATA[<p>We’ve been able to play video in the browser without a plugin for a couple of years now, and whilst there are still some codec annoyances, things appear to have settled down on the video front. The next step is adding resources to the video to make it more accessible and provide more options to the viewer.</p>]]></description>
			<content:encoded><![CDATA[<p>We’ve been able to play video in the browser without a plugin for a couple of years now, and whilst there are still some codec annoyances, things appear to have settled down on the video front. The next step is adding resources to the video to make it more accessible and provide more options to the viewer.</p>
<p>We currently have no means to provide information about what’s happening or being said in the video, which means the video isn’t very accessible and the user can’t easily navigate to a particular section of the video. Thankfully, there’s a new format specification in the works called <a href="http://www.whatwg.org/specs/web-apps/current-work/webvtt.html">WebVTT (Web Video Text Tracks)</a>. As of now, it’s only in the WHATWG spec, but the recently established <a href="http://www.w3.org/community/texttracks/">W3C Web Media Text Tracks Community Group</a> should introduce a WebVTT spec to the W3C soon.</p>
<p class="callout">You may recall a similar format called WebSRT (Web Subtitle Resource Tracks) that was recently under discussion. WebSRT was renamed to, and has been replaced by, WebVTT.</p>
<p>A WebVTT (.vtt) file is simply plain text containing several types of information about the video:</p>
<dl>
<dt>Subtitles</dt>
<dd>The transcription or translation of the dialogue.</dd>
<dt>Captions</dt>
<dd>Similar to subtitles, but may also include sound effects and other audio information.</dd>
<dt>Descriptions</dt>
<dd>Intended to be a separate text file that describes the video through a screenreader.</dd>
<dt>Chapters</dt>
<dd>Intended to help the user navigate through the video.</dd>
<dt>Metadata</dt>
<dd>Information and content about the video, which isn’t intended to be displayed to the viewer by default, though you may wish to do so using JavaScript.</dd>
</dl>
<p>This article will mostly be talking about <a href="#contents">subtitles and captions</a>, but it will briefly touch on <a href="#chapters">chapters</a> too.</p>
<p class="callout">Beyond the scope of this article but worth mentioning is the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#text-track-api">text track API</a>, which, amongst other things, denotes how many text tracks there are and which ones have loaded and are ready for use. If you have used this API, <a href="http://html5doctor.com/ask-the-doctor/">let us know</a>.</p>
<section id="how">
<h2>How to Make and Link to a WebVTT file <a href="#how" class="permalink">#</a></h2>
<p>All you need to make a WebVTT file is a simple text editor. Type <code>WEBVTT</code> as the first line of the file and save it as a .vtt file. In the future, we expect existing captioning tools such as <a href="http://www.universalsubtitles.org/">Universal Subtitles</a> to export to WebVTT format.</p>
<figure>
<pre><code>WEBVTT</code></pre>
<figcaption>The simplest possible valid WebVTT file</figcaption>
</figure>
<p>That’s all you need to get started. Next, we have to link to the file in the HTML document. We do this via the <a href="http://html5doctor.com/video-the-track-element-and-webm-codec/"><code>&lt;track&gt;</code> element</a>, which is a child of the video element. The <code>&lt;track&gt;</code> element has several optional attributes:</p>
<ul>
<li>the source WebVTT file (<code>src</code>),</li>
<li>the language of the track (<code>srclang</code>),</li>
<li>a user-readable <code>label</code>, and</li>
<li>what <code>kind</code> of track it is. The values of the <code>kind</code> attribute come from the list above (i.e., <code>subtitles</code>, <code>captions</code>, etc.).</li>
</ul>
<p>In the following example, we’re using a <code>&lt;track&gt;</code> element for subtitles:</p>
<pre><code>&lt;video width=&quot;640&quot; height=&quot;480&quot; controls&gt;
  &lt;source src=&quot;video.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;source src=&quot;video.webm&quot; type=&quot;video/webm&quot; /&gt;
  &lt;track src=&quot;subtitles.vtt&quot; kind=&quot;subtitles&quot; srclang=&quot;en&quot; label=&quot;English&quot; /&gt;
  &lt;!-- fallback for rubbish browsers --&gt;
&lt;/video&gt;</code></pre>
<p>A few notes about the attributes:</p>
<ul>
<li>If no <code>kind</code> is specified, the default is <code>subtitles</code>.</li>
<li>If the <code>kind</code> is <code>subtitles</code>, then <code>srclang</code> is required.</li>
<li>There should not be two tracks of the same <code>kind</code> with the same <code>label</code>.</li>
</ul>
<p>In the above example, we use a <code>&lt;video&gt;</code> element with two different <code>&lt;src&gt;</code> elements (for cross-browser loveliness). After the sources comes the <code>&lt;track&gt;</code> element. You can have several <code>&lt;track&gt;</code> elements as you might have subtitles, captions, and descriptions all in different languages.</p>
<p class="callout"><code>&lt;track&gt;</code> doesn’t presuppose a particular file format. <a href="http://html5labs.interoperabilitybridges.com/prototypes/video-captioning/video-captioning/info">Microsoft supports</a> the <a href="http://www.w3.org/TR/ttaf1-dfxp/"><abbr title="Timed Text Markup Language">TTML</abbr></a> format, but this format will not be implemented by other browser vendors.</p>
</section>
<section id="contents">
<h2>WebVTT Contents <a href="#contents" class="permalink">#</a></h2>
<p>We now know how to make a WebVTT file and how to reference it in an HTML document, but what goes inside it? Within the file, we list what are known as “cues”. The WebVTT file might only have one cue, but it can contain as many as you want. Each cue starts with an ID, followed by the time settings, followed by the text. Each cue is separated by a blank line. Here’s an example of captions:</p>
<figure>
<pre><code>WEBVTT

1
00:00:01.000 --&gt; 00:00:10.000
This is the first line of text, displaying from 1-10 seconds

2
00:00:15.000 --&gt; 00:00:20.000
And the second line of text
separated over two lines</code></pre>
<figcaption>WebVTT example content</figcaption>
</figure>
<p>The above example has two cues. Times must be written in <code>hh:mm:ss.mmm</code> format, so the timings in this example occur in the first twenty seconds. The second cue will split the text over two lines automatically.</p>
<p>If you have a segment of text that needs to appear in a karaoke/paint-on caption style, then you can place timers inline with text:</p>
<figure>
<pre><code>1
00:00:01.000 --&gt; 00:00:10.000
Never gonna give you up &lt;00:00:01.000&gt; Never gonna let you down &lt;00:00:05.000&gt; Never gonna run around and desert you</code></pre>
<figcaption>Karaoke-style captioning</figcaption>
</figure>
</section>
<section id="styling">
<h2>Styling Options <a href="#styling" class="permalink">#</a></h2>
<p>The previous examples specify the minimum configuration you need for subtitling and captioning, but you can style your captions too. Let’s start with the cue settings, which are done on the same line as the time settings:</p>
<dl>
<dt><code>D:vertical / D:vertical-lr</code></dt>
<dd>Display the text vertically rather than horizontally. This also specifies whether the text grows to the left (<code>vertical</code>) or to the right (<code>vertical-lr</code>).</dd>
<dt><code>L:X / L:X%</code></dt>
<dd>Either a number or a percentage. If a percentage, then it is the position from the top of the frame. If a number, this represents what line number it will be.</dd>
<dt><code>T:X%</code></dt>
<dd>The position of the text horizontally on the video. <code>T:100%</code> would place the text on the right side of the video.</dd>
<dt><code>A:start / A:middle / A:end</code></dt>
<dd>The alignment of the text within its box – <code>start</code> is left-aligned, <code>middle</code> is centre-aligned, and <code>end</code> is right-aligned.</dd>
<dt><code>S:X%</code></dt>
<dd>The width of the text box as a percentage of the video width.</dd>
</dl>
<p>To make use of these settings, put them alongside the time settings, like this:</p>
<pre><code>00:00:01.000 --&gt; 00:00:10.000 A:middle T:50%
00:00:01.000 --&gt; 00:00:10.000 A:end D:vertical
00:00:01.000 --&gt; 00:00:10.000 A:start T:100% L:0%</code></pre>
<p>which would result in something like the following:</p>
<figure>
    <img src="http://html5doctor.com/wp-content/uploads/2011/11/video-subtitles-demo1.png" alt="Examples of subtitle display" width="354" height="109" /></p>
<figcaption>Examples of subtitle display and alignment</figcaption>
</figure>
<p>Along with the above cue settings, you can use inline styles for text:</p>
<dl>
<dt>Bold text</dt>
<dd><code>&lt;b&gt;Lorem ipsum&lt;/b&gt;</code></dd>
<dt>Italic text</dt>
<dd><code>&lt;i&gt;dolor sit amet&lt;/i&gt;</code></dd>
<dt>Underlined text</dt>
<dd><code>&lt;u&gt;consectetuer adipiscing&lt;/u&gt;</code></dd>
<dt>Ruby text</dt>
<dd><code>&lt;ruby&gt;見&lt;rt&gt;み&lt;/rt&gt;&lt;/ruby&gt;</code></dd>
</dl>
<p>You can even apply a CSS class to a section of text using <code>&lt;c.myClass&gt;Lorem ipsum&lt;/c&gt;</code>, giving us many more styling options.</p>
<p>Finally, you can add a declaration representing the name of the voice: <code>&lt;v Tom&gt;Hello world&lt;/v&gt;</code>. This declaration accomplishes three things:</p>
<ol>
<li>The caption will display the voice (Tom) in addition to the caption text.</li>
<li>The name of the voice can be read by a screenreader, possibly event using a different voice for male or female names.</li>
<li>It offers a hook for styling so that, for example, all captions for Tom could be in blue.</li>
</ol>
<section id="chapters">
<h3>Chapters</h3>
<p>You can provide a chapter list for the video the same way you would provide subtitles or captions. Start with the same <code>WEBVTT</code> declaration, and then for each cue, declare the chapter number, the start and stop times, and the chapter title:</p>
<figure>
<pre><code>&lt;track src=&quot;chapters.vtt&quot; kind=&quot;chapters&quot; srclang=&quot;en&quot; /&gt;</code></pre>
<figcaption>HTML <code>&lt;track&gt;</code> element for providing chapters to a video</figcaption>
</figure>
<figure>
<pre><code>WEBVTT

Chapter 1
00:00:01.000 --&gt; 00:00:10.000>
Introduction to HTML5</code></pre>
<figcaption>WebVTT file containing video chapter markers</figcaption>
</figure>
</section>
</section>
<section id="browsers">
<h2>Browser Support <a href="#browsers" class="permalink">#</a></h2>
<p>One slight glitch with WebVTT: not a single browser currently supports it. All major browsers have started working on implementations, so we should see some results soon. Thankfully, in the meantime, there are several JavaScript polyfills available:</p>
<ul>
<li><a href="http://www.storiesinflight.com/js_videosub/">js_videosub</a></li>
<li><a href="http://www.delphiki.com/html5/playr/">Playr</a></li>
<li><a href="http://mediaelementjs.com/">MediaElementJS</a></li>
<li><a href="http://dev.mennerich.name/showroom/html5_video/">LeanBack player</a> (and upcoming <a href="http://leanbackplayer.com/test/webvtt.html">new version</a>)</li>
<li><a href="https://github.com/cgiffard/Captionator">Captionator</a>&nbsp;</li>
</ul>
</section>
<section id="demo">
<h2>Demo <a href="#demo" class="permalink">#</a></h2>
<p>We&#8217;ve put together a <a href="http://html5doctor.com/demos/webvtt/">quick demo</a> which uses the <a href="http://www.delphiki.com/html5/playr/">Playr</a> polyfill. We started using <a href="http://mediaelementjs.com/">MediaElementJS</a>, but it doesn’t sport as many features as <a href="http://www.delphiki.com/html5/playr/">Playr</a>, such as separate lines of text and CSS classes. In the <a href="http://html5doctor.com/demos/webvtt/">demo</a>, the subtitles start at 2 seconds and 15 seconds and use bold, underline, and custom styles. Here’s the <a href="http://html5doctor.com/demos/webvtt/subtitles.vtt">associated WebVTT file</a>.</p>
</section>
<section id="conclusion">
<h2>Conclusion <a href="#conclusion" class="permalink">#</a></h2>
<p>This article covers the basics of creating a WebVTT file suitable for subtitles or captions for a video. We know how to add cues and chapters and how to add styles and change how the text appears on the video. Although no browser yet supports it, there’s a lot more to come for accessible video, so stay tuned to the <a href="http://www.w3.org/community/texttracks/">W3C Web Media Text Tracks Community Group</a>.</p>
<p>What are your thoughts on WebVTT? Are any of you using it now? How can it be improved?</p>
<p>Finally, let’s thank <a href="http://twitter.com/#!/silviapfeiffer">@silviapfeiffer</a> for taking the time to answer some questions about WebVTT and for her tremendous work in this field.</p>
</section>
<section id="reading">
<h2>Reading <a href="#reading" class="permalink">#</a></h2>
<ul>
<li>Follow <a href="http://twitter.com/#!/silviapfeiffer">@silviapfeiffer</a></li>
<li><a href="http://www.w3.org/community/texttracks/">W3C Web Media Text Tracks Community Group</a></li>
<li><a href="http://blog.gingertech.net/2011/06/27/recent-developments-around-webvtt/">Recent developments around WebVTT</a></li>
<li><a href="http://html5videoguide.net/presentations/WebVTT/">Presentation: HTML5 video accessibility and the WebVTT file format</a></li>
<li><a href="http://www.youtube.com/watch?v=gK72pcu3cpk">HTML5 video accessibility and the WebVTT file format &#8211; Audio Described</a></li>
<li><a href="http://leanbackplayer.com/other/webvtt.html">A review with notes and thoughts for LeanBack Player</a></li>
<li><a href="http://quuz.org/webvtt/">WebVTT validator</a></li>
<li><a href="http://www.iandevlin.com/blog/2011/05/html5/webvtt-and-video-subtitles">WebVTT and Video Subtitles</a></li>
<li><a href="http://www.openmediadevelopers.org/pmwiki.php/Main/OVC2011VidA11y">The Open Video Alliance</a></li>
<li><a href="http://www.delphiki.com/webvtt/">Understanding WebVTT file format (draft)</a></li>
<li><a href="http://scottbw.wordpress.com/2011/06/28/creating-subtitles-and-audio-descriptions-with-html5-video/">Creating subtitles and audio descriptions with HTML5 video</a></li>
</ul>
</section>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/video-the-track-element-and-webm-codec/" rel="bookmark" class="crp_title">Video: the track element and webM codec</a></li>
<li><a href="http://html5doctor.com/the-video-element/" rel="bookmark" class="crp_title">The video element</a></li>
<li><a href="http://html5doctor.com/html5-simplequiz-4-figures-captions-and-alt-text/" rel="bookmark" class="crp_title">HTML5 Simplequiz #4: figures, captions and alt text</a></li>
<li><a href="http://html5doctor.com/your-questions-answered-8/" rel="bookmark" class="crp_title">Your Questions Answered #8</a></li>
<li><a href="http://html5doctor.com/html5-for-web-developers/" rel="bookmark" class="crp_title">HTML5 for Web Developers</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/video-subtitling-and-webvtt/" rel="bookmark">Video Subtitling and WebVTT</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on November 29, 2011.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/video-subtitling-and-webvtt/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>video + canvas = magic</title>
		<link>http://html5doctor.com/video-canvas-magic/</link>
		<comments>http://html5doctor.com/video-canvas-magic/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 14:34:53 +0000</pubDate>
		<dc:creator>Tab Atkins Jnr</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[JavaScript APIs]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=2554</guid>
		<description><![CDATA[<p>You've already learned about the <code>&#60;video&#62;</code> and <code>&#60;canvas&#62;</code> elements, but did you know that they were designed to be used together?  In fact, the two elements are absolutely wondrous when you combine them together.  I'm going to show off a few super-simple demos using the two elements together, which should help suggest cool future projects for you fellow web authors.</p>]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve already learned about the <a href="http://html5doctor.com/the-video-element/"><code>&lt;video&gt;</code></a> and <a href="http://html5doctor.com/an-introduction-to-the-canvas-2d-api/"><code>&lt;canvas&gt;</code></a> elements, but did you know that they were designed to be used together? In fact, the two elements are absolutely wondrous when you combine them! I&#8217;m going to show off a few super-simple demos using these two elements, which I hope will prompt cool future projects from you fellow web authors. (All of these demos work in every modern browser except Internet Explorer.)</p>

<h2>First, the basics</h2>

<p>If you&#8217;re just starting with <abbr>HTML</abbr>5, you may not be familiar with the <code>&lt;video&gt;</code> element and how to use it. Here&#8217;s a simple example that we&#8217;ll be using in the later demos:</p>

<pre><code>&lt;video controls loop&gt;
    &lt;source src=video.webm type=video/webm&gt;
    &lt;source src=video.ogg type=video/ogg&gt;
    &lt;source src=video.mp4 type=video/mp4&gt;
&lt;/video&gt;
</code></pre>

<p>The <code>&lt;video&gt;</code> element contains two attributes: <code>@controls</code> and <code>@loop</code>. <code>@controls</code> tells the browser to give the video the standard set of video controls: play/pause, scrubber, volume, etc. <code>@loop</code> tells the browser to start the video over again from the beginning once it ends.</p>

<p>Then, inside the <code>&lt;video&gt;</code> element, we have three child <code>&lt;source&gt;</code> elements, each pointing to a different encoding of the same video. The browser will try each source in order and play the first one that it understands.</p>

<p><a href="http://html5doctor.com/demos/video-canvas-magic/demo0.html">See this code in action</a>, playing the intro to one of the greatest cartoon series of all time.</p>

<figure>
  <img src="http://html5doctor.com/wp-content/uploads/2010/10/video_canvas_fig1.jpg" alt="" />
  <figcaption>HTML5 Video playing in Chrome</figcaption>
</figure>

<p>(A note about fallback: all of these demos assume that your browser has <code>&lt;video&gt;</code> support, which isn&#8217;t true in <abbr>IE</abbr>8 or earlier. Normally, it&#8217;s good practice to specify a Flash fallback or similar for those browsers, but that wouldn&#8217;t accomplish much here — all of the techniques I demonstrate rely on basic integration between the <code>&lt;video&gt;</code> element and the <code>&lt;canvas&gt;</code> element, which you can&#8217;t achieve with a Flash player. So I&#8217;ve omitted any non-<code>&lt;video&gt;</code> fallback content in these examples. I&#8217;ve still provided multiple sources, though, so all current browsers that do support <code>&lt;video&gt;</code> will be able to play it.)</p>

<h2>Now, a simple example</h2>

<p>Now that we know how to play a video, let&#8217;s mix in some <code>&lt;canvas&gt;</code> shenanigans. First, <a href="http://html5doctor.com/demos/video-canvas-magic/demo1.html">check out the demo</a>, then come back here for a code walkthrough.  I&#8217;ll wait.</p>

<p>&hellip;</p>

<figure>
  <img src="http://html5doctor.com/wp-content/uploads/2010/10/video_canvas_fig2.jpg" alt="" />
  <figcaption>Drawing video onto the canvas at full screen</figcaption>
</figure>

<p>Done? Cool! Now, how does this work? Surely it requires a few hundred lines of JavaScript, right? If you&#8217;ve cheated and already looked at the source code of the demo page, you&#8217;ll know how easy it is.</p>
  
<p>We start with this <abbr>HTML</abbr>:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;title&gt;Video/Canvas Demo 1&lt;/title&gt;

&lt;canvas id=c&gt;&lt;/canvas&gt;
&lt;video id=v controls loop&gt;
    &lt;source src=video.webm type=video/webm&gt;
    &lt;source src=video.ogg type=video/ogg&gt;

    &lt;source src=video.mp4 type=video/mp4&gt;
&lt;/video&gt;
</code></pre>

<p>Same video code as before, but now with a <code>&lt;canvas&gt;</code> element thrown into the mix. Kinda empty and useless at the moment, though. We&#8217;ll script it into action later.</p>

<p>Now, let&#8217;s pair that with some <abbr>CSS</abbr> to get things positioned right:</p>

<pre><code>&lt;style&gt;

body {
    background: black;
}

#c {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
}

#v {
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -180px 0 0 -240px;
}
&lt;/style&gt;
</code></pre>

<p>This just centers the video in the screen and stretches the canvas to the full width and height of the browser window. Since the canvas comes first in the document, it&#8217;ll be behind the video, exactly where we want it.</p>

<p>Now, here comes the magic!</p>

<pre><code>&lt;script&gt;
document.addEventListener('DOMContentLoaded', function(){
    var v = document.getElementById('v');
    var canvas = document.getElementById('c');
    var context = canvas.getContext('2d');

    var cw = Math.floor(canvas.clientWidth / 100);
    var ch = Math.floor(canvas.clientHeight / 100);
    canvas.width = cw;
    canvas.height = ch;

    v.addEventListener('play', function(){
        draw(this,context,cw,ch);
    },false);

},false);

function draw(v,c,w,h) {
    if(v.paused || v.ended) return false;
    c.drawImage(v,0,0,w,h);
    setTimeout(draw,20,v,c,w,h);
}
&lt;/script&gt;
</code></pre>

<p>Take that in for a moment. Just breathe deeply and absorb it. So short, so sweet, so pretty&hellip;</p>

<p>Now, let&#8217;s step through it.</p>

<pre><code>    var v = document.getElementById('v');
    var canvas = document.getElementById('c');
    var context = canvas.getContext('2d');

    var cw = Math.floor(canvas.clientWidth / 100);
    var ch = Math.floor(canvas.clientHeight / 100);
    canvas.width = cw;
    canvas.height = ch;
</code></pre>

<p>This part is simple. I grab hold of the video and canvas elements on the page, and I grab the canvas&#8217;s 2D-context so I can draw on it. Then I do some quick calculating to find out how wide and tall I want the canvas&#8217;s drawing surface to be. The <code>&lt;canvas&gt;</code> element itself is already stretched to the size of the screen via <abbr>CSS</abbr>, so this&#8217;ll make each pixel of the drawing surface equal to about 100&#215;100 pixels on the screen.</p>

<p>That last bit may need some explanation if you&#8217;re new to canvas. Normally, the visual size and the drawing-surface size of a <code>&lt;canvas&gt;</code> element will be the same. In that case, drawing a line 50px long will display a line 50px long. But that doesn&#8217;t have to be true — you can set the drawing surface&#8217;s size through the <code>@width</code> and <code>@height</code> properties on the <code>&lt;canvas&gt;</code> element itself, and then change the visual size of the canvas with <abbr>CSS</abbr> to be something different. The browser will then automatically upscale or downscale the drawing appropriately to make the drawing surface fill the visual size. In this case, I&#8217;m setting the drawing surface of the canvas to be very small — on most screens, it&#8217;ll be about 10px wide and 7px tall — and then stretching the visual size with <abbr>CSS</abbr> so that each pixel I draw gets blown up 100-fold by the browser. That&#8217;s what causes the cool visual effect in the demo.</p>

<pre><code>    v.addEventListener('play', function(){
        draw(v,context,cw,ch);
    },false);
</code></pre>

<p>Another simple part. Here I attach some code to the &#8220;play&#8221; event on the video element. This event gets fired whenever the user hits the &#8220;play&#8221; button to start watching the video. All I do is call the <code>draw()</code> function with the appropriate parameters: the video itself, the canvas&#8217;s drawing context, and the canvas&#8217;s width and height.</p>

<pre><code>function draw(v,c,w,h) {
    if(v.paused || v.ended) return false;
    c.drawImage(v,0,0,w,h);
    setTimeout(draw,20,v,c,w,h);
}
</code></pre>

<p>The first line just makes the function stop immediately if the user pauses or stops the video, so it&#8217;s not burning <abbr>CPU</abbr> when nothing&#8217;s changing. The third line calls the <code>draw()</code> function again, allowing the browser a little breathing space to do other things like update the video itself. I&#8217;m putting in a 20ms delay, so we&#8217;ll get roughly 50fps, which is more than enough.</p>

<p>The second line is where the magic happens — it draws the current frame of the video directly onto the canvas.  Yes, it&#8217;s exactly as simple as it looks. Just pass the video element and the x, y, width, and height of the rectangle on the canvas you want it to draw into. In this case, it&#8217;s filling up the entire canvas, but you could do less (or more!) if you wanted.</p>

<p>I&#8217;m using another trick here. Remember how the canvas is really tiny? The video will be at least 20 times bigger than the canvas on most screens, so how do we draw it onto such a tiny canvas? The <code>drawImage()</code> function handles that for us — it automatically scales whatever you hand it in the first argument so that it fills the rectangle you specify. That means we authors don&#8217;t have to worry about averaging the pixel colors (or extrapolating, if you&#8217;re drawing a small video into a big rectangle) because the browser does it all for us. I&#8217;ll use this trick more in the future, so watch out for it.</p>

<p>And&hellip;that&#8217;s it! The entire demo is done in 20 lines of easy-to-read JavaScript code, instantly producing a nifty background effect for any video you wish to play. You can trivially adjust the size of the &#8220;pixels&#8221; on the canvas by adjusting the lines that set the <var>cw</var> and <var>ch</var> variables.</p>

<h2>Directly manipulating video pixels</h2>

<p>The last demo was cool, but it just let the browser do all the heavy lifting. The browser downscaled the video, drew it onto the canvas, and then upscaled the canvas pixels, all automatically. Let&#8217;s try our hand at doing some of this ourselves! <a href="http://html5doctor.com/demos/video-canvas-magic/demo2.html">Check out the demo</a> to see this in action, where I convert the video to grayscale on the fly.</p>

<figure>
  <img src="http://html5doctor.com/wp-content/uploads/2010/10/video_canvas_fig3.jpg" alt="" />
  <figcaption>Video made greyscale with canvas manipulation</figcaption>
</figure>

<p>The HTML for the page is basically identical:</p>

<pre><code>&lt;video id=v controls loop&gt;
    &lt;source src=video.webm type=video/webm&gt;
    &lt;source src=video.ogg type=video/ogg&gt;
    &lt;source src=video.mp4 type=video/mp4&gt;
&lt;/video&gt;
&lt;canvas id=c&gt;&lt;/canvas&gt;

</code></pre>

<p>Nothing new here, so let&#8217;s move onto the script.</p>

<pre><code>document.addEventListener('DOMContentLoaded', function(){
    var v = document.getElementById('v');
    var canvas = document.getElementById('c');
    var context = canvas.getContext('2d');
    var back = document.createElement('canvas');
    var backcontext = back.getContext('2d');

    var cw,ch;

    v.addEventListener('play', function(){
        cw = v.clientWidth;
        ch = v.clientHeight;
        canvas.width = cw;
        canvas.height = ch;
        back.width = cw;
        back.height = ch;
        draw(v,context,backcontext,cw,ch);
    },false);

},false);

function draw(v,c,bc,w,h) {
    if(v.paused || v.ended) return false;
    // First, draw it into the backing canvas
    bc.drawImage(v,0,0,w,h);
    // Grab the pixel data from the backing canvas
    var idata = bc.getImageData(0,0,w,h);
    var data = idata.data;
    // Loop through the pixels, turning them grayscale
    for(var i = 0; i &lt; data.length; i+=4) {
        var r = data[i];
        var g = data[i+1];
        var b = data[i+2];
        var brightness = (3*r+4*g+b)&gt;&gt;&gt;3;
        data[i] = brightness;
        data[i+1] = brightness;
        data[i+2] = brightness;
    }
    idata.data = data;
    // Draw the pixels onto the visible canvas
    c.putImageData(idata,0,0);
    // Start over!
    setTimeout(function(){ draw(v,c,bc,w,h); }, 0);
}
</code></pre>

<p>The script is a bit longer this time, because we&#8217;re actually doing some work. But it&#8217;s still really simple!</p>

<pre><code>document.addEventListener('DOMContentLoaded', function(){
    var v = document.getElementById('v');
    var canvas = document.getElementById('c');
    var context = canvas.getContext('2d');
    var back = document.createElement('canvas');
    var backcontext = back.getContext('2d');

    var cw,ch;

    v.addEventListener('play', function(){
        cw = v.clientWidth;
        ch = v.clientHeight;
        canvas.width = cw;
        canvas.height = ch;
        back.width = cw;
        back.height = ch;
        draw(v,context,backcontext,cw,ch);
    },false);
</code></pre>

<p>This is almost the same as I had before, with two real differences.</p>

<p>First, I&#8217;m creating a second canvas and pulling the context out of it as well. This is a &#8220;backing canvas&#8221;, which I&#8217;ll use to perform intermediate operations before painting the final result into the visible canvas in the markup. The backing canvas doesn&#8217;t even need to be added to the document. It can just hang out here in my script. This strategy will be used a lot in later examples, and it&#8217;s quite useful in general, so take note of it.</p>

<p>Second, I&#8217;m waiting to resize the canvases until the video is played, rather than just sizing them immediately.  This is because the <code>&lt;video&gt;</code> element probably hasn&#8217;t loaded its video up when the <code>DOMContentLoaded</code> event fires, so it&#8217;s still using the default size for the element. By the time it&#8217;s ready to play, though, it knows the size of the video and has sized itself appropriately. At that point, we can set up the canvases to be the same size as the video.</p>

<pre><code>function draw(v,c,bc,w,h) {
    if(v.paused || v.ended) return false;
    bc.drawImage(v,0,0,w,h);
</code></pre>

<p>Same as the first demo, the <code>draw()</code> function begins by checking if it should stop, then just draws the video onto a canvas. Note that I&#8217;m drawing it onto the <em>backing</em> canvas, which, again, is just sitting in my script and isn&#8217;t displayed in the document. The visible canvas is reserved for the displaying the grayscale version, so I use the backing canvas to load up the initial video data.</p>

<pre><code>    var idata = bc.getImageData(0,0,w,h);
    var data = idata.data;
</code></pre>

<p>Here&#8217;s the first new bit. You can draw something onto a canvas with either the normal canvas drawing functions or <code>drawImage()</code>, or you can just manipulate the pixels directly through the ImageData object.  <code>getImageData()</code> returns the pixels from a rectangle of the canvas. In this case, I&#8217;m just getting the whole thing.</p>

<p><strong>Warning!</strong> If you&#8217;re following along and trying to run these demos on your desktop, this is where you&#8217;ll probably run into trouble. The <code>&lt;canvas&gt;</code> element keeps track of where the data inside of it comes from, and if it knows that you got something from another website (for example, if the <code>&lt;video&gt;</code> element you painted into the canvas is pointing to a cross-origin file), it&#8217;ll &#8220;taint&#8221; the canvas. You&#8217;re not allowed to grab the pixel data from a tainted canvas. Unfortunately, <code>file:</code> urls count as &#8220;cross-origin&#8221; for this purpose, so you can&#8217;t run this on your desktop. Either fire up a web server on your computer and view the page from localhost, or upload it to some other server you control.</p>

<pre><code>    for(var i = 0; i &lt; data.length; i+=4) {
        var r = data[i];
        var g = data[i+1];
        var b = data[i+2];
</code></pre>

<p>Now, a quick note about the ImageData object. It returns the pixels in a special way in order to make them easy to manipulate. If you have, say, a 100&#215;100 pixel canvas, it contains a total of 10,000 pixels. The ImageData array for it will then have 40,000 elements, because the pixels are broken up by component and listed sequentially. Each group of four elements in the ImageData array represent the red, green, blue, and alpha channels for that pixel. To loop through the pixels, just increment your counter by 4 every time, like I do here. Each channel, then, is an integer between 0 and 255.</p>

<pre><code>        var brightness = (3*r+4*g+b)&gt;&gt;&gt;3;
        data[i] = brightness;
        data[i+1] = brightness;
        data[i+2] = brightness;
</code></pre>

<p>Here, a quick bit of math converts the <abbr>RGB</abbr> value of the pixel into a single &#8220;brightness&#8221; value. As it turns out, our eyes respond most strongly to green light, slightly less so to red, and much less so to blue. So, I weight the channels appropriately before taking the average. Then, we just feed that single value back to all three channels. As we probably all know, when the red, green, and blue values of a color are equal, you get gray. (During this whole process, I&#8217;m completely ignoring the fourth member of each group, the alpha channel, because it&#8217;s always going to be 255.)</p>

<pre><code>    idata.data = data;
</code></pre>

<p>Shove the modified pixel array back into the ImageData object&hellip;</p>

<pre><code>    c.putImageData(idata,0,0);
</code></pre>

<p>&hellip;and then shove the whole thing into the visible canvas! We didn&#8217;t need to do any complicated drawing at all! Just grab the pixels, manipulate them, and shove them back in. So easy!</p>

<p>A final note: real-time full-video pixel manipulation is one of those rare places where micro-optimizations actually matter. You can see their effects in my code here. Originally, I didn&#8217;t pull the pixel data out of the ImageData object, and just wrote &#8220;var r = idata.data[i];&#8221; and so on each time, which meant several extra property lookups in every iteration of the loop. I also originally just divided the brightness by 8 and floored the value, which is slightly slower than bit-shifting by 3 places. In normal code, these sorts of things are <em>completely</em> insignificant, but when you&#8217;re doing them several million times per second (the video is 480&#215;360, and thus contains nearly 200,000 pixels, each of which is individually handled roughly 100 times a second), those tiny delays add up into a noticeable lag.</p>

<h2>More advanced pixel manipulation</h2>

<p>You can operate on more than just a single pixel at a time, too, composing some fairly complex visual effects. As I noted at the end of the previous section, performance matters a lot here, but you&#8217;d be surprised what you can squeeze out with a little creativity. <a href="http://html5doctor.com/demos/video-canvas-magic/demo4.html">As you can see in the demo</a>, I&#8217;ll be creating an emboss effect in this example, which requires you to use several input pixels together to compute the value of each output pixel.</p>

<figure>
  <img src="http://html5doctor.com/wp-content/uploads/2010/10/video_canvas_fig4.jpg" alt="" />
  <figcaption>Embossed video with canvas manipulation</figcaption>
</figure>

<p>Here&#8217;s the code. The <abbr>HTML</abbr> and most of the beginning code is identical to the previous example, so I&#8217;ve omitted everything but the <code>draw()</code> function:</p>

<pre><code>function draw(v,c,bc,cw,ch) {
    if(v.paused || v.ended) return false;
    // First, draw it into the backing canvas
    bc.drawImage(v,0,0,cw,ch);
    // Grab the pixel data from the backing canvas
    var idata = bc.getImageData(0,0,cw,ch);
    var data = idata.data;
    var w = idata.width;
    var limit = data.length
    // Loop through the subpixels, convoluting each using an edge-detection matrix.
    for(var i = 0; i &lt; limit; i++) {
        if( i%4 == 3 ) continue;
        data[i] = 127 + 2*data[i] - data[i + 4] - data[i + w*4];
    }
    // Draw the pixels onto the visible canvas
    c.putImageData(idata,0,0);
    // Start over!
    setTimeout(draw,20,v,c,bc,cw,ch);
}
</code></pre>

<p>Now let&#8217;s step through that.</p>

<pre><code>function draw(v,c,bc,cw,ch) {
    if(v.paused || v.ended) return false;
    // First, draw it into the backing canvas
    bc.drawImage(v,0,0,cw,ch);
    // Grab the pixel data from the backing canvas
    var idata = bc.getImageData(0,0,cw,ch);
    var data = idata.data;
</code></pre>

<p>Same as the last example. Check to see if we should stop, then draw the video onto the backing canvas and grab the pixel data from it.</p>

<pre><code>var w = idata.width;
</code></pre>

<p>The significance of this line needs some explanation. I&#8217;m already passing the canvas&#8217;s width into the function (as the <var>cw</var> variable), so why am I re-measuring its width here? Well, I was actually lying to you earlier when I explained how large the pixel array will be. The browser <em>might</em> have one pixel of canvas map to one pixel of ImageData, but browsers are allowed to use higher resolutions in the image data, representing each pixel of canvas as a 2&#215;2 block of ImageData pixels, or maybe 3&#215;3, or maybe even greater!</p>

<p>If they use a &#8220;high-resolution backing store&#8221;, as this is called, it means better display, as aliasing artifacts (jagged edges on diagonal lines) become much smaller and less noticeable. It also means that rather than a 100&#215;100 pixel canvas giving you an ImageData.data object with 40,000 numbers, it might have 160,000 numbers instead. By asking the ImageData for its width and height, we ensure that we loop through the pixel data properly no matter whether the browser uses a low-res or high-res backing store for it.</p>

<p>It&#8217;s very important that you use this properly whenever you need the width or height of the data you pulled out as an ImageData object. If too many people screw it up and just use the canvas&#8217;s width and height instead, then browsers will be forced to always use a low-res backing store to be compatible with those broken scripts!</p>

<pre><code>    var limit = data.length;
    for(var i = 0; i &lt; limit; i++) {
        if( i%4 == 3 ) continue;
        data[i] = 127 + 2*data[i] - data[i + 4] - data[i + w*4];
    }
</code></pre>

<p>I&#8217;m grabbing the data&#8217;s length and stuffing it into a variable, so I don&#8217;t have to pay for a property access on every single iteration of the loop. (Remember, micro-optimizations matter when you&#8217;re doing real-time video manipulation!) Then I just loop through the pixels, like I did before. If the pixel happens to be for the alpha channel (every fourth number in the array), I can just skip it — I don&#8217;t want to change the transparency. Otherwise, I&#8217;ll do a little math to find the difference between the current pixel&#8217;s color channel and the similar channels of the pixels below and to the right, then just combine that difference with the &#8220;average&#8221; gray value of 127. This has the effect of making areas where the pixels are the same color a flat medium gray, but edges where the color suddenly changes will turn either bright or dark.</p>

<p>There&#8217;s another optimization here. Because I&#8217;m only comparing the current pixel with pixels &#8220;further ahead&#8221; in the data which I haven&#8217;t looked at yet, I can just store the changed value right back in the original data, because nothing will ever look at the current pixel&#8217;s data again after this point. This means I don&#8217;t have to allocate a big array to hold the results before turning it back into an ImageData object.</p>

<pre><code>    c.putImageData(idata,0,0);
    setTimeout(draw,20,v,c,bc,cw,ch);
</code></pre>

<p>Finally, draw the modified ImageData object into the visible canvas, and set up another call to the function in 20 milliseconds. This is the same as the previous example.</p>

<h2>Wrapping up</h2>

<p>So, we&#8217;ve explored the basics of combining <abbr>HTML</abbr>5&#8242;s <code>&lt;canvas&gt;</code> and <code>&lt;video&gt;</code> elements today. The demos were very basic, but they illustrated all the essential techniques you&#8217;ll need to do something even cooler on your own:</p>

<ol>
<li>You can draw a video directly onto a canvas.</li>
<li>When you draw onto a canvas, the browser will automatically scale the image for you if necessary.</li>
<li>When you display a canvas, the browser will again scale it automatically if the visible size is different from the size of the backing-store.</li>
<li>You can do direct pixel-level manipulation of a canvas by just grabbing the ImageData, changing it, and drawing it back in.</li>
</ol>

<p>In Part 2 of this article [Ed: coming soon!], I&#8217;ll explore some more interesting applications of video/canvas integration, including a real-time video-to-ASCII converter!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul class="related"><li><a href="http://html5doctor.com/an-introduction-to-the-canvas-2d-api/" rel="bookmark" class="crp_title">An introduction to the Canvas 2D API</a></li><li><a href="http://html5doctor.com/getusermedia/" rel="bookmark" class="crp_title">It&#8217;s Curtains for Marital Strife Thanks to getUserMedia</a></li><li><a href="http://html5doctor.com/the-video-element/" rel="bookmark" class="crp_title">The video element</a></li><li><a href="http://html5doctor.com/using-modernizr-to-detect-html5-features-and-provide-fallbacks/" rel="bookmark" class="crp_title">Using Modernizr to detect HTML5 features and provide fallbacks</a></li><li><a href="http://html5doctor.com/review-html5-now-dvd/" rel="bookmark" class="crp_title">Review: HTML5 Now (DVD)</a></li></ul></div><p><a href="http://html5doctor.com/video-canvas-magic/" rel="bookmark">video + canvas = magic</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on October 20, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/video-canvas-magic/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>HTML5 Simplequiz #3: how to mute a video</title>
		<link>http://html5doctor.com/html5-simplequiz-3-how-to-mute-a-video/</link>
		<comments>http://html5doctor.com/html5-simplequiz-3-how-to-mute-a-video/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 08:35:16 +0000</pubDate>
		<dc:creator>Bruce Lawson</dc:creator>
				<category><![CDATA[Attributes]]></category>
		<category><![CDATA[JavaScript APIs]]></category>
		<category><![CDATA[multimedia]]></category>
		<category><![CDATA[Simplequiz]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[muted]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=2628</guid>
		<description><![CDATA[This is a bit of a special Simplequiz this week. Simon Pieters, who works on multimedia QA for Opera and is one of those working on the HTML5 spec, asked us to run a quiz that would help the spec writers decide on a new aspect of the language. ]]></description>
			<content:encoded><![CDATA[<p>This is a bit of a special Simplequiz this week. Simon Pieters (<a href="http://twitter.com/zcorpan">@zcorpan</a>), who works on multimedia QA for Opera and is one of those working on the HTML5 spec, asked us to run a quiz that would help the spec writers decide on a new aspect of the language. What power you wield, gentle reader! Over to Simon&hellip;</p>
<p>This SimpleQuiz is a bit different to previous SimpleQuizzes, since we&#8217;d like to use the result of this quiz to inform a design decision in the HTML5 spec. The question concerns how to mute a video in markup, and how this should be reflected in the DOM.</p>
<p>The use case is wanting to have multiple videos playing at once, but with all but one being muted at a time. This can be done today by setting <code>.muted = true</code> with script, but it would be more convenient to be able to mute with markup.</p>
<p>The <code>.muted</code> IDL attribute reflects the user setting of muted for the video element &#8212; if the user clicks &#8220;mute&#8221; in the native video controls, then the value of <code>.muted</code> changes, and vice versa. It would make sense for the browser to remember the mute setting for individual video elements on page reload (or later visit), so that the user doesn&#8217;t have to re-mute them.</p>
<p>This is where it starts to get hairy if we introduce a content attribute for muting. (Note that code fragments below aren&#8217;t real code, just suggestions.)</p>
<p>We could introduce <code>muted=""</code> which is reflected by <code>.muted</code> (i.e. if one changes, so does the other), but this would cause the DOM to mutate during parsing if the remembered setting doesn&#8217;t match the markup, i.e. you would get <code>muted=""</code> to appear in the DOM if the video is muted by the user even though there was no such attribute in the markup, which could confuse your scripts or style sheets if it&#8217;s not what you expected to happen.</p>
<p>We could introduce <code>defaultmuted=""</code> which is reflected by <code>.defaultMuted</code>, and just let the user setting change <code>.muted</code>, but <code>defaultmuted=""</code> is a bit long and ugly in markup.</p>
<p>We could have <code>muted=""</code> which is reflected by <code>.defaultMuted</code> and let the user setting change <code>.muted</code>, but it might be confusing for some people. On the other hand it is consistent with <code>&lt;input value&gt;</code> and <code>.defaultValue</code>.</p>
<p>What do you think? Which is the best option? Is there another option that is better than any of the above?
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/html5-audio-the-state-of-play/" rel="bookmark" class="crp_title">HTML5 Audio — The State of Play</a></li>
<li><a href="http://html5doctor.com/html5-simplequiz-4-figures-captions-and-alt-text/" rel="bookmark" class="crp_title">HTML5 Simplequiz #4: figures, captions and alt text</a></li>
<li><a href="http://html5doctor.com/the-nsfw-element/" rel="bookmark" class="crp_title">The nsfw element</a></li>
<li><a href="http://html5doctor.com/the-video-element/" rel="bookmark" class="crp_title">The video element</a></li>
<li><a href="http://html5doctor.com/html5-simplequiz-2-citing-people/" rel="bookmark" class="crp_title">HTML5 Simplequiz #2: citing people</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/html5-simplequiz-3-how-to-mute-a-video/" rel="bookmark">HTML5 Simplequiz #3: how to mute a video</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on October 15, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/html5-simplequiz-3-how-to-mute-a-video/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Video: the track element and webM codec</title>
		<link>http://html5doctor.com/video-the-track-element-and-webm-codec/</link>
		<comments>http://html5doctor.com/video-the-track-element-and-webm-codec/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 13:45:42 +0000</pubDate>
		<dc:creator>Bruce Lawson</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Attributes]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[multimedia]]></category>
		<category><![CDATA[codec]]></category>
		<category><![CDATA[track]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[webm]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=2089</guid>
		<description><![CDATA[There are a couple of interesting developments in the world of HTML5 multimedia that you'll be interested in&#8212;the webM video format, and a proposed solution to HTML5 multimedia accessibility.]]></description>
			<content:encoded><![CDATA[<p>There are a couple of interesting developments in the world of <abbr>HTML</abbr>5 multimedia that you&#8217;ll be interested in. The first is the new <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#the-track-element"><code>&lt;track&gt;</code> element</a> (currently only in the WHAT-WG spec due to political stuff).</p>

<p><code>&lt;track&gt;</code> is a child of a <code>&lt;video&gt;</code> or <code>&lt;audio&gt;</code> element that links to a <b>timed track</b>, or time-based data. The kind of data is set via a <code>kind</code> attribute, which can take values of <code>subtitles</code>, <code>captions</code>, <code>descriptions</code>, <code>chapters</code> or <code>metadata</code>, depending on the type of information you&#8217;re adding to your media. These point to a source file containing timed text that the browser will expose via some kind of user interface, if the visitor requires additional data.</p>

<p>This will allow for &#8220;write once, use everywhere&#8221; accessibility; anyone linking to that file with a <code>&lt;video&gt;</code> or <code>&lt;audio&gt;</code> element that includes the element can access your information.</p>

<pre><code>&lt;track kind=captions src=blah.srt&gt;</code></pre>

<p>The file format is a new format called <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#websrt">WebSRT</a>, which competes with about <a href="http://wiki.whatwg.org/wiki/Timed_track_formats">50 other timed formats</a>, including some W3C formats (hence the omission of <code>&lt;track&gt;</code> from the W3C spec).</p><p>Added 9 July 2010: Here&#8217;s a readable <a href="http://www.delphiki.com/websrt/">overview of the SRT format</a>.</p>

<p>Given that the format itself isn&#8217;t fully specified yet, it will be a while until we see implementation in browsers. But it&#8217;s good to know that there will be an official way to add accessibility information to media. Until then, I have a <a href="http://dev.opera.com/articles/view/accessible-html5-video-with-javascripted-captions/">JavaScript hack</a> to take timed <code>&lt;span&gt;</code>s out of an in-page transcript to superimpose over a video.</p>

<h2>WebM video format</h2>
<p>The big news of the last month is that Google open-sourced the VP8 video codec that it acquired when it <a href="http://investor.google.com/releases/2010/0219.html">took over On2 Technologies</a>. When combined with the Vorbis audio codec (that Spotify uses) and wrapped in a subset of the <a href="http://en.wikipedia.org/wiki/Matroska">Matroska container format</a>, it&#8217;s collectively known as <a href="http://www.webmproject.org/">WebM</a>.</p>

<p>All YouTube videos are being transcoded to WebM, and Adobe have also announced they will include it in their Flash player. It&#8217;s available in an <a href="http://www.opera.com/browser/next">Opera 10.60 beta</a>, a <a href="http://nightly.mozilla.org/webm/">Firefox testing build</a>, and a <a href="http://www.chromium.org/getting-involved/dev-channel">Chromium dev channel</a>. Even Microsoft have said that IE9 will support it if the codec is installed on the computer.</p>

<p>The <a href="http://www.streamingmedia.com/Articles/Editorial/Featured-Articles/First-Look-H.264-and-VP8-Compared-67266.aspx">VP8 video codec itself is high-quality</a> (Google had said that Ogg Theora wasn&#8217;t good enough compression-to-quality for YouTube, but Theora was based on the VP3 precursor to VP8). It&#8217;s available for <a href="http://zaheer.merali.org/articles/2010/06/02/webm-and-vp8-streaming-live-from-flumotion/">streaming</a> too.</p>

<p>If you want to encode to WebM, you can try the <a href="http://www.mirovideoconverter.com/">Miro Video Converter</a> utility. Although it doesn&#8217;t allow you to optimise settings, it&#8217;s very easy to use. As the codec becomes more widespread, expect to see many more tools for content creation, editing, and transcoding.</p>

<p>Once production versions of the browsers are available, you should encode your videos with WebM as the first option, Ogg for older versions of Opera, Firefox and Chrome, falling back to royalty-encumbered H.264 for Safari and links to downloads or a Flash player for legacy browsers:</p>

<pre><code>&lt;video controls&gt;
&lt;source src=video.webm type='video/webm; codecs="vorbis,vp8"'&gt;
&lt;source src=video.mp4 type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'&gt;
&lt;source src=video.ogv type='video/ogg; codecs="theora, vorbis"'&gt;
&lt;!-- embed Flash here --&gt;
&lt;p&gt;Your browser does not support video; download the &lt;a href=&quot;video.webm&quot;&gt;WebM&lt;/a&gt;, &lt;a href=&quot;video.mp4&quot;&gt;mp4&lt;/a&gt; or &lt;a href=&quot;video.ogg&quot;&gt;Ogg&lt;/a&gt; video for off-line viewing.&lt;/p&gt;
&lt;/video&gt;</code>
</pre>

<p>If, however, you&#8217;re having problems with the iPad, put the MP4 version first in the <code>&lt;source&gt;</code> element; apparently there&#8217;s a bug that causes the iPad only to see the first <code>&lt;source&gt;</code> element.</p>

<p>It’s a long haul, and it’s not over yet, but <code>&lt;track&gt;</code> and .webM show significant progress towards our goal of accessible, open, and royalty-free video playing natively in the browser.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul class="related"><li><a href="http://html5doctor.com/video-subtitling-and-webvtt/" rel="bookmark" class="crp_title">Video Subtitling and WebVTT</a></li><li><a href="http://html5doctor.com/youtube-and-vimeo-support-html5-video/" rel="bookmark" class="crp_title">YouTube and Vimeo support HTML5 Video</a></li><li><a href="http://html5doctor.com/the-video-element/" rel="bookmark" class="crp_title">The video element</a></li><li><a href="http://html5doctor.com/native-audio-in-the-browser/" rel="bookmark" class="crp_title">Native Audio in the browser</a></li><li><a href="http://html5doctor.com/review-html5-now-dvd/" rel="bookmark" class="crp_title">Review: HTML5 Now (DVD)</a></li></ul></div><p><a href="http://html5doctor.com/video-the-track-element-and-webm-codec/" rel="bookmark">Video: the track element and webM codec</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on June 24, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/video-the-track-element-and-webm-codec/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Your Questions Answered #5</title>
		<link>http://html5doctor.com/your-questions-5/</link>
		<comments>http://html5doctor.com/your-questions-5/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:30:55 +0000</pubDate>
		<dc:creator>Richard Clark</dc:creator>
				<category><![CDATA[Attributes]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[Questions]]></category>
		<category><![CDATA[Structure]]></category>
		<category><![CDATA[aside]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[img]]></category>
		<category><![CDATA[nav]]></category>
		<category><![CDATA[outline]]></category>
		<category><![CDATA[section]]></category>
		<category><![CDATA[sectioning]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=1400</guid>
		<description><![CDATA[We're back with our first round up of your questions for 2010. In this article we'll be covering a range of topics including sections and sectioning, the <code>img</code> element, scaling video and a proposal for a <code>field</code> element. ]]></description>
			<content:encoded><![CDATA[<p><img src="http://html5doctor.com/wp-content/uploads/2009/07/html5doctor-treatment.gif" alt="Doctor treating a patient illustration" class="alignright size-full wp-image-424" /> We&#8217;re back with our first roundup of your questions for 2010. In this article, we&#8217;ll be covering a range of topics including sections and sectioning, the <code>&lt;img&gt;</code> element, scaling video, and a proposal for a <code>&lt;field&gt;</code> element. </p>
<h2>Headers and sidebars</h2>
<p>Ad asked:</p>
<blockquote><p>Hello,</p>
<p>I have 2 questions:</p>
<p>1. If I have my main navigation above the masterhead would best practise be having the nav tag inside of a header tag with the h1 and h2 in a hgroup? Or should the nav and header tag be separate?</p>
<p>2. I am building a blog in HTML5. It has a blog-like sidebar with articles, contact info and about info in it. Would the best tag to wrap this in be section or aside?</p>
<p>Thank you so much for your time,<br />
Ad Taylor</p></blockquote>
<p>Placing your <code>&lt;nav&gt;</code> within your <code>&lt;header&gt;</code> is fine and valid. However, if it makes more sense to leave it outside, then you can do that too. You don&#8217;t need to put the <code>&lt;hgroup&gt;</code> inside the <code>&lt;nav&gt;</code> though.</p>
<p>See our articles on <a href="http://html5doctor.com/the-header-element/"><code>&lt;header&gt;</code></a> and <a href="http://html5doctor.com/nav-element/"><code>&lt;nav&gt;</code></a> for more on this.</p>
<p>Regarding your second question, I would use <code>&lt;aside&gt;</code> (as we&#8217;ve done on the HTML5 doctor site) and then use multiple sections within that. Also see Bruce&#8217;s article on <a href="http://html5doctor.com/designing-a-blog-with-html5/">Designing a blog with HTML5</a>.</p>
<p>Hope that helps.</p>
<p>Cheers, Rich</p>
<h2>HTML5 <code>&lt;img&gt;</code> element</h2>
<p>Martijn asked:</p>
<blockquote><p>As you are, according to the slogan, &#8220;helping [me] implement HTML5 today,&#8221; I thought to bother you people with a spec. related question.</p>
<p>What should an UA do with an image without specified width and height attributes?</p>
<p>The dimension attributes part of the specification keeps stating &#8220;if specified&#8221; for every rule but doesn&#8217;t give any &#8220;if not specified&#8221;.</p>
<p>The part of the specification defining the img element itself does not state anything of importance about the dimension attributes apart from how the attributes in the DOM should be created by the UA.</p>
<p>Interesting is to note that they have omitted these attributes in all their img element examples.</p>
<p>In the dimension attribute section they go state the following.</p>
<p> &#8211; The dimension attributes are not intended to be used to stretch the image.</p>
<p>So we can only use them to make images smaller? This is odd as well so let&#8217;s say by stretch they mean to say both expending and shrinking in size. In this case the attributes can only be used for two cases:</p>
<p>1. To state the exact width and height of the image. Something that seems redundant unless not using those attributes means the UA can display the image at any size (which it might, as nothing about this is defined in the spec.).</p>
<p>2. To give a 0 in both attributes. By this I am telling the UA that the image is not to be seen by the user.</p>
<p>Am I missing something or is the specification missing this?</p>
<p>Looking forward to getting your prescription ;)</p>
<p>Kind Regards, Martijn</p></blockquote>
<p>If no dimension attributes are specified, the browser will leave no space for the image, and once the image has been loaded (after the rest of the page), it will then need to reflow the entire page, as that&#8217;s the first time it knows the size of the image. This can cause the content you&#8217;re reading scrolling off the page.</p>
<p>If you give the size of the image as attributes in the HTML, the browser will leave space and render the image there once it&#8217;s loaded without reflowing the page. On a mobile phone, reflowing the page unnecessarily drains the battery, and users can get vertigo from the page&#8217;s text jumping around to accommodate images.</p>
<p>Thanks, Bruce</p>
<h2>Section and Sectioning</h2>
<p>Yanoo asked:</p>
<blockquote><p>Hi,</p>
<p>What do you mean when you are talking about &#8220;sectioning&#8221;? And why don&#8217;t header and footer require sectioning?</p>
<p>I think about section and sectioning like about part of something defined. News, comment, page content, sidebar, *header*, and *footer*. Is it bad representation?</p></blockquote>
<p>Sectioning relates to the headings in some block of related content and defining what is related to what in a hierarchy of headings (<code>&lt;h1&gt;</code>&ndash;<code>&lt;h6&gt;</code>). The outlining algorithm can produce a table of contents from the nested <code>&lt;section&gt;</code>, <code>&lt;article&gt;</code>, <code>&lt;nav&gt;</code>, and <code>&lt;aside&gt;</code> elements.</p>
<p>Headers and footers themselves do not change the outline; a header or footer may contain no headings. If a header or footer <em>does</em> contain a heading, then that heading does come into the outline. See our article on <a href="http://html5doctor.com/the-section-element/">the section element</a>.</p>
<p>Thanks, Bruce</p>
<h2>Scaling the Video</h2>
<p>Ian asked:</p>
<blockquote><p>Hi there,</p>
<p>Not sure if this question is an appropriate one, but any help would be really appreciated.</p>
<p>I&#8217;m going about updating my video website, chutney.ie, and would love to implement HTML5. I am interested in replicating the scaling effect/style used on the <a href="http://www.mozilla.com/en-US/firefox/3.5/firstrun/">Mozilla welcome page</a>.</p>
<p>Not being overly knowledgeable in this area, I would love to know how to begin &mdash; is this effect a Flash based animation, or something that can be achieved with HTML alone?</p>
<p>Again, any nudge in the right direction would be great.</p>
<p>Many thanks,</p>
<p>Ian</p></blockquote>
<p>I&#8217;m not sure how Mozilla did it, but you can use some of the Webkit and Mozilla transforms on the <code>&lt;video&gt;</code> element. For example, you can cause the video to grow on hover &mdash; <a href="http://people.opera.com/patrickl/articles/introduction-html5-video/transitions/">see this example in Chrome, Safari, or Opera</a>. You can also use the <code>:target</code> pseudoclass to initiate animations. Alternatively, you can use a JavaScript <code>onClick</code> event to create the same effect. </p>
<p>You can also combine <code>&lt;video&gt;</code> and <code>&lt;canvas&gt;</code> to provide some interesting results (laying the <code>&lt;canvas&gt;</code> over the <code>&lt;video&gt;</code>). For more on the <code>&lt;video&gt;</code> element and what it can do, please read the <a href="http://dev.opera.com/articles/view/introduction-html5-video/">Introduction to <abbr>HTML</abbr>5 Video</a> on dev Opera written by <a href="http://twitter.com/brucel">Bruce Lawson</a> and <a href="http://twitter.com/patrick_h_lauke">Patrick Lauke</a>.</p>
<p>Cheers, Rich</p>
<h2>We need a <code>&lt;field&gt;</code> tag</h2>
<p>John wrote in and proposed a field element:</p>
<blockquote><p>Hey there. First off thanks for the site. I was excited to find it. I spent a little time on the W3C site and honestly couldn&#8217;t figure out how to submit suggestions there. So going to submit mine to you guys and maybe you can pass it on (if it is good) or point me to someone that can help. Ok to the point:</p>
<p>We are getting nice new tags to with HTML5 (nav, footer, etc) to help us create more semantic code. I think what we really need is a <code>field</code> tag &mdash; after all what are fieldsets sets of?</p>
<p>Everyone wraps up their labels and inputs with some element. Some of us do this with UL, some people do it with DT/DD, some with DIVs and some people out there insist that a form is tabular data.</p>
<p>We are all just bastardizing these elements because there is no clear semantic wrapper for field elements of a form.</p>
<p>I think you get the point. I&#8217;m trying to keep this email short. If you think there is anything to this argument, I have a more detailed summary (with example code) at:</p>
<p><a href="http://john.mirick.me/2009/10/what-is-really-set-of-shouldnt-we-have.html">http://john.mirick.me/2009/10/what-is-really-set-of-shouldnt-we-have.html</a></p>
<p>I would love to hear your thoughts on this.</p>
<p>Thanks!<br />
John</p></blockquote>
<p>While a field element would be nice &mdash; it would stop the argument over how best to mark-up forms &mdash; you have to ask yourself whether or not it actually adds any semantic or functional value to an HTML document. Yes, wrapping inputs and their labels in a field would make things easier to read and drop the need for the <code>for</code> attribute on the label (since the relationship can be assumed), but doing so would not be backwards compatible. In theory, we could continue to add <code>for</code> until there is a suitable time to drop it, but again I question the value of such a tag.</p>
<p>The purpose of wrapping form input/label pairs is generally to ease styling. My personal stance is that unless there are case studies showing how such an element can add more value to HTML forms, this proposal won&#8217;t make it very far.</p>
<p>Regards, Mike</p>
<h2>Got a question for us?</h2>
<p>That wraps up this round of questions. If you&#8217;ve got a query about the HTML5 spec or how to implement it, you can <a href="http://html5doctor.com/ask-the-doctor/">get in touch</a> with us and we&#8217;ll do our best to help. </p>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/your-questions-answered-8/" rel="bookmark" class="crp_title">Your Questions Answered #8</a></li>
<li><a href="http://html5doctor.com/your-questions-answered-7/" rel="bookmark" class="crp_title">Your Questions Answered #7</a></li>
<li><a href="http://html5doctor.com/your-questions-answered-11/" rel="bookmark" class="crp_title">Your Questions Answered #11</a></li>
<li><a href="http://html5doctor.com/your-questions-answered-6/" rel="bookmark" class="crp_title">Your Questions Answered #6</a></li>
<li><a href="http://html5doctor.com/your-questions-18/" rel="bookmark" class="crp_title">Your Questions 18</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/your-questions-5/" rel="bookmark">Your Questions Answered #5</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on March 2, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/your-questions-5/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>YouTube and Vimeo support HTML5 Video</title>
		<link>http://html5doctor.com/youtube-and-vimeo-support-html5-video/</link>
		<comments>http://html5doctor.com/youtube-and-vimeo-support-html5-video/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 16:08:28 +0000</pubDate>
		<dc:creator>Richard Clark</dc:creator>
				<category><![CDATA[Browser Compatibility]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[vimeo]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=1315</guid>
		<description><![CDATA[Unless you've been hiding under an <abbr>XHTML</abbr>2 shaped rock for the past week or so you'll know that both YouTube and Vimeo have announced plans to support the <abbr>HTML</abbr>5 video element.]]></description>
			<content:encoded><![CDATA[<p>Unless you&#8217;ve been hiding under an <abbr>XHTML</abbr>2 shaped rock for the past week or so, you&#8217;ll know that both YouTube and Vimeo have announced plans to support the <abbr>HTML</abbr>5 video element. Two <a href="http://youtube-global.blogspot.com/2010/01/introducing-youtube-html5-supported.html" title="Introducing YouTube HTML5 Supported Videos">blog</a> <a href="http://www.vimeo.com/blog:268" title="Try our new HTML5 player! on Vimeo Staff Blog">posts</a> published last week announced that the two major players in online video are experimenting with the <abbr>HTML</abbr>5 <a href="http://html5doctor.com/the-video-element/"><code>&lt;video&gt;</code> element</a>.</p>
<p><img src="http://html5doctor.com/wp-content/uploads/2010/01/yt-vimeo.jpg" alt="YouTube and Vimeo Logos" /></p>
<h2>Will it work cross browser?</h2>
<p>The videos will work natively in Safari and Chrome (well, YouTube would certainly have to, wouldn&#8217;t it?). They&#8217;ll also work in <abbr>IE</abbr> if you have <a href="http://code.google.com/chrome/chromeframe/">ChromeFrame</a> installed (which we all know is cheating). If you&#8217;re using a browser that doesn&#8217;t support <abbr>HTML</abbr>5 video it will default back to the Flash method they currently employ.</p>
<p>Both YouTube and Vimeo use the H.264 codec to encode the videos &mdash; and that&#8217;s where things start to get complicated.</p>
<p>Since no official codec is defined in the spec <ins>because</ins> browser manufacturers have chosen to use different codecs to render <abbr>HTML</abbr>5 video. Opera and Mozilla use the Ogg Theora codec (more on that later), while Apple and Google use H.264. Who knows which side of the fence Microsoft will come down on, but I feel duty bound to mention that the licensors of the H.264 codec include both <a href="http://www.mpegla.com/main/programs/AVC/Pages/Licensors.aspx">Microsoft and Apple</a>.</p>
<h2>The elephant in the room</h2>
<p>There&#8217;s one major problem here: Ogg Theora, the open source video codec supported by both Firefox and Opera, is not supported on either site. It&#8217;s a shame these browsers aren&#8217;t supported, especially since <a href="http://blog.mozilla.com/blog/2010/01/21/firefox-3-6-release/">Firefox 3.6 was released last week</a> and announced support for full-screen video in its native video player.</p>
<h3>Why use Ogg?</h3>
<p>As previously stated, Ogg is an open source codec, meaning it&#8217;s free to use and implement. By contrast, support for native H.264 decoding in a browser costs approximately &#036;5 million per year. (See <a href="http://www.mpegla.com/main/programs/avc/Documents/AVC_TermsSummary.pdf"><cite>summary of AVC/H.264 license terms [PDF]</cite></a>.) It also seems that people creating H.264 content will be liable for royalties starting in 2011.</p>
<p>Far be it from me to get into the ins and outs of the debate over which codec to use, but it seems that open source would be the better way to go. Silivia Pfeiffer (a contractor for Mozilla) <a href="http://blog.gingertech.net/2010/01/25/html5-video-25-h-264-reach-vs-95-ogg-theora-reach/">claims</a> that serving as Ogg Theora will reach more people than serving as H264.</p>
<p>Google, on the other hand, which owns YouTube has said that Theora is not a good enough codec, claiming &#8220;If [youtube] were to switch to theora and maintain even a semblance of the current youtube quality it would take up most available bandwidth across the Internet&#8221;, a claim hotly (and convincingly) contested in Greg Maxwell&#8217;s <a href="http://people.xiph.org/~greg/video/ytcompare/comparison.html">YouTube / Ogg/Theora comparison</a>.</p>
<p>YouTube and Vimeo seem to have discounted Ogg. I&#8217;d love to find out if there are other plans to add support for Firefox and Opera.</p>
<h2>Where does that leave us?</h2>
<p>Ignoring the whole video codec debate, it leaves us in some ways back where we started &mdash; dealing with proprietary software or complicated licensing to create online content rather than using technologies that will allow us to have a truly open web.</p>
<p>With Apple, Google, Mozilla, and Opera not likely to budge on their respective codec choices for <abbr>HTML</abbr>5 video, we can only hope that the developers at market-leading sites like YouTube and Vimeo can implement cross-browser interoperable video just like Kroc Camen&#8217;s <a href="http://camendesign.com/code/video_for_everybody">Video for Everybody</a>. Judging by the aforementioned blog posts, both sites have more plans in the pipeline, which is encouraging.</p>
<p>The codec battles are only beginning, and we&#8217;re waiting to see which direction one big gun will point. Last year, Google (which owns YouTube) <a href="http://googleblog.blogspot.com/2009/08/innovation-in-video-on-web.html">announced</a> that is paying $104million for a company called On2 Technologies, &#8220;a leading creator of high-quality video compression technology&#8221; and which made the original <a href="http://en.wikipedia.org/wiki/VP3#History">VP3 codec</a> which is the basis for Ogg Theora.</p>
<p>What are their plans? To release a &#8220;better&#8221; Theora-like codec into the community? We can only speculate.</p>
<p>Back to today. Although not perfect, these sites&#8217; support for the <code>&lt;video&gt;</code> element is still a massive leap forward for <abbr>HTML</abbr>5. Who knows &mdash; if more large sites continue to adopt <abbr>HTML</abbr>5, maybe it&#8217;ll be ready in 2010 rather than 2022!</p>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/video-the-track-element-and-webm-codec/" rel="bookmark" class="crp_title">Video: the track element and webM codec</a></li>
<li><a href="http://html5doctor.com/the-video-element/" rel="bookmark" class="crp_title">The video element</a></li>
<li><a href="http://html5doctor.com/your-questions-answered-6/" rel="bookmark" class="crp_title">Your Questions Answered #6</a></li>
<li><a href="http://html5doctor.com/native-audio-in-the-browser/" rel="bookmark" class="crp_title">Native Audio in the browser</a></li>
<li><a href="http://html5doctor.com/review-html5-now-dvd/" rel="bookmark" class="crp_title">Review: HTML5 Now (DVD)</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/youtube-and-vimeo-support-html5-video/" rel="bookmark">YouTube and Vimeo support HTML5 Video</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on January 23, 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/youtube-and-vimeo-support-html5-video/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Why designers should care about HTML5</title>
		<link>http://html5doctor.com/why-designers-should-care-about-html5/</link>
		<comments>http://html5doctor.com/why-designers-should-care-about-html5/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 13:01:06 +0000</pubDate>
		<dc:creator>Cennydd Bowles</dc:creator>
				<category><![CDATA[Comment]]></category>
		<category><![CDATA[JavaScript APIs]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[drag and drop]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=973</guid>
		<description><![CDATA[After a while on the fringes of our collective consciousness, HTML5 is finally getting the attention it deserves. The development community (as typified by the SuperFriends) has come together to debate practical elements of the spec, argue over the inclusion of controversial elements, and assess the timeframe over which we can unleash HTML5 in the wild.]]></description>
			<content:encoded><![CDATA[<p>After a while on the fringes of our collective consciousness, <abbr title="Hypertext Markup Language 5">HTML5</abbr> is finally getting the attention it deserves. The development community (as typified by the <a href="http://www.zeldman.com/superfriends/">SuperFriends</a>) has come together to debate practical elements of the spec, argue over the inclusion of controversial elements, and assess the timeframe over which we can unleash <abbr>HTML</abbr>5 in the wild.</p>
<p>However those of us more accustomed to the world of Post-Its, sketches, and .psds – the designers – haven’t been so vocal. Perhaps we&#8217;ve been distracted by the bright lights of <a href="http://www.css3.info/">CSS3</a> and those surface thrills we’ve longed for. (Rounded corners! Gradients! Transparency!) Or, alternatively, we&#8217;ve been in the thrall of <code>@font-face</code> and looking forward to the coming age of passable web typography.</p>
<p>Understandable. But it’s time designers got excited about <abbr>HTML</abbr>5 too.</p>
<p>Partly, it’s just good practice. Whatever your flavour of design &ndash; visual, web, interaction, user experience &ndash; knowing the native technology makes you better at your job. Just as composers should understand the capabilities of the orchestra&#8217;s instruments, designers need to understand the language of the web.</p>
<p>But there’s more to <abbr>HTML</abbr>5 than simply keeping our skills sharp. It could make a big difference to the way we design for the web.</p>
<h2>Semantic elements</h2>
<p>Information architects (and, by extension, user experience designers) should be excited by the new <abbr>HTML</abbr>5 elements – <code>&lt;nav&gt;</code>, <code>&lt;header&gt;</code>, <code>&lt;aside&gt;</code> and so on. While they won’t immediately revolutionise today’s web, they’re an investment for the future. Doing useful stuff with information is the central theme of <abbr title="information architecture">IA</abbr>, and therefore its practitioners should be at the forefront of the new experiences that machine-readable semantics will offer. <abbr>HTML</abbr>5 allows us to mark text up in a more meaningful way than a sea of <code>&lt;div&gt;</code>s, meaning we’ll soon see applications appearing at a sub-page level. We’ve started to scratch the surface – think about the <a href="https://addons.mozilla.org/en-US/firefox/addon/4106">Operator toolbar</a> or customisable UIs à la <a href="http://www.google.com/ig">iGoogle</a> – but we’ll need detailed design thinking to work out how to bring the benefits of semantic richness to the end user.</p>
<h2>APIs and other extensions</h2>
<p>While it’s clear that <a href="http://www.quirksmode.org/blog/archives/2009/09/the_html5_drag.html">some of the <abbr>HTML</abbr>5 APIs are far from perfect</a> right now, when they&#8217;re refined they will offer us intriguing new opportunities and challenges.</p>
<p>Designers of location-based services should of course find the <a href="http://dev.w3.org/geo/api/spec-source.html">geolocation API</a> invaluable. The <a href="http://blog.whatwg.org/the-road-to-html-5-contenteditable">contentEditable attribute</a> gives us further power to make the web truly read/write without resorting to JavaScript and custom interfaces. New input types (eg <code>type=&quot;search&quot;</code>) can provide extra visual cues about input function, although of course this depends on the solutions chosen by the browser manufacturers.</p>
<p>Until now, it’s been easy to consider our domain as bounded by the viewport and the web server. But <abbr>HTML</abbr>5 is another step toward seamlessness: the merging of desktop, offline and online. For instance, the <a href="/native-drag-and-drop/">drag and drop API</a> could see the line between online and desktop experience blur further. Local storage could allow for a web-like experience in areas of poor connectivity. This convergence is clearly a good thing, but we must also design how to expose those hidden seams at the user’s request. Users should stay in control of how their locations are published and what data is synchronised to their machine.</p>
<h2>&lt;video&gt;, &lt;audio&gt;, &lt;canvas&gt;</h2>
<p>There is of course something of a reported schism between the standards world and the Flash world. Some see the advent of these new media elements (particularly <code>&lt;canvas&gt;</code>) as heralding the death of Adobe’s poster child.</p>
<p>I don&#8217;t think this is either likely or desirable. Neither technology is perfect. Flash is, of course, proprietary and thus subject to the whims of a third party that stands between browser and user. <code>&lt;canvas&gt;</code> has <a href="http://esw.w3.org/topic/HTML/AddedElementCanvas">known accessibility problems</a>. But the two can live in harmony, if we play to their respective strengths. Some current Flash applications might be better suited to <code>&lt;canvas&gt;</code>, particularly those based around dynamic visualisation: graphs, animations, infographics. Some applications will benefit from the powerful capabilities of Flash: games, heavily interactive widgets.</p>
<p>This aside, there’s clearly a user experience benefit in not having to rely on an external plugin to play rich media elements, and it will be interesting to see the uptake of the <code>&lt;video&gt;</code> and <code>&lt;audio&gt;</code> elements. Although it will initially be down to browser makers to define the interface elements involved, we will need to figure out how to integrate them into everyday web experiences. The good news is that they can be styled in the same way as any other <abbr>HTML</abbr> element. If your visual aesthetic relies on slanted images with box shadows, it&#8217;s trivial to apply this to video too.</p>
<p>That said, we can&#8217;t ignore the elephant in the room: <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2009-June/020620.html">the thorny codec issue</a>. I&#8217;m sure we&#8217;d all agree that the sooner it&#8217;s resolved, the better.</p>
<h2>What can designers do?</h2>
<p>Only the most patient and detail-oriented designer will relish the idea of reading the spec in full and arguing the finer points on the <a href="http://www.whatwg.org/mailing-list">WHATWG list</a>. That’s just not the way designers roll.</p>
<p>But as a community it’s important that we start talking about <abbr>HTML</abbr>5. If you&#8217;re new to <abbr>HTML</abbr>, now&#8217;s a great time to learn. The <a href="/article-archive/">articles on this site</a> and <a href="http://www.alistapart.com/articles/previewofhtml5/">A preview of HTML5</a> give useful guidance on the differences between <abbr>HTML</abbr>5 and its predecessors. Above all, designers should get chatting with their developer friends: there can’t be many left who no longer have an opinion on this technology. How do they see their practices changing? What can we do today to prepare our sites for the advent of HTML5? How can we build on its strong points to make the web a better place?</p>
<p>We don&#8217;t yet know what we&#8217;ll accomplish with <abbr>HTML</abbr>5, but then it&#8217;s not often that the vocabulary of the web changes this deeply. However, one thing is clear: if we prepare now, we have a great chance to bring innovation to our users&#8217; online lives.</p>
<p class="disclaimer">This article was jointly published on <a href="http://www.cennydd.co.uk/">Ineffable</a>, Cennydd&#8217;s personal website.</p>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/reviewing-html5-for-web-designers/" rel="bookmark" class="crp_title">Reviewing HTML5 for Web Designers</a></li>
<li><a href="http://html5doctor.com/html5-briefing-notes-journalists-analysts/" rel="bookmark" class="crp_title">HTML5: briefing notes for journalists and analysts</a></li>
<li><a href="http://html5doctor.com/native-audio-in-the-browser/" rel="bookmark" class="crp_title">Native Audio in the browser</a></li>
<li><a href="http://html5doctor.com/web-directions-atmedia-2010/" rel="bookmark" class="crp_title">HTML5 Doctor at Web Directions @media</a></li>
<li><a href="http://html5doctor.com/draw-attention-with-mark/" rel="bookmark" class="crp_title">Draw attention with mark</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/why-designers-should-care-about-html5/" rel="bookmark">Why designers should care about HTML5</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on October 14, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/why-designers-should-care-about-html5/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Your questions answered #1</title>
		<link>http://html5doctor.com/your-questions-answered-1/</link>
		<comments>http://html5doctor.com/your-questions-answered-1/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 10:59:36 +0000</pubDate>
		<dc:creator>Richard Clark</dc:creator>
				<category><![CDATA[Elements]]></category>
		<category><![CDATA[Questions]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[html4.01]]></category>
		<category><![CDATA[section]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=390</guid>
		<description><![CDATA[One week on since our official launch and we've been overwhelmed by your response to the site. It's great to see a large number of you wanting to get involved with the discussion relating to <abbr>HTML</abbr> 5 and asking about what you can and can't do as well as the pro's and cons of the specification. In this post we're going to cover a few of the questions we've received that don't require a full post answer but still need to be addressed.]]></description>
			<content:encoded><![CDATA[<p><img src="http://html5doctor.com/wp-content/uploads/2009/07/html5doctor-treatment.gif" alt="Doctor treating a patient illustration" class="alignright size-full wp-image-424" /> One week on since our official launch and we&#8217;ve been overwhelmed by your response to the site. It&#8217;s great to see a large number of you wanting to get involved with the discussion relating to <abbr>HTML</abbr> 5 and asking about what you can and can&#8217;t do as well as the pro&#8217;s and cons of the specification.</p>
<p>In this post we&#8217;re going to cover a few of the questions we&#8217;ve received that don&#8217;t require a full post answer but still need to be addressed. We&#8217;ll post more answers everytime we&#8217;ve collated a bunch of questions so don&#8217;t be afraid to ask, however groundbreaking or insignificant it might be. Ok here we go for starters&hellip;</p>
<h2>Automated Conversion?</h2>
<p>Andy Mabbett wrote to ask:</p>
<blockquote><p>Are there (or will there be) any automated or semi-automated tools which will take my (valid) HTML 4.01 Strict documents and convert them to HTML5?</p></blockquote>
<p>While we don&#8217;t know about any specific conversion tools for converting to <abbr>HTML</abbr> 5 from <abbr>HTML</abbr> 4.01. There are several articles (see below) describing how you can name your classes more semantically in preparation for using <abbr>HTML</abbr> 5. </p>
<ul>
<li><a href="http://forabeautifulweb.com/blog/about/more_on_developing_naming_conventions_microformats_and_html5/">More on developing naming conventions, Microformats and HTML5</a></li>
<li><a href="http://jontangerine.com/log/2008/03/preparing-for-html5-with-semantic-class-names">Preparing for HTML5 with Semantic Class Names</a></li>
<li><a href="http://boblet.tumblr.com/post/60552152/html5">HTML5 id/class name cheatsheet</a></li>
</ul>
<p>A final point on this is that I&#8217;m not sure that it would be wise to have a converter in order to move from <abbr>HTML</abbr> 4.01 to <abbr>HTML</abbr> 5, a machine however clever will not really be able to understand the true meaning of <code>&lt;aside&gt;</code> or <code>&lt;figure&gt;</code> for example. I&#8217;d be interested to hear other peoples thoughts on this though?</p>
<h2>When should I start using <abbr>HTML</abbr> 5?</h2>
<p>James asked us (presumably a little tongue in cheek):</p>
<blockquote><p>
Dear Doctor, </p>
<p>When will I know that it is time to start using HTML5 &#8220;for real&#8221;? Will there be an announcement? </p>
<p>yours etc,<br />
James</p></blockquote>
<p>Now I&#8217;d love there to be an official annoucement, in fact I might just announce it now! <strong>You can all start using <abbr>HTML</abbr> 5 today</strong>. There I said it, I feel so much better now. Seriously though, there is no reason for you not to start using <abbr>HTML</abbr> 5 now in sites you&#8217;re developing. I&#8217;m not saying that you have to use it religiously, but at you should at least start thinking about it in your development roadmaps. We can see on our <a href="http://html5gallery.com/">sister site</a> that there are a number of sites using <abbr>HTML</abbr> 5 &#8220;in the wild&#8221;. The amount of implementation varies greatly (some including <code>&lt;div&gt;</code>&#8216;s around their <code>&lt;header&gt;</code> elements for styling purposes for example) but they have begun to incorporate <abbr>HTML</abbr> 5 right now.</p>
<p>Lastly, <a href="http://molly.com/">Molly</a> recently gave a talk at <a href="http://www.vivabit.com/atmedia2009/">@media</a> which touched upon this subject, she told us that</p>
<blockquote><p>Implementation trumps specification</p></blockquote>
<p>which I happen to firmly believe, after all <abbr>CSS</abbr> 2.1 isn&#8217;t a formal specification yet but almost everyone is using it. If you&#8217;re not sure where to start then I suggest taking a look at what browser implementations are currently like, which is where this <a href="http://wiki.whatwg.org/wiki/Implementations_in_Web_browsers">Wiki from the WHATWG</a> comes in. Hope that answers your question James.</p>
<h2>Main Body</h2>
<p>Darren asked:</p>
<blockquote><p>How do I markup the main body of a page, are there &lt;content&gt; tags? Can I serve a SWF Flash file using &lt;VIDEO&gt; tags? </p>
<p>Regards Darren</p></blockquote>
<p>There isn&#8217;t a <code>&lt;content&gt;</code> tag (element), the most appropriate element for that would be <code>&lt;section&gt;</code>, however if only a single article is contained in that area you should use <code>&lt;article&gt;</code>.</p>
<p>As for the second part to your question, you *can&#8217;t* use a SWF file natively as the source to the <code>&lt;video&gt;</code> tag, or FLV file for that matter.  However, for the foreseeable future you&#8217;re still going to need to embed flash for video, via nesting the flash within the <code>&lt;video&gt;</code> tag.</p>
<p>First you&#8217;ll use the <code>&lt;video&gt;</code> with nested source elements to fall through the different supported codecs.  Then when all else fails, particularly for IE, you&#8217;ll serve up the flash video via the <code>&lt;object&gt;</code> and <code>&lt;embed&gt;</code> combo.  This is because IE8 and lower doesn&#8217;t support the <code>&lt;video&gt;</code> you&#8217;re going to need to fall back on something that works.</p>
<p>Make sure you read Tom&#8217;s article about <a href="/the-video-element/">the <code>&lt;video&gt;</code> element</a>, but you should also find this article on <a href="http://camendesign.com/code/video_for_everybody">Video for Everybody</a> useful to see how to degrade through the codecs.</p>
<h2>More articles!</h2>
<p>Although not really a question I wanted to drop this in, August wrote to tell us:</p>
<blockquote><p>The <code>&lt;aside&gt;</code> article is awesome. Great explanation of a very semantic HTML5 element. More of those, please!</p></blockquote>
<p>Thanks for the great feedback August, we&#8217;re happy to help, rest assured we&#8217;ve got plenty of articles lined up along those lines, in fact I know we&#8217;ve got a few crackers lined up for the next couple of weeks, so watch this space.</p>
<h2>And finally&hellip;</h2>
<p>If your question hasn&#8217;t been answered in this post or we haven&#8217;t got back to you directly then it&#8217;s more than likely that we&#8217;ll be covering it soon in a more detailed post so be sure to check back or subscribe to the <a href="http://html5doctor.com/feed/">RSS feed</a> for all future articles.</p>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/your-questions-answered-2/" rel="bookmark" class="crp_title">Your questions answered #2</a></li>
<li><a href="http://html5doctor.com/your-questions-12/" rel="bookmark" class="crp_title">Your Questions Answered #12</a></li>
<li><a href="http://html5doctor.com/your-questions-answered-6/" rel="bookmark" class="crp_title">Your Questions Answered #6</a></li>
<li><a href="http://html5doctor.com/the-video-element/" rel="bookmark" class="crp_title">The video element</a></li>
<li><a href="http://html5doctor.com/your-questions-answered-8/" rel="bookmark" class="crp_title">Your Questions Answered #8</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/your-questions-answered-1/" rel="bookmark">Your questions answered #1</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on July 6, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/your-questions-answered-1/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The video element</title>
		<link>http://html5doctor.com/the-video-element/</link>
		<comments>http://html5doctor.com/the-video-element/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 23:58:46 +0000</pubDate>
		<dc:creator>Tom Leadbetter</dc:creator>
				<category><![CDATA[Attributes]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://html5doctor.com/?p=65</guid>
		<description><![CDATA[The &#60;video&#62; element is brand new in HTML 5 and allows you to, get this, play a movie in your website! The data of this element is supposed to be video but it might also have audio or images associated with it. Of course, this will only work in a few browsers: Safari 3.1+, Firefox [...]]]></description>
			<content:encoded><![CDATA[<p>The &lt;video&gt; element is brand new in HTML 5 and allows you to, get this, play a movie in your website! The data of this element is supposed to be video but it might also have audio or images associated with it.</p>
<p>Of course, this will only work in a few browsers: Safari 3.1+, Firefox 3.5+, and latest builds of Opera (oh, and potentially the next release of Chrome).<span id="more-65"></span></p>
<h2>The ‘old’ way</h2>
<p>Ugh, look at this horrid code:</p>
<pre><code>&lt;object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;
&lt;param name="allowFullScreen" value="true" /&gt;
&lt;param name="allowscriptaccess" value="always" /&gt;
&lt;param name="src" value="http://www.youtube.com/v/oHg5SJYRHA0&amp;hl=en&amp;fs=1&amp;" /&gt;
&lt;param name="allowfullscreen" value="true" /&gt;
&lt;embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/oHg5SJYRHA0&amp;hl=en&amp;fs=1&amp;" allowscriptaccess="always" allowfullscreen="true"&gt;
&lt;/embed&gt;
&lt;/object&gt;</code></pre>
<p>Yuck. And as you know, you need Flash for this. Or it is often delivered via javascript as well so it is not perfect.</p>
<h2>The HTML 5 way</h2>
<p>Nice, clean, minimal code:</p>
<pre><code>&lt;video width=&quot;640&quot;  height=&quot;360&quot; src=&quot;http://www.youtube.com/demo/google_main.mp4&quot;  controls autobuffer&gt;
&lt;p&gt; Try this page in Safari  4! Or you can &lt;a  href=&quot;http://www.youtube.com/demo/google_main.mp4&quot;&gt;download the  video&lt;/a&gt; instead.&lt;/p&gt;
  &lt;/video&gt;
</code></pre>
<h3>Autoplay</h3>
<p>The video tag has an attribute that allows the video to play when the page loads.</p>
<pre><code>&lt;video src="abc.mov" autoplay&gt;
&lt;/video&gt;</code></pre>
<p>But <a href="http://www.punkchip.com/2009/04/autoplay-is-bad-for-all-users/">autoplay is bad ok</a>? Youtube and the like autoplay their videos. But before you push the launch button for your HTML 5 site, strongly consider whether it should autoplay a video.</p>
<h3>Download</h3>
<p>If the browser doesn’t know what to do with video tag, or if there is a display error, you can offer a download to the video instead:</p>
<h3>Autobuffer</h3>
<p>Autobuffer attribute is used when autoplay is <strong>not</strong> used but the page/site owner thinks the video will be watched at some point. The video is downloaded in the background, so when the user starts the video, it will be able to play at least some of the content. If both autoplay and autobuffer are used, then autobuffer is ignored.</p>
<p>It is worth pointing out at this point that the browser automatically downloads the video anyway, with or without autobuffer and there is nothing you can do about it. This has bandwidth and loading time issues, particularly if you have a lot of video on your page.</p>
<h3>Poster</h3>
<p>Use the poster attribute to display a frame of the video (as a .jpg, .png, whatever), in case the video doesn’t load for some reason. It can be a local image or elsewhere on the web</p>
<pre><code>&lt;video width="640" height="360" src="http://www.youtube.com/demo/google_main.mp" autobuffer controls poster="whale.png"&gt;
&lt;p&gt;Try this page in Safari 4! Or you can &lt;a href="http://www.youtube.com/demo/google_main.mp4"&gt;download the video&lt;/a&gt; instead.&lt;/p&gt;
&lt;/video&gt;</code></pre>
<p>You should use the poster attribute because you don’t want the user to see nothing.</p>
<h3>Controls</h3>
<p>Adding this attribute means you can use your own play/pause/etc buttons for your video. Safari has lovely default controls but you can create your own.</p>
<h3>Subtitles</h3>
<p>There is no attribute for subtitles (yet – hello HTML 5 group) but just thought I’d mention it. Personally I love the way the JW FLV player handles it, but this is a very interesting read: <a href="http://blog.gingertech.net/2008/12/12/attaching-subtitles-to-html5-video/">http://blog.gingertech.net/2008/12/12/attaching-subtitles-to-html5-video/</a></p>
<p>But ideally, we will be able to delivery subtitles/description audio without javascript.</p>
<h2>Current issues</h2>
<h3>Codecs</h3>
<p>I won’t claim to be a video/audio codec expert but there are a few outstanding issues in this area, which <a href="http://www.topfstedt.de/weblog/?p=382">this article</a> does a good job explaining.</p>
<h3>Internet Explorer</h3>
<p>IE hasn’t a clue and as the market leader, will need to be addressed. Thankfully here at HTML 5 Doctor, we have a few hints and tips for IE that will be coming shortly.</p>
<h3>Physical file</h3>
<p>So far, the video tag needs to link to a physical file (see example at the top). What we need here is a way to just import, say a YouTube video, using the video tag, like we did with the embed tag.</p>
<p>When I set out writing this article, what I wanted to do was kick it back to 2008 and Rickroll the lot of you but so far I haven’t found a way to do it with the video tag.</p>
<p>Here’s what I think you should be able to do with the video tag:</p>
<pre><code>&lt;video src="http://www.youtube.com/v/oHg5SJYRHA0&amp;hl=en&amp;fs=1&amp;" autoplay&gt;
&lt;/video&gt;</code></pre>
<p>How awesome would that be?</p>
<h2>Conclusion</h2>
<p>I think there is a <strong>long</strong> way to go yet but this tag has real potential. The issue over codecs looks certain to run and run, but you can put fall backs in the code, like the download link. You could use a combination of the video, object, embed elements, but that markup will be pretty horrendous:</p>
<pre><code>&lt;video width="640" height="360" src="http://www.youtube.com/demo/google_main.mp4" autobuffer controls poster="whale.png"&gt;
&lt;object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="640"height="360" codebase="http://www.apple.com/qtactivex/qtplugin.cab"&gt;
&lt;param value="http://www.youtube.com/demo/google_main.mp4"&gt;
&lt;param value="true"&gt;
&lt;param value="false"&gt;
&lt;embed src="http://www.youtube.com/demo/google_main.mp4" width="640"height="360" autoplay="true" controller="false" pluginspage="http://www.apple.com/quicktime/download/"&gt;
&lt;/embed&gt;
&lt;/object&gt;
&lt;/video&gt;</code></pre>
<h2>In the meantime</h2>
<p>If you don’t want to use the video tag yet, then here is <strong>valid</strong> XHTML code to display a video:</p>
<pre><code>&lt;object width="460" height="265" data="http://vimeo.com/moogaloop.swf?clip_id=5072163" type="application/x-shockwave-flash"&gt;
&lt;param value="http://vimeo.com/moogaloop.swf?clip_id=5072163"&gt;&lt;/param&gt;
&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;
&lt;param value="always"&gt;&lt;/param&gt;
&lt;/object&gt;</code></pre>
<h2>Further reading</h2>
<ul>
<li><a href="http://dev.w3.org/html5/spec/Overview.html#video">Editor&#8217;s Draft 17 June 2009</a></li>
<li><a href="http://www.brucelawson.co.uk/2009/accessibility-of-html5-video-and-audio-elements/">Accessibility of HTML 5 video and audio elements </a></li>
<li><a href="http://www.alobbs.com/1369/Setting_up_a_HTML5_on_line_video_site.html">Setting up a HTML 5 on-line video site</a></li>
<li><a href="http://blog.dailymotion.com/2009/05/27/watch-videowithout-flash/">Watch Video…without Flash</a></li>
<li><a href="http://www.youtube.com/html5">YouTube HTML 5 demo</a></li>
<li><a href="http://henriksjokvist.net/archive/2009/2/using-the-html5-video-tag-with-a-flash-fallback">Using the HTML 5 video tag with a Flash fallback</a></li>
<li><a href="http://www.computedstyle.com/2009/05/lessons-from-building-basic-video.html">Lessons From Building a Basic Video Player in HTML 5</a></li>
</ul>
<div id="crp_related">
<h3>Related Posts:</h3>
<ul class="related">
<li><a href="http://html5doctor.com/video-the-track-element-and-webm-codec/" rel="bookmark" class="crp_title">Video: the track element and webM codec</a></li>
<li><a href="http://html5doctor.com/native-audio-in-the-browser/" rel="bookmark" class="crp_title">Native Audio in the browser</a></li>
<li><a href="http://html5doctor.com/youtube-and-vimeo-support-html5-video/" rel="bookmark" class="crp_title">YouTube and Vimeo support HTML5 Video</a></li>
<li><a href="http://html5doctor.com/video-subtitling-and-webvtt/" rel="bookmark" class="crp_title">Video Subtitling and WebVTT</a></li>
<li><a href="http://html5doctor.com/review-html5-now-dvd/" rel="bookmark" class="crp_title">Review: HTML5 Now (DVD)</a></li>
</ul>
</div>
<p><a href="http://html5doctor.com/the-video-element/" rel="bookmark">The video element</a> originally appeared on <a href="http://html5doctor.com">HTML5 Doctor</a> on June 18, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5doctor.com/the-video-element/feed/</wfw:commentRss>
		<slash:comments>126</slash:comments>
<enclosure url="http://www.youtube.com/demo/google_main.mp4" length="4519255" type="video/mp4" />
		</item>
	</channel>
</rss>

