mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-28 11:23:45 +02:00
Set up examples folder structure
This commit is contained in:
@@ -25,7 +25,7 @@ Closing sources manually is _technically_ not required and will happen automatic
|
||||
|
||||
### Backpressure
|
||||
|
||||
Media sources are the means by which backpressure is propagated from the output pipeline into your application logic. The `Output` may want to apply backpressure if the encoders or the [StreamTarget](./writing-overview/#streamtarget)'s writable can't keep up.
|
||||
Media sources are the means by which backpressure is propagated from the output pipeline into your application logic. The `Output` may want to apply backpressure if the encoders or the [StreamTarget](./writing-overview#streamtarget)'s writable can't keep up.
|
||||
|
||||
Backpressure is communicated by media sources via promises. All media sources with an `add` method return a promise:
|
||||
```ts
|
||||
@@ -67,7 +67,7 @@ type VideoEncodingConfig = {
|
||||
) => unknown;
|
||||
};
|
||||
```
|
||||
- `codec`: The [video codec](./supported-formats-and-codecs/#video-codecs) used for encoding.
|
||||
- `codec`: The [video codec](./supported-formats-and-codecs#video-codecs) used for encoding.
|
||||
- `bitrate`: The target number of bits per second. Alternatively, this can be a [subjective quality](#subjective-qualities).
|
||||
- `latencyMode`: The latency mode as specified by the WebCodecs API. Media stream-driven video sources will automatically use the `realtime` setting.
|
||||
- `keyFrameInterval`: The maximum interval in seconds between two adjacent key frames. Defaults to 5 seconds. More frequent key frames improve seeking behavior but increase file size. When using multiple video tracks, this value should be set to the same value for all tracks.
|
||||
@@ -97,7 +97,7 @@ type AudioEncodingConfig = {
|
||||
) => unknown;
|
||||
};
|
||||
```
|
||||
- `codec`: The [audio codec](./supported-formats-and-codecs/#audio-codecs) used for encoding. Can be omitted for uncompressed PCM codecs.
|
||||
- `codec`: The [audio codec](./supported-formats-and-codecs#audio-codecs) used for encoding. Can be omitted for uncompressed PCM codecs.
|
||||
- `bitrate`: The target number of bits per second. Alternatively, this can be a [subjective quality](#subjective-qualities).
|
||||
- `fullCodecString`: Allows you to optionally specify the full codec string used by the audio encoder, as specified in the [WebCodecs Codec Registry](https://www.w3.org/TR/webcodecs-codec-registry/). For example, you may set it to `'mp4a.40.2'` when using AAC. Keep in mind that the codec string must still match the codec specified in `codec`. If you don't set this field, a codec string will be generated automatically.
|
||||
- `onEncodedPacket`: Called for each successfully encoded packet. Useful for determining encoding progress.
|
||||
|
||||
@@ -407,7 +407,13 @@ fileInput.addEventListener('change', (event) => {
|
||||
});
|
||||
```
|
||||
|
||||
### `UrlSource`
|
||||
### `UrlSource` <Badge type="warning" text="beta" />
|
||||
|
||||
::: warning
|
||||
This is a **beta** feature. `UrlSource` tends to make tons of requests and is potentially slow. This is something that will be fixed in the near future.
|
||||
|
||||
It still works, but keep in mind it's going to be much higher-latency than reading directly from disk or from memory.
|
||||
:::
|
||||
|
||||
This source fetches data from a URL. This is useful for reading files over the network.
|
||||
```ts
|
||||
@@ -417,9 +423,7 @@ const source = new UrlSource('https://example.com/bigbuckbunny.mp4');
|
||||
```
|
||||
|
||||
::: warning
|
||||
Keep in mind that reading data over the network is typically much higher-latency than reading directly from disk or from memory.
|
||||
|
||||
Also, if you're using this source in the browser and the URL is on a different origin, make sure [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) is properly configured.
|
||||
If you're using this source in the browser and the URL is on a different origin, make sure [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) is properly configured.
|
||||
:::
|
||||
|
||||
`UrlSource` accepts a few options as its second parameter:
|
||||
|
||||
@@ -38,7 +38,7 @@ output.addAudioTrack(audioSource);
|
||||
output.addSubtitleTrack(subtitleSource);
|
||||
```
|
||||
|
||||
For each track you want to add, you'll need to create a unique [media source](./media-source) for it. You'll be able to add media data to the output via these media sources. A media source can only ever be used for one output track.
|
||||
For each track you want to add, you'll need to create a unique [media source](./media-sources) for it. You'll be able to add media data to the output via these media sources. A media source can only ever be used for one output track.
|
||||
|
||||
Optionally, you can specify additional track metadata when adding tracks:
|
||||
```ts
|
||||
@@ -115,7 +115,7 @@ await output.start(); // Resolves once the output is ready to receive media data
|
||||
|
||||
## Adding media data
|
||||
|
||||
After starting an `Output`, you can use the media sources you used to add tracks to pipe media data to the output file. The API for this is different for each [media source](./media-source), but it typically looks something like this:
|
||||
After starting an `Output`, you can use the media sources you used to add tracks to pipe media data to the output file. The API for this is different for each [media source](./media-sources), but it typically looks something like this:
|
||||
```ts
|
||||
mediaSource.add(...);
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user