@handy-common-utils/media-utils
v1.19.1
Published
A pure-JavaScript media info parser and audio extractor for browsers and Node.js that works without FFmpeg, WASM, or external binaries.
Maintainers
Readme
@handy-common-utils/media-utils
A pure-JavaScript library for efficiently parsing media information and extracting audio streams. It works with all popular formats and codecs directly in the browser and Node.js, without relying on external binaries like FFmpeg or WASM.
Why Use @handy-common-utils/media-utils?
- Pure JavaScript: No reliance on FFmpeg, WASM, or any 3rd party media parsing or processing tools or packages.
- Universal Compatibility: Fully compatible with both Node.js and Browser environments.
- Wide Format Support: Supports all popular container formats (MP4, MKV, WebM, MOV, AVI, WMV, MPEG-TS, etc.) and audio/video codecs.
- Convenient API: Easily process data from Web Streams, Node.js Streams, and Node.js file systems.
- Fast Audio Extraction: Extract audio streams from video files without re-encoding to preserve quality and speed.
Installation
npm install @handy-common-utils/media-utilsGetting Media Information
Use getMediaInfo() to extract crucial metadata like duration, stream details (video/audio), and codec information from any supported media format. All popular container formats and audio/video codecs are supported.
getMediaInfo() works with Web Streams. If you'd like to use Node.js Stream or Node.js file system, try Readable.toWeb() or getMediaInfoFromFile().
Example: Quick Start
import { getMediaInfoFromFile } from '@handy-common-utils/media-utils';
// Read from a file path (Node.js only)
const info = await getMediaInfoFromFile('path/to/video.mp4');
console.log(JSON.stringify(info, null, 2));
// {
// parser: 'media-utils',
// container: 'mp4',
// containerDetail: 'mp42, isom, mp42',
// durationInSeconds: 734,
// videoStreams: [
// {
// id: 1,
// codec: 'h264',
// codecDetail: 'avc1.64001f',
// width: 1280,
// height: 534,
// fps: 24,
// bitrate: 1830000,
// durationInSeconds: 734,
// },
// ],
// audioStreams: [
// {
// id: 2,
// codec: 'aac',
// codecDetail: 'mp4a.40.02',
// profile: 'LC',
// channelCount: 2,
// sampleRate: 44100,
// bitrate: 192000,
// durationInSeconds: 734,
// },
// ],
// }Verified Combinations
This table lists the combinations verified by our test suite.
| Format/Container | Video Codec | Audio Codec(s) | File Remark | Supported | | :--------------- | :---------- | :------------- | :---------- | :-------: | | aac | | aac | | ✅ | | asf/wma | | wmav2 | | ✅ | | asf/wmv | wmv2 | wmav2 | | ✅ | | avi | h264 | adpcm_ms | | ✅ | | avi | h264 | mp3 | | ✅ | | avi | h264 | pcm_s16le | | ✅ | | avi | h264 | pcm_u8 | | ✅ | | avi | mjpeg | pcm_s16le | | ✅ | | avi | mpeg4 | ac3 | 5 channels | ✅ | | mkv | h264 | aac, aac | | ✅ | | mkv | h264 | aac | | ✅ | | mkv | h264 | mp3 | | ✅ | | mkv | msmpeg4v2 | mp3 | | ✅ | | mkv | | | streaming | ✅ | | mov | h264 | aac | | ✅ | | mov | h264 | mp3 | | ✅ | | mov | h264 | pcm_s16le | | ✅ | | mov | h264 | pcm_s32be | | ✅ | | mp3 | | mp3 | | ✅ | | mp4 | h264 | aac | | ✅ | | mp4 | h264 | mp3 | | ✅ | | mpegts | h264 | aac | | ✅ | | mpegts | mpeg2video | mp2 | | ✅ | | mxf | h264 | pcm_s24le | | ✅ | | mxf | mpeg2video | pcm_s16le | | ✅ | | ogg | | opus | | ✅ | | ogg | | vorbis | | ✅ | | wav | | pcm_s16le | | ✅ | | webm | av1 | opus | | ✅ | | webm | vp8 | vorbis | | ✅ | | webm | vp9 | opus | | ✅ | | webm | vp9 | vorbis | | ✅ |
Note: For streaming MKV, no stream details are available.
Integration with Third-Party Parsers (Optional)
While @handy-common-utils/media-utils provides built-in support for all popular formats,
it can also automatically integrate with other well-known Javascript parsers as a fallback or for specific needs.
media-utils(built-in): This is the recommended default, all popular formats are supported.mp4box: mp4box, handles only MP4/MOV containers.isoboxer: codem-isoboxer, handles only MP4/MOV containers.remotion: @remotion/media-parser, handles more formats than mp4box and isoboxer.
If you install any of these packages, getMediaInfo() will use them as a fallback mechanism.
To force a specific parser, use the useParser option:
// Force mp4box parser (must be installed separately)
const infoMp4Box = await getMediaInfoFromFile('path/to/video.mp4', { useParser: 'mp4box' });
// Use built-in parser and fall back to others ('auto' is the default if not specified)
const infoAuto = await getMediaInfoFromFile('path/to/video.mp4', { useParser: 'auto' });Extracting Audio Stream
The extractAudio() function allows you to extract an audio stream from a video container
(MP4, MOV, MKV, AVI, etc.) without re-encoding.
This process is extremely fast and preserves the original audio quality and codec.
extractAudio() works with Web Streams. If you'd like to use Node.js Stream or Node.js file system,
try Readable.toWeb(), Writable.toWeb, extractAudioFromFile() or extractAudioFromFileToFile().
Example: Extracting to File
import { extractAudioFromFileToFile } from '@handy-common-utils/media-utils';
// Extracts the first audio stream and writes it to a new file.
// The output format is automatically determined by the extracted audio codec.
await extractAudioFromFileToFile('input-video.mp4', 'output-audio.aac');Verified Extraction Combinations
| Format/Container | Video Codec | Audio Codec(s) | File Remark | Supported | Extracted Audio | | :--------------- | :---------- | :------------- | :---------- | :-------: | :----------------------- | | asf/wmv | wmv2 | wmav2 | | ✅ | wmav2 in asf | | avi | h264 | adpcm_ms | | ✅ | adpcm_ms in wav | | avi | h264 | mp3 | | ✅ | mp3 in mp3 | | avi | h264 | pcm_s16le | | ✅ | pcm_s16le in wav | | avi | h264 | pcm_u8 | | ✅ | pcm_u8 in wav | | avi | mjpeg | pcm_s16le | | ✅ | pcm_s16le in wav | | mkv | h264 | aac | | ✅ | aac in aac | | mkv | h264 | mp3 | | ✅ | mp3 in mp3 | | mkv | msmpeg4v2 | mp3 | | ✅ | mp3 in mp3 | | mov | h264 | aac | | ✅ | aac in aac | | mov | h264 | mp3 | | ✅ | mp3 in mp3 | | mov | h264 | pcm_s16le | | ✅ | pcm_s16le in wav | | mov | h264 | pcm_s32be | | ✅ | pcm_s32le in wav | | mp4 | h264 | aac | | ✅ | aac in aac | | mp4 | h264 | mp3 | | ✅ | mp3 in mp3 | | mpegts | h264 | aac | | ✅ | aac in aac | | mpegts | h264 | mp3 | | ✅ | mp3 in mp3 | | mpegts | mpeg2video | mp2 | | ✅ | mp2 in mp3 | | mxf | h264 | pcm_s24le | | ✅ | pcm_s24le in wav | | mxf | mpeg2video | pcm_s16le | | ✅ | pcm_s16le in wav | | webm | vp9 | opus | | ✅ | opus in ogg | | webm | vp9 | vorbis | | ✅ | vorbis in ogg |
Advanced Usage: Stream-to-Stream
You can use the core extractAudio() function for greater control over input and output streams:
import { extractAudio, createReadableStreamFromFile } from '@handy-common-utils/media-utils';
import fs from 'node:fs';
import { Writable } from 'node:stream';
const inputStream = await createReadableStreamFromFile('input.mov');
// Use a Node.js Writable Stream, converted to a Web WritableStream
const outputStream = Writable.toWeb(fs.createWriteStream('output.mp3'));
await extractAudio(inputStream, outputStream, {
// Optional: Specify which track to extract (trackId takes precedence)
trackId: 2,
// streamIndex: 0,
});Input: Stream or Blob
getMediaInfo() and extractAudio() accept either a Web ReadableStream or a Blob.
A File in the browser is also a Blob, and in Node.js 19.8 or later fs.openAsBlob(path) opens a file as a Blob.
Both give the same results; they differ in how much data is read and kept in memory.
| | ReadableStream | Blob (including File) |
| :---------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------ | :---------------------------------------------------------------------------------------- |
| Supported formats, parsers and results | All | All (same results, except bytesRead, see below) |
| maxBytesToRead / maxBytesToReadForMediaInfo, sampleTableInfo and the mediaInfo option of extractAudio() | Supported | Supported |
| Reading | Forward only, once | From any position, as many times as needed |
| Data read for detecting the format | Kept in memory while detecting, so that another parser can start again from the beginning | Not kept, each parser opens its own stream from the Blob |
| MP4/MOV with the moov box after the mdat box | The whole file is read, and kept in memory while detecting (use maxBytesToRead to fail early instead) | The mdat box is skipped without being read (with the 'media-utils' parser) |
| bytesRead in the result | Bytes read, including the ones read only to skip them | Bytes actually read, skipped bytes are not counted |
| maxBytesToRead applies to | The total read from the stream | Each parsing attempt |
| extractAudio() without mediaInfo | The stream is teed: what detection reads is kept until the extraction has processed it | The Blob is read once for detecting and once more for extracting, nothing extra is kept |
Notes:
- For most files, detection reads only the header, so the difference is small. It matters for MP4/MOV files with the
moovbox at the end (not "fast start"), and for formats whose parser reads the whole file (MXF, and MP3 without a VBR header): with a stream, all of it goes through memory. - Only the built-in 'media-utils' MP4/MOV parser skips data in a
Blob. The third-party parsers (mp4box,remotion,isoboxer) read aBlobfrom the beginning like a stream. getMediaInfoFromFile(),extractAudioFromFile()andextractAudioFromFileToFile()read the file as aBlob(using Node.jsfs.openAsBlob()).
Reading large files with limited memory
- Use a
Blobwhen you can, for example aFilefrom<input type="file">or drag and drop, rather thanfile.stream(). - With a stream, use
maxBytesToRead. If the information can't be determined within that number of bytes,MaxBytesExceededErroris thrown instead of reading (and keeping) more. - Detect once, extract once. Pass the result of
getMediaInfo(input, { useParser: 'media-utils', sampleTableInfo: true })toextractAudio()as themediaInfooption. Detection is then skipped, and the input is read only once for extracting the audio.
import { extractAudio, getMediaInfo } from '@handy-common-utils/media-utils';
// In the browser, file comes from <input type="file"> or drag and drop
try {
const mediaInfo = await getMediaInfo(file, { useParser: 'media-utils', sampleTableInfo: true, maxBytesToRead: 4 * 1024 * 1024 });
await extractAudio(file, outputWritableStream, { mediaInfo });
} catch (error) {
if ((error as any)?.isMaxBytesExceededError || (error as any)?.isUnsupportedFormatError) {
// can't extract the audio, use the original file
} else {
throw error;
}
}Errors
In case the input is corrupted or the format or codec is not recognisable, UnsupportedFormatError would be thrown.
In case the maxBytesToRead option is used and the media information can't be determined within that number of bytes,
MaxBytesExceededError would be thrown.
Logging Control
Log messages are single line text strings printed to console. The verbosity of the logging can be controlled through function options and environment variables.
Unless explicitly configured, nothing would be logged (quiet is true by default).
Options
Both getMediaInfo and extractAudio accept logging options:
quiet(boolean): Suppresses all console output. Default:true.debug(boolean): Enables detailed debug logging. Default:false.
// Enable debug logs for troubleshooting
await getMediaInfoFromFile('video.mp4', { quiet: false, debug: true });Note: If quiet is true, debug logging is automatically disabled.
Environment Variables
Environment variables take precedence over function options.
MEDIA_UTILS_LOG_QUIET: Set to 'true' or 'false' to control quiet mode.MEDIA_UTILS_LOG_DEBUG: Set to 'true' or 'false' to control debug logging.
MEDIA_UTILS_LOG_QUIET=false MEDIA_UTILS_LOG_DEBUG=true node my-script.jsUtility Functions (Node.js Only)
These functions are provided to help integrate Node.js filesystem operations with the library's Web Stream-based API.
createReadableStreamFromFile(filePath: string)
Creates a Web ReadableStream from a Node.js file path.
import { createReadableStreamFromFile } from '@handy-common-utils/media-utils';
const stream = await createReadableStreamFromFile('path/to/media.mp4');
// Now the stream can be passed to getMediaInfo or extractAudioImportant: The caller is responsible for consuming or explicitly cancelling the stream (stream.cancel())
to release the underlying file handle if the stream is not fully consumed.
The good news is, getMediaInfo and extractAudio always does that.
readFromStreamToFile(stream: ReadableStream<Uint8Array>, filePath: string)
Reads a Web ReadableStream and writes its content to a file.
The output directory is automatically created if it doesn't exist.
import { readFromStreamToFile } from '@handy-common-utils/media-utils';
// Assuming you have a ReadableStream from some processing
await readFromStreamToFile(myStream, 'path/to/output.mp4');Environment Compatibility
| Platform | Minimum for Stream APIs (getMediaInfo, extractAudio) | Minimum for File APIs (*FromFile, *FromFileToFile) |
| :---------------- | :---------------------------------------------------------------------- | :----------------------------------------------------- |
| Node.js | 18.0.0 (released 2022) | 19.8.0 (released 2023) |
| Chrome / Edge | 93+ (released 2021) | N/A (Node-only) |
| Firefox | 100+ (released 2022) (91+ for getMediaInfo only, released 2021) | N/A (Node-only) |
| Safari | 15.4+ (released 2022) | N/A (Node-only) |
Browser Safety: The Node-only functions (
getMediaInfoFromFile,extractAudioFromFile,extractAudioFromFileToFile, etc.) import Node.js built-ins (node:fs,node:path,node:stream) lazily inside their function bodies. Modern bundlers (such as Vite, Webpack, or Rollup) targeting the browser will bundle the library cleanly without build-time errors unless those Node-only functions are actually invoked in browser code.
API
@handy-common-utils/media-utils
Modules
| Module | Description | | ----------------------------------------- | ----------- | | extract-audio | - | | get-media-info | - | | index | - | | input-streams | - | | media-info | - | | utils | - |
Extract Audio
extract-audio
Interfaces
| Interface | Description | | -------------------------------------------------------------------- | ----------- | | ExtractAudioOptions | - |
Functions
| Function | Description |
| --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| extractAudio | Extract raw audio data from the input |
| extractAudioFromFile | Extract raw audio data from a file The file is read as a Blob (using Node.js fs.openAsBlob()), which avoids buffering large amounts of data in memory. This function works in Node.js environment but not in browser. |
| extractAudioFromFileToFile | Extract raw audio data from a file and write to an output file This function works in Node.js environment but not in browser. |
Functions
Function: extractAudio()
extractAudio(
input,output,optionsInput?):Promise<void>
Extract raw audio data from the input
How the input is read:
- If the
mediaInfooption is provided, the input is read only once, for extracting the audio. - Otherwise, if the input is a Blob, it is read once for detecting the format (large parts can be skipped without being read, see MediaInput), and then once more for extracting the audio.
- Otherwise (the input is a stream without
mediaInfo), the stream is teed: one branch for detecting the format and the other for extracting the audio. Everything read for detecting the format is kept in memory until the extraction has processed it. For an MP4/MOV file with themoovbox after themdatbox, that is the whole file. Use themaxBytesToReadForMediaInfooption to limit it.
Parameters
| Parameter | Type | Description |
| --------------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| input | MediaInput | The input data provided through a readable stream or a Blob (a File in the browser is also a Blob) |
| output | WritableStream<Uint8Array<ArrayBufferLike>> | The output stream to write extracted audio to |
| optionsInput? | ExtractAudioOptions | Options for the extraction process |
Returns
Promise<void>
Promise that resolves when extraction is complete
Function: extractAudioFromFile()
extractAudioFromFile(
filePath,output,options?):Promise<void>
Extract raw audio data from a file
The file is read as a Blob (using Node.js fs.openAsBlob()), which avoids buffering large amounts of data in memory.
This function works in Node.js environment but not in browser.
Parameters
| Parameter | Type | Description |
| ---------- | ---------------------------------------------------------------------- | --------------------------------------------- |
| filePath | string | The path to the media file |
| output | WritableStream<Uint8Array<ArrayBufferLike>> | The output stream to write extracted audio to |
| options? | ExtractAudioOptions | Options for the extraction process |
Returns
Promise<void>
Function: extractAudioFromFileToFile()
extractAudioFromFileToFile(
inputFilePath,outputFilePath,options?):Promise<void>
Extract raw audio data from a file and write to an output file This function works in Node.js environment but not in browser.
Parameters
| Parameter | Type | Description |
| ---------------- | ---------------------------------------------------------------------- | ---------------------------------- |
| inputFilePath | string | The path to the input media file |
| outputFilePath | string | The path to the output audio file |
| options? | ExtractAudioOptions | Options for the extraction process |
Returns
Promise<void>
Interfaces
Interface: ExtractAudioOptions
Extends
Properties
| Property | Type | Description | Inherited from |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| debug? | boolean | Whether to enable debug logging. Default value is false. | - |
| maxBytesToReadForMediaInfo? | number | The maximum number of bytes that can be read from the input for detecting its format, see GetMediaInfoOptions.maxBytesToRead. It does not limit the reading for extracting the audio, and it is ignored when mediaInfo is provided. When the input is a stream, the bytes read for detecting the format are kept in memory until the extraction has processed them, so this option also limits the memory used. Default: no limit. | - |
| mediaInfo? | GetMediaInfoResult | Media information of the input, obtained earlier from the same input by getMediaInfo(input, { useParser: 'media-utils', sampleTableInfo: true }). When provided, the input is not parsed again for detecting its format. The input is then read only once, from the beginning to the end, and nothing read from it is kept in memory apart from the data being processed. It must be the result for exactly the same input. sampleTableInfo: true is required for MP4/MOV inputs. A result for a different input can't be detected, and gives a corrupted output or an error. | - |
| onProgress? | (progress) => void | Optional callback to receive progress updates (0-100). | - |
| quiet? | boolean | Whether to suppress console output. Default value is true. | - |
| streamIndex? | number | The index of the stream/track to extract audio from. If this option is provided, trackId is ignored. If trackId is not provided and this option is not specified, the first audio stream/track will be extracted. | - |
| trackId? | number | The ID of the track to extract audio from If this option is provided, streamIndex is ignored. If both trackId and streamIndex are not provided, the first audio stream/track will be extracted. | - |
| useParser? | "auto" | "mp4box" | "remotion" | "isoboxer" | "media-utils" | Which parser library/package to use The default is 'auto', which will try to use mp4box first and fallback to remotion if mp4box fails. | ParserRelatedOptions.useParser |
Get Media Info
get-media-info
Type Aliases
| Type Alias | Description | | ----------------------------------------------------------------------- | ----------- | | GetMediaInfoOptions | - | | GetMediaInfoResult | - |
Functions
| Function | Description |
| ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| getMediaInfo | Get media information from a stream or a Blob |
| getMediaInfoFromFile | Get media information from a file path. The file is read as a Blob (using Node.js fs.openAsBlob()), which allows random access without keeping much data in memory. This function works in Node.js environment but not in browser. |
Functions
Function: getMediaInfo()
getMediaInfo(
input,optionsInput?):Promise<GetMediaInfoResult>
Get media information from a stream or a Blob
Parameters
| Parameter | Type | Description |
| --------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| input | MediaInput | The input, either a Web ReadableStream (not Node Readable) or a Blob (a File in the browser is also a Blob). To convert a Node Readable to Web ReadableStream, use Readable.toWeb(nodeReadable). To open a file as a Blob in Node.js, use fs.openAsBlob(path). A Blob is read without keeping much data in memory, see MediaInput. |
| optionsInput? | GetMediaInfoOptions | Options for the parser |
Returns
Promise<GetMediaInfoResult>
The media information
Function: getMediaInfoFromFile()
getMediaInfoFromFile(
filePath,options?):Promise<GetMediaInfoResult>
Get media information from a file path.
The file is read as a Blob (using Node.js fs.openAsBlob()), which allows random access
without keeping much data in memory.
This function works in Node.js environment but not in browser.
Parameters
| Parameter | Type | Description |
| ---------- | ------------------------------------------------------------------------- | -------------------------- |
| filePath | string | The path to the media file |
| options? | GetMediaInfoOptions | Options for the parser |
Returns
Promise<GetMediaInfoResult>
The media information
Type Aliases
Type Alias: GetMediaInfoOptions
GetMediaInfoOptions =
ParserRelatedOptions&object
Type Declaration
| Name | Type | Description |
| ------------------ | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| debug? | boolean | Whether to enable debug logging. Default value is false. |
| maxBytesToRead? | number | The maximum number of bytes (a positive integer) that can be read from the input for determining the media information. If a parser needs to read more than this, a MaxBytesExceededError is thrown (its isMaxBytesExceededError is true, and no other parser is tried after it). When the input is a stream, the limit applies to the total number of bytes read from the stream. Because the data read from a stream is kept in memory while parsing (so that another parser can be tried from the beginning of the stream), this option also limits the memory used for a stream input. When the input is a Blob, nothing is kept in memory, and the limit applies to each parsing attempt. Bytes skipped without being read (see MediaInput) are not counted. Parsers read in blocks (usually 64 KB, and 1 MB for the third-party parsers), and some formats are read to the end (for example MXF, and MP3 without a VBR header), or for some megabytes (MPEG-TS). MP4/MOV files with the moov box after the mdat box are read to the end too, unless the input is a Blob. So a limit of a few megabytes is recommended, and such files fail with it. Default: no limit. |
| quiet? | boolean | Whether to suppress console output. Default value is true. |
| sampleTableInfo? | boolean | Whether to keep and return the sample table information (sampleTableInfo) of MP4/MOV audio streams. It is needed when the result is passed to extractAudio() as the mediaInfo option for an MP4/MOV input. Only the 'media-utils' parser supports it; other parsers ignore it. Ignored for other formats. Default: false (sample tables are not returned to save memory) |
Type Alias: GetMediaInfoResult
GetMediaInfoResult =
MediaInfo&object
Type Declaration
| Name | Type | Description |
| ------------ | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| bytesRead? | number | Number of bytes read from the stream. In most cases, the parser does not need to read the whole stream. |
| parser | Exclude<GetMediaInfoOptions["useParser"], undefined> | - |
Index
index
References
allAudioCodecs
Re-exports allAudioCodecs
allContainers
Re-exports allContainers
allVideoCodecs
Re-exports allVideoCodecs
AudioCodecDetails
Re-exports AudioCodecDetails
AudioCodecType
Re-exports AudioCodecType
AudioStreamInfo
Re-exports AudioStreamInfo
ContainerDetails
Re-exports ContainerDetails
ContainerType
Re-exports ContainerType
createReadableStreamFromFile
Re-exports createReadableStreamFromFile
createWritableStreamFromFile
Re-exports createWritableStreamFromFile
ensureBufferData
Re-exports ensureBufferData
extractAudio
Re-exports extractAudio
extractAudioFromFile
Re-exports extractAudioFromFile
extractAudioFromFileToFile
Re-exports extractAudioFromFileToFile
ExtractAudioOptions
Re-exports ExtractAudioOptions
findAudioCodec
Re-exports findAudioCodec
findContainer
Re-exports findContainer
findVideoCodec
Re-exports findVideoCodec
getGlobalLogger
Re-exports getGlobalLogger
getMediaInfo
Re-exports getMediaInfo
getMediaInfoFromFile
Re-exports getMediaInfoFromFile
GetMediaInfoOptions
Re-exports GetMediaInfoOptions
GetMediaInfoResult
Re-exports GetMediaInfoResult
isBlobInput
Re-exports isBlobInput
isPCM
Re-exports isPCM
isWMA
Re-exports isWMA
MaxBytesExceededError
Re-exports MaxBytesExceededError
MediaInfo
Re-exports MediaInfo
MediaInput
Re-exports MediaInput
ParserRelatedOptions
Re-exports ParserRelatedOptions
ParsingError
Re-exports ParsingError
readBeginning
Re-exports readBeginning
readFromStreamToFile
Re-exports readFromStreamToFile
setupGlobalLogger
Re-exports setupGlobalLogger
toAudioCodec
Re-exports toAudioCodec
toContainer
Re-exports toContainer
toVideoCodec
Re-exports toVideoCodec
UnsupportedFormatError
Re-exports UnsupportedFormatError
VideoCodecDetails
Re-exports VideoCodecDetails
VideoCodecType
Re-exports VideoCodecType
VideoStreamInfo
Re-exports VideoStreamInfo
Input Streams
input-streams
Interfaces
| Interface | Description | | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | | LimitedStream | A stream that counts and limits the bytes read from an underlying stream. | | RandomAccessInput | Random access to the input, available when the input is a Blob. | | ReadCounter | Shared byte counter used by createLimitedStream. |
Functions
| Function | Description |
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| createLimitedStream | Wraps a stream so that the bytes read are counted, and the stream errors with MaxBytesExceededError when more than counter.maxBytesToRead bytes would be needed. |
| createRandomAccessInput | Creates the random access helper for a Blob, with all the streams sharing the same counter. |
| openInputStream | Opens a stream from the beginning of the input. If the input is a Blob, a new stream is created from it and the limit is applied to it. If the input is a stream, it is returned as is (the limit, if any, is applied by the caller). |
| validateMaxBytesToRead | Validates the maxBytesToRead option. |
Functions
Function: createLimitedStream()
createLimitedStream(
source,counter):LimitedStream
Internal
Wraps a stream so that the bytes read are counted, and the stream errors with MaxBytesExceededError
when more than counter.maxBytesToRead bytes would be needed.
Bytes are pulled from the underlying stream only when the returned stream is read (high water mark 0), so that nothing is read ahead. Several limited streams can share the same counter, the limit then applies to the total.
Parameters
| Parameter | Type | Description |
| --------- | ------------------------------------------------------ | ---------------------------- |
| source | ReadableStream<Uint8Array<ArrayBufferLike>> | The underlying stream |
| counter | ReadCounter | The counter, possibly shared |
Returns
The limited stream and a function for cancelling the underlying stream
Function: createRandomAccessInput()
createRandomAccessInput(
blob,counter):RandomAccessInput
Internal
Creates the random access helper for a Blob, with all the streams sharing the same counter.
Parameters
| Parameter | Type | Description |
| --------- | ------------------------------------------------------ | ----------------------------------------- |
| blob | Blob | The Blob |
| counter | ReadCounter | The counter, which also carries the limit |
Returns
The random access helper
Function: openInputStream()
openInputStream(
input,maxBytesToRead?):object
Internal
Opens a stream from the beginning of the input. If the input is a Blob, a new stream is created from it and the limit is applied to it. If the input is a stream, it is returned as is (the limit, if any, is applied by the caller).
Parameters
| Parameter | Type | Description |
| ----------------- | ---------------------------------------------- | ----------------------------------------------------- |
| input | MediaInput | The input |
| maxBytesToRead? | number | Optional limit, only applied when the input is a Blob |
Returns
object
The stream, and a function to be called when done, which cancels the stream if it was opened from a Blob
| Name | Type |
| --------- | ----------------------------------------------------- |
| close() | () => void |
| stream | ReadableStream<Uint8Array<ArrayBufferLike>> |
Function: validateMaxBytesToRead()
validateMaxBytesToRead(
maxBytesToRead):number|undefined
Validates the maxBytesToRead option.
Parameters
| Parameter | Type | Description |
| ---------------- | --------------------------------- | ----------------------- |
| maxBytesToRead | number | null | undefined | The value of the option |
Returns
number | undefined
The value if it is valid, or undefined if there is no limit
Interfaces
Interface: LimitedStream
Internal
A stream that counts and limits the bytes read from an underlying stream.
Properties
| Property | Type | Description |
| ----------------------------------------- | ----------------------------------------------------- | --------------------- |
| stream | ReadableStream<Uint8Array<ArrayBufferLike>> | The stream to be read |
Methods
cancelSource()
cancelSource():
void
Stops reading from the underlying stream and cancels it immediately, without waiting for the cancellation to complete. (Cancelling a branch of a teed stream doesn't complete until the other branch is cancelled too.) The limited stream closes, as if the underlying stream had ended.
####### Returns
void
Interface: RandomAccessInput
Internal
Random access to the input, available when the input is a Blob.
Properties
| Property | Type | Description |
| ------------------------------------- | -------- | -------------------------------- |
| size | number | Total size of the input in bytes |
Methods
close()
close():
void
Cancels all the streams opened by streamFrom(), whether or not their readers have been released.
####### Returns
void
streamFrom()
streamFrom(
offset):ReadableStream<Uint8Array<ArrayBufferLike>>
Opens a new stream that starts at the given offset
####### Parameters
| Parameter | Type | Description |
| --------- | -------- | ------------------------------------------ |
| offset | number | The offset from the beginning of the input |
####### Returns
ReadableStream<Uint8Array<ArrayBufferLike>>
The stream
Interface: ReadCounter
Internal
Shared byte counter used by createLimitedStream.
Properties
| Property | Type | Description |
| ---------------------------------------------------------- | -------- | ------------------------------------------------------------------------- |
| bytesRead | number | Number of bytes passed through so far |
| maxBytesToRead? | number | Maximum number of bytes allowed to pass through, undefined means no limit |
Media Info
media-info
Classes
| Class | Description | | ---------------------------------------------------------- | ----------- | | AudioCodecDetails | - | | ContainerDetails | - | | VideoCodecDetails | - |
Interfaces
| Interface | Description | | --------------------------------------------------------- | ----------- | | AudioStreamInfo | - | | MediaInfo | - | | VideoStreamInfo | - |
Type Aliases
| Type Alias | Description | | --------------------------------------------------------- | ----------- | | AudioCodecType | -
