epiclabs-io / epic-video-comparator

Javascript library which implements a video comparator component: two overlaped and synchronized video players each one playing an independent source.
https://epiclabs-io.github.io/epic-video-comparator-demo/
MIT License
83 stars 8 forks source link

Epic Video Comparator · npm version Travis CI Status

LIVE DEMO

JavaScript library which implements a video comparator component: two overlapped and synchronized video players each one playing an independent source. It is based on epic-video-player library, which currently supports native HTML video (WebM, Ogg Theora Vorbis, Ogg Opus, Ogg FLAC and MP4 H.264), MPEG-DASH(dash.js) and HLS (hls.js) streams.

video-comparator-overview

For ABR sources, it is also possible to select the desired rendition to be played:

video-comparator-quality-selector

Installation

Install epic-video-comparator into your project

$ npm install @epiclabs/epic-video-comparator --save

Using it as CommonJS module

import { Comparator } from '@epiclabs/epic-video-comparator';
...
const comparatorConfig = {
    leftUrl: 'https://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.mpd',
    rightUrl: 'https://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.mpd',
    mediaControls: true,
    loop: true,
};
const myComp = new Comparator(comparatorConfig, document.getElementById('comparator-container'));

Using it as UMD module within <script> tag

<head>
    ...
    <script src="https://github.com/epiclabs-io/epic-video-comparator/raw/master/bundle/index.min.js"></script>
    ...
</head>
<body>
    ...
    <div id="comparator-container"></div>
    ...
    <script type="text/javascript">
        document.addEventListener('DOMContentLoaded', function () {
            var comparatorConfig = {
                leftUrl: 'https://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.mpd',
                rightUrl: 'https://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.mpd',
                mediaControls: true,
                loop: true,
            };
            window.myComp = new evc.Comparator(comparatorConfig, document.getElementById('comparator-container'));
        });
    </script>
    ...
</body>

Development

$ git clone https://github.com/epiclabs-io/epic-video-comparator.git
$ cd epic-video-comparator
$ npm install
$ npm run build

API

Methods

Events

The events are binded to the comparator container. Usage example:

var container = document.getElementById('comparator-container');
container.addEventListener('created', () => console.log('created!'));
Event Description
created Fires when the comparator is created (it occurs during comparator creation or reload but also when a new rendition is selected on any side).
fullscreen_toggle Fires when the comparator toggles its fullscreen mode.

Object interfaces

Name Properties Default value
IComparatorConfig autoplay?: boolean;
leftUrl: string;
loop?: boolean;
rightUrl: string;
mediaControls?: boolean;
stats?: IStatsConfig / boolean
true
-
true
-
true
IStatsConfig defaults
IStatsConfig showDuration?: boolean;
showBitrate?: boolean;
showResolution?: boolean;
showVideoCodec?: boolean;
showAudioCodec?: boolean;
showDroppedFrames?: boolean;
showBuffered?: boolean;
showStartupTime?: boolean;
custom?: boolean;
true
true
true
true
true
true
true
true
false