diff --git a/docs/guide/input-formats.md b/docs/guide/input-formats.md index a61fb88..352283a 100644 --- a/docs/guide/input-formats.md +++ b/docs/guide/input-formats.md @@ -47,7 +47,7 @@ You can also use them for checking the actual format of an `Input`: ```ts import { MP3 } from 'mediabunny'; -const isMp3 = input.getFormat() === MP3; +const isMp3 = (await input.getFormat()) === MP3; ``` There is a special `ALL_FORMATS` constant exported by Mediabunny which contains every input format singleton. Use this constant if you want to support as many formats as possible: @@ -82,13 +82,13 @@ This means you can also perform input format checks using `instanceof` instead o import { Mp3InputFormat } from 'mediabunny'; // Check if the file is MP3: -input.getFormat() instanceof Mp3InputFormat; +(await input.getFormat()) instanceof Mp3InputFormat; // Check if the file is Matroska (MKV + WebM): -input.getFormat() instanceof MatroskaInputFormat; +(await input.getFormat()) instanceof MatroskaInputFormat; // Check if the file is MP4 or QuickTime: -input.getFormat() instanceof IsobmffInputFormat; +(await input.getFormat()) instanceof IsobmffInputFormat; ``` ::: info diff --git a/docs/guide/media-sinks.md b/docs/guide/media-sinks.md index 67cb295..5465275 100644 --- a/docs/guide/media-sinks.md +++ b/docs/guide/media-sinks.md @@ -437,9 +437,9 @@ let sumOfSquares = 0; let totalSampleCount = 0; for await (const sample of sink.samples()) { - const bytesNeeded = sample.allocationSize({ format: 'f32' }); + const bytesNeeded = sample.allocationSize({ format: 'f32', planeIndex: 0 }); const floats = new Float32Array(bytesNeeded / 4); - sample.copyTo(floats, { format: 'f32' }); + sample.copyTo(floats, { format: 'f32', planeIndex: 0 }); for (let i = 0; i < floats.length; i++) { sumOfSquares += floats[i] ** 2; diff --git a/docs/guide/media-sources.md b/docs/guide/media-sources.md index 0314e38..723e7a1 100644 --- a/docs/guide/media-sources.md +++ b/docs/guide/media-sources.md @@ -56,7 +56,7 @@ type VideoEncodingConfig = { meta: EncodedVideoChunkMetadata | undefined ) => unknown; onEncoderConfig?: ( - config: AudioEncoderConfig + config: VideoEncoderConfig ) => unknown; }; ``` diff --git a/docs/guide/output-formats.md b/docs/guide/output-formats.md index ef7f83a..cd871ec 100644 --- a/docs/guide/output-formats.md +++ b/docs/guide/output-formats.md @@ -119,10 +119,10 @@ The available options are the same `IsobmffOutputFormatOptions` used by [MP4](#m This output format creates WebM files. ```ts -import { Output, WebmOutputFormat } from 'mediabunny'; +import { Output, WebMOutputFormat } from 'mediabunny'; const output = new Output({ - format: new WebmOutputFormat(options), + format: new WebMOutputFormat(options), // ... }); ``` diff --git a/docs/guide/quick-start.md b/docs/guide/quick-start.md index 05bd247..dec220f 100644 --- a/docs/guide/quick-start.md +++ b/docs/guide/quick-start.md @@ -255,7 +255,7 @@ await audioSource.add(audioBuffer2); await output.finalize(); -const buffer = output.target.buffer; // Uint8Array containing the final MP4 file +const buffer = output.target.buffer; // ArrayBuffer containing the final MP4 file ``` ::: info @@ -442,7 +442,7 @@ conversion.onProgress = (progress) => { await conversion.execute(); // Conversion is complete -const buffer = output.target.buffer; // Uint8Array containing the final MP4 file +const buffer = output.target.buffer; // ArrayBuffer containing the final MP4 file ``` ::: info diff --git a/docs/guide/reading-media-files.md b/docs/guide/reading-media-files.md index d9e00c8..4fa9b5a 100644 --- a/docs/guide/reading-media-files.md +++ b/docs/guide/reading-media-files.md @@ -362,7 +362,7 @@ const decoder = new VideoDecoder({ decoder.configure(await videoTrack.getDecoderConfig()); // Let's crank through all packets from timestamp 37s to 50s: -let currentPacket = sink.getKeyPacket(37); +let currentPacket = await sink.getKeyPacket(37); while (currentPacket && currentPacket.timestamp < 50) { decoder.decode(currentPacket.toEncodedVideoChunk()); currentPacket = await sink.getNextPacket(currentPacket); diff --git a/docs/guide/supported-formats-and-codecs.md b/docs/guide/supported-formats-and-codecs.md index 28b890c..f5275a4 100644 --- a/docs/guide/supported-formats-and-codecs.md +++ b/docs/guide/supported-formats-and-codecs.md @@ -156,7 +156,7 @@ import { getFirstEncodableVideoCodec(['avc', 'vp9', 'av1']); // => Promise getFirstEncodableAudioCodec(['opus', 'aac']); // => Promise -getEncodableVideoCodecs( +getFirstEncodableVideoCodec( ['avc', 'hevc', 'vp8'], { width: 1920, height: 1080, bitrate: 1e7 }, ); // => Promise diff --git a/docs/guide/writing-media-files.md b/docs/guide/writing-media-files.md index f34db98..00fa8e8 100644 --- a/docs/guide/writing-media-files.md +++ b/docs/guide/writing-media-files.md @@ -213,7 +213,7 @@ const output = new Output({ output.target.buffer; // => null await output.finalize(); -output.target.buffer; // => Uint8Array +output.target.buffer; // => ArrayBuffer ``` This target is a great choice for small-ish files (< 100 MB), but since all data will be kept in memory, using it for large files is suboptimal. If the output gets very large, the page might crash due to memory exhaustion. For these cases, using `StreamTarget` is recommended. diff --git a/docs/index.md b/docs/index.md index 620547f..10a13de 100644 --- a/docs/index.md +++ b/docs/index.md @@ -45,11 +45,11 @@ const videoTrack = await input.getPrimaryVideoTrack(); const { displayWidth, displayHeight, rotation } = videoTrack; const audioTrack = await input.getPrimaryAudioTrack(); -const { sampleRate, channelCount } = audioTrack; +const { sampleRate, numberOfChannels } = audioTrack; // Get the frame halfway through the video const sink = new VideoSampleSink(videoTrack); -const { canvas } = await sink.getSample(duration / 2); +const frame = await sink.getSample(duration / 2); // Loop over all frames of the video for await (const frame of sink.samples()) { @@ -89,7 +89,7 @@ await output.start(); // Add media data here... -await output.finalize; +await output.finalize(); const { buffer } = output.target; // Contains the final file ``` diff --git a/package-lock.json b/package-lock.json index af3b8e5..8a692e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "": { "name": "mediabunny", "version": "0.1.0", - "license": "MIT", + "license": "MPL-2.0", "dependencies": { "@types/dom-mediacapture-transform": "^0.1.10", "@types/dom-webcodecs": "^0.1.13"