All Projects → wix-playground → vidi

wix-playground / vidi

Licence: other
<video> playback simplified

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vidi

Magicalexoplayer
The Easiest Way To Play/Stream Video And Audio Using Google ExoPlayer In Your Android Application
Stars: ✭ 171 (+451.61%)
Mutual labels:  stream, hls
nginx-audio-track-for-hls-module
🔉 Nginx module that generates audio track for HTTP Live Streaming (HLS) streams on the fly.
Stars: ✭ 122 (+293.55%)
Mutual labels:  stream, hls
replay
A React video player facilitating adaptive stream playback with custom UI and a React-friendly API.
Stars: ✭ 202 (+551.61%)
Mutual labels:  hls, mpeg-dash
Hls.js
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
Stars: ✭ 10,791 (+34709.68%)
Mutual labels:  stream, hls
bitmovin-player-web-samples
Showcases build around the Bitmovin Adaptive Streaming Player, demonstrating usage and capabilities of the HTML5 based HLS and MPEG-DASH player, as well as the Flash based Fallback.
Stars: ✭ 69 (+122.58%)
Mutual labels:  hls, mpeg-dash
Nginx Vod Module
NGINX-based MP4 Repackager
Stars: ✭ 1,378 (+4345.16%)
Mutual labels:  stream, hls
shaka-player-react
A simple React component wrapper for shaka-player
Stars: ✭ 79 (+154.84%)
Mutual labels:  hls, mse
Huong-dan-cai-dat-stream-server-va-chuyen-doi-video-sang-streaming
Hướng dẫn cài đặt stream server và chuyển đổi video thường sang dạng TS Streaming
Stars: ✭ 29 (-6.45%)
Mutual labels:  stream, hls
video-server
Server which connects to set of existing RTSP's and provides HLS/MSE-based streams.
Stars: ✭ 12 (-61.29%)
Mutual labels:  hls, mse
hls-segment-reader
Node.js Readable for retrieving HLS segments.
Stars: ✭ 18 (-41.94%)
Mutual labels:  stream, hls
Backoffice Administration
Stars: ✭ 89 (+187.1%)
Mutual labels:  stream, hls
smart rtmpd
RTMP server, smart, compact, high performance(c, c++), high concurrency, easy to maintain, easy to deploy, (supports multiple operating systems Windows and Linux, ARM, FreeBSD)
Stars: ✭ 159 (+412.9%)
Mutual labels:  hls, mpeg-dash
Shinobi
☮️ 🇵🇸 Shinobi CE - The Free Open Source CCTV platform written in Node.JS (Camera Recorder - Security Surveillance Software - Restreamer
Stars: ✭ 1,099 (+3445.16%)
Mutual labels:  stream, hls
Desktoplivestreaming
DesktopLiveStreaming
Stars: ✭ 138 (+345.16%)
Mutual labels:  stream, hls
Free Hls Live
Free live streaming with Free-HLS (Free HLS 直播姬)
Stars: ✭ 47 (+51.61%)
Mutual labels:  stream, hls
mock-hls-server
Fake a live/event HLS stream from a VOD one. Useful for testing. Supports looping.
Stars: ✭ 61 (+96.77%)
Mutual labels:  stream, hls
wsa
WSA(Websocket Streaming Agent) is a stream server target for mp4/h264 streaming over websocket
Stars: ✭ 35 (+12.9%)
Mutual labels:  stream, hls
livego
直播服务器 hls stream online RTMP AMF HLS HTTP-FLV
Stars: ✭ 30 (-3.23%)
Mutual labels:  stream, hls
ghichep-StreamingVideo
Ghi chép về Livestream sử dụng Opensource - Xây dựng một máy chủ Livestream theo cách đơn giản nhất - NGINX RTMP Dockerfile
Stars: ✭ 40 (+29.03%)
Mutual labels:  stream, hls
orcanode
Software for live-streaming and recording lossy or lossless compressed audio (HLS, DASH, FLAC) via AWS S3 buckets. ⭐
Stars: ✭ 23 (-25.81%)
Mutual labels:  hls, mpeg-dash

vidi - <video> playback simplified.

npm Build Status

The browser world is highly fragmented, and browser vendors all have their own preferences and priorities regarding video encoding standards and adaptive streaming methods. This results in a lack of compatiblity between browsers, with each browser supporting some methods while providing no support for other methods.

vidi makes it easy dealing with otherwise complex <video> playback scenarios.

How does vidi help?

  • Automatically picks a playback format based on the current browser's capabilities.
  • Provides seamless playback of adaptive content, even when native support is not available, by leveraging MSE-based libraries.
  • Normalizes and simplifies <video> events so that callbacks receive relevant information per the event type.

Compatible web browsers

  • Chrome (tested with v51.0.2704.84)
  • Firefox (tested with v47.0)
  • Internet Explorer 11 (tested on Windows 10)
  • Safari (tested with 9)

Getting started

Installation

vidi is currently only available via npm. At the root folder of the project run:

npm install vidi --save

Usage

We begin by importing vidi into our module, and initializing it.

If you're using ES6:

import {Vidi} from 'vidi';

Otherwise:

const Vidi = require('vidi').Vidi;

Then get the <video> element from the document, and create a Vidi instance:

// Assuming there is a <video> element in the document with id 'my-video-element'.
const videoElement = document.getElementById('my-video-element');

// Create a new Vidi instance, providing it the <video> element
const vidi = new Vidi(videoElement);

Set the source of the video stream:

vidi.src = 'http://my-url/video.mp4';

The type of stream is automatically detected from the URL. The following extensions are recognized: .mp4 (MP4), .webm (WebM), .m3u8 (HLS manifest), and .mpd (DASH manifest).

If the URL does not end with the file extension, the type can be specified explicitly:

vidi.src = { url: 'http://my-url/video-source', type: Vidi.MediaStreamTypes.HLS };

After a <video> and a src are provided, we have a working HTML5 media playback of all the supported source formats.

And now, the real magic occurs...

Multiple sources (of different formats) can be provided as an array:

vidi.src = [
  'http://my-url/video.mp4',
  'http://my-url/video.webm',
  'http://my-url/video.m3u8'
];

Types can still be specified explicitly (for all or some of the sources):

vidi.src = [
  'http://my-url/video.mp4',
  { url: 'http://my-url/video.webm', type: Vidi.MediaStreamTypes.WEBM },
  'http://my-url/video.m3u8'
];

vidi assumes the URLs point to different formats of the same video, and will automatically detect and choose the ideal format for the current browser.

The order of sources in the array doesn't matter. The logic uses the following prioritization system to pick the most suitable format (from highest priority to lowest):

  1. Adaptive sources that can be played via native browser support. Example: HLS on Safari
  2. Adaptive sources that can be played via MSE-based libraries. Example: DASH on Chrome
  3. Progressive sources (MP4 and WebM) that can be played via native browser support.

The algorithm bases decisions using browser feature detection.

Events

vidi provides an easy to use event system. Listeners (callbacks) receive relevant data, per event type, as parameters of the call.

It also normalizes several "status" changing native events (play, playing, pause, seeking, seeked, and ended) into a single statuschange event.

The following events can be listened to:

Event Type <video> info sent to the listener
statuschange PlaybackStatus value. One of:
  • vidi.PlaybackStatus.PLAYING
  • vidi.PlaybackStatus.PAUSED
  • vidi.PlaybackStatus.ENDED
  • vidi.PlaybackStatus.PLAYING_BUFFERING
  • vidi.PlaybackStatus.PAUSED_BUFFERING
durationchange Duration (in milliseconds)
timeupdate Current time (in milliseconds)
ratechange Playback rate (0 to 1, where 1 is full-speed, 0.5 is half-speed, etc)
volumechange An object containing volume and muted keys
loadstart PlaybackState object containing all data above combined
error See Error Handling section below.

The main Vidi class extends EventEmitter3, so any method from that implementation can be used on the created instances.

For example, subscribing to events can be done using the .on() method:

vidi.on('durationchange', function (newDuration) {
    console.log('New duration of video: ' + newDuration);
});

To unsubscribe a listener:

vidi.off('durationchange', durationChangeHandler);

Error Handling

Work in progress!

vidi aligns the different error codes in each possible playback flow into a single system.

Error codes are available on the main Vidi class:

Vidi.Errors.SRC_LOAD_ERROR // for src load failures in all flows

// More to come soon...

Listening for errors is done just like other events:

vidi.on('error', function(errorCode, url, originalEvent) {
    if (errorCode === Vidi.Errors.SRC_LOAD_ERROR) {
        // couldn't load src. url is provided as a second parameter
        // show a friendly message (or switch to a placeholder?)
    }
});

Adaptive playback via MSE-based libraries

When native browser support for adaptive content is not available, vidi uses MSE-based libraries (dash.js and hls.js) to allow seamless playback of MPEG-DASH and HLS media streams.

vidi normalizes the different APIs of each library into a single coherent interface, while also allowing for basic customization.

Initially preferred bitrate for adaptive sources can be configured per Vidi instance, via the setInitialBitrate method:

vidi.setInitialBitrate(3000); // 3000kbps
vidi.src = '...';

Media Levels

Work in progress!

vidi exposes two events which fire when a new adaptive source is played.

The levels event provides an array of MediaLevels, each representing a sub-streams in the adaptive source.

interface MediaLevel {
    width?: number;
    height?: number;
    bitrate?: number;
    name?: string;
}

vidi.on('levels', function (levels: MediaLevels[]) {
    // map the information to a GUI quality selector...
});

In addition, the currentLevel event is fired when playback switches to a new level:

vidi.on('currentLevel', function (levelIdx: number) {
    // highlight the current level in the GUI quality selector
});

Pseudo-adaptive:

Work in progress!

When two or more sources point to the same format, they are treated as different MediaLevels instead of separate sources. Same API as adaptive sources.

vidi.src = [
    { url: 'http://my-url/low_quality.mp4', type: Vidi.MediaStreamTypes.MP4, name: '480p' },    //    |---
    { url: 'http://my-url/medium_quality.mp4', type: Vidi.MediaStreamTypes.MP4, name: '720p' }, //  <=|    These three will be grouped by Vidi
    { url: 'http://my-url/high_quality.mp4', type: Vidi.MediaStreamTypes.MP4, name: '1080p' },  //    |---
    { url: 'http://my-url/adaptive-stream.m3u8', type: Vidi.MediaStreamTypes.HLS },
];

Development

The project is set up using the following tools: TypeScript, npm, webpack, mocha, and chai.

To get dev mode running, use the following commands:

git clone [email protected]:wix/vidi.git
cd vidi
npm install
npm start

Then browse to: http://localhost:8080/webpack-dev-server

Common commands

npm build - build using TypeScript

npm minify - bundle and minify using webpack

npm start - start webpack-dev-server

npm test - run tests, builds project first

npm run mediaserver - starts a local http media server (see the http-media-server folder)

License

We use a custom license, see LICENSE.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].