mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Merge remote-tracking branch 'origin/main' into mpeg-ts
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { test } from 'vitest';
|
||||
import { Output } from '../../src/output.js';
|
||||
import { WebMOutputFormat } from '../../src/output-format.js';
|
||||
import { BufferTarget } from '../../src/target.js';
|
||||
import { VideoSampleSource } from '../../src/media-source.js';
|
||||
import { VideoSample } from '../../src/sample.js';
|
||||
import { QUALITY_MEDIUM } from '../../src/encode.js';
|
||||
|
||||
test('VideoSampleSource.close() should be idempotent after finalize()', async () => {
|
||||
const output = new Output({
|
||||
format: new WebMOutputFormat(),
|
||||
target: new BufferTarget(),
|
||||
});
|
||||
|
||||
const videoSource = new VideoSampleSource({
|
||||
codec: 'vp8',
|
||||
bitrate: QUALITY_MEDIUM,
|
||||
});
|
||||
|
||||
output.addVideoTrack(videoSource);
|
||||
await output.start();
|
||||
|
||||
const canvas = new OffscreenCanvas(100, 100);
|
||||
const ctx = canvas.getContext('2d')!;
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(0, 0, 100, 100);
|
||||
|
||||
const sample = new VideoSample(canvas, { timestamp: 0, duration: 1 / 30 });
|
||||
await videoSource.add(sample);
|
||||
sample.close();
|
||||
|
||||
await output.finalize();
|
||||
|
||||
videoSource.close(); // This previously threw
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { Input } from '../../src/input.js';
|
||||
import { UrlSource } from '../../src/source.js';
|
||||
import { ALL_FORMATS } from '../../src/input-format.js';
|
||||
import { AudioBufferSink } from '../../src/media-sink.js';
|
||||
import { assert } from '../../src/misc.js';
|
||||
|
||||
// VLC creates OGG files with an empty EOS page, which previously caused decoding errors
|
||||
test('can decode OGG Vorbis file with empty EOS page', async () => {
|
||||
using input = new Input({
|
||||
source: new UrlSource('/vorbis-eos.ogg'),
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
|
||||
const track = await input.getPrimaryAudioTrack();
|
||||
assert(track);
|
||||
|
||||
const sink = new AudioBufferSink(track);
|
||||
const buffers: AudioBuffer[] = [];
|
||||
|
||||
for await (const { buffer } of sink.buffers(4, 10)) {
|
||||
buffers.push(buffer);
|
||||
}
|
||||
|
||||
expect(buffers.length).toBeGreaterThan(0);
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { Output } from '../../src/output.js';
|
||||
import { OggOutputFormat } from '../../src/output-format.js';
|
||||
import { NullTarget } from '../../src/target.js';
|
||||
import { AudioBufferSource } from '../../src/media-source.js';
|
||||
|
||||
test('maximumPageDuration option', async () => {
|
||||
const sampleRate = 48000;
|
||||
const durationSeconds = 2;
|
||||
const audioBuffer = new AudioBuffer({ numberOfChannels: 1, length: sampleRate * durationSeconds, sampleRate });
|
||||
|
||||
// First, create an Ogg file without the maximumPageDuration option
|
||||
let pageCountWithoutOption = 0;
|
||||
{
|
||||
const output = new Output({
|
||||
format: new OggOutputFormat({
|
||||
onPage: () => {
|
||||
pageCountWithoutOption++;
|
||||
},
|
||||
}),
|
||||
target: new NullTarget(),
|
||||
});
|
||||
|
||||
const audioSource = new AudioBufferSource({ codec: 'opus', bitrate: 64000 });
|
||||
output.addAudioTrack(audioSource);
|
||||
|
||||
await output.start();
|
||||
await audioSource.add(audioBuffer);
|
||||
audioSource.close();
|
||||
await output.finalize();
|
||||
}
|
||||
|
||||
// Then, create an Ogg file with maximumPageDuration set to 0.1 seconds
|
||||
let pageCountWithOption = 0;
|
||||
{
|
||||
const output = new Output({
|
||||
format: new OggOutputFormat({
|
||||
maximumPageDuration: 0.1,
|
||||
onPage: () => {
|
||||
pageCountWithOption++;
|
||||
},
|
||||
}),
|
||||
target: new NullTarget(),
|
||||
});
|
||||
|
||||
const audioSource = new AudioBufferSource({ codec: 'opus', bitrate: 64000 });
|
||||
output.addAudioTrack(audioSource);
|
||||
|
||||
await output.start();
|
||||
await audioSource.add(audioBuffer);
|
||||
audioSource.close();
|
||||
await output.finalize();
|
||||
}
|
||||
|
||||
expect(pageCountWithoutOption).toBe(3);
|
||||
expect(pageCountWithOption).toBe(23); // It created more pages
|
||||
});
|
||||
Reference in New Issue
Block a user