• This repository has been archived on 21/Oct/2022
  • Stars
    star
    100
  • Rank 328,881 (Top 7 %)
  • Language
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Explainer repo for a proposal to improve the responsive capabilities of the HTML video element

โš ๏ธ This project is archived and the repository is no longer maintained.

HTML Video Element:

Proposal For Reintroduction of Media (and srcset/sizes) in Source Elements

The web is often too slow and data intensive for users because it's difficult for developers to correctly deliver an appropriate video size to different devices. According to the HTTP Archive, video delivery size is heavier on mobile devices (1897.3 KB) than desktop devices (1592.1 KB). We need better and simpler tools to deliver video responsively.

The following explainer summarizes the problems caused by HTML's lack of support for offering multiple video source resolutions.

Problem statement

The HTML video element allows authors to specify multiple source files for a video based on their file type (eg, mp4 and webm), but it does not offer any means of specifying multiple resolutions, orientations, or aspect ratios of a video based on the needs of a device and a video's surrounding page layout. Due to this limitation, users who visit websites that contain standard HTML video are at risk of downloading files that may be larger or smaller than their device needs. Videos that are larger than a screen's resolution will decrease page performance and data consumption, while videos that are smaller than a screen's resolution will appear low-quality, and videos that are merely the wrong orientation can not make adequate use of a device's available viewport space.

In several browsers, the video element formerly supported media attributes on its source elements, which allowed authors to specify a CSS media type or query where the source should be selected by a user agent. Despite being implemented in multiple browsers, the feature was removed from browsers and the HTML specification, without any proposed replacement for the functionality it once provided. One exception is the feature was never removed from Webkit, so it still works in Safari browsers, which is great.

Due to that removal, there is no current cross-browser way to deliver an appropriately sized video across devices using HTML video alone, leaving authors to resort rely on more complex alternatives, such as using JavaScript to analyze user agent conditions in order to modify a video element's available sources, or other alternatives like server-side detection or third party video embedding. As a complimentary feature, itโ€™s worth noting that there is a DASH protocol for streaming video based on speed and network capabilities, but no parallel option to manage size for literal dimension in a layout.

Reintroducing the ability to offer multiple source resolutions for a video will offer:

  1. users a more contextual, more performant, and less bandwidth-costly browsing experience,
  2. authors better control over the source sizes they offer users, and more flexibility for art direction
  3. site owners savings in hosting costs by saving bytes where possible

Proposed Solution

HTML video source elements should offer a set of flexible features for source selection that are consistent with that of the HTML img element and the HTML picture element; namely, the media, srcset and sizes attributes.

Primarily of concern, as with picture, video sources could be specified using media in cases where an author would like a particular source to be used as long as the media conditions match (the "art direcion" use case). As a stretch goal, it would be ideal if video also supported the srcset and sizes attributes for cases where the author would like to offer the user agent various sizes of a video and allow it to choose the most appropriate given the browsing conditions.

Picture and Img Element Examples for Inspiration

An example of the standard picture element using media, srcset, and sizes features (note: code examples credit to TutsPlus):

<picture>
    <source media="(min-width: 1200px)" srcset="image-large.png 1200w">
    <source media="(min-width: 800px)" srcset="image-medium.png 800w">
    <img src="image-small.png" alt="Image description">
</picture>

An example of picture using a combination of media and srcset:

<picture>
    <source
        media="(orientation: landscape)"
        srcset="image-small.png 320w,
                image-medium.png 800w,
                image-large.png 1200w"
        sizes="(min-width: 60rem) 80vw,
               (min-width: 40rem) 90vw,
               100vw">
    <source
        srcset="image-small-portrait.png 160w,
                image-medium-portrait.png 400w,
                image-large-portrait.png 600w"
        sizes="(min-width: 60rem) 80vw,
               (min-width: 40rem) 90vw,
               100vw">
    <img src="image-small.png" alt="Image description">
</picture>

Additionally, the img element offers srcset and sizes directly, for cases when picture and media attributes aren't necessary:

<img src="image-small.png"
    srcset="image-small.png 320w, image-medium.png 800w, image-large.png 1200w"
    sizes="(min-width: 60rem) 80vw,
           (min-width: 40rem) 90vw,
           100vw"
    alt="Image description">

Proposed Code Examples using video

Following the picture examples above, here's how the video element could look:

<video>
    <source media="(min-width: 1200px)" src="video-large.webm 1200w" type="video/webm">
    <source media="(min-width: 1200px)" src="video-large.mp4 1200w" type="video/mp4">
    <source media="(min-width: 800px)" src="video-medium.webm 800w" type="video/webm">
    <source media="(min-width: 800px)" src="video-medium.mp4 800w" type="video/mp4">
    <source src="video-small.webm" type="video/webm">
    <source src="video-small.mp4" type="video/mp4">
</video>

Stretch-Goal: srcset and sizes, like picture supports

A video using a combination of media and srcset to factor in device orientation for the video.

<video>
  <source
        type="video/webm"
        media="(orientation: landscape)"
        srcset="video-small.webm 320w,
                video-medium.webm 800w,
                video-large.webm 1200w"
        sizes="(min-width: 60rem) 80vw,
               (min-width: 40rem) 90vw,
               100vw">
    <source
        type="video/mp4"
        media="(orientation: landscape)"
        srcset="video-small.mp4 320w,
                video-medium.mp4 800w,
                video-large.mp4 1200w"
        sizes="(min-width: 60rem) 80vw,
               (min-width: 40rem) 90vw,
               100vw">
  
    <source
        type="video/webm"
        srcset="video-portrait-small.webm 320w,
                video-portrait-medium.webm 800w,
                video-portrait-large.webm 1200w"
        sizes="(min-width: 60rem) 80vw,
               (min-width: 40rem) 90vw,
               100vw">
    <source
        type="video/mp4"
        srcset="video-portrait-small.mp4 320w,
                video-portrait-medium.mp4 800w,
                video-portrait-large.mp4 1200w"
        sizes="(min-width: 60rem) 80vw,
               (min-width: 40rem) 90vw,
               100vw">
</video>

Like img, a video element could offer srcset and sizes directly, for cases when only one file type is available, and media attributes aren't necessary.

<video src="video-small.mp4"
    srcset="video-small.mp4 320w, video-medium.mp4 800w, video-large.mp4 1200w"
    sizes="(min-width: 60rem) 80vw,
           (min-width: 40rem) 90vw,
           100vw"></video>

Existing Alternatives

Multiple patterns exist today that allow us to serve contextual video size and quality to devices, but they are more complicated than an HTML-only solution could provide. Here are some examples:

  • Generating HTML video sources with JavaScript, after querying media conditions (implementations may use DOM scripting, framework templating, and more):
<video id="myvideo"></video>
<script>
   document.getElementById("myvideo").src = 'path/to/video-' + (matchMedia( "(min-width: 400px)" ).matches ? 'lrg' : 'sml') + '.mp4';
</script>
  • The future DASH standard offers a server-side solution for conditioning video streams based on speed and network capabilities. Once supported, it could nicely complement an HTML-driven responsive video approach, but it requires server-based coordination that may not be available to authors and does not allow for fine clientside control over delivering video to particular media breakpoints and variations. https://developer.mozilla.org/en-US/docs/Web/Media/DASH_Adaptive_Streaming_for_HTML_5_Video
  • Various popular third-party video embedding services (Youtube, Vimeo, etc) offer a solution to delivering video with contextual quality and size, typically using iframes or client/server scripting. These do not typically give authors HTML control over varying video delivery by clientside media conditions.

Possible Alternatives

The following suggestions could address some but not all concerns addressed by this proposal.

  • Yoav Weiss suggested that perhaps picture could instead gain better support for selecting multiple video sources, assuming they are silent. This of course only covers ambient "background" videos, but would not be a great solution for videos that require controls, audio, vtt tracks, etc.
  • Similar to Yoav's suggestion, if CSS gained support for video formats as background-images, that could potentially improve our control for silent ambient videos in layout.

Challenges, and Differences from Picture

Some differences in how and when sources are selected with video and with picture are likely necessary.

  • One of these that comes to mind is whether or not sources are re-evaluated for matches when UA or viewport conditions change. It seems reasonable to expect that a srcset/sizes driven selection could be selected just once when first parsed, whereas sources that are specified for particular media types and queries should probably be re-evaluated throughout a session, so that changes to device orientation, layout, or viewport size are respected.
  • Per Simon Pieters, changing a video source is complicated for reasons beyond download size:

"Loading a new resource is "destructive" (resets currentTime etc)." "How would you change video loading to make media="" useful? Is it ok to destructively load a different resource when you rotate your phone? Or do you want a seamless switch-over ร  la DASH?"

Discussion Encouraged!

Please feel free to add an issue to the tracker with any questions or comments. We aim to improve this summary over time until it (hopefully) finds a better home.

Also, please feel free to share the article that pairs with this explainer: http://filamentgroup.com/lab/video-with-sizes/

Thanks! Scott Jehl Filament Group, Inc http://filamentgroup.com

More Repositories

1

loadCSS

Load CSS asynchronously
JavaScript
6,727
star
2

tablesaw

A group of plugins for responsive tables.
JavaScript
5,499
star
3

grunticon

A mystical CSS icon solution.
HTML
3,311
star
4

criticalCSS

Finds the Above the Fold CSS for your page, and outputs it into a file
JavaScript
1,695
star
5

fixed-sticky

DEPRECATED: A position: sticky polyfill that works with filamentgroup/fixed-fixed for a safer position:fixed fallback.
JavaScript
1,486
star
6

Responsive-Images

NOTE: use Picturefill instead. An Experiment with Mobile-First Images that Scale Responsively & Responsibly
JavaScript
1,383
star
7

SocialCount

Unmaintained (see the README): Simple barebones project to show share counts from various social networks.
JavaScript
1,358
star
8

select-css

Cross-browser styles for consistent select element styling
CSS
1,237
star
9

glyphhanger

Your web font utility belt. It can subset web fonts. It can find unicode-ranges for you automatically. It makes julienne fries.
JavaScript
1,114
star
10

Southstreet

Filament Group's core tools & workflow for delivering rich cross-device web applications
JavaScript
1,087
star
11

responsive-carousel

A jQuery-based script for responsive carousels that work with mouse, touch, and keyboard
JavaScript
907
star
12

Overthrow

A tiny, no-frills, framework-independent, targeted overflow: auto polyfill for use in responsive design.
JavaScript
906
star
13

loadJS

A simple function for asynchronously loading JavaScript files
JavaScript
895
star
14

Ajax-Include-Pattern

An Ajax-Include Pattern for Modular Content
JavaScript
627
star
15

tappy

Retired (see README): Tappy! - a lightweight normalized tap event.
HTML
573
star
16

politespace

Politely add spaces to numeric form values to increase readability (credit card numbers, phone numbers, etc).
JavaScript
537
star
17

grunt-criticalcss

Grunt wrapper for criticalcss
JavaScript
530
star
18

enhance

A JavaScript workflow designed to progressively enhance sites in a qualified manner.
JavaScript
489
star
19

shoestring

A lightweight, simple DOM utility made to run on a tight budget.
JavaScript
441
star
20

imaging-heap

A command line tool to measure the efficiency of your responsive image markup across viewport sizes and device pixel ratios.
JavaScript
401
star
21

snapper

A CSS Snap-Points based carousel (and lightweight polyfill)
JavaScript
361
star
22

jQuery-Visualize

HTML5 canvas charts driven by HTML table elements
JavaScript
353
star
23

a-font-garde

A variety of test cases and tools for safe font-icon usage.
JavaScript
292
star
24

jQuery-UI-Date-Range-Picker

A range picker built on top of jQuery UI's Datepicker Control
JavaScript
272
star
25

X-rayHTML

A little something to help build documentation pages.
JavaScript
260
star
26

AppendAround

A pattern for responsive markup
JavaScript
236
star
27

jqm-pagination

jQuery Mobile Pagination for touch, mouse, and keyboard
JavaScript
214
star
28

jQuery-Equal-Heights

This repository is unmaintained. Please see the included readme for more information.
JavaScript
206
star
29

formcore

A set of forms.
HTML
205
star
30

font-loading

Research on fonts
HTML
193
star
31

quickconcat

a simple dynamic concatenator for html, css, and js files, written in php
PHP
182
star
32

fixed-fixed

CSS position:fixed qualifier.
HTML
179
star
33

RWD-Nav-Patterns

Experimental navigation structure and behavior patterns based on progressive enhancement and responsive web design.
CSS
146
star
34

jQuery-Custom-File-Input

CSS-Friendly File Input
JavaScript
132
star
35

svg-to-png

Turn a folder full of SVGs into PNGs!
JavaScript
125
star
36

layersnap

Build SVG transitions simply and declaratively
JavaScript
110
star
37

woff2-feature-test

A simple feature test for the WOFF2 font format
JavaScript
107
star
38

RWD-Table-Patterns

This repository has been retired. Please see the readme below for more information.
JavaScript
105
star
39

EnhanceJS

Are you looking for the new "Enhance"? Try here https://github.com/filamentgroup/enhance
JavaScript
105
star
40

scoped-media-query

An element query workaround. A Sass mixin for scoping CSS styles to apply only within given selector/media query pairs.
SCSS
104
star
41

jQuery-File-Download

One issue we have not yet seen addressed is the Ajaxโ€™s inability to receive a response in any form but text. Since it is now common for web applications to offer options for exporting your data in desktop app formats โ€” such as .doc or .xls โ€” we wrote a jQuery plugin to facilitate requests from the front end that result in a file for download. The plugin does not actually use Ajax, but its syntax follows the conventions of jQuery's native Ajax functions, making it a natural addition to our jQuery toolset.
JavaScript
98
star
42

faux-pas

A script to highlight elements that are mismatched incorrectly to @โ€‹font-face blocks, which may result in shoddy faux bold or faux italic rendering.
HTML
97
star
43

enlarge

zoom a photo
JavaScript
91
star
44

cookie

Get, set, forget cookies!
JavaScript
91
star
45

elementary

A CSS workflow for mimicking element queries
JavaScript
87
star
46

porthole

Activate stuff when it's in the viewport
JavaScript
86
star
47

jQuery-Menu

Dropdown, iPod Drilldown, and Flyout styles with ARIA Support and ThemeRoller Ready
CSS
83
star
48

collapsible

Toggle your collapsible content
JavaScript
81
star
49

dialog

Just a simple, minimal jQuery dialog with typical interactivity
JavaScript
80
star
50

jQuery-Preload-CSS-Images

A solution that automates the age-old task of preloading images in web applications.
JavaScript
75
star
51

fg-modal

A modal web component
JavaScript
71
star
52

grumpicon

Grunticon Web App.
JavaScript
71
star
53

gulpicon

A gulp task wrapper for grunticon-lib.
Handlebars
67
star
54

jQuery-Custom-Input

Accessible, custom designed checkbox and radio button inputs styled with CSS (and a dash of jQuery)
HTML
63
star
55

checkboxradio

jQuery Plugin for progressively enhanced radio buttons and checkboxes
JavaScript
54
star
56

select

Minimally custom-styled select element
CSS
53
star
57

Revolver

A 360ยฐ panoramic photo viewer
JavaScript
50
star
58

resizeasaurus

A little utility to add resizing behavior to test intrinsically sized responsive components.
HTML
49
star
59

jQuery-Pixel-Em-Converter

jQuery Plugin for Retaining Scalable Interfaces with Pixel-to-Em Conversion
JavaScript
48
star
60

jQuery-Mobile-FixedToolbar-Legacy-Polyfill

Brings jQM Fixed Toolbar support to browsers that don't natively support position:fixed (like iOS4)
HTML
43
star
61

grunticon-lib

Stand-alone library for Grunticon
JavaScript
42
star
62

cq

A minimal container query web component
JavaScript
39
star
63

Overthrow-Sidescroller

The Sidescroller extension for Overthrow
JavaScript
37
star
64

jQuery-Mobile-Themed-DatePicker

This is jQuery UI's datepicker plugin with jQuery Mobile's theming and script handling applied.
HTML
36
star
65

auto-complete

A very small auto-complete component.
JavaScript
36
star
66

jQuery-Tree-Control

An accessible HTML tree component
JavaScript
34
star
67

anims

Just some CSS utilities for build and loop animations.
CSS
34
star
68

jQuery-Slider

Accessible, custom slider widget based on a standard HTML select
JavaScript
34
star
69

directory-encoder

Takes a directory of images, turns it into some CSS.
JavaScript
33
star
70

Accessible-jQuery-Tabs

A simple jQuery plugin for accessible tabs widget
HTML
30
star
71

face-off

This repository has been retired. Please see the readme below for more information.
HTML
29
star
72

Heart.js

A lightweight โ€œtickerโ€ plugin.
HTML
28
star
73

tau

Tau is a small and simple 360ยฐ gallery
JavaScript
26
star
74

Menu

jQuery Plugin for progressively enhanced menus
JavaScript
26
star
75

jQuery-Collapsible-Content

An accessible collapsible content panel plugin
JavaScript
25
star
76

directory-colorfy

Turn a folder of SVGs into a different color, quickly!
JavaScript
24
star
77

script-media-query

An @media (script) polyfill experiment
JavaScript
21
star
78

fg-carousel

An accessible carousel web component
JavaScript
18
star
79

Details

JavaScript
17
star
80

iconoclash

A workflow for configurable external svg sets.
JavaScript
12
star
81

iframe-caching

HTML
12
star
82

marquee

HTML
11
star
83

creditable

Utilities for working with credit card form input.
JavaScript
11
star
84

postcss-media-query-optimizer

A postcss plugin that will optimize your media queries.
JavaScript
10
star
85

servers-workers

Service Worker examples to be used at the CDN level.
JavaScript
9
star
86

component

just our typical auto enhance-able component skeleton
JavaScript
9
star
87

jqm-mail

An experimental responsive web app layout using jQuery Mobile controls
HTML
8
star
88

fg-collapse

An accessible collapsible web component
JavaScript
8
star
89

getmeta

get a meta tag's value by its name
JavaScript
8
star
90

3D-feature-test

Using progressive enhancement to apply 3D flip animation only to capable browsers
CSS
7
star
91

node-faux-pas

A command line utility to test a URL for faux web font rendering and mismatched web font code.
JavaScript
7
star
92

wc-experiments

web components and such
JavaScript
6
star
93

pym

A lightweight zoom library
JavaScript
4
star
94

validator

Form validation goodies
JavaScript
4
star
95

toss

A JavaScript function that scrolls any overflow container to a set of coordinates using an animated duration.
JavaScript
3
star
96

Trunca-

JavaScript
2
star
97

demo-head

Header for demo pages
CSS
2
star
98

compare-embed

HTML
1
star
99

flex-luthor

A small wrapper library to help with responsive intrinsic-sized Flexbox layouts that wrap based on content and container width and avoiding viewport-based media queries.
Nunjucks
1
star