Git Product home page Git Product logo

mediainfo.js's Introduction

mediainfo.js

This is a JavaScript port of the excellent MediaInfoLib and can run directly in a browser or in Node.js. It is transpiled from C++ source code using Emscripten.

Demo

Try mediainfo.js in your browser: https://mediainfo.js.org

Usage

Browser

You can either use a CDN to include the script file directly in your page or use a JavaScript bundler like webpack.

  • CDN:
    <script type="text/javascript" src="https://unpkg.com/mediainfo.js/dist/mediainfo.min.js"></script>
  • Bundler: npm install mediainfo.js

WASM file loading

Be aware that mediainfo.js is a WebAssembly port of MediaInfoLib. Thus it depends on MediaInfoModule.wasm which weighs around 4.2 MiB. The WASM module is loaded and instantiated automatically. By default it uses location.href as the base for constructing the module file URL.

E.g. if the webpage is served from https://example.com/, the WASM module file is loaded from https://example.com/MediaInfoModule.wasm. You can freely override this behavior using Emscripten Module locateFile.

For the CDN version have a look at this example. If you're using a bundler there are examples for React/webpack and Angular on how to achieve this.

Node.js

Install mediainfo.js from NPM.

$ npm install -g mediainfo.js

You can use it directly from the shell.

$ mediainfo.js /path/to/media.avi

Or use it as a library.

require('mediainfo.js')().then((mediainfo) => {
  // mediainfo ready…
})

Examples

API

MediaInfo(opts, successCallback, errorCallback)

Create an instance of mediainfo.

Defaults: opts = { chunkSize: 256*1024, coverData: false, format: 'object', full: false, ... }

  • chunkSize: Chunk size used by analyzeData (in bytes)
  • coverData: Whether to extract binary cover data (Base64-encoded)
  • format: Format of result value (choices: object, JSON, XML, HTML or text)
  • full: Full information display (all internal tags)
  • Other Emscripten Module attributes
  • Returns a Promise if no callback is given.
const MediaInfo = require('mediainfo.js')
MediaInfo(opts, callback, errorCallback)

Media files can be several gigabytes in size. The preferred way is to load data in chunks to prevent memory exhaustion. analyzeData is a helper method that facilitates this somewhat cumbersome process.

mediainfo.analyzeData(getSize, readChunk, cb)

Convenience method for analyzing a buffer chunk by chunk.

  • You need to provide two callback functions. They can either return a Promise or directly the value.
    • getSize() - Return total buffer size.
    • readChunk(size, offset) - Read data chunk of size with offset and return an Uint8Array.
  • Returns a Promise if no callback is given.

Low-level methods

The mediainfo object also exposes a number of low-level methods analogous to the MediaInfoLib buffer methods.

close(), inform(), openBufferContinue(data, size), openBufferContinueGotoGet(), openBufferFinalize(), openBufferInit(size, offset)

Build

Install Emscripten preferably using Emscripten SDK.

$ git clone https://github.com/emscripten-core/emsdk.git
$ cd emsdk
$ ./emsdk install latest
$ ./emsdk activate latest
$ source ./emsdk_env.sh
$ export PATH=$PATH:$(pwd)/upstream/bin # for wasm-opt

In the project root of mediainfo.js run the following to build.

$ npm install
$ npm run build

Find the resulting files mediainfo.js, mediainfo.min.js and mediainfo.wasm in the dist directory.

Tests

You can run a test suite against the dist build.

$ npm run test

License

This program is freeware under BSD-2-Clause license conditions: MediaInfo(Lib) License

This product uses MediaInfo library, Copyright (c) 2002-2020 MediaArea.net SARL.

mediainfo.js's People

Contributors

buzz avatar tannerrogalsky avatar corbenf-shuttlerock avatar davidlyons avatar elkindev avatar iwestlin avatar trendy avatar matthewleon avatar tomwilsonmerkle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.