Skip to main content

Usage

Factory function mediaInfoFactory

Instantiate MediaInfo by utilizing the factory function mediaInfoFactory. This function manages the loading of the WASM file and can be invoked with either a callback or asynchronously. Ensure to close the MediaInfo instance using the close() method when finished, instead of instantiating and closing it repeatedly. Retain the instance for the duration of its required usage.

import mediaInfoFactory from 'mediainfo.js';

const mediainfo = await mediaInfoFactory();
const result = mediainfo.analyzeFile(...);
mediainfo.close();

Options

You can configure the MediaInfo instance using MediaInfoFactoryOptions.

Notable options include:

  • format: See result output format for details.
  • full: Enables the display of all internal tags.
  • locateFile: Customizes the path for loading the WASM file.

MediaInfo object

analyzeData is provided as a convenient wrapper around the more low-level methods of the MediaInfo object. It supports asynchronous invocation or callbacks and operates on chunks of Uint8Array. Ensure to provide the following arguments:

  • size: The file size, which can be either a number or a function returning a number.
  • readChunk: Reads a data chunk from the file, returning an Uint8Array. This function can also be asynchronous.
const someBlob = ...;

const fileSize = 123456;

async function readChunk(chunkSize, offset) {
const buffer = await someBlob.slice(offset, offset + chunkSize).arrayBuffer();
return new Uint8Array(buffer);
}

const result = await mediaInfo.analyzeData(fileSize, readChunk);

Result

Choose the result output format by using the format option on the mediaInfoFactory function.

Possible values: object (default), JSON, XML, HTML, text.

Media files may contain multiple tracks of types such as General, Video, Audio, Text, Image, Menu, or Other.

tip

For a comprehensive list of possible fields, consult the API documentation.

Output as JavaScript object

The default output format object returns the result as a JavaScript object. This is typically the most useful option.

note

The library including the result object is fully typed to enhance the developer experience in supported editors.

String output

The remaining output options return the result as a string.

String result formats
{
"creatingLibrary": { "name": "MediaInfoLib", "version": "24.04", "url": "https://mediaarea.net/MediaInfo" },
"media": {
"@ref": "",
"track": [
{
"@type": "General",
"AudioCount": "1",
"ImageCount": "1",
"Format": "MPEG Audio",
"FileSize": "6357777",
"Duration": "203.493",
"OverallBitRate_Mode": "VBR",
"OverallBitRate": "243044",
"StreamSize": "175116",
"Title": "Povo Que Caís Descalço",
"Album": "CC Affiliates Mixtape #1",
"Album_Performer": "Creative Commons",
"Track": "Povo Que Caís Descalço",
"Track_Position": "1",
"Compilation": "Yes",
"Performer": "Dead Combo",
"Genre": "International",
"Recorded_Date": "2017-03-03 15:14:12 UTC",
"Encoded_Library": "LAME3.99r",
"Copyright": "Attribution-NonCommercial 3.0 International: http://creativecommons.org/licenses/by-nc/3.0/",
"Cover": "Yes",
"Cover_Mime": "image/jpeg",
"Comment": "URL: http://freemusicarchive.org/music/Dead_Combo/Creative_Commons_The_2015_Unofficial_Mixtape/01_Povo_Que_Cais_Descalco / Comments: http://freemusicarchive.org/ / Curator: Creative Commons / Copyright: Attribution-NonCommercial 3.0 International: http://creativecommons.org/licenses/by-nc/3.0/"
},
{
"@type": "Audio",
"Format": "MPEG Audio",
"Format_Version": "1",
"Format_Profile": "Layer 3",
"Format_Settings_Mode": "Joint stereo",
"Duration": "203.494",
"BitRate_Mode": "VBR",
"BitRate": "243044",
"BitRate_Minimum": "32000",
"Channels": "2",
"SamplesPerFrame": "1152",
"SamplingRate": "44100",
"SamplingCount": "8974080",
"FrameRate": "38.281",
"FrameCount": "7790",
"Compression_Mode": "Lossy",
"StreamSize": "6182244",
"Encoded_Library": "LAME3.99r",
"Encoded_Library_Settings": "-m j -V 0 -q 0 -lowpass 22.1 --vbr-mt -b 32"
},
{
"@type": "Image",
"Format": "JPEG",
"Width": "800",
"Height": "800",
"ColorSpace": "YUV",
"ChromaSubsampling": "4:4:4",
"BitDepth": "8",
"Compression_Mode": "Lossy",
"StreamSize": "142880"
}
]
}
}