Skip to content

buzz/mediainfo.js

Repository files navigation

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

import MediaInfoFactory from 'mediainfo.js'

MediaInfoFactory().then((mediainfo) => {
  mediainfo.analyzeFile(...)
})

See the API docs for detailed instructions.

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"></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 its load path is determined from the script location.

E.g. if the script is loaded from https://example.com/dist/umd/index.js, the WASM module file is loaded from https://example.com/dist/MediaInfoModule.wasm. This setup works out-of-the-box for the UMD build.

❗️ If you're bundling your project, you need to ensure the module loader can fetch the WASM binary by configuring your bundler/web server accordingly (see the examples section).

You can also override the WASM binary location by specifying a custom locateFile function to MediaInfoFactory.

Node.js

Install mediainfo.js from NPM.

$ npm install -g mediainfo.js

It can be used as a CLI from the shell.

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

Or use it as a library.

Examples

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

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

$ pnpm install
$ pnpm build

Find the resulting files in the dist directory.

Tests

You can run a test suite against the dist build.

$ pnpm test

License

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

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