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.
Try mediainfo.js in your browser: https://mediainfo.js.org
import mediaInfoFactory from 'mediainfo.js'
mediaInfoFactory().then((mediainfo) => {
mediainfo.analyzeFile(...)
})
See the API docs for detailed instructions.
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
Be aware that mediainfo.js needs to load the MediaInfoModule.wasm
file (around
2 MiB). The WASM module is loaded and instantiated automatically. By
default its load path is determined from the script location. This works
out-of-the-box for the UMD and Node.js version.
❗️ If using a bundler, you need to ensure the module loader can fetch the WASM file by configuring your bundler/web server accordingly (examples).
Note that you can override the WASM file location by specifying a custom
locateFile
function to mediaInfoFactory
.
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.
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
You also need to have Binaryen and wabt available on your system.
In the project root of mediainfo.js run the following to build.
$ pnpm install
$ pnpm build
Find the resulting files in the dist
directory.
You can run a test suite against the dist build.
$ pnpm test
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.