{"id":4190,"date":"2010-02-25T01:32:20","date_gmt":"2010-02-25T00:32:20","guid":{"rendered":"http:\/\/www.chipwreck.de\/blog\/?p=4190"},"modified":"2018-06-05T20:33:00","modified_gmt":"2018-06-05T18:33:00","slug":"html-5-video-tag-and-attributes","status":"publish","type":"post","link":"https:\/\/www.chipwreck.de\/blog\/2010\/02\/25\/html-5-video-tag-and-attributes\/","title":{"rendered":"HTML 5 Video \u2013 Tag and Attributes"},"content":{"rendered":"<p>This post is about the basic use of the HTML 5 video-tag and its attributes, the next one will be talking about events, DOM attributes and how to control video via javascript.<!--more--><\/p>\n<p><em>[Update 8 Dec 2011: Added .webm-codec]<\/em><\/p>\n<p>A full-blown HTML 5 video-tag looks like this:<\/p>\n<pre lang=\"html\">\r\n&lt;video width=\"320px\" height=\"240px\" autobuffer=\"autobuffer\" autoplay=\"autoplay\" loop=\"loop\" controls=\"controls\" poster=\"\/_img\/videostill.jpg\"&gt;\r\n    &lt;source src='video.mp4' type='video\/mp4; codecs=\"amp4v.20.8, mp4a.40.2\"'&gt;\r\n    &lt;source src='video.mpg' type='video\/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'&gt;\r\n    &lt;source src='video.ogv' type='video\/ogg; codecs=\"theora, vorbis\"'&gt;\r\n&lt;\/video&gt;\r\n<\/pre>\n<p>Or in its shortest variant:<\/p>\n<pre lang=\"html\">\r\n&lt;video src=\"video.mp4\"&gt;&lt;\/video&gt;\r\n<\/pre>\n<h4>The video attributes:<\/h4>\n<p><kbd>width<\/kbd> and <kbd>height:<\/kbd> define the dimensions of the playback-window, if not set the browser tries to use the dimensions from the video.<\/p>\n<p><kbd>loop:<\/kbd> sets the video to play in a loop.<\/p>\n<p><kbd>autoplay:<\/kbd> starts the video immediately.<\/p>\n<p><kbd>controls:<\/kbd> tells the browser to display a set of controls for playback, seeking and volume. Which controls these are and how they look depends on the browser.<\/p>\n<p><kbd>autobuffer:<\/kbd> Automatically start buffering (loading) the video, so it&#8217;s first loaded if you start playing. Currently Chrome and Safari ignore this attribute, so the video is being buffered on page load.<\/p>\n<p><kbd>poster:<\/kbd> Here you can supply an image which will be displayed while the movie is not loaded yet.<\/p>\n<h4>Controls display:<\/h4>\n<p>Here&#8217;s how the different browsers (Mac) in their current version render the video controls:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2010\/02\/browser-video-controls.png\" alt=\"Display of video controls in different browsers\" title=\"browser-video-controls\" width=\"337\" height=\"239\" class=\"alignnone size-full wp-image-4222\" srcset=\"https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2010\/02\/browser-video-controls.png 337w, https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2010\/02\/browser-video-controls-120x85.png 120w, https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2010\/02\/browser-video-controls-300x212.png 300w\" sizes=\"auto, (max-width: 337px) 100vw, 337px\" \/><\/p>\n<p>One can of course choose to disable these controls and provide your own ones &#8211; more about this in the next post.<\/p>\n<h4>The source tag:<\/h4>\n<p>You can use more than one video source to provide the video in different formats (read: codecs). Now the browser plays the first one it&#8217;s able to play. Since there is no single video codec all (useful) browser currently can handle this is necessary at the moment.<\/p>\n<p>Notice the two types of quotes in this tag: The source tag has two attributes, <kbd>src<\/kbd> and <kbd>type<\/kbd>, and the type is specified in two parts: MIME-type and a codec-definition:<\/p>\n<p><code lang=\"html\">src='video.mp4' type='video\/mp4; codecs=\"amp4v.20.8, mp4a.40.2\"'<\/code><\/p>\n<p>Firefox currently only plays ogg\/theora, Safari does mpeg\/H.264 and Chrome can play both formats.<\/p>\n<h4>Specifying video codecs<\/h4>\n<p>The codec specification itself is somewhat complicated, here a short overview which codecs are currently supported and how to specify them:<\/p>\n<ul>\n<li class=\"item\">H.264 Simple baseline profile video (main and extended video compatible) level 3 and Low-Complexity AAC audio in MP4 container:<\/li>\n<li class=\"item\"><kbd>type='video\/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">H.264 Extended profile video (baseline-compatible) level 3 and Low-Complexity AAC audio in MP4 container:<\/li>\n<li class=\"item\"><kbd>type='video\/mp4; codecs=\"avc1.58A01E, mp4a.40.2\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">H.264 Main profile video level 3 and Low-Complexity AAC audio in MP4 container<\/li>\n<li class=\"item\"><kbd>type='video\/mp4; codecs=\"avc1.4D401E, mp4a.40.2\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">H.264 &#8216;High&#8217; profile video (incompatible with main, baseline, or extended profiles) level 3 and Low-Complexity AAC audio in MP4 container<\/li>\n<li class=\"item\"><kbd>type='video\/mp4; codecs=\"avc1.64001E, mp4a.40.2\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">MPEG-4 Visual Simple Profile Level 0 video and Low-Complexity AAC audio in MP4 container<\/li>\n<li class=\"item\"><kbd>type='video\/mp4; codecs=\"mp4v.20.8, mp4a.40.2\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">MPEG-4 Advanced Simple Profile Level 0 video and Low-Complexity AAC audio in MP4 container<\/li>\n<li class=\"item\"><kbd>type='video\/mp4; codecs=\"mp4v.20.240, mp4a.40.2\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">MPEG-4 Visual Simple Profile Level 0 video and AMR audio in 3GPP container<\/li>\n<li class=\"item\"><kbd>type='video\/3gpp; codecs=\"mp4v.20.8, samr\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">Theora video and Vorbis audio in Ogg container<\/li>\n<li class=\"item\"><kbd>type='video\/ogg; codecs=\"theora, vorbis\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">Theora video and Speex audio in Ogg container<\/li>\n<li class=\"item\"><kbd>type='video\/ogg; codecs=\"theora, speex\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">Dirac video and Vorbis audio in Ogg container<\/li>\n<li class=\"item\"><kbd>type='video\/ogg; codecs=\"dirac, vorbis\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">Theora video and Vorbis audio in Matroska container<\/li>\n<li class=\"item\"><kbd>type='video\/x-matroska; codecs=\"theora, vorbis\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<li class=\"item\">Webm format<\/li>\n<li class=\"item\"><kbd>type='video\/webm; codecs=\"vp8, vorbis\"'<\/kbd><\/li>\n<li class=\"item\">&nbsp;<\/li>\n<\/ul>\n<p>Taken from the <a href=\"https:\/\/dev.w3.org\/html5\/pf-summary\/video.html\" class=\"external\">current specification &raquo;<\/a><\/p>\n<p>The next post will be about video events, DOM attributes and how to control them via Javascript.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is about the basic use of the HTML 5 video-tag and its attributes, the next one will be talking about events, DOM attributes and how to control video via javascript.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[55,10,54,79],"class_list":["post-4190","post","type-post","status-publish","format-standard","hentry","category-webdevelopment","tag-javascript-mootools","tag-mootools","tag-track","tag-webdesign"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paPEN-15A","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/4190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/comments?post=4190"}],"version-history":[{"count":1,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/4190\/revisions"}],"predecessor-version":[{"id":8202,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/4190\/revisions\/8202"}],"wp:attachment":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/media?parent=4190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/categories?post=4190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/tags?post=4190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}