• Stars
    star
    444
  • Rank 94,441 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 8 years ago
  • Updated 5 months ago

Reviews

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

Repository Details

An m3u8 parser.

m3u8-parser

Build Status Greenkeeper badge Slack Status

NPM

m3u8 parser

Installation

npm install --save m3u8-parser

The npm installation is preferred, but Bower works, too.

bower install  --save m3u8-parser

Usage

var manifest = [
  '#EXTM3U',
  '#EXT-X-VERSION:3',
  '#EXT-X-TARGETDURATION:6',
  '#EXT-X-MEDIA-SEQUENCE:0',
  '#EXT-X-DISCONTINUITY-SEQUENCE:0',
  '#EXTINF:6,',
  '0.ts',
  '#EXTINF:6,',
  '1.ts',
  '#EXTINF:6,',
  '2.ts',
  '#EXT-X-ENDLIST'
].join('\n');

var parser = new m3u8Parser.Parser();

parser.push(manifest);
parser.end();

var parsedManifest = parser.manifest;

Parsed Output

The parser ouputs a plain javascript object with the following structure:

Manifest {
  allowCache: boolean,
  endList: boolean,
  mediaSequence: number,
  discontinuitySequence: number,
  playlistType: string,
  custom: {},
  playlists: [
    {
      attributes: {},
      Manifest
    }
  ],
  mediaGroups: {
    AUDIO: {
      'GROUP-ID': {
        NAME: {
          default: boolean,
          autoselect: boolean,
          language: string,
          uri: string,
          instreamId: string,
          characteristics: string,
          forced: boolean
        }
      }
    },
    VIDEO: {},
    'CLOSED-CAPTIONS': {},
    SUBTITLES: {}
  },
  dateTimeString: string,
  dateTimeObject: Date,
  targetDuration: number,
  totalDuration: number,
  discontinuityStarts: [number],
  segments: [
    {
      byterange: {
        length: number,
        offset: number
      },
      duration: number,
      attributes: {},
      discontinuity: number,
      uri: string,
      timeline: number,
      key: {
        method: string,
        uri: string,
        iv: string
      },
      map: {
        uri: string,
        byterange: {
          length: number,
          offset: number
        }
      },
      'cue-out': string,
      'cue-out-cont': string,
      'cue-in': string,
      custom: {}
    }
  ]
}

Supported Tags

Basic Playlist Tags

Media Segment Tags

Media Playlist Tags

Master Playlist Tags

Experimental Tags

m3u8-parser supports 3 additional Media Segment Tags not present in the HLS specification.

EXT-X-CUE-OUT

The EXT-X-CUE-OUT indicates that the following media segment is a break in main content and the start of interstitial content. Its format is:

#EXT-X-CUE-OUT:<duration>

where duration is a decimal-floating-point or decimal-integer number that specifies the total duration of the interstitial in seconds.

EXT-X-CUE-OUT-CONT

The EXT-X-CUE-OUT-CONT indicates that the following media segment is a part of interstitial content and not the main content. Every media segment following a media segment with an EXT-X-CUE-OUT tag SHOULD have an EXT-X-CUE-OUT-CONT applied to it until there is an EXT-X-CUE-IN tag. A media segment between a EXT-X-CUE-OUT and EXT-X-CUE-IN segment without a EXT-X-CUE-OUT-CONT is assumed to be part of the interstitial. Its format is:

#EXT-X-CUE-OUT-CONT:<n>/<duration>

where n is a decimal-floating-point or decimal-integer number that specifies the time in seconds the first sample of the media segment lies within the interstitial content and duration is a decimal-floating-point or decimal-integer number that specifies the total duration of the interstitial in seconds. n SHOULD be the sum of EXTINF durations for all preceding media segments up to the EXT-X-CUE-OUT tag for the current interstitial. duration SHOULD match the duration specified in the EXT-X-CUE-OUT tag for the current interstitial.'

EXT-X-CUE-IN

The EXT-X-CUE-IN indicates the end of the interstitial and the return of the main content. Its format is:

#EXT-X-CUE-IN

There SHOULD be a closing EXT-X-CUE-IN tag for every EXT-X-CUE-OUT tag. If a second EXT-X-CUE-OUT tag is encountered before an EXT-X-CUE-IN tag, the client MAY choose to ignore the EXT-X-CUE-OUT and treat it as part of the interstitial, or reject the playlist.

Example media playlist using EXT-X-CUE- tags.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXTINF:10,
0.ts
#EXTINF:10,
1.ts
#EXT-X-CUE-OUT:30
#EXTINF:10,
2.ts
#EXT-X-CUE-OUT-CONT:10/30
#EXTINF:10,
3.ts
#EXT-X-CUE-OUT-CONT:20/30
#EXTINF:10,
4.ts
#EXT-X-CUE-IN
#EXTINF:10,
5.ts
#EXTINF:10,
6.ts
#EXT-X-ENDLIST

Not Yet Supported

Custom Parsers

To add a parser for a non-standard tag the parser object allows for the specification of custom tags using regular expressions. If a custom parser is specified, a custom object is appended to the manifest object.

const manifest = [
  '#EXTM3U',
  '#EXT-X-VERSION:3',
  '#VOD-FRAMERATE:29.97',
  ''
].join('\n');

const parser = new m3u8Parser.Parser();
parser.addParser({
  expression: /^#VOD-FRAMERATE/,
  customType: 'framerate'
});

parser.push(manifest);
parser.end();
parser.manifest.custom.framerate // "#VOD-FRAMERATE:29.97"

Custom parsers may additionally be provided a data parsing function that take a line and return a value.

const manifest = [
  '#EXTM3U',
  '#EXT-X-VERSION:3',
  '#VOD-FRAMERATE:29.97',
  ''
].join('\n');

const parser = new m3u8Parser.Parser();
parser.addParser({
  expression: /^#VOD-FRAMERATE/,
  customType: 'framerate',
  dataParser: function(line) {
    return parseFloat(line.split(':')[1]);
  }
});

parser.push(manifest);
parser.end();
parser.manifest.custom.framerate // 29.97

Custom parsers may also extract data at a segment level by passing segment: true to the options object. Having a segment level custom parser will add a custom object to the segment data.

const manifest = [
    '#EXTM3U',
    '#VOD-TIMING:1511816599485',
    '#EXTINF:8.0,',
    'ex1.ts',
    ''
  ].join('\n');

const parser = new m3u8Parser.Parser();
parser.addParser({
  expression: /#VOD-TIMING/,
  customType: 'vodTiming',
  segment: true
});

parser.push(manifest);
parser.end();
parser.manifest.segments[0].custom.vodTiming // #VOD-TIMING:1511816599485

Custom parsers may also map a tag to another tag. The old tag will not be replaced and all matching registered mappers and parsers will be executed.

const manifest = [
    '#EXTM3U',
    '#EXAMPLE',
    '#EXTINF:8.0,',
    'ex1.ts',
    ''
  ].join('\n');

const parser = new m3u8Parser.Parser();
parser.addTagMapper({
  expression: /#EXAMPLE/,
  map(line) {
    return `#NEW-TAG:123`;
  }
});
parser.addParser({
  expression: /#NEW-TAG/,
  customType: 'mappingExample',
  segment: true
});

parser.push(manifest);
parser.end();
parser.manifest.segments[0].custom.mappingExample // #NEW-TAG:123

Including the Parser

To include m3u8-parser on your website or web application, use any of the following methods.

<script> Tag

This is the simplest case. Get the script in whatever way you prefer and include it on your page.

<script src="//path/to/m3u8-parser.min.js"></script>
<script>
  var parser = new m3u8Parser.Parser();
</script>

Browserify

When using with Browserify, install m3u8-parser via npm and require the parser as you would any other module.

var m3u8Parser = require('m3u8-parser');

var parser = new m3u8Parser.Parser();

With ES6:

import { Parser } from 'm3u8-parser';

const parser = new Parser();

RequireJS/AMD

When using with RequireJS (or another AMD library), get the script in whatever way you prefer and require the parser as you normally would:

require(['m3u8-parser'], function(m3u8Parser) {
  var parser = new m3u8Parser.Parser();
});

License

Apache-2.0. Copyright (c) Brightcove, Inc

More Repositories

1

video.js

Video.js - open source HTML5 video player
JavaScript
37,092
star
2

videojs-contrib-hls

HLS library for video.js
JavaScript
2,835
star
3

http-streaming

HLS, DASH, and future HTTP streaming protocols library for video.js
JavaScript
2,410
star
4

videojs-youtube

YouTube playback technology for Video.js
JavaScript
1,097
star
5

mux.js

Lightweight utilities for inspecting and manipulating video container formats.
JavaScript
1,057
star
6

videojs-vr

A plugin to add 360 and VR video support to video.js.
JavaScript
522
star
7

videojs-contrib-ads

A Tool for Building Video.js Ad Plugins
JavaScript
376
star
8

videojs-playlist

Playlist plugin for videojs
JavaScript
352
star
9

video-js-swf

Custom Flash Player for VideoJS
JavaScript
338
star
10

videojs-contrib-dash

Video.js plugin for supporting the MPEG-DASH playback through a video.js player
JavaScript
293
star
11

videojs-overlay

A video.js plugin to display simple overlays during playback.
JavaScript
239
star
12

videojs-flash

The Flash tech for video.js
JavaScript
214
star
13

videojs-vimeo

Support Vimeo source for Video.js
JavaScript
195
star
14

videojs-contrib-eme

Supports Encrypted Media Extensions for playback of encrypted content in Video.js
JavaScript
192
star
15

hls-fetcher

JavaScript
163
star
16

videojs-contrib-quality-levels

JavaScript
155
star
17

videojs-contrib-media-sources

Code for working with the media source extensions API and video.js
JavaScript
145
star
18

themes

Videojs themes 💅
CSS
130
star
19

videojs-playlist-ui

A playlist video picker for video.js
JavaScript
127
star
20

thumbcoil

Tools for inspecting MPEG2TS, fMP4, and FLV files and the codec bitstreams therein
JavaScript
121
star
21

videojs-errors

A video.js plugin that displays error messages to video viewers.
JavaScript
85
star
22

generator-videojs-plugin

Yeoman generator for video.js plugins.
JavaScript
81
star
23

mpd-parser

JavaScript
77
star
24

vtt.js

A JavaScript implementation of the WebVTT specification, forked from vtt.js for use with Video.js
JavaScript
68
star
25

font

Icon font used for Video.js
CSS
59
star
26

videojs.com

The Video.js Website
MDX
57
star
27

designer

A video.js player skin editor using a live CSS editor
JavaScript
42
star
28

aes-decrypter

JavaScript
32
star
29

videojs-playbackrate-adjuster

A Video.js middleware that adjusts controls based on playback rate
JavaScript
28
star
30

videojs-contextmenu-ui

A cross-device context menu UI for video.js players.
JavaScript
28
star
31

cdn

The video.js CDN
JavaScript
24
star
32

ie8

Video.js files for IE8 compatibility
JavaScript
23
star
33

video.js-component

Video.js - HTML5 Video Player - Component
JavaScript
15
star
34

docs

videojs docs
JavaScript
14
star
35

plugin-concat

Concatenate videos for playback by videojs/http-streaming in a Video.js player
JavaScript
10
star
36

videojs-adaptive

Building support for adaptive streaming video formats into video.js
JavaScript
10
star
37

doc-generator

Auto-generate API docs for the video.js codebase and plugins
JavaScript
8
star
38

videojs-settings-menu

A place to incubate a new settings menu for videojs.
JavaScript
8
star
39

videojs-media-session

Media Session API plugin
JavaScript
8
star
40

videojs-4to5

Tools to ease the transition from video.js 4.x to 5.x.
JavaScript
7
star
41

thumb.co.il

The fancy front-end for Thumbcoil!
JavaScript
7
star
42

standard

JavaScript Standard Style — One Style to Rule Them All
JavaScript
6
star
43

vhs-utils

Objects and functions shared throughout @videojs/http-streaming code
JavaScript
6
star
44

remark-preset-lint-videojs

A remark linting preset for Video.js
JavaScript
5
star
45

videojs-placeholder

A placeholder for videojs packages
5
star
46

web-media-box

TypeScript
5
star
47

blog

The video.js blog
Stylus
4
star
48

videojs-languages

JavaScript
4
star
49

grunt-videojs-languages

A grunt task to convert video.js language JSON files in to includable scripts.
JavaScript
4
star
50

videojs-generate-rollup-config

Generate a standard rollup config, so that plugins don't need the same script in every repository.
JavaScript
3
star
51

eslint-config-videojs

JavaScript
3
star
52

webwackify

launch a web worker that can require() in the browser with browserify and webpack
JavaScript
3
star
53

autoplay-tests

Autoplay test examples
HTML
2
star
54

tooling

A monorepo for all videojs project and plugin tooling
JavaScript
2
star
55

spellbook

JavaScript
2
star
56

ffrwd

ffrwd is an extensible HTML5 streaming media player capable of playing HLS, MPEG-DASH and more!
1
star
57

generator-helpers

A package to keep all of our generator helpers packages, so everything can be updated more easily.
1
star
58

.github

1
star
59

xhr

A small xhr wrapper
JavaScript
1
star
60

babel-config

A standard babel config, so that plugins don't need the same script in every repository.
JavaScript
1
star
61

rfcs

RFCs for changes to Video.js
1
star
62

videojs-bundler-sample

sample and test project for using Video.js with various bundler configurations
JavaScript
1
star
63

videojs-contrib-quality-menu

Adds a quality selector button to the Video.js control bar for Video.js 8+
JavaScript
1
star