{"_id":"59bba3e115d1e1002426165c","category":{"_id":"59bba3e115d1e10024261654","version":"59bba3e115d1e10024261652","project":"55e6dcb32d0d3021000daf70","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-04T12:01:11.730Z","from_sync":false,"order":1,"slug":"basics","title":"Basics"},"project":"55e6dcb32d0d3021000daf70","user":"55e6dc8a2d0d3021000daf6e","parentDoc":null,"version":{"_id":"59bba3e115d1e10024261652","project":"55e6dcb32d0d3021000daf70","__v":1,"createdAt":"2017-09-15T09:56:49.752Z","releaseDate":"2017-09-15T09:56:49.752Z","categories":["59bba3e115d1e10024261653","59bba3e115d1e10024261654","59bba3e115d1e10024261655","59bba3e115d1e10024261656","59bba3e115d1e10024261657"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-09-04T12:30:35.913Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"There are two ways to include video sources into your `<video>` element. The shorter way is this one:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<video class=\\\"afterglow\\\" id=\\\"myvideo\\\" width=\\\"1280\\\" height=\\\"720\\\" src=\\\"/path/to/myvideo.mp4\\\" />\\n</video>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\n*[Width and height](doc:mandatory-parameters) should of course match your video's actual dimensions.*\n\nThe drawback of this method is that you can only specify one source. This will work for many browsers (if you use MP4, read below) but there maybe some that need the video file transcoded to WebM or OGG.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Providing multiple sources\"\n}\n[/block]\nIf you want to provide more than one format for your video, you will have to pass each of them as a single `<source>` element.\n\nThis is how to provide several sources:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<video class=\\\"afterglow\\\" id=\\\"myvideo\\\" width=\\\"1280\\\" height=\\\"720\\\">\\n  <source type=\\\"video/mp4\\\" src=\\\"/path/to/myvideo.mp4\\\" />\\n  <source type=\\\"video/webm\\\" src=\\\"/path/to/myvideo.webm\\\" />\\n  <source type=\\\"video/ogg\\\" src=\\\"/path/to/myvideo.ogg\\\" />\\n</video>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nIn this case, the browser would try to playback the MP4 file. If it failed (maybe because it doesn't know the codec or stuff like this) it will try the next source it finds, WebM in this case.\n\nYou can order your sources the way you want to. We'd recommend using MP4 - WebM - OGG, but that's just a feeling we got during the last few years. This order seemed most stable to us.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Resolution switching\"\n}\n[/block]\nIf you want to provide a low res and a high res version of your video, just do so. In order to have afterglow recognize your high res (HD) version, add the attribute `data-quality=\"hd\"` to it. Just like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<video class=\\\"afterglow\\\" id=\\\"myvideo\\\" width=\\\"1280\\\" height=\\\"720\\\">\\n  <source type=\\\"video/mp4\\\" src=\\\"/path/to/myvideo.mp4\\\" />\\n  <source type=\\\"video/mp4\\\" src=\\\"/path/to/myvideo_hd.mp4\\\" data-quality=\\\"hd\\\"/>\\n  <source type=\\\"video/webm\\\" src=\\\"/path/to/myvideo.webm\\\" />\\n  <source type=\\\"video/webm\\\" src=\\\"/path/to/myvideo_hd.webm\\\" data-quality=\\\"hd\\\"/>\\n  <source type=\\\"video/ogg\\\" src=\\\"/path/to/myvideo.ogg\\\" />\\n  <source type=\\\"video/ogg\\\" src=\\\"/path/to/myvideo_hd.ogg\\\" data-quality=\\\"hd\\\"/>\\n</video>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nIf you want to start with the HD version, just provide the HD version in the first place.\n\nThere are working examples for both SD first and HD first [here](doc:using-resolution-switching).\n\nResolution switching works only for local sources, not for [Youtube clips](doc:youtube-video).\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"We always use the `<source>` markup\",\n  \"body\": \"In most of the examples you can find in the documentation, we use the `<source>` element even if we don't provide multiple sources. That's just for readability reasons and helps us getting the logic straight. There is the player and the thing it plays, so let's separate them.\\n\\nAlthough we like the `<source>` element, it's not generally recommended over the other way. So find your own way of working things out. ;-)\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"When it comes to video playback, the most commonly used webbrowsers (like Chrome, Firefox, Safari, Internet Explorer, etc.) are not very reliable. Most of the firms creating those browsers want to establish their own video format and don't really force general standards for HTML5 video.\\n\\nThe result of their fights with each other is that you, as a website creator, have to cope with lot's of different behaviours. Some browsers prefer MP4, others like WebM, OGG is also sometimes mentioned and then there is Windows 7 or some mobile devices not playing HTML5 video at all.\\n\\nWe'd always recommend including your videos as MP4 files which has proven to cover most of the modern browsers and devices. In order to cover as many browsers and devices as possible, you probably should also include WebM and OGG transcoded versions.\",\n  \"title\": \"Which video formats to use?\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"MP4 != MP4\",\n  \"body\": \"Be aware that *MP4* is just a container format. It can contain many different video codecs and bandwidths.\\n\\nRecommended settings for video encoding with a good balance between quality and bandwidth are:\\n\\n- video codec: H264\\n- audio codec: AAC\\n- video bandwidth: *video width in pixels* x 1.5 + 500\\n- audio bandwidth: 96 Kbps - 128 Kbps\\n\\nThese settings result in videos that most devices are able to play back and that should look quite good. \\n\\nThis is just some advice from our experience. The needed bandwidth hugely depends on what your video is actually showing, on the target audience (mobile/desktop), and so on...\"\n}\n[/block]","excerpt":"About different video sources and why to include multiple transcodings","slug":"video-sources","type":"basic","title":"Video sources"}

Video sources

About different video sources and why to include multiple transcodings

There are two ways to include video sources into your `<video>` element. The shorter way is this one: [block:code] { "codes": [ { "code": "<video class=\"afterglow\" id=\"myvideo\" width=\"1280\" height=\"720\" src=\"/path/to/myvideo.mp4\" />\n</video>", "language": "html" } ] } [/block] *[Width and height](doc:mandatory-parameters) should of course match your video's actual dimensions.* The drawback of this method is that you can only specify one source. This will work for many browsers (if you use MP4, read below) but there maybe some that need the video file transcoded to WebM or OGG. [block:api-header] { "type": "basic", "title": "Providing multiple sources" } [/block] If you want to provide more than one format for your video, you will have to pass each of them as a single `<source>` element. This is how to provide several sources: [block:code] { "codes": [ { "code": "<video class=\"afterglow\" id=\"myvideo\" width=\"1280\" height=\"720\">\n <source type=\"video/mp4\" src=\"/path/to/myvideo.mp4\" />\n <source type=\"video/webm\" src=\"/path/to/myvideo.webm\" />\n <source type=\"video/ogg\" src=\"/path/to/myvideo.ogg\" />\n</video>", "language": "html" } ] } [/block] In this case, the browser would try to playback the MP4 file. If it failed (maybe because it doesn't know the codec or stuff like this) it will try the next source it finds, WebM in this case. You can order your sources the way you want to. We'd recommend using MP4 - WebM - OGG, but that's just a feeling we got during the last few years. This order seemed most stable to us. [block:api-header] { "type": "basic", "title": "Resolution switching" } [/block] If you want to provide a low res and a high res version of your video, just do so. In order to have afterglow recognize your high res (HD) version, add the attribute `data-quality="hd"` to it. Just like this: [block:code] { "codes": [ { "code": "<video class=\"afterglow\" id=\"myvideo\" width=\"1280\" height=\"720\">\n <source type=\"video/mp4\" src=\"/path/to/myvideo.mp4\" />\n <source type=\"video/mp4\" src=\"/path/to/myvideo_hd.mp4\" data-quality=\"hd\"/>\n <source type=\"video/webm\" src=\"/path/to/myvideo.webm\" />\n <source type=\"video/webm\" src=\"/path/to/myvideo_hd.webm\" data-quality=\"hd\"/>\n <source type=\"video/ogg\" src=\"/path/to/myvideo.ogg\" />\n <source type=\"video/ogg\" src=\"/path/to/myvideo_hd.ogg\" data-quality=\"hd\"/>\n</video>", "language": "html" } ] } [/block] If you want to start with the HD version, just provide the HD version in the first place. There are working examples for both SD first and HD first [here](doc:using-resolution-switching). Resolution switching works only for local sources, not for [Youtube clips](doc:youtube-video). [block:callout] { "type": "success", "title": "We always use the `<source>` markup", "body": "In most of the examples you can find in the documentation, we use the `<source>` element even if we don't provide multiple sources. That's just for readability reasons and helps us getting the logic straight. There is the player and the thing it plays, so let's separate them.\n\nAlthough we like the `<source>` element, it's not generally recommended over the other way. So find your own way of working things out. ;-)" } [/block] [block:callout] { "type": "info", "body": "When it comes to video playback, the most commonly used webbrowsers (like Chrome, Firefox, Safari, Internet Explorer, etc.) are not very reliable. Most of the firms creating those browsers want to establish their own video format and don't really force general standards for HTML5 video.\n\nThe result of their fights with each other is that you, as a website creator, have to cope with lot's of different behaviours. Some browsers prefer MP4, others like WebM, OGG is also sometimes mentioned and then there is Windows 7 or some mobile devices not playing HTML5 video at all.\n\nWe'd always recommend including your videos as MP4 files which has proven to cover most of the modern browsers and devices. In order to cover as many browsers and devices as possible, you probably should also include WebM and OGG transcoded versions.", "title": "Which video formats to use?" } [/block] [block:callout] { "type": "warning", "title": "MP4 != MP4", "body": "Be aware that *MP4* is just a container format. It can contain many different video codecs and bandwidths.\n\nRecommended settings for video encoding with a good balance between quality and bandwidth are:\n\n- video codec: H264\n- audio codec: AAC\n- video bandwidth: *video width in pixels* x 1.5 + 500\n- audio bandwidth: 96 Kbps - 128 Kbps\n\nThese settings result in videos that most devices are able to play back and that should look quite good. \n\nThis is just some advice from our experience. The needed bandwidth hugely depends on what your video is actually showing, on the target audience (mobile/desktop), and so on..." } [/block]