Skip to main content

Target

The base class for targets, specifying where output files are written.

Properties

((start: number, end: number) => unknown) | null
Called each time data is written to the target. Will be called with the byte range into which data was written.
This callback is extremely chatty and gets called very frequently. Use it to track the size of the output file as it grows.

BufferTarget

A target that writes data directly into an ArrayBuffer in memory. Great for performance, but not suitable for very large files. The buffer will be available once the output has been finalized.

Constructor

No parameters required.

Properties

ArrayBuffer | null
Stores the final output buffer. Until the output is finalized, this will be null.

Example


StreamTarget

This target writes data to a WritableStream, making it a general-purpose target for writing data anywhere. It is also compatible with FileSystemWritableFileStream for use with the File System Access API. The WritableStream can also apply backpressure, which will propagate to the output and throttle the encoders.

Constructor

WritableStream<StreamTargetChunk>
required
The writable stream to write data to.
StreamTargetOptions
Optional configuration.

Options

boolean
default:"false"
When set to true, data created by the output will first be accumulated and only written out once it has reached sufficient size, using a default chunk size of 16 MiB. This is useful for reducing the total amount of writes, at the cost of latency.
number
default:"16777216"
When using chunked: true, this specifies the maximum size of each chunk. Defaults to 16 MiB.

StreamTargetChunk type

'write'
required
The operation type. Always 'write'. This ensures automatic compatibility with FileSystemWritableFileStream.
Uint8Array<ArrayBuffer>
required
The data to write.
number
required
The byte offset in the output file at which to write the data.

Example


FilePathTarget

A target that writes to a file at the specified path. Intended for server-side usage in Node, Bun, or Deno.
Writing is chunked by default. The internally held file handle will be closed when .finalize() or .cancel() are called on the corresponding Output.

Constructor

string
required
The path to the file to write to.
FilePathTargetOptions
Optional configuration. Same as StreamTargetOptions.

Options

boolean
default:"true"
When set to true, data created by the output will first be accumulated and only written out once it has reached sufficient size. Defaults to true for FilePathTarget.
number
default:"16777216"
The maximum size of each chunk. Defaults to 16 MiB.

Example


NullTarget

This target just discards all incoming data. It is useful for when you need an Output but extract data from it differently, for example through format-specific callbacks (onMoof, onMdat, …) or encoder events.

Constructor

No parameters required.

Example