• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 9 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

A lightweight browser-based MPEG-4 (ISOBMFF) file/box parser.

codem-isoboxer

Build Status

Description

codem-isoboxer is a lightweight JavaScript MP4 (MPEG-4, ISOBMFF) parser. It is meant to be small, fast and efficient. A typical use-case would be inclusion in a new player framework (for emerging standards such as MPEG-DASH which rely on ISOBMFF for most situations, or HLS using fragmented MP4) or to extract metadata from MPEG-4 files:

  • Parsing emsg boxes for in-band events;
  • Parsing mdat boxes for extracting subtitles;
  • Validating ISOBMFF segments before playing them back;
  • [etc.]

Currently a limited set of ISOBMFF boxes is supported:

ISO/IEC 14496-12:2012 (ISOBMFF)

  • dinf
  • edts
  • elst
  • free / skip
  • ftyp / styp
  • hdlr
  • mdat
  • mdia
  • mdhd
  • meco
  • mehd
  • mfhd
  • mfra
  • mfro
  • minf
  • moov / moof
  • mp4a / enca
  • mvex
  • mvhd / mfhd
  • sidx
  • ssix
  • stbl
  • stsd
  • strk
  • subs
  • tfhd / tkhd
  • tfdt
  • tfra
  • traf / trak
  • tref
  • trex
  • trun
  • udta

ISO/IEC 23009-1:2014 (MPEG-DASH)

  • emsg

ISO/IEC 14496-30:2014 (Timed text and other visual overlays in ISOBMFF)

  • vttC
  • vttc
  • vtte
  • vlab
  • payl
  • sttg

ISO/IEC 14496-15:2014 (Carriage of network abstraction layer (NAL) unit structured video in ISO base media file format)

  • avc1/2/3/4 / hev1 / hvc1 / encv

Support for more boxes can easily be added by adding additional box parsers in src/parsers. Some utility functions are included to help with reading the various ISOBMFF data types from the raw file. Also, see the Box Support page on the Wiki for a full list.

Requirements

A modern web browser with support for:

  • ArrayBuffer
  • DataView
  • TextDecoder (optional)

Usage

Include one of the files in the dist folder (regular or minified) in your web page/application:

<script type="text/javascript" src="iso_boxer.min.js"></script>

Then, you can parse a file by calling the parseBuffer function:

var parsedFile = ISOBoxer.parseBuffer(arrayBuffer);
console.log(parsedFile.boxes);

The arrayBuffer can be obtained for example by issuing an XMLHttpRequest with responsetype set to arrayBuffer, or by using the FileReader API to read a local file.

codem-isoboxer makes no assumptions on the validity of the given file and/or segment. It also does minimal handling of the data types and provides mostly a raw interface. Some frequently used attributes are parsed to easier-to-use types, such as the major brand and list of compatible brands in the ftyp box.

For traversing the box structure you can use the _parent property. It returns exactly what you expect: the parent of the current box. The opposite is the boxes property (only available on container boxes such as moov), which gives you its children. Every box also has a _root property which returns the top-level (file) container.

Another way to use the software is to only retrieve the boxes you are interested in. This way you don't have to traverse the box structure yourself:

var parsedFile = ISOBoxer.parseBuffer(arrayBuffer); // Parse the file
var ftyp       = parsedFile.fetch('ftyp');          // Fetch the first box with the specified type (`ftyp`)
var mdats      = parsedFile.fetchAll('mdat');       // Fetch all the boxes with the specified type (`mdat`)

Traversal of the box structure is always depth first. Note that while you jump directly to a box using the fetch commands, the entire parsed structure is still available, so the _parent, _root and boxes properties are still available.

An additional utility method is included to convert DataViews into strings. This uses the TextDecoder interface is available, otherwise it falls back to a naïve implementation (bytes to character codes). If the TextDecoder interface is available you can supply an additional encoding parameter (defaults to utf-8) to the function.

var parsedFile = ISOBoxer.parseBuffer(arrayBuffer); // Parse the file
var mdat       = parsedFile.fetch('mdat');          // Get the first 'mdat' box
var text       = ISOBoxer.Utils.dataViewToString(mdat.data); // Convert the data into a string (e.g. captions)

Basic support for incomplete buffers is also available. Boxes and containers that cannot be fully parsed (due to an empty buffer) will be marked with an _incomplete property. You can simply add new data to the ArrayBuffer when it becomes available and re-parse the buffer.

NodeJS

Does it work in NodeJS? Well, it's really meant to be run in a web browser, but since Node supports most features it shouldn't be a problem. You can install it using NPM:

npm install codem-isoboxer

Then use it in your code (NodeJS v0.10.36 tested, 0.12.x should work as well):

var ISOBoxer    = require('codem-isoboxer'),
    fs          = require('fs');
var arrayBuffer = new Uint8Array(fs.readFileSync('my_test_file.mp4')).buffer;
var parsedFile  = ISOBoxer.parseBuffer(arrayBuffer);

Et voila. It does not support any of the fancy stream stuff from Node. Also, the Node console has some issues with printing objects that contain buffers/dataviews/circular references. It might not look pretty in the console, but it works.

Development

Check out the source from Github. Make changes to the files in /src (not in /dist). We use grunt to build the distribution files. If you add a box parser be sure to include a comment that points toward the relevant section in the specs. And if at all possible add a (small!) file to test/fixtures to provide an example. The test directory is not included in the published package on npmjs.org because of the included MPEG-4 files.

Building

grunt

Using grunt watcher

You can use grunt-contrib-watch to watch for changes to the source and automatically build it:

grunt watch

Tests

Included is a small set of tests which check the code against a known set of ISOBMFF files. The tests use NodeJS with jasmine-node. Make sure you have the grunt watcher running, as it tests against the resulting build of the JavaScript files. Usage:

# npm install jasmine-node -g
# jasmine-node test/spec

When adding new parsers please consider adding an ISOBMFF test file and a relevant test spec.

Please note, for size concerns, tests are only included in the Github repository and not in the released packages on NPM.

Advanced build options

Writing functionality

By default, codem-isoboxer build file contains all the code that manages the parsing AND the writing functionalities. If you are only interested in the parsing functionality, you can generate a build without writing functionality. The syntax for building is:

grunt --no-writing

Modular build

codem-isoboxer now has the option for modular builds. This means you can specify which boxes you are interested in during build time and you will get a generated file containing only the necessary boxes. This can help you further decrease the size of the library if you know you will only need access to some boxes. The syntax for building is:

grunt --boxes=moov,mdat

This will generate a build that only contains the code to parse these boxes and can yield significantly smaller builds. The list needs to be comma-separated. Be sure not to include any white-space in it. Note that some parsers share identical code (e.g. ftyp/styp, free/skip and all the regular container boxes). Including one of those will automatically include the other ones as well, but at no additional build size. See src/parsers for a list of available parsers and see which parsers share code.

codem-isoboxer does not take into account the box hierarchy/dependency when building, you must explicitly specify which boxes you need (e.g. if you want to parse mvhd you must also include moov). Boxes that are not included don't have their properties set, but you can still access their type and size properties and the raw data (._raw).

Demo

Open test/index.html in your browser. Use the file picker to select a local MPEG-4 file to parse it. Results will be in the window.parsedFile variable. Inspect it from your browser's console. Some test files are included in test/fixtures (not included in the package published on npmjs.org).

License

codem-isoboxer is released under the MIT license, see LICENSE.txt.

More Repositories

1

dash.js

A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers.
JavaScript
5,073
star
2

dash-live-source-simulator

DASH live source simulator providing reference live content.
Python
147
star
3

media-tools

A collection of tools for analyzing, handling, and creating media and media containers
Python
84
star
4

DASH-IF-Conformance

This repository provides the source code for MPEG-DASH/DASH-IF Conformance Software/Validator. It has been extended according to further standards, such as CMAF, DVB-DASH, HbbTV, and CTA WAVE.
HTML
67
star
5

livesim2

DASH Live Source Simulator v2 in Go
Go
36
star
6

DASH-IF-IOP

DASH-IF Interoperability Points issue tracker and document source code
Makefile
32
star
7

ClearKey-Content-Protection

The repository holds a description and an issue tracker for how ClearKey-based content protection should be used with MPEG DASH.
28
star
8

CPIX

Shell
25
star
9

Conformance-Software

Deprecated, moved to: https://github.com/Dash-Industry-Forum/DASH-IF-Conformance
HTML
20
star
10

MPEG-Conformance-and-reference-source

Contains several MPEG reference software modules. Not actively maintained. The ISOSegmentValidator is moved to - https://github.com/Dash-Industry-Forum/ISOSegmentValidator
C++
20
star
11

Ingest

HTML
13
star
12

dash-video-element

A custom element (web component) for playing DASH (Dynamic Adaptive Streaming over Http) videos.
JavaScript
11
star
13

Guidelines-TimingModel

DASH-IF implementation guidelines: the DASH timing model
9
star
14

CMAF-Conformance

CMAF sub repository of DASH-IF-Conformance. This repo contains CTAWAVE conformance functionalities as a submodule. CTA WAVE Github project is located at https://github.com/orgs/Dash-Industry-Forum/projects/6 but it is not visible to the public. To see this page & contribute, please get in contact with repository admin to be added as a collaborator.
PHP
9
star
15

cea608.js

A JavaScript project designed to extract CEA-608 captions.
JavaScript
8
star
16

ISOSegmentValidator

C++
7
star
17

Content-Steering

A standardized means of steering DASH players between substitutable content sources by way of a remote steering server.
6
star
18

Live

Collects issues about the Live document
5
star
19

DASH

XSLT
5
star
20

Dash-Industry-Forum.github.io

Public website for DASH IF
HTML
5
star
21

Watermarking

Discussion around watermarking solutions in DASH-IF
4
star
22

Test-Content

Documents Test Content Generation
Shell
4
star
23

Test-Vectors

DASH-IF Test Vectors
4
star
24

Guidelines-Security

DASH-IF implementation guidelines: content protection and security
4
star
25

webRTC

Discussions around webRTC-based Streaming
4
star
26

cpix-test-vectors

CPIX test vectors
4
star
27

Academic-Track

3
star
28

AdInsertion

3
star
29

ATSC

Tracks bugs for DASH profile for ATSC
CSS
3
star
30

Identifiers

Collects Identifiers to be added to DASH-IF
Shell
3
star
31

CPIX-Transfer-Protocol

3
star
32

HLS

PHP
3
star
33

Test-Assets-Dataset-Public

JavaScript
3
star
34

DocumentAuthoringExample

Example document that illustrates the capabilities of the GitHub document authoring workflow and can be used as a testbench.
3
star
35

dash.js-browserstack

Spike for automated BrowserStack UATs for dash.js
JavaScript
3
star
36

Resources

Resources for each of the working groups and task forces
2
star
37

Events

Addresses discussions around Event Processing and APIs
HTML
2
star
38

DRM

Collect DRM related comments
2
star
39

SAND-Test-Vectors

Test vectors for ISO/IEC 23009-5 Server And Network assisted DASH
Python
2
star
40

dashjs.org

The public website for the dash.js project
JavaScript
2
star
41

Conformance-Frontend

Sub-module for the Integrated Conformance Software Tool
HTML
2
star
42

Codecs

Adds the registration of codecs
Shell
1
star
43

DynamicServiceValidator

JavaScript
1
star
44

MPEG

Collects issues that need to be reported to MPEG
1
star
45

SAND

Comments and Bugs against the DASH-IF SAND Documentation
1
star
46

FeatureTest

Issues corresponsing to each feature at http://testassets.dashif.org/
1
star
47

livesim-content

Test content for livesim2
HTML
1
star
48

SAND-HTTP-Conformance-Server

HTTP server validating SAND messages and the protocol used by a DASH client according to ISO/IEC 23009-5 SAND
Python
1
star
49

dash-live-source-simulator-drm-data-generator

Generates DRM test data (keys and related) for the live source simulator
PowerShell
1
star
50

SAND-HTTP-Conformance-Client

SAND client validating SAND messages sent by a SAND server, a.k.a DANE
Python
1
star
51

TAC

Token-based Authorization
1
star
52

Conformance-Frontend-HLS

Submodule of the Integrated Conformance Software Tool
HTML
1
star
53

Test-Cases

This repository collects test cases. Bugs are only closed once we have at least one test vector that covers this feature
1
star
54

HbbTV_DVB

Submodule of https://github.com/Dash-Industry-Forum/DASH-IF-Conformance
PHP
1
star
55

IOPv5

IOP v5 editing for tracking issues
1
star
56

MPEG-CENC

Discusses issues on MPEG Common Encryption
1
star