Latest Trends

Implement HTML5 video support in 5 easy steps

May 20, 2010 @ 7 Comments

Supporting HTML5 video for your site was never easy, well, until now! Actually, there is nothing to implement. Modern browsers already support <video> tag. All you need to do is convert your videos into HTML5 compatible formats and provide some user interface controls elements for the video. In this tutorial I will walk you through the process in 5 easy steps. Lets Begin!

You own a video site and have some great videos. But the Stevey boy won’t allow you to get onto iPad with that Flash thing. No problem. See below what we can do (Right click and see no flash there. Test it on your iPads too!):


Step1: Convert your video compression into HTML5 supported codecs

Now, there are two main contenders here: H.264 and Ogg Theora.

You will need to download a converter to help you converter your video with one of these two codecs. I recommended converting to both as Safari won’t support Ogg Theora and Firefox won’t support H.264.

Here are some free utilities that can help you convert your video in these formats: XVid4PSP (+ AviSynth), Miro Video ConverterOgg Theora Converter. Choose the one that best suits your needs.

Step 2. Download an HTML5 video player

There are already a number of HTML5 video players available. Some of there are free and open source offering different features and capabilities like static image, playlists, browser detect and flash fallback options, etc. mostly jQuery based.

Here are some of these players: JW Player, Kaltura, OSM Player, SublimeVideo

I chose JW Player for this demo. But, the steps will be similar for any other player you choose.

Extract the zip file and extract it into appropriate location on your host server.

Step 3. Embed the player scripts in your site

The player will have some javascript files to be included in your headers.  JW Player also uses jQuery. JQuery can be embedded as follows:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>

Next embed the JW Player’s script file (depending on your upload location)

<script type="text/javascript" src="/jwplayer/jquery.jwplayer.js"></script>

Replace your flash video embed code with the video tag and provide the sources. You need to provide the width and height of the player, a static image to be displayed before the video is loaded and played as poster and finally the locations of the video in mp4 (H.264) and ogv (ogg) formats.

<video id="myplayer" width="480" height="270" poster="/upload/myvideo.jpg">
<source src="/videos/myvideo.mp4" type="video/mp4" />
<source src="/videos/myvideo.ogv" type="video/ogg" />
</video>

Finally, load the JW Player with a jQuery function call with the default skin.

<script type="text/javascript">
$('#myplayer').jwplayer({
skin:'/jwplayer/five/five.xml'
});
</script>

Step 4. Add Flash fallback options for unsupported browsers

In case of JW player this is a very minor step. JW player includes a flash player as a file player.swf. Just a line needs to be added to the previous jQuery function call (Remember the comma in between the skin and flashplayer):

<script type="text/javascript">
$('#myplayer').jwplayer({
skin:'/jwplayer/five/five.xml',
flashplayer:'/jwplayer/player.swf'
});
</script>

Step 5. Add some branding and do customization

There will be different types of customizations available for different players like logos, skins, playlists. For JW player changing the skin parameter above can change the look of the player. Themes can be create using jQuery UI theming tools like Themeroller. It’s just an XML file.

I will just change the logo on the player with the following line (the id corresponds to the id of video tag):

<style type="text/css">
#myplayer_logo{
background-image:url("http://www.html5trends.com/logo.png") !important,
width:235px !important
}</style>

And we are done. So Simple! This is the complete code for this demo:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/wp-content/uploads/demos/jwplayer/jquery.jwplayer.js"></script>
<video id="myplayer" width="480" height="270" poster="http://www.longtailvideo.com/jw/upload/bunny.jpg">
<source src="http://www.longtailvideo.com/jw/upload/bunny.mp4" type="video/mp4" />
<source src="http://www.longtailvideo.com/jw/upload/bunny.ogv" type="video/ogg" />
</video>
<style type="text/css">
#myplayer_logo{background-image:url("http://www.html5trends.com/logo.png") !important;
width:235px !important}
</style>
<script type="text/javascript">
$('#myplayer').jwplayer({
flashplayer:'/wp-content/uploads/demos/jwplayer/player.swf',
skin:'/wp-content/uploads/demos/jwplayer/five/five.xml'
});
</script>
Share

Related posts:

  1. Kaltura: The jQuery of HTML5 media
  2. Full Screen support for YouTube HTML5 video with a Chrome extension
  3. HTML5 JW Video Player from LongTail
  4. On2 HTML5 video codec VP8 to be open sourced?
  5. Incorporating HTML5 Video in webapps (Video)
  • Sdfhl

    Great. I mean great guide. Good job!

  • http://www.snipe.net snipe

    Very helpful, thank you! Any idea how to use a youtube url as the flash option, but fall back to the mp4/HTML5 version for incompatible browsers? Since the src is defined in the video tag, I’m not sure how I’d specify one url for flash and another for HTML5.

  • http://gauravmishra.com/ Gaurav Mishra

    Thanks for this!

  • http://www.funnyjokesfunny.com/ funny jokes funny

    Now its easy easy to Implement HTML5 video thanks for saving my time

  • Jpiombo

    I only see a black square in IE7 and IE9, not flash loaded… Does anyone have the same problem?

  • PatriciaL

    This information really helps me start with converting html5 video,
    all explained. Maybe a little tricky for  beginners.. Anyone tried easyhtml5video.com? It looks like it does all these things but automatically?

    Thanks a lot for sharing.

  • http://marinwebpro.com Leonel

    Hi Patricia,
    I just tried easyhtml5video.com  and yes it does convert Flash video to html5 for the standard browsers (mp4, webm, ogv/ogg) in one fell swoop, there is one limitation however, it does not provide a conversion to m4v which is want you need if you want your videos to play on any of the apple mobile platforms.  I also don’t like the watermark on the video.  If you want to convert videos for the apple devices there is a free app at  http://handbrake.fr/downloads.php – the “Universal” setting under Presets will cover all the devices under the Apple title.

    Once you have the m4v conversion you can add it to the easyhtml5 code please note that I dropped the type=”video/m4v”  element, for some reason if left in it will not play on your iP*.*

© 2012 HTML5 Trends.