Questions tagged [html5-video]

HTML5 video is an element introduced in the HTML5 draft specification for the purpose of creating a standards-compliant, plugin-free way for playing videos and movies, partially replacing the object element.

HTML5 video is an element introduced in the HTML5 draft specification for the purpose of creating a standards-compliant, plugin-free way for playing videos and movies, partially replacing the object element.

Basic usage

You can embed a video element into a HTML5 document by using the following code:

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

Attributes

The video element has the following specific attributes:

  • src gives the address of the media resource to show
  • crossorigin is a CORS settings attribute
  • postergives the address of an image file that the user agent can show while no video data is available
  • preload sets the preload behavior, valid values being none, metadata and auto
  • autoplay is a boolean attribute. When present, the user agent will automatically begin playback of the video as soon as it can do so without stopping
  • mediagroup can be used to link multiple media elements together by implicitly creating a MediaController
  • loop is a boolean attribute that, if specified, indicates that the media element is to seek back to the start of the media resource upon reaching the end
  • muted is a boolean attribute that controls the default state of the audio output of the media resource, potentially overriding user preferences
  • controls is a boolean attribute that, if present, indicates that the author has not provided a scripted controller and would like the user agent to provide its own set of controls
  • width & height specify the dimensions of the element in pixels

JavaScript API & Events

The HTML5 video element can be easily controlled from JavaScript.

For example you can easily pause and play a video by doing the following:

document.getElementsByTagName('video')[0].play();
document.getElementsByTagName('video')[0].pause();

It also has properties:

var time = document.getElementsByTagName('video')[0].currentTime; //will return the current position of the playhead

And it also fires events:

document.getElementsByTagName('video')[0].addEventListener('ended',function(){
   alert('That\'s all folks!');
},false);

For a wonderful overview refer to the demo page of the W3.

Media Encoding

Browser vendors all support different codec and container formats, so you should encode your video more than once and serve several files simultaneously to ensure your visitor will be able to watch them. A common approach (at the time of writing, i.e. spring 2012) is to serve the following:

  • Make one version that uses WebM (VP8 + Vorbis)
  • Make another version that uses H.264 baseline video and AAC “low complexity” audio in an MP4 container
  • Make another version that uses Theora video and Vorbis audio in an Ogg container

Be aware that this is CONSTANTLY CHANGING, so before you set up your video do research on what is currently supported and what the future outlook does look like!

Flash & Download Fallback

Since video is still unsupported in many browsers used (IE 7+8 for example) it should be considered a good idea to serve Flash Video as a fallback. For browsers that cannot play any video at all you can also serve a link to a simple download.

This can be done by adding the traditional object style Flash content into the fallback part of the video element:

<video controls poster="video.jpg" width="854" height="480">
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  <source src="video.ogg" type="video/ogg">
  <object type="application/x-shockwave-flash" data="player.swf" width="854" height="504">
    <param name="allowfullscreen" value="true">
    <param name="allowscriptaccess" value="always">
    <param name="flashvars" value="file=video.mp4">
    <!--[if IE]><param name="movie" value="player.swf"><![endif]-->
    <img src="video.jpg" width="854" height="480" alt="Video">
    <p>Your browser can’t play HTML5 video. <a href="video.webm"> Download it</a> instead.</p>
  </object>
</video>

FAQ (on StackOverflow)

Available libraries

There are many JavaScript libraries that offer tools to handle tasks (and fix cross-browser issues) that you will encounter when using the video-element. These are a few (if you know anything else feel free to add them):

Tools for encoding video

Further reading

Attributions & Notes

This tag-wiki was compiled with the help and contents of Dive into HTML 5, dev.opera.com, w3.org and the MDN. In case anyone has vast experience regarding HTML5 video and mobile devices I think this would be a great addition to this wiki page!

7933 questions
41
votes
2 answers

can't seek html5 video or audio in chrome

I've been fiddling with the hell that is HTML5 video/audio for a couple of weeks now. Usually the reason why something failed popped up after a while, but I've been, unable to find why I get forwarding and rewinding problems in chrome. Anyhow... The…
toxkillfraex
  • 748
  • 1
  • 6
  • 10
40
votes
1 answer

How to use VLC live streams with HTML5 video?

I tried HTTP Ogg/Theora and works alright with Chrome but not with Firefox 7. VLC Configuration: For testing, I've been streaming the desktop using the following vlc command line configuration: vlc.exe screen:// :screen-fps=30 :screen-caching=100 …
Bruno Santos
  • 1,530
  • 1
  • 15
  • 22
39
votes
6 answers

Why HTML5 video doesn't play in IOS 8 WebApp(webview)?

Simple HTML5 video plays on safari browser. but after adding it to home screen(Standalone WebApp), it doesn't work. It is working on iOS7 but stopped working on iOS8.
inaam husain
  • 615
  • 1
  • 7
  • 8
39
votes
2 answers

Add text above HTML5 Video

Need Help on adding text on top of, so the text is overlaying an HTML 5 Video, And I also need to add a form inputs and buttons as well below is my HTML5 Video Code.
38
votes
12 answers

iPad Safari mobile seems to ignore z-indexing position for html5 video elements

I got a video element on a page that's working fine both in safari mobile and desktop. I have a seme-transparent pull-down menu that's working fine. The problem is, when the menu is over the video element, on the desktop safari i can see the video…
Marek Maurizio
  • 1,073
  • 2
  • 11
  • 22
38
votes
4 answers

Possible to stream videos using Amazon S3/CloudFront with HTML5 player?

I want to use an HTML5 video player and stream videos. Is this possible with S3/CloudFront? I understand Amazon uses the RTMP streaming protocol and HTML5's video tag does not support RTMP. Is there any way to stream videos with HTML5 players?
at.
  • 50,922
  • 104
  • 292
  • 461
37
votes
7 answers

HTML5 video background color not matching background color of website -- in some browsers, sometimes

I have a video that the client wants to sit "seamlessly" in the website. The background HEX color of the video matches the HEX background color of the website, and renders as such in some browsers, some versions, some of the time? What is most…
tayvano
  • 1,308
  • 1
  • 11
  • 18
37
votes
2 answers

Image placeholder fallback for HTML5 Video

I'm using the following code to implement an HTML5 video on a page
36
votes
13 answers

HTML5 - mp4 video does not play in IE9

I have an mp4 video that I want to play in IE9 using HTML5
user623892
36
votes
5 answers

How to check if the browser can play mp4 via html5 video tag?

How to check if the browser can play mp4 via html5 video tag?
Coepr
  • 377
  • 1
  • 3
  • 3
36
votes
2 answers

HTML5 solution to upload a webcam/camera video stream to server

Using getUserMedia I can capture video stream from client's webcam/camera. And using video tag I can show it on client's browser. Code: