The video element

The <video> 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 3.5+, and latest builds of Opera (oh, and potentially the next release of Chrome).

The ‘old’ way

Ugh, look at this horrid code:

<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">
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="src" value="http://www.youtube.com/v/oHg5SJYRHA0&hl=en&fs=1&" />
<param name="allowfullscreen" value="true" />
<embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/oHg5SJYRHA0&hl=en&fs=1&" allowscriptaccess="always" allowfullscreen="true">
</embed>
</object>

Yuck. And as you know, you need Flash for this. Or it is often delivered via javascript as well so it is not perfect.

The HTML 5 way

Nice, clean, minimal code:

<video width="640"  height="360" src="http://www.youtube.com/demo/google_main.mp4"  controls autobuffer>
<p> Try this page in Safari  4! Or you can <a  href="http://www.youtube.com/demo/google_main.mp4">download the  video</a> instead.</p>
  </video>

Autoplay

The video tag has an attribute that allows the video to play when the page loads.

<video src="abc.mov" autoplay>
</video>

But autoplay is bad ok? 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.

Download

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:

Autobuffer

Autobuffer attribute is used when autoplay is not 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.

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.

Poster

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

<video width="640" height="360" src="http://www.youtube.com/demo/google_main.mp" autobuffer controls poster="whale.png">
<p>Try this page in Safari 4! Or you can <a href="http://www.youtube.com/demo/google_main.mp4">download the video</a> instead.</p>
</video>

You should use the poster attribute because you don’t want the user to see nothing.

Controls

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.

Subtitles

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: http://blog.gingertech.net/2008/12/12/attaching-subtitles-to-html5-video/

But ideally, we will be able to delivery subtitles/description audio without javascript.

Current issues

Codecs

I won’t claim to be a video/audio codec expert but there are a few outstanding issues in this area, which this article does a good job explaining.

Internet Explorer

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.

Physical file

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.

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.

Here’s what I think you should be able to do with the video tag:

<video src="http://www.youtube.com/v/oHg5SJYRHA0&hl=en&fs=1&" autoplay>
</video>

How awesome would that be?

Conclusion

I think there is a long 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:

<video width="640" height="360" src="http://www.youtube.com/demo/google_main.mp4" autobuffer controls poster="whale.png">
<object classid="clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b" width="640"height="360" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param value="http://www.youtube.com/demo/google_main.mp4">
<param value="true">
<param value="false">
<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/">
</embed>
</object>
</video>

In the meantime

If you don’t want to use the video tag yet, then here is valid XHTML code to display a video:

<object width="460" height="265" data="http://vimeo.com/moogaloop.swf?clip_id=5072163" type="application/x-shockwave-flash">
<param value="http://vimeo.com/moogaloop.swf?clip_id=5072163"></param>
<param name="allowFullScreen" value="true"></param>
<param value="always"></param>
</object>

Further reading

Share and Save:
  • Twitter
  • Digg
  • Sphinn
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Netvibes
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • HackerNews
  • LinkedIn
  • NewsVine
  • Tumblr

33 Responses to “ The video element ”

Comment by Brian Lang at

I’m reading your site in Google Reader via RSS.
Articles such as this where you use a tag in the title of the document simply show up in Google Reader as The element. The tag itself gets rendered. Perhaps you could encode the titles using the Html entities lt and gt?

Comment by Rich Clark at

Hi Brian

Thanks for bringing this up, it’s something we’ve spotted and aim to fix. The titles were encoded that way but don’t seem to be escaping properly, it’s something I’m going to look into this weekend.

Cheers

Rich

Comment by MySchizoBuddy at

It works in Google Chrome 3 (its a development version at the time of this writing)

Comment by zcorpan at

The last snippet is not valid HTML5 because param is a void element and thus the end tag is not allowed. You can use /> syntax in HTML5 though.

Comment by Hikari at

hehe the XHTML object code was nice :P

I believe that the biggests advantage for the video element is to be able to easily (for the webmaster, for the browser developer and for the visiting user) embed video on sites.

What I mean is that today we can just upload a png or even a gif image to our site, or to imageshark if we don’t wanna pay for the bandwidth, and use a simple img element to show it. With videos, otherwise, there is no easy way to upload a mkv, avi or even mp4 to our site and easily show it inside HTML. I won’t even talk about free video hosting services that would let we offer a direct link to it, without forcing user to visit their site and wait 60 seconds for the download…

That forces us to use youtube services to host and deliver an embedded player for it. We are forced to use this horrible, worse than that bad old .rm, FLV format.

The only other options are to host the file ourselves and give a simple anchor link for downloading it. But youtube proved that this approach is not as good as browser embedded player… unfortunately we need a way to lock visitors on our site until they are done downloading and watching the video (yes, I HATE this idea, but that’s the way to get popularity), so that they leave comments about it.

What I wanted to do is leave an embedded video player together with a direct link to it, and have it on a free host elsewhere :P

Comment by Lisa at

Thanks, i am struggling to get this working under IE & FF, however Safari is picking up the code fine, are the extra scripts i need running to make it compatible for other browsers ?

Comment by Alex at

“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.

Uhh, you do realize http://www.youtube.com/v/oHg5SJYRHA0&hl=en&fs=1&amp; is a physical file? It’s just not the file that has the actual video in it, so it would make no sense for the video element to support it.
should work (although it didn’t work for me), since it points to the actual MP4 file on YouTube.

Comment by JuggieBuggie at

Physical file

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.

You never ever did that with embed. You started a plugin that imported a Flash file that would cause the video file to download and play.

The problem is not caused by html5, it’s caused by youtube, which is hiding its video files behind a temporal session id. If Youtube would drop that and instead expose stable URLs for the video files the problem would be solved. But it will not do that, because Youtube wants the branding of the surrounding flash based player, because Youtube is not for fun – it’s for making money. So if you would like to present video without having to complie to Youtubes money making goals: don’t use Youtube.

Comment by iw at

It’s amazing. Everybody is talking about marvelous video tag… Guys calm down. Don’t you see that the object tag has already all the power you need. Nobody needs another tag! It would be better if borwsers implemented fully the object tag functionality and… voila with a single object you could embed audio/video/whatever – read the W3C html/xhtml standard it’s all there – but no browser fully implements it….

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <b> <blockquote cite=""> <cite> <del datetime=""> <em> <i> <q cite=""> <strong>

You can also use <code>, and remember to use &lt; and &gt; for brackets.