{"library":"mp4box","title":"MP4Box.js","description":"MP4Box.js is a robust JavaScript library designed for comprehensive processing of MP4 files, including parsing, segmentation, and sample extraction. It enables advanced functionalities directly within web browsers or Node.js environments, making it a critical tool for working with the Media Source Extensions (MSE) API for adaptive streaming. The current stable version is 2.3.0, with a history of frequent minor and patch releases, indicating active development and maintenance. Key differentiators include its progressive parsing capabilities, cross-platform support, and its direct inspiration from the well-established GPAC MP4Box tool, providing a powerful and familiar API for developers handling MP4 media.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install mp4box"],"cli":null},"imports":["import MP4Box from 'mp4box';","const mp4boxfile = MP4Box.createFile();","import type { MP4File, MP4Info, MP4Track } from 'mp4box';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import MP4Box from 'mp4box';\n\nconst mp4boxfile = MP4Box.createFile();\nmp4boxfile.onError = function(e) {\n  console.error('MP4Box error:', e);\n};\nmp4boxfile.onMoovStart = function () {\n  console.log('Starting to receive File Information (moov box)');\n};\nmp4boxfile.onReady = function(info) {\n  console.log('Received File Information:', info);\n  // Example: Log track details\n  info.tracks.forEach(track => {\n    console.log(`Track ID: ${track.id}, Type: ${track.movie_type}, Codec: ${track.codec}, Duration: ${track.duration/track.timescale}s`);\n  });\n};\n\n// Simulate appending data (e.g., from a fetched MP4 file)\nasync function loadMp4Data() {\n  // In a real scenario, 'url' would be the path to your MP4 file\n  const url = 'https://raw.githubusercontent.com/gpac/mp4box.js/master/test/initial-media/mp4/frag_raw.mp4';\n  const response = await fetch(url);\n  const reader = response.body.getReader();\n  let offset = 0;\n  while (true) {\n    const { done, value } = await reader.read();\n    if (done) {\n      mp4boxfile.flush(); // Signal end of file\n      break;\n    }\n    const buffer = value.buffer; // value is a Uint8Array, get its underlying ArrayBuffer\n    buffer.fileStart = offset; // Important for MP4Box to track byte ranges\n    mp4boxfile.appendBuffer(buffer);\n    offset += buffer.byteLength;\n  }\n}\n\nloadMp4Data();","lang":"typescript","description":"This quickstart demonstrates how to progressively parse an MP4 file by fetching data chunks and appending them to an `MP4File` instance. It sets up `onMoovStart` and `onReady` callbacks to log file metadata as it becomes available. The example fetches a small MP4 from GitHub to simulate real-world usage.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}