mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Add per-sink decoder preferences (hardwareAcceleration, optimizeForLatency) (#406)
* Add per-sink decoder preferences to VideoSampleSink and CanvasSink
Adds an optional VideoSinkDecoderOptions ({ hardwareAcceleration,
optimizeForLatency }) parameter to VideoSampleSink, exposed on CanvasSink
via options.decoderOptions, applied to the decoder config before the
VideoDecoderWrapper is constructed.
Motivation: applications that run many sinks concurrently (multi-track
video editors) need to manage hardware decode sessions deliberately -
the number of concurrent hardware sessions is OS-limited, undocumented,
and exceeding it fails silently on some platforms (macOS VideoToolbox
accepts configure() and decode() and simply never outputs). Such an
application places overflow sinks on 'prefer-software' explicitly.
optimizeForLatency is exposed alongside it since it is the other
WebCodecs decoder-config preference an application may want per sink.
The override composes with the existing interlaced-AVC Chromium
workaround, which runs later and can only strengthen the preference
toward software.
Validation mirrors decode.ts's validateVideoDecodingConfig.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* Modify docs
---------
Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Vanilagy <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
Vanilagy
parent
324fae5153
commit
4affad934e
@@ -225,6 +225,11 @@ Create the sink like so:
|
||||
import { VideoSampleSink } from 'mediabunny';
|
||||
|
||||
const sink = new VideoSampleSink(videoTrack);
|
||||
|
||||
// Optionally, configure the decoder:
|
||||
const sink = new VideoSampleSink(videoTrack, {
|
||||
hardwarePreference: 'prefer-software',
|
||||
});
|
||||
```
|
||||
|
||||
#### Single retrieval
|
||||
@@ -363,6 +368,8 @@ type CanvasSinkOptions = {
|
||||
rotation?: 0 | 90 | 180 | 270;
|
||||
crop?: { left: number; top: number; width: number; height: number };
|
||||
poolSize?: number;
|
||||
alpha?: boolean;
|
||||
decoderOptions?: VideoSinkDecoderOptions;
|
||||
};
|
||||
```
|
||||
- `width`\
|
||||
@@ -380,6 +387,10 @@ type CanvasSinkOptions = {
|
||||
Specifies the rectangular region of the input video to crop to. The crop region will automatically be clamped to the dimensions of the input video track. Cropping is performed after rotation but before resizing. The crop region is in the _display pixel space_ of the underlying video data.
|
||||
- `poolSize`\
|
||||
See [Canvas pool](#canvas-pool).
|
||||
- `alpha`\
|
||||
Whether the output canvases should have transparency instead of a black background. Defaults to `false`. Set this to `true` when using this sink to read transparent videos.
|
||||
- `decoderOptions`\
|
||||
Additional preferences for the underlying video decoder.
|
||||
|
||||
Some examples:
|
||||
```ts
|
||||
|
||||
Reference in New Issue
Block a user