Wednesday, November 2, 2011

HTML5 Video

HTML5 Video


Many modern websites show videos. HTML5 provides a standard for showing them.

Check if your browser supports HTML5 video



Videos on the Web

Until now, there has never been a standard for showing a video or movie on a web page.
Today, most videos are shown through a plugin (like flash). However, different browsers may have different plugins.
HTML5 defines a new element which specifies a standard way to include video: the <video> element.

Video Formats

Currently, there are 3 supported video formats for the video element:
Format IE Firefox Opera Chrome Safari
Ogg No 3.5+ 10.5+ 5.0+ No
MPEG 4 9.0+ No No 5.0+ 3.0+
WebM No 4.0+ 10.6+ 6.0+ No
  • Ogg = Ogg files with Theora video codec and Vorbis audio codec
  • MPEG4 = MPEG 4 files with H.264 video codec and AAC audio codec
  • WebM = WebM files with VP8 video codec and Vorbis audio codec

How It Works

To show a video in HTML5, this is all you need:

Example

<video width="320" height="240" controls="controls">
  <source src="movie.mp4" type="video/mp4" />
  <source src="movie.ogg" type="video/ogg" />
  Your browser does not support the video tag.
</video>

Try it yourself »
The control attribute adds video controls, like play, pause, and volume.
It is also a good idea to always include width and height attributes. If height and width are set, the space required for the video is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the video, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the video load).
You should also insert text content between the <video> and </video> tags for browsers that do not support the <video> element.
The <video> element allows multiple <source> elements. <source> elements can link to different video files. The browser will use the first recognized format.
Today, Firefox, Opera, and Chrome support Ogg files. Internet Explorer, Chrome, and Safari support MPEG4 files.
To cover all the major browsers, use two <source> elements: One pointing to an MPEG4 file, and one pointing to an Ogg file.


HTML5 video Tags

Tag Description
<video> Defines a video or movie
<source> Defines multiple media resources for media elements, such as <video> and <audio>
<track> Defines text tracks in mediaplayers

No comments:

Post a Comment

Online visitors counter users online