Video for Everybody!
- How It Works
-
The Code
- IMPORTANT Notes
-
Encoding the Videos
- Using HD Video
-
What’s Next?
- Video Controls
- Common Demands
- Related Projects
- Acknowledgements
Video for Everybody is simply a chunk of HTML code that embeds a video
into a website using the HTML5 <video> element, falling back to
QuickTime and Flash automatically, without the use of JavaScript or browser-sniffing. It
therefore works in RSS readers (no JavaScript), on the iPhone / iPad (don’t support Flash) and on
many, many browsers and platforms.
You may also be interested in reading the sister article “The End of Video for
Everybody!”.
Hosting of the video generously provided by
André M. Åslund of
Vorwärts GmbH.
Download Video:
Apple iTunes “MP4” •
Open Format “OGG”
How It Works
If your browser supports it, HTML5 video is used. No Flash—no crash.
HTML5 video in Firefox
In other browsers that do not support <video>, it falls
back to QuickTime.
QuickTime fallback in IE8
(which allows playback on the iPhone OS 2; OS 3 and above use HTML5 video)
If QuickTime is not installed, Adobe Flash is used. You can host locally or embed any
Flash file, such as a YouTube video. It’s
important to note that the user is not prompted to install QuickTime if they don’t
have it. Fallback is instant and automatic.
Flash fallback in IE8
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 video embedding method.
Final fallback image, you could use a different image that points to the download links
This is all done without JavaScript and requires only two video
encodes, one OGG file, and one MP4 file. Instructions on how to convert your videos to these formats with
the correct settings are provided further down this article.
It’s compatible with HTML 4, HTML5 (valid markup), XHTML 1 and additionally
also works when served as application/xhtml+xml.
For a full browser compatibility list, see the Video for
Everybody Test Page.
The Code
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.
<!-- "Video For Everybody" v0.3.2
=================================================================================================================== -->
<!-- first try HTML5 playback. if serving as XML, expand `controls` to `controls="controls"` and autoplay likewise -->
<video width="640" height="360" poster="__POSTER__.JPG" controls>
<!-- you must use `</source>` to avoid a closure bug in Firefox 3 / Camino 2! -->
<source src="__VIDEO__.OGV" type="video/ogg"><!-- Firefox native OGG video --></source>
<source src="__VIDEO__.MP4" type="video/mp4"><!-- Safari / iPhone video --></source>
<!-- IE only QuickTime embed: IE6 is ignored as it does not support `<object>` in `<object>` so we skip QuickTime
and go straight to Flash further down. the line break after the `classid` is required due to a bug in IE -->
<!--[if gt IE 6]>
<object width="640" height="375" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"><!
[endif]-->
<!-- non-IE QuickTime embed (hidden from IE): the self-closing comment tag allows non-IE browsers to
see the HTML whilst being compatible with serving as XML -->
<!--[if !IE]><!-->
<object width="640" height="375" type="video/quicktime" data="__VIDEO__.MP4">
<!--<![endif]-->
<param name="src" value="__VIDEO__.MP4" />
<param name="showlogo" value="false" />
<param name="autoplay" value="false" />
<!-- fallback to Flash -->
<object width="640" height="384" type="application/x-shockwave-flash"
data="__FLASH__.SWF?image=__POSTER__.JPG&file=__VIDEO__.MP4">
<!-- Firefox uses the `data` attribute above, IE/Safari uses the param below -->
<param name="movie" value="__FLASH__.SWF?image=__POSTER__.JPG&file=__VIDEO__.MP4" />
<!-- fallback image. download links are below the video. warning: putting anything more than
the fallback image in the fallback may trigger an iPhone OS3+ bug where the video will not play -->
<img src="__POSTER__.JPG" width="640" height="360" alt="__Title of video__"
title="No video playback capabilities, please download the video below"
/>
</object><!--[if gt IE 6]><!-->
</object><!--<![endif]-->
</video>
<!-- you *must* offer a download link as they may be able to play the file locally. customise this bit all you want -->
<p>Download Video: <a href="__VIDEO__.MP4">Apple iTunes "MP4"</a> | <a href="__VIDEO__.OGV">Open Format "OGG"</a></p>
(If you would like your video to automatically start playing, check out the sample code on the
test page.)
Here’s a compacted version as an example:
(Technically only one line break is required to deal with an IE bug on line 4)
<video width="640" height="360" poster="__POSTER__.JPG" controls>
<source src="__VIDEO__.OGV" type="video/ogg"></source>
<source src="__VIDEO__.MP4" type="video/mp4"></source><!--[if gt IE 6]>
<object width="640" height="375" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"><!
[endif]--><!--[if !IE]><!-->
<object width="640" height="375" type="video/quicktime" data="__VIDEO__.MP4">
<!--<![endif]-->
<param name="src" value="__VIDEO__.MP4" />
<param name="showlogo" value="false" />
<param name="autoplay" value="false" />
<object width="640" height="384" type="application/x-shockwave-flash"
data="__FLASH__.SWF?image=__POSTER__.JPG&file=__VIDEO__.MP4">
<param name="movie" value="__FLASH__.SWF?image=__POSTER__.JPG&file=__VIDEO__.MP4" />
<img src="__POSTER__.JPG" width="640" height="360" alt="__Title of video__"
title="No video playback capabilities, please download the video below" />
</object><!--[if gt IE 6]><!--></object><!--<![endif]-->
</video>
<p>Download Video: <a href="__VIDEO__.MP4">Apple iTunes "MP4"</a> | <a href="__VIDEO__.OGV">Open Format "OGG"</a></p>
IMPORTANT Notes
-
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
-
Replace __VIDEO__.MP4
with the path to your video encoded to MP4 and
replace __VIDEO__.OGV
with the path to your video encoded to OGG
-
Replace __POSTER__.JPG
with 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 of video__” for the poster
image’s alt text). Not all browsers support the poster attribute,
it’s advisable to encode the poster image into the first frame of your video
-
Replace __FLASH__.SWF
with 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
-
Set the width and height parameters correctly. Please note that these appear five times
throughout and you will notice that QuickTime is 15 pixels higher and
Flash 24 pixels higher—this is because the controls for these fallbacks don’t
overlay the video like HTML5 does. The Flash height is specific to
JWPlayer, YouTube’s controls are taller
-
Safari and QuickTime buffer the video automatically. Whilst it’s
possible to prevent this on QuickTime with different read: complicated
syntax, it’s not possible to prevent this on <video> without crippling
non-JavaScript users and I don’t recommend that. The
bug has been assigned,
and we can only hope for a fix soon
-
A current bug in
Firefox means that when JavaScript is disabled (NoScript
for example) the video controls do not display. For now, right-click on the video for the
controls, use autoplay on your videos or rely on users allowing your site in NoScript
-
The Eolas ‘Click to Activate’ issue affects Flash / QuickTime in
Internet Explorer 6 / 7 as the ActiveX controls are not inserted using
JavaScript—however Microsoft removed ‘Click to Activate’ in a later update
patch. This issue will not affect users who have run Windows Update
-
There are some instances where people will simply not be able to view the video inside the
web-page (Palm Prē, Android). On Linux systems without Firefox 3.5+,
Flash or MPEG4 codecs, the browser may attempt to play the video using the
MPlayer / Totem (or other) plugin which will display a blank, broken
video interface (due to not having an MPEG4 decoder) instead of the fallback. It is absolutely
essential that you provide download links outside of the video to ensure your message gets through
-
If you are using classic ASP (not .NET) to serve your pages, beware that ASP does not allow an
object within an object in the HTML (it preprocesses it looking for server-side objects). Use ASP
code to escape the inner object; an example can be found
here
(with thanks to Val Cohen for alerting me to this)
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
-
Firefox will only play OGG, and it will not degrade
to Flash if you leave out the OGG video
-
For best results I recommend including the poster image as the first frame when you encode the
video (Not all browsers support poster yet)
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.ogv" type="video/ogg"></source>
<source src="video.mov" type="video/mp4"></source>
<source src="video-desktop.mp4" type="video/mp4"></source>
What happens here is that the browser will try OGG first and if that isn’t supported it will try 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.
What’s Next?
Video for Everybody is not a complete solution. It is the template for you to get started. Please help
test Video for Everybody on a wide range of browsers,
plugins and devices.
Please send anything Video for Everybody related to me at
kroccamen@gmail.com and consider subscribing to the
RSS for updates.
Video Controls
Some may find the collection of different video controls depending on whether HTML5, QuickTime or
Flash is used quite ugly and would prefer a common set of controls for branding purposes. For HTML5 you
can roll your own
controls using any HTML and a
bit of JavaScript but Video for
Everybody is only the base template for the creative individual to work with.
SublimeVideo is an HTML5 video player with
a nice interface, but be aware that it does not yet work without JavaScript and it is not
free for commercial use (nor is JWPlayer, but VfE allows you to use any Flash
video player you want).
I would like to develop a consistent interface for Video for Everybody but I need the help of somebody
who will be able to develop the Flash code. Please get in
touch if you would like to help.
Common Demands
Why don’t you do Flash first, then QuickTime?
The code did used to do that but it was twice as long and people moaned and complained and dismissed the whole
notion of HTML5 video on the basis of lines of code that less than 0.1% of viewers would actually read.
Internet Explorer 6 does not support <object> within <object> so
that meant that I had to use many more IE conditional comments to filter
Flash and QuickTime correctly and it made everything very complicated. The code is more
manageable this way and QuickTime is less crashy than Flash anyway.
The QuickTime layer is mainly providing support for iPhone OS 2.0 and Opera.
Once Opera 10.5 is common and iPhone OS 2.0 has fallen out of common use then the
QuickTime layer can be ditched and it’ll be just HTML5 → Flash.
Why don’t you include Silverlight?
-
I don’t want to help make Silverlight the next Flash
-
Silverlight is only good for a minority of IE users, and 99% of
IE users already have Flash
-
It would bloat the code, and the goal is to make it smaller over time as we ditch layers
(QuickTime can go once iPhone OS 2.0 is gone and Opera 10.5
is common)
-
I have to test in IE6 / IE7 on XP / IE7 on Vista / IE8 on XP / IE8 on Vista and IE8 on Win7, Opera
9/10/10.5 (Mac/PC), Safari (Mac/PC), Chrome (Mac/PC), Camino 1 & 2, iPhone OS 2 & 3 and
Firefox 3/3.5/3.6—and where possible all of those same browsers without Flash and
QuickTime installed, Flash installed but not QuickTime,
QuickTime installed but not Flash and Flash &
QuickTime installed. Can you now imagine having to do that all again with/without
Silverlight?
Why don’t you include Cortado, a Java applet that can play OGG video?
The user-experience is more important than the underlying technology. The problem with Java is the
user-experience. The loading of a Java applet causes a noticeable pause whilst the Java Runtime
Environment loads. Even on my powerful Mac, the page loading freezes and the hard disk thrashes for a few
seconds. On low powered machines I’ve seen the entire computer lock up for 10 seconds. On Windows you
get a tray-icon appear and a bubble pop-up from said tray icon distracting you. This is simply unacceptable for
playing a video, not to mention the annoying Java update application that tries to install the
Yahoo Toolbar every time. I’m in no way willing to force that user experience on people.
You are of course free to modify Video for Everybody to include Cortado! If it serves your
demographic or needs better, by all means do so.
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
VfE, I’ll list it here.
(I will not list projects that cannot play the video in an RSS reader. Using JavaScript to
insert <video> defeats the entire purpose.)
- Univers Video Plugin
-
A WordPress plugin that provides you a simple interface for inserting video. It uses
Video for Everybody for the base template but steps up to a custom interface if
JavaScript is available. The plugin even does server-side encoding. The Flash
interface is designed to closely mimic the look of Firefox’s native
<video> controls to provide consistency, regardless of technology used. Absolutely
stunning work.
- Degradable HTML5 audio and video Plugin
-
Another WordPress plugin. It doesn’t use VfE, but does provide
HTML5 video and Flash fallback without JavaScript detection.
Acknowledgements