mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Fix incorrect API usage in docs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -56,7 +56,7 @@ type VideoEncodingConfig = {
|
||||
meta: EncodedVideoChunkMetadata | undefined
|
||||
) => unknown;
|
||||
onEncoderConfig?: (
|
||||
config: AudioEncoderConfig
|
||||
config: VideoEncoderConfig
|
||||
) => unknown;
|
||||
};
|
||||
```
|
||||
|
||||
@@ -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),
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -156,7 +156,7 @@ import {
|
||||
getFirstEncodableVideoCodec(['avc', 'vp9', 'av1']); // => Promise<VideoCodec | null>
|
||||
getFirstEncodableAudioCodec(['opus', 'aac']); // => Promise<AudioCodec | null>
|
||||
|
||||
getEncodableVideoCodecs(
|
||||
getFirstEncodableVideoCodec(
|
||||
['avc', 'hevc', 'vp8'],
|
||||
{ width: 1920, height: 1080, bitrate: 1e7 },
|
||||
); // => Promise<VideoCodec | null>
|
||||
|
||||
@@ -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.
|
||||
|
||||
+3
-3
@@ -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
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user