mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import { expect, test } from 'vitest';
|
|
import { Input } from '../../src/input.js';
|
|
import { BufferSource, UrlSource } from '../../src/source.js';
|
|
import { ALL_FORMATS } from '../../src/input-format.js';
|
|
import { assert } from '../../src/misc.js';
|
|
import { AudioSampleSink, VideoSampleSink } from '../../src/media-sink.js';
|
|
import { Output } from '../../src/output.js';
|
|
import { MpegTsOutputFormat } from '../../src/output-format.js';
|
|
import { BufferTarget } from '../../src/target.js';
|
|
import { Conversion } from '../../src/conversion.js';
|
|
|
|
// https://github.com/Vanilagy/mediabunny/issues/370
|
|
test('Negative audio timestamps are preserved', async () => {
|
|
using input = new Input({
|
|
source: new UrlSource('/edts.mp4'),
|
|
formats: ALL_FORMATS,
|
|
});
|
|
|
|
const track = await input.getPrimaryAudioTrack();
|
|
assert(track);
|
|
|
|
expect(await track.getFirstTimestamp()).toBeLessThan(0);
|
|
|
|
const sink = new AudioSampleSink(track);
|
|
|
|
for await (using sample of sink.samples()) {
|
|
expect(sample.timestamp).toBe(await track.getFirstTimestamp());
|
|
break;
|
|
}
|
|
});
|
|
|
|
test('No B-frames are skipped when software-decoding AVC', async () => {
|
|
using input = new Input({
|
|
source: new UrlSource('/missing-reorder-metadata-v1.mp4'),
|
|
formats: ALL_FORMATS,
|
|
});
|
|
|
|
const track = await input.getPrimaryVideoTrack();
|
|
assert(track);
|
|
|
|
const sink = new VideoSampleSink(track, {
|
|
hardwareAcceleration: 'prefer-software',
|
|
});
|
|
let count = 0;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
for await (using sample of sink.samples()) {
|
|
count++;
|
|
}
|
|
|
|
expect(count).toBe(48);
|
|
});
|
|
|
|
test('No B-frames are skipped when software-decoding AVC, Annex B edition', async () => {
|
|
using input = new Input({
|
|
source: new UrlSource('/missing-reorder-metadata-v1.mp4'),
|
|
formats: ALL_FORMATS,
|
|
});
|
|
|
|
// Force Annex B by converting to MPEG-TS
|
|
const output = new Output({
|
|
format: new MpegTsOutputFormat(),
|
|
target: new BufferTarget(),
|
|
});
|
|
|
|
const conversion = await Conversion.init({ input, output, copy: { mode: 'forced' } });
|
|
await conversion.execute();
|
|
|
|
using newInput = new Input({
|
|
source: new BufferSource(output.target.buffer!),
|
|
formats: ALL_FORMATS,
|
|
});
|
|
|
|
const track = await newInput.getPrimaryVideoTrack();
|
|
assert(track);
|
|
|
|
const sink = new VideoSampleSink(track, {
|
|
hardwareAcceleration: 'prefer-software',
|
|
});
|
|
let count = 0;
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
for await (using sample of sink.samples()) {
|
|
count++;
|
|
}
|
|
|
|
expect(count).toBe(48);
|
|
});
|