mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-30 12:23:52 +02:00
Merge branch 'v2' into cursors
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { Input } from '../../src/input.js';
|
||||
import { BufferSource, FilePathSource } from '../../src/source.js';
|
||||
import path from 'node:path';
|
||||
import { ALL_FORMATS } from '../../src/input-format.js';
|
||||
import { Output } from '../../src/output.js';
|
||||
import { Mp4OutputFormat } from '../../src/output-format.js';
|
||||
import { BufferTarget } from '../../src/target.js';
|
||||
import { Conversion } from '../../src/conversion.js';
|
||||
import { EncodedPacketSink } from '../../src/media-sink.js';
|
||||
import { extractAvcNalUnits } from '../../src/codec-data.js';
|
||||
|
||||
const __dirname = new URL('.', import.meta.url).pathname;
|
||||
|
||||
test('Annex B to length-prefixed conversion, MP4', async () => {
|
||||
using originalInput = new Input({
|
||||
source: new FilePathSource(path.join(__dirname, '..', 'public/annex-b-avc.mkv')),
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
const originalVideoTrack = (await originalInput.getPrimaryVideoTrack())!;
|
||||
const originalDecoderConfig = (await originalVideoTrack.getDecoderConfig())!;
|
||||
expect(originalDecoderConfig.description).toBeUndefined();
|
||||
expect(originalVideoTrack.codec).toBe('avc');
|
||||
|
||||
const originalSink = new EncodedPacketSink(originalVideoTrack);
|
||||
const originalFirstPacket = await originalSink.getFirstPacket();
|
||||
expect([...originalFirstPacket!.data.slice(0, 4)]).toEqual([0, 0, 0, 1]);
|
||||
|
||||
const originalNalUnits = extractAvcNalUnits(originalFirstPacket!.data, originalDecoderConfig);
|
||||
|
||||
const output = new Output({
|
||||
format: new Mp4OutputFormat(),
|
||||
target: new BufferTarget(),
|
||||
});
|
||||
|
||||
const conversion = await Conversion.init({ input: originalInput, output });
|
||||
await conversion.execute();
|
||||
|
||||
using newInput = new Input({
|
||||
source: new BufferSource(output.target.buffer!),
|
||||
formats: ALL_FORMATS,
|
||||
});
|
||||
const newVideoTrack = (await newInput.getPrimaryVideoTrack())!;
|
||||
const newDecoderConfig = (await newVideoTrack.getDecoderConfig())!;
|
||||
expect(newDecoderConfig.description).toBeDefined();
|
||||
expect(newVideoTrack.codec).toBe('avc');
|
||||
|
||||
const newSink = new EncodedPacketSink(newVideoTrack);
|
||||
const newFirstPacket = await newSink.getFirstPacket();
|
||||
expect([...newFirstPacket!.data.slice(0, 4)]).not.toEqual([0, 0, 0, 1]); // Successfully converted
|
||||
|
||||
const newNalUnits = extractAvcNalUnits(newFirstPacket!.data, newDecoderConfig);
|
||||
expect(newNalUnits).toEqual(originalNalUnits); // Content is the same though
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import { test } from 'vitest';
|
||||
import { AudioSample, VideoSample } from '../../src/sample.js';
|
||||
|
||||
test('VideoSample creation from bytes', async () => {
|
||||
const bytes = new Uint8Array(1024);
|
||||
const sample = new VideoSample(bytes, {
|
||||
codedWidth: 1280,
|
||||
codedHeight: 720,
|
||||
format: 'RGBA',
|
||||
timestamp: 0,
|
||||
});
|
||||
|
||||
sample.close();
|
||||
});
|
||||
|
||||
test('AudioSample creation from bytes', async () => {
|
||||
const bytes = new Uint8Array(1024);
|
||||
const sample = new AudioSample({
|
||||
data: bytes,
|
||||
numberOfChannels: 2,
|
||||
format: 's16',
|
||||
sampleRate: 48000,
|
||||
timestamp: 0,
|
||||
});
|
||||
|
||||
sample.close();
|
||||
});
|
||||
Reference in New Issue
Block a user