Video for Everybody!
- How It Works
- IMPORTANT Notes
- Adding Custom Controls
Encoding the Videos
- Using HD Video
- A Warning About H.264
- Using WebM Video
- Related Projects
Video for Everybody is simply a chunk of HTML code that embeds a video into a website using the
and on many browsers and platforms.
Note: This article page, as part of my HTML5 website, does not work in Internet
Please use the Video for Everybody Test Page to see the demo, which does display in all browsers.
How It Works
If your browser supports it, HTML5 video is used. No Flash—no crash.
If HTML5 video is not supported, Adobe Flash is used.
You can host locally or embed any Flash file, such as a YouTube video.
Finally, if all else fails, a placeholder image is shown and the user can download the video using the links provided. If the user doesn’t have Flash they are not prompted to install it. Users have enough problems with security already without random websites prompting them to install things—and it’s even more annoying for people who don’t want or cannot use Flash anyway. This is one aspect that makes VfE different than any other Flash video embedding method.
It’s compatible with HTML 4, HTML5 (valid markup), XHTML 1 and additionally also works when served as
For a full browser compatibility list, see the Video for Everybody Test Page.
Here follows the full source code. It’s very large because it’s fully commented.
You can easily compact this down (one such example follows afterwards).
Do not miss the important notes below or you will be kicking yourself after wasting hours trying to get it to work.
<!-- first try HTML5 playback: if serving as XML, expand `controls` to `controls="controls"` and autoplay likewise --> <!-- warning: playback does not work on iPad/iPhone if you include the poster attribute! fixed in iOS4.0 --> <video width="640" height="360" controls> <!-- MP4 must be first for iPad! --> <source src="__VIDEO__.MP4" type="video/mp4" /><!-- WebKit video --> <source src="__VIDEO__.OGV" type="video/ogg" /><!-- Firefox / Opera --> <!-- fallback to Flash: --> <object width="640" height="360" type="application/x-shockwave-flash" data="__FLASH__.SWF"> <!-- Firefox uses the `data` attribute above, IE/Safari uses the param below --> <param name="movie" value="__FLASH__.SWF" /> <param name="flashvars" value="controlbar=over&image=__POSTER__.JPG&file=__VIDEO__.MP4" /> <!-- fallback image. note the title field below, put the title of the video there --> <img src="__VIDEO__.JPG" width="640" height="360" alt="__TITLE__" title="No video playback capabilities, please download the video below" /> </object> </video> <!-- you *must* offer a download link as they may be able to play the file locally. customise this bit all you want --> <p> <strong>Download Video:</strong> Closed Format: <a href="__VIDEO__.MP4">"MP4"</a> Open Format: <a href="__VIDEO__.OGV">"Ogg"</a> </p>
(If you would like your video to automatically start playing, check out the sample code on the
Here’s a compacted version as an example:
<video width="640" height="360" controls> <source src="__VIDEO__.MP4" type="video/mp4" /> <source src="__VIDEO__.OGV" type="video/ogg" /> <object width="640" height="360" type="application/x-shockwave-flash" data="__FLASH__.SWF"> <param name="movie" value="__FLASH__.SWF" /> <param name="flashvars" value="controlbar=over&image=__POSTER__.JPG&file=__VIDEO__.MP4" /> <img src="__VIDEO__.JPG" width="640" height="360" alt="__TITLE__" title="No video playback capabilities, please download the video below" /> </object> </video> <p> <strong>Download Video:</strong> Closed Format: <a href="__VIDEO__.MP4">"MP4"</a> Open Format: <a href="__VIDEO__.OGV">"Ogg"</a> </p>
And one that auto plays: (notice the changes “
autoplay” and “
<video width="640" height="360" controls autoplay> <source src="__VIDEO__.MP4" type="video/mp4" /> <source src="__VIDEO__.OGV" type="video/ogg" /> <object width="640" height="360" type="application/x-shockwave-flash" data="__FLASH__.SWF"> <param name="movie" value="__FLASH__.SWF" /> <param name="flashvars" value="autostart=true&controlbar=over&image=__POSTER__.JPG&file=__VIDEO__.MP4" /> <img src="__VIDEO__.JPG" width="640" height="360" alt="__TITLE__" title="No video playback capabilities, please download the video below" /> </object> </video> <p> <strong>Download Video:</strong> Closed Format: <a href="__VIDEO__.MP4">"MP4"</a> Open Format: <a href="__VIDEO__.OGV">"Ogg"</a> </p>
It’s advised you subscribe to the RSS to be kept informed of new releases in case you get caught out by new bugs introduced by vendors *cough*Apple*cough*. The version isn’t <1 for no reason.
Ensure your server is using the correct mime-types. Firefox will not play the Ogg video if the mime-type is wrong. Place these lines in your .htaccess file to send the correct mime-types to browsers
AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/webm .webm
__VIDEO__.MP4with the path to your video encoded to MP4 (a warning on using H.264) and
__VIDEO__.OGVwith the path to your video encoded to Ogg.
Optionally you could also include a WebM video.
__POSTER__.JPGwith the path to an image you want to act as a title screen to the video, it will be shown before the video plays, and as a representative image when the video is unable to play (Also replace “__TITLE__” for the poster image’s
alttext). Not all browsers support the
posterattribute, it’s advisable to encode the poster image into the first frame of your video.
DO NOT INCLUDE THE
<video poster="…">) FOR iPad / iPhone 3.x SUPPORT. There is a major bug with iPhone OS 3 that means that playback will not work on any HTML5 video tag that uses both the
<source>elements. This was fixed in iPhone OS 4.0, but of course for now there will still be a large number of OS 3 users. This bug does not affect use of the poster image in the
flashvarsparameter, which you should retain
__FLASH__.SWFwith the path to the Flash video player you are using. I use JW Player (download and place ‘player.swf’ in the right place), but this could be any Flash resource including YouTube. Sample code for using YouTube can be seen on the Video for Everybody YouTube Test Page
Safari buffers the video automatically even if autobuffer is absent. This has been fixed in WebKit nightlies with a change to the HTML5 spec; the “preload="none"” attribute on the video element prevents autobuffering. A current bug in WebKit causes Safari to perpetually display “loading” until the play button is clicked
The iPhone will not autoplay. This is done to save bandwidth which may cost some users.
It is not a bug, it’s a feature
HTML5 video on Android, even the latest version, is badly broken. Resolution support varies from one handset to the next, usually the fallback image doesn’t show and the code requires special adjustments. The Android emulator is completely useless. THERE IS NO WAY TO TEST ON ANDROID WITHOUT A PHYSICAL PHONE. BLAME GOOGLE. I would love to update the code to work better with Android, but until Google fixes their code or sends me a phone, I can’t do that. They’ve had only three years to do it so far
Some web hosts, in trying to save bandwidth, gzip everything by default—including video files! In Firefox and Opera, seeking will not be possible or the video may not play at all if a video file is gzipped. If this is occurring to you please check your server / hosts and disable the gzipping of Ogg and other media files. You can switch off gzipping for video files in your .htaccess file by adding this line:
SetEnvIfNoCase Request_URI \.(og[gv]|mp4|m4v|webm)$ no-gzip dont-vary
With thanks to Bas van Bergen for this tip
There are some instances where people will simply not be able to view the video inside the web-page (e.g. Opera Mobile / Mini). It is absolutely essential that you provide download links outside of the video to ensure your message gets through
A parsing bug in Camino 2.0 / Firefox 3.0 means that the image element inside the video element will ‘leak’ outside of the video element. This is not visible however unless some kind of background image or colour is applied to that image element. You can stop this by either wrapping the video element in another element or modifying the code from “
<source … />” to “
<source …></source>”. This works, but will not validate as HTML5
Adding Custom Controls
Designers however don’t like the inconsistency and would like a unified set of controls. VideoJS uses VfE and custom controls you can style how you please with CSS.
Encoding the Videos
Full instructions are beyond the scope of this article, please refer to Mark Pilgrim’s Video on the Web article for an excellent introduction to video formats and encoding instructions.
There is no restriction on the resolution of the Ogg video
The iPhone can play MOV and MPEG4 videos with a maximum size of 640x480 and only allows the Base Profile for H.264 (See Apple’s own instructions for the specifics). If your desired video is bigger than that, please read the instructions below for how to adjust the code to use hi-res videos whilst keeping iPhone compatibility
The iPad can play H.264 up to 720p, 30 FPS
Firefox will only play Ogg (WebM is also supported in Firefox 4), and it will not degrade to Flash if there is no Firefox-compatible video file
For best results I recommend including the poster image as the first frame when you encode the video
Using HD Video
If you would like to use a larger video than 640x480, you can use a QuickTime reference movie to auto-select between
an iPhone compatible version and the full-size video. In QuickTime Pro use the ‘File » Export for
Web…’ option to output a reference movie (you can also use Apple’s
MakeRefMovie tool for
finer control). You’ll have three files along these lines: “video.mov”,
“video-desktop.mp4” (or m4v) and “video-iphone.mp4”. Now replace the two
source elements in the code with these three: (substituting the right file paths)
<source src="video.mov" type="video/mp4"></source> <source src="video-desktop.mp4" type="video/mp4"></source> <source src="video.ogv" type="video/ogg"></source>
What happens here is that the browser will play the QuickTime reference movie (Safari / iPhone / iPad) which will auto-select between the desktop and iPhone versions of the video automatically. If the MOV format isn’t supported by the browser (Chrome for example), we point to the same MPEG4 video that the QuickTime reference movie uses.
A Warning About H.264
I made Video for Everybody because since I don’t have Flash installed I wanted to create a way websites could provide me access to their videos (currently needlessly trapped inside Flash) without having to lose viewers from older browsers. VfE is not a tool I would use myself (other videos on this site are HTML5/Ogg only) because of the threat that H.264 represents to freedom on the web. Websites that are already serving H.264 video to users using Flash have already made the conscious decision to buy into H.264. I am not making that decision for you with Video for Everybody.
Just be aware that if you decide to use H.264 video for commercial use then you will need to purchase a licence from the MPEG-LA. Be warned that ‘commercial use’ may also include the scenario where your website has advertisements, even though your use of video is unrelated to those adverts. If you are making any any money in any way from a page that also includes an H.264 video, then you should contact the MPEG-LA for help on licencing.
On the 27th of August 2010, the MPEG-LA announced (arguably in response to growing WebM support) that the terms of “free use” of H.264 Internet broadcast would not change in 2016. This does not change a thing.
This is similar to Nikon announcing that they will not charge you if you put your pictures up on Flickr, or HP promising that they will never charge you additionally if you photocopy something that you printed on a LaserJet.Mike Shaver
Using WebM Video
On the 19th of May 2010 Google released the VP8 codec as open-source and royalty free with the full intent to drive broad adoption via industry backing and switching YouTube over to the new format in the long term. “WebM” is a rebranded Matroska container utilising VP8 video and Vorbis audio.
This represents major competition to H.264—Mozilla, Google and Opera have already added support into special builds of their browsers and even Microsoft have about-faced on their H.264-only policy and said that IE9 will support WebM—but only if the codec has been installed by the user. Obviously absent from any support is Apple, and this means that unfortunately codec-fragmentation will continue into the foreseeable future so that you will still need to provide more than one video encode.
Adding a WebM video to Video for Everybody is easy, just add it to the source list! It has to go below the MP4 video due to an iPad bug that ignores anything but the first source element, and ideally above the Ogg source so that browsers that play both Ogg and WebM choose the WebM video first. Here is an example source stack:
<source src="video.mp4" type="video/mp4" /> <source src="video.webm" type="video/webm" /> <source src="video.ogv" type="video/ogg" />
Note the new mime type, which you will have to add to your server.
At this extremely early stage for WebM I will not provide any help via e-mail on how to encode or use WebM video. If you don’t know how to use it already, it’s not for you—wait until support is added to your favourite tools and more information is readily available. I will update this article as the situation with WebM progresses.
If you’ve modified Video for Everybody to do something else, or have created an HTML5 video related project, please let me know and if it upholds the same principles as Video for Everybody, I’ll list it here.
<video> defeats the entire purpose.)
- External Video for Everybody
- A WordPress plugin that provides a shortcode to insert video using Video for Everybody. The author has also provided an excellent bash script to automate the process of encoding the video files.
- Degradable HTML5 audio and video Plugin
- Another WordPress plugin. It doesn’t use VfE, but does provide HTML5 video and Flash fallback.
- Bas van Bergen for the tip on gzipped video files
- Steve Haffernan for
video.js and demonstrating the better
- Val Cohen for spotting the ASP problem with VfE_QT
- Guido García for Blackberry Bold 9000 / Curve 8900 & Nokia N96 testing
- Corey Weiner for iPad testing
- Zeno Crivelli (SublimeVideo)
- Terrell Kelley for spotting the Firefox 3.0 bug with self-closing
- André M. Åslund of Vorwärts GmbH for the current hosting of the video files
- Mike Hadfield for the VfE Playback button
- Chris Double for previously hosting the video files
- LongTail Video for JWPlayer, the Flash fallback player
- Everybody who has promoted it, thank you