mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
* Add custom quality factors and quantizer bitrate mode (closes #327) * Fix quantizer mode fallback and per-frame quantizer edge cases * Clean up quantizer mode tests * Quantizer implementation * Add quality tests * Improve conversion codec error message, make test more lenient * Add quantizer support blog post --------- Co-authored-by: Vanilagy <[email protected]>
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import { expect, test } from 'vitest';
|
|
import { Output } from '../../src/output.js';
|
|
import { Mp4OutputFormat } from '../../src/output-format.js';
|
|
import { NullTarget } from '../../src/target.js';
|
|
import { VideoSampleSource } from '../../src/media-source.js';
|
|
import { canEncodeVideo, Quality } from '../../src/encode.js';
|
|
import { VideoSample } from '../../src/sample.js';
|
|
|
|
test('Odd video dimensions fail for AVC', async () => {
|
|
const output = new Output({
|
|
format: new Mp4OutputFormat(),
|
|
target: new NullTarget(),
|
|
});
|
|
|
|
const source = new VideoSampleSource({
|
|
codec: 'avc',
|
|
quality: new Quality('high'),
|
|
});
|
|
output.addVideoTrack(source);
|
|
|
|
await output.start();
|
|
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = 1281;
|
|
canvas.height = 720;
|
|
const sample = new VideoSample(canvas, { timestamp: 0 });
|
|
|
|
await expect(source.add(sample)).rejects.toThrow('even number'); // The error message is explicit
|
|
});
|
|
|
|
test('Odd video dimensions fail for HEVC', async () => {
|
|
const output = new Output({
|
|
format: new Mp4OutputFormat(),
|
|
target: new NullTarget(),
|
|
});
|
|
|
|
const source = new VideoSampleSource({
|
|
codec: 'hevc',
|
|
quality: new Quality('high'),
|
|
});
|
|
output.addVideoTrack(source);
|
|
|
|
await output.start();
|
|
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = 1281;
|
|
canvas.height = 720;
|
|
const sample = new VideoSample(canvas, { timestamp: 0 });
|
|
|
|
await expect(source.add(sample)).rejects.toThrow('even number');
|
|
});
|
|
|
|
test('Odd video dimensions pass for VP9', async () => {
|
|
const output = new Output({
|
|
format: new Mp4OutputFormat(),
|
|
target: new NullTarget(),
|
|
});
|
|
|
|
const source = new VideoSampleSource({
|
|
codec: 'vp9',
|
|
quality: new Quality('high'),
|
|
});
|
|
output.addVideoTrack(source);
|
|
|
|
await output.start();
|
|
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = 1281;
|
|
canvas.height = 720;
|
|
const sample = new VideoSample(canvas, { timestamp: 0 });
|
|
|
|
await source.add(sample);
|
|
});
|
|
|
|
test('Odd video dimensions encodability checks', async () => {
|
|
expect(await canEncodeVideo('avc', { width: 1920, height: 1081 })).toBe(false);
|
|
expect(await canEncodeVideo('hevc', { width: 1920, height: 1081 })).toBe(false);
|
|
expect(await canEncodeVideo('vp8', { width: 1920, height: 1081 })).toBe(true);
|
|
expect(await canEncodeVideo('vp9', { width: 1920, height: 1081 })).toBe(true);
|
|
expect(await canEncodeVideo('av1', { width: 1920, height: 1081 })).toBe(true);
|
|
});
|