webcodecs-node 0.2.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/__tests__/AudioData.test.js +2 -1
- package/dist/__tests__/AudioData.test.js.map +1 -1
- package/dist/__tests__/AudioDecoder.test.js +8 -8
- package/dist/__tests__/AudioDecoder.test.js.map +1 -1
- package/dist/__tests__/AudioEncoder.test.js +3 -3
- package/dist/__tests__/AudioEncoder.test.js.map +1 -1
- package/dist/__tests__/EncodedChunks.test.js +3 -2
- package/dist/__tests__/EncodedChunks.test.js.map +1 -1
- package/dist/__tests__/HardwareAcceleration.test.js +2 -1
- package/dist/__tests__/HardwareAcceleration.test.js.map +1 -1
- package/dist/__tests__/ImageDecoder.test.js +16 -45
- package/dist/__tests__/ImageDecoder.test.js.map +1 -1
- package/dist/__tests__/ImageDecoder.wpt.test.d.ts +8 -0
- package/dist/__tests__/ImageDecoder.wpt.test.d.ts.map +1 -0
- package/dist/__tests__/ImageDecoder.wpt.test.js +135 -0
- package/dist/__tests__/ImageDecoder.wpt.test.js.map +1 -0
- package/dist/__tests__/NodeAvDecoder.test.d.ts +2 -0
- package/dist/__tests__/NodeAvDecoder.test.d.ts.map +1 -0
- package/dist/__tests__/NodeAvDecoder.test.js +206 -0
- package/dist/__tests__/NodeAvDecoder.test.js.map +1 -0
- package/dist/__tests__/NodeAvEncoder.test.d.ts +2 -0
- package/dist/__tests__/NodeAvEncoder.test.d.ts.map +1 -0
- package/dist/__tests__/NodeAvEncoder.test.js +176 -0
- package/dist/__tests__/NodeAvEncoder.test.js.map +1 -0
- package/dist/__tests__/VideoDecoder.test.js +5 -5
- package/dist/__tests__/VideoDecoder.test.js.map +1 -1
- package/dist/__tests__/VideoEncoder.test.js +3 -3
- package/dist/__tests__/VideoEncoder.test.js.map +1 -1
- package/dist/__tests__/VideoFrame.test.js +4 -1
- package/dist/__tests__/VideoFrame.test.js.map +1 -1
- package/dist/backends/index.d.ts +3 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +2 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/types.d.ts +168 -0
- package/dist/backends/types.d.ts.map +1 -0
- package/dist/backends/types.js +25 -0
- package/dist/backends/types.js.map +1 -0
- package/dist/codec-utils/audio-codecs.d.ts +60 -0
- package/dist/codec-utils/audio-codecs.d.ts.map +1 -0
- package/dist/codec-utils/audio-codecs.js +117 -0
- package/dist/codec-utils/audio-codecs.js.map +1 -0
- package/dist/codec-utils/formats.d.ts +42 -0
- package/dist/codec-utils/formats.d.ts.map +1 -0
- package/dist/codec-utils/formats.js +147 -0
- package/dist/codec-utils/formats.js.map +1 -0
- package/dist/codec-utils/index.d.ts +9 -0
- package/dist/codec-utils/index.d.ts.map +1 -0
- package/dist/codec-utils/index.js +12 -0
- package/dist/codec-utils/index.js.map +1 -0
- package/dist/codec-utils/types.d.ts +87 -0
- package/dist/codec-utils/types.d.ts.map +1 -0
- package/dist/codec-utils/types.js +10 -0
- package/dist/codec-utils/types.js.map +1 -0
- package/dist/containers/Demuxer.d.ts +114 -0
- package/dist/containers/Demuxer.d.ts.map +1 -0
- package/dist/containers/Demuxer.js +256 -0
- package/dist/containers/Demuxer.js.map +1 -0
- package/dist/containers/Muxer.d.ts +142 -0
- package/dist/containers/Muxer.d.ts.map +1 -0
- package/dist/containers/Muxer.js +295 -0
- package/dist/containers/Muxer.js.map +1 -0
- package/dist/containers/extract.d.ts +25 -0
- package/dist/containers/extract.d.ts.map +1 -0
- package/dist/containers/extract.js +64 -0
- package/dist/containers/extract.js.map +1 -0
- package/dist/containers/index.d.ts +40 -0
- package/dist/containers/index.d.ts.map +1 -0
- package/dist/containers/index.js +41 -0
- package/dist/containers/index.js.map +1 -0
- package/dist/containers/transcode.d.ts +138 -0
- package/dist/containers/transcode.d.ts.map +1 -0
- package/dist/containers/transcode.js +536 -0
- package/dist/containers/transcode.js.map +1 -0
- package/dist/core/AudioData.d.ts +5 -1
- package/dist/core/AudioData.d.ts.map +1 -1
- package/dist/core/AudioData.js +69 -13
- package/dist/core/AudioData.js.map +1 -1
- package/dist/core/EncodedAudioChunk.d.ts +1 -1
- package/dist/core/EncodedAudioChunk.d.ts.map +1 -1
- package/dist/core/EncodedAudioChunk.js +1 -1
- package/dist/core/EncodedAudioChunk.js.map +1 -1
- package/dist/core/EncodedVideoChunk.d.ts.map +1 -1
- package/dist/core/EncodedVideoChunk.js +3 -19
- package/dist/core/EncodedVideoChunk.js.map +1 -1
- package/dist/core/VideoFrame.d.ts +31 -11
- package/dist/core/VideoFrame.d.ts.map +1 -1
- package/dist/core/VideoFrame.js +244 -81
- package/dist/core/VideoFrame.js.map +1 -1
- package/dist/decoders/AudioDecoder.d.ts +14 -12
- package/dist/decoders/AudioDecoder.d.ts.map +1 -1
- package/dist/decoders/AudioDecoder.js +113 -173
- package/dist/decoders/AudioDecoder.js.map +1 -1
- package/dist/decoders/ImageDecoder.d.ts +1 -3
- package/dist/decoders/ImageDecoder.d.ts.map +1 -1
- package/dist/decoders/ImageDecoder.js +39 -192
- package/dist/decoders/ImageDecoder.js.map +1 -1
- package/dist/decoders/VideoDecoder.d.ts +14 -13
- package/dist/decoders/VideoDecoder.d.ts.map +1 -1
- package/dist/decoders/VideoDecoder.js +115 -166
- package/dist/decoders/VideoDecoder.js.map +1 -1
- package/dist/demos/demo-1080p-transcode.d.ts +8 -0
- package/dist/demos/demo-1080p-transcode.d.ts.map +1 -0
- package/dist/demos/demo-1080p-transcode.js +188 -0
- package/dist/demos/demo-1080p-transcode.js.map +1 -0
- package/dist/demos/demo-containers.d.ts +7 -0
- package/dist/demos/demo-containers.d.ts.map +1 -0
- package/dist/demos/demo-containers.js +140 -0
- package/dist/demos/demo-containers.js.map +1 -0
- package/dist/demos/demo-conversion.js +2 -2
- package/dist/demos/demo-conversion.js.map +1 -1
- package/dist/demos/demo-four-corners.d.ts +6 -0
- package/dist/demos/demo-four-corners.d.ts.map +1 -0
- package/dist/demos/demo-four-corners.js +218 -0
- package/dist/demos/demo-four-corners.js.map +1 -0
- package/dist/demos/demo-hwaccel-conversion.js +1 -1
- package/dist/demos/demo-hwaccel-conversion.js.map +1 -1
- package/dist/demos/demo-hwaccel.js +1 -1
- package/dist/demos/demo-hwaccel.js.map +1 -1
- package/dist/demos/demo-samples.js +232 -68
- package/dist/demos/demo-samples.js.map +1 -1
- package/dist/demos/demo-streaming.js +6 -6
- package/dist/demos/demo-streaming.js.map +1 -1
- package/dist/encoders/AudioEncoder.d.ts +14 -13
- package/dist/encoders/AudioEncoder.d.ts.map +1 -1
- package/dist/encoders/AudioEncoder.js +138 -228
- package/dist/encoders/AudioEncoder.js.map +1 -1
- package/dist/encoders/VideoEncoder.d.ts +13 -14
- package/dist/encoders/VideoEncoder.d.ts.map +1 -1
- package/dist/encoders/VideoEncoder.js +92 -161
- package/dist/encoders/VideoEncoder.js.map +1 -1
- package/dist/ffmpeg/index.d.ts +3 -2
- package/dist/ffmpeg/index.d.ts.map +1 -1
- package/dist/ffmpeg/index.js +3 -3
- package/dist/ffmpeg/index.js.map +1 -1
- package/dist/formats/conversions/batch-converter.d.ts +61 -0
- package/dist/formats/conversions/batch-converter.d.ts.map +1 -0
- package/dist/formats/conversions/batch-converter.js +274 -0
- package/dist/formats/conversions/batch-converter.js.map +1 -0
- package/dist/formats/conversions/frame-converter.d.ts +17 -0
- package/dist/formats/conversions/frame-converter.d.ts.map +1 -1
- package/dist/formats/conversions/frame-converter.js +144 -10
- package/dist/formats/conversions/frame-converter.js.map +1 -1
- package/dist/formats/conversions/index.d.ts +2 -0
- package/dist/formats/conversions/index.d.ts.map +1 -1
- package/dist/formats/conversions/index.js +4 -0
- package/dist/formats/conversions/index.js.map +1 -1
- package/dist/hardware/decoder-args.d.ts +2 -7
- package/dist/hardware/decoder-args.d.ts.map +1 -1
- package/dist/hardware/decoder-args.js +2 -32
- package/dist/hardware/decoder-args.js.map +1 -1
- package/dist/hardware/detection.d.ts +1 -1
- package/dist/hardware/detection.d.ts.map +1 -1
- package/dist/hardware/detection.js +54 -27
- package/dist/hardware/detection.js.map +1 -1
- package/dist/hardware/encoder-args.d.ts +2 -11
- package/dist/hardware/encoder-args.d.ts.map +1 -1
- package/dist/hardware/encoder-args.js +2 -71
- package/dist/hardware/encoder-args.js.map +1 -1
- package/dist/hardware/index.d.ts +2 -2
- package/dist/hardware/index.d.ts.map +1 -1
- package/dist/hardware/index.js +2 -2
- package/dist/hardware/index.js.map +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts +4 -17
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.js +57 -185
- package/dist/mediabunny/FFmpegAudioDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts +6 -39
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.js +66 -329
- package/dist/mediabunny/FFmpegAudioEncoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts +5 -38
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.js +39 -283
- package/dist/mediabunny/FFmpegVideoDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts +9 -37
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.js +49 -336
- package/dist/mediabunny/FFmpegVideoEncoder.js.map +1 -1
- package/dist/node-av/HardwarePipeline.d.ts +36 -0
- package/dist/node-av/HardwarePipeline.d.ts.map +1 -0
- package/dist/node-av/HardwarePipeline.js +243 -0
- package/dist/node-av/HardwarePipeline.js.map +1 -0
- package/dist/node-av/NodeAvAudioDecoder.d.ts +46 -0
- package/dist/node-av/NodeAvAudioDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvAudioDecoder.js +350 -0
- package/dist/node-av/NodeAvAudioDecoder.js.map +1 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts +50 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvAudioEncoder.js +506 -0
- package/dist/node-av/NodeAvAudioEncoder.js.map +1 -0
- package/dist/node-av/NodeAvImageDecoder.d.ts +114 -0
- package/dist/node-av/NodeAvImageDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvImageDecoder.js +406 -0
- package/dist/node-av/NodeAvImageDecoder.js.map +1 -0
- package/dist/node-av/NodeAvVideoDecoder.d.ts +43 -0
- package/dist/node-av/NodeAvVideoDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvVideoDecoder.js +365 -0
- package/dist/node-av/NodeAvVideoDecoder.js.map +1 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts +56 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvVideoEncoder.js +509 -0
- package/dist/node-av/NodeAvVideoEncoder.js.map +1 -0
- package/dist/polyfill.d.ts.map +1 -1
- package/dist/polyfill.js +11 -9
- package/dist/polyfill.js.map +1 -1
- package/dist/utils/aac.d.ts.map +1 -1
- package/dist/utils/aac.js +6 -0
- package/dist/utils/aac.js.map +1 -1
- package/dist/utils/buffer-pool.d.ts +109 -0
- package/dist/utils/buffer-pool.d.ts.map +1 -0
- package/dist/utils/buffer-pool.js +278 -0
- package/dist/utils/buffer-pool.js.map +1 -0
- package/dist/utils/codec-cache.d.ts +65 -0
- package/dist/utils/codec-cache.d.ts.map +1 -0
- package/dist/utils/codec-cache.js +116 -0
- package/dist/utils/codec-cache.js.map +1 -0
- package/dist/utils/errors.d.ts +62 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +84 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/event-target.d.ts +42 -0
- package/dist/utils/event-target.d.ts.map +1 -0
- package/dist/utils/event-target.js +96 -0
- package/dist/utils/event-target.js.map +1 -0
- package/dist/utils/hardware-pool.d.ts +88 -0
- package/dist/utils/hardware-pool.d.ts.map +1 -0
- package/dist/utils/hardware-pool.js +266 -0
- package/dist/utils/hardware-pool.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +12 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/timeout.d.ts +44 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/timeout.js +73 -0
- package/dist/utils/timeout.js.map +1 -0
- package/dist/utils/type-guards.d.ts +11 -1
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/dist/utils/type-guards.js.map +1 -1
- package/package.json +20 -34
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapted WebCodecs ImageDecoder tests from WPT assets.
|
|
3
|
+
*
|
|
4
|
+
* Focuses on verifying JPEG EXIF orientation handling for both RGB and
|
|
5
|
+
* 4:2:0 YUV inputs using the four-colors fixtures.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import { ImageDecoder } from '../ImageDecoder.js';
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = path.dirname(__filename);
|
|
13
|
+
const WEB_CODECS_TESTS_DIR = path.resolve(__dirname, '../../webcodecs-tests');
|
|
14
|
+
const COLOR_YELLOW = [0xff, 0xff, 0x00, 0xff];
|
|
15
|
+
const COLOR_RED = [0xff, 0x00, 0x00, 0xff];
|
|
16
|
+
const COLOR_BLUE = [0x00, 0x00, 0xff, 0xff];
|
|
17
|
+
const COLOR_GREEN = [0x00, 0xff, 0x00, 0xff];
|
|
18
|
+
const BASE_MATRIX = [
|
|
19
|
+
[COLOR_YELLOW, COLOR_RED],
|
|
20
|
+
[COLOR_BLUE, COLOR_GREEN],
|
|
21
|
+
];
|
|
22
|
+
function rotateMatrix(matrix, count) {
|
|
23
|
+
let result = matrix.map(row => row.slice());
|
|
24
|
+
for (let i = 0; i < count; i++) {
|
|
25
|
+
result = result[0].map((_value, index) => result.map(row => row[index]).reverse());
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function flipMatrix(matrix) {
|
|
30
|
+
return matrix.map(row => [...row].reverse());
|
|
31
|
+
}
|
|
32
|
+
function expectedMatrixForOrientation(orientation) {
|
|
33
|
+
let matrix = BASE_MATRIX.map(row => row.slice());
|
|
34
|
+
switch (orientation) {
|
|
35
|
+
case 1: // top-left, default
|
|
36
|
+
break;
|
|
37
|
+
case 2: // top-right, mirror along y-axis
|
|
38
|
+
matrix = flipMatrix(matrix);
|
|
39
|
+
break;
|
|
40
|
+
case 3: // bottom-right, 180 degrees
|
|
41
|
+
matrix = rotateMatrix(matrix, 2);
|
|
42
|
+
break;
|
|
43
|
+
case 4: // bottom-left, mirror along x-axis
|
|
44
|
+
matrix = flipMatrix(rotateMatrix(matrix, 2));
|
|
45
|
+
break;
|
|
46
|
+
case 5: // left-top, mirror along x-axis + 270° CW
|
|
47
|
+
matrix = flipMatrix(rotateMatrix(matrix, 1));
|
|
48
|
+
break;
|
|
49
|
+
case 6: // right-top, 90° CW
|
|
50
|
+
matrix = rotateMatrix(matrix, 1);
|
|
51
|
+
break;
|
|
52
|
+
case 7: // right-bottom, mirror along x-axis + 90° CW
|
|
53
|
+
matrix = flipMatrix(rotateMatrix(matrix, 3));
|
|
54
|
+
break;
|
|
55
|
+
case 8: // left-bottom, 270° CW
|
|
56
|
+
matrix = rotateMatrix(matrix, 3);
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported orientation ${orientation}`);
|
|
60
|
+
}
|
|
61
|
+
return matrix;
|
|
62
|
+
}
|
|
63
|
+
async function decodeFourColorsJpeg(orientation, useYuv) {
|
|
64
|
+
const filename = useYuv
|
|
65
|
+
? 'four-colors-limited-range-420-8bpc.jpg'
|
|
66
|
+
: 'four-colors.jpg';
|
|
67
|
+
const filePath = path.join(WEB_CODECS_TESTS_DIR, filename);
|
|
68
|
+
if (!fs.existsSync(filePath)) {
|
|
69
|
+
throw new Error(`Missing WebCodecs test asset: ${filename}`);
|
|
70
|
+
}
|
|
71
|
+
const fileBytes = fs.readFileSync(filePath);
|
|
72
|
+
const buffer = new Uint8Array(fileBytes);
|
|
73
|
+
const orientationOffset = useYuv ? 0x31 : 0x1f;
|
|
74
|
+
buffer[orientationOffset] = orientation;
|
|
75
|
+
const decoder = new ImageDecoder({ data: buffer, type: 'image/jpeg' });
|
|
76
|
+
await decoder.completed;
|
|
77
|
+
const { image } = await decoder.decode();
|
|
78
|
+
decoder.close();
|
|
79
|
+
return image;
|
|
80
|
+
}
|
|
81
|
+
function getPixel(pixels, width, x, y) {
|
|
82
|
+
const idx = (y * width + x) * 4;
|
|
83
|
+
return [
|
|
84
|
+
pixels[idx],
|
|
85
|
+
pixels[idx + 1],
|
|
86
|
+
pixels[idx + 2],
|
|
87
|
+
pixels[idx + 3],
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
function expectColorClose(actual, expected, tolerance) {
|
|
91
|
+
for (let i = 0; i < 4; i++) {
|
|
92
|
+
expect(Math.abs(actual[i] - expected[i])).toBeLessThanOrEqual(tolerance);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function expectFourColorsLayout(frame, orientation, tolerance) {
|
|
96
|
+
const width = frame.displayWidth ?? frame.codedWidth;
|
|
97
|
+
const height = frame.displayHeight ?? frame.codedHeight;
|
|
98
|
+
const dest = new ArrayBuffer(width * height * 4);
|
|
99
|
+
await frame.copyTo(dest, { format: 'RGBA' });
|
|
100
|
+
const pixels = new Uint8Array(dest);
|
|
101
|
+
const expectedMatrix = expectedMatrixForOrientation(orientation);
|
|
102
|
+
const samples = [
|
|
103
|
+
{ actual: getPixel(pixels, width, 0, 0), expected: expectedMatrix[0][0], label: 'top-left' },
|
|
104
|
+
{ actual: getPixel(pixels, width, width - 1, 0), expected: expectedMatrix[0][1], label: 'top-right' },
|
|
105
|
+
{ actual: getPixel(pixels, width, 0, height - 1), expected: expectedMatrix[1][0], label: 'bottom-left' },
|
|
106
|
+
{
|
|
107
|
+
actual: getPixel(pixels, width, width - 1, height - 1),
|
|
108
|
+
expected: expectedMatrix[1][1],
|
|
109
|
+
label: 'bottom-right',
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
for (const sample of samples) {
|
|
113
|
+
expectColorClose(sample.actual, sample.expected, tolerance);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
describe('ImageDecoder WPT-adapted orientation tests', () => {
|
|
117
|
+
const ORIENTATIONS = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
118
|
+
describe.each([
|
|
119
|
+
{ label: 'RGB JPEG', useYuv: false, tolerance: 0 },
|
|
120
|
+
{ label: 'YUV 4:2:0 JPEG', useYuv: true, tolerance: 3 },
|
|
121
|
+
])('$label', ({ useYuv, tolerance }) => {
|
|
122
|
+
it.each(ORIENTATIONS)('decodes EXIF orientation %s', async (orientation) => {
|
|
123
|
+
const frame = await decodeFourColorsJpeg(orientation, useYuv);
|
|
124
|
+
const expectedWidth = orientation > 4 ? 240 : 320;
|
|
125
|
+
const expectedHeight = orientation > 4 ? 320 : 240;
|
|
126
|
+
const width = frame.displayWidth ?? frame.codedWidth;
|
|
127
|
+
const height = frame.displayHeight ?? frame.codedHeight;
|
|
128
|
+
expect(width).toBe(expectedWidth);
|
|
129
|
+
expect(height).toBe(expectedHeight);
|
|
130
|
+
await expectFourColorsLayout(frame, orientation, tolerance);
|
|
131
|
+
frame.close();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=ImageDecoder.wpt.test.js.map
|
|
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AE,SAAS,EAAE,CAAC,EAAE;KACxD,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE;QACrC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CACnB,6BAA6B,EAC7B,KAAK,EAAE,WAAmB,EAAE,EAAE;YAC5B,MAAM,KAAK,GAAG,MAAM,oBAAoB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;YAC9D,MAAM,aAAa,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YAClD,MAAM,cAAc,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YACnD,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,UAAU,CAAC;YACrD,MAAM,MAAM,GAAG,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,WAAW,CAAC;YAExD,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAClC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAEpC,MAAM,sBAAsB,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;YAC5D,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeAvDecoder.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/NodeAvDecoder.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { VideoEncoder } from '../encoders/VideoEncoder.js';
|
|
2
|
+
import { VideoDecoder } from '../decoders/VideoDecoder.js';
|
|
3
|
+
import { VideoFrame } from '../core/VideoFrame.js';
|
|
4
|
+
/**
|
|
5
|
+
* Helper function to create test frames
|
|
6
|
+
*/
|
|
7
|
+
function createTestFrame(width, height, frameIndex) {
|
|
8
|
+
const data = new Uint8Array(width * height * 4);
|
|
9
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
10
|
+
data[i] = 50 + frameIndex * 10; // R
|
|
11
|
+
data[i + 1] = 100; // G
|
|
12
|
+
data[i + 2] = 150; // B
|
|
13
|
+
data[i + 3] = 255; // A
|
|
14
|
+
}
|
|
15
|
+
return new VideoFrame(data, {
|
|
16
|
+
format: 'RGBA',
|
|
17
|
+
codedWidth: width,
|
|
18
|
+
codedHeight: height,
|
|
19
|
+
timestamp: frameIndex * 33333,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Helper to encode frames and return chunks for decoding tests
|
|
24
|
+
*/
|
|
25
|
+
async function encodeFrames(codec, width, height, numFrames) {
|
|
26
|
+
const chunks = [];
|
|
27
|
+
let description;
|
|
28
|
+
let err = null;
|
|
29
|
+
const encoder = new VideoEncoder({
|
|
30
|
+
output: (chunk, metadata) => {
|
|
31
|
+
chunks.push(chunk);
|
|
32
|
+
if (metadata?.decoderConfig?.description) {
|
|
33
|
+
description = metadata.decoderConfig.description;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
error: (e) => { err = e; },
|
|
37
|
+
});
|
|
38
|
+
encoder.configure({
|
|
39
|
+
codec,
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
framerate: 30,
|
|
43
|
+
bitrate: 500_000,
|
|
44
|
+
});
|
|
45
|
+
for (let f = 0; f < numFrames; f++) {
|
|
46
|
+
const frame = createTestFrame(width, height, f);
|
|
47
|
+
encoder.encode(frame, { keyFrame: f === 0 });
|
|
48
|
+
frame.close();
|
|
49
|
+
}
|
|
50
|
+
await encoder.flush();
|
|
51
|
+
encoder.close();
|
|
52
|
+
return { chunks, description, error: err };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Helper to decode chunks and return frames
|
|
56
|
+
*/
|
|
57
|
+
async function decodeChunks(codec, chunks, width, height, outputFormat = 'I420', description) {
|
|
58
|
+
const frames = [];
|
|
59
|
+
let err = null;
|
|
60
|
+
const decoder = new VideoDecoder({
|
|
61
|
+
output: (frame) => frames.push(frame),
|
|
62
|
+
error: (e) => { err = e; },
|
|
63
|
+
});
|
|
64
|
+
decoder.configure({
|
|
65
|
+
codec,
|
|
66
|
+
codedWidth: width,
|
|
67
|
+
codedHeight: height,
|
|
68
|
+
outputFormat,
|
|
69
|
+
description,
|
|
70
|
+
});
|
|
71
|
+
for (const chunk of chunks) {
|
|
72
|
+
decoder.decode(chunk);
|
|
73
|
+
}
|
|
74
|
+
await decoder.flush();
|
|
75
|
+
decoder.close();
|
|
76
|
+
return { frames, error: err };
|
|
77
|
+
}
|
|
78
|
+
describe('NodeAV VideoDecoder backend', () => {
|
|
79
|
+
const width = 64;
|
|
80
|
+
const height = 64;
|
|
81
|
+
const numFrames = 3;
|
|
82
|
+
describe('H.264 (AVC) decoding', () => {
|
|
83
|
+
it('decodes h264 chunks produced by node-av encoder', async () => {
|
|
84
|
+
const codec = 'avc1.42001E';
|
|
85
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
86
|
+
if (encodeError)
|
|
87
|
+
throw encodeError;
|
|
88
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
89
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height);
|
|
90
|
+
if (decodeError)
|
|
91
|
+
throw decodeError;
|
|
92
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
93
|
+
frames.forEach((f) => f.close());
|
|
94
|
+
}, 20000);
|
|
95
|
+
it('outputs RGBA format when requested', async () => {
|
|
96
|
+
const codec = 'avc1.42001E';
|
|
97
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
98
|
+
if (encodeError)
|
|
99
|
+
throw encodeError;
|
|
100
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height, 'RGBA');
|
|
101
|
+
if (decodeError)
|
|
102
|
+
throw decodeError;
|
|
103
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
104
|
+
expect(frames[0].format).toBe('RGBA');
|
|
105
|
+
frames.forEach((f) => f.close());
|
|
106
|
+
}, 20000);
|
|
107
|
+
});
|
|
108
|
+
describe('H.265 (HEVC) decoding', () => {
|
|
109
|
+
it('decodes hevc chunks produced by node-av encoder', async () => {
|
|
110
|
+
const codec = 'hev1.1.6.L93.B0';
|
|
111
|
+
const { chunks, description, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
112
|
+
if (encodeError)
|
|
113
|
+
throw encodeError;
|
|
114
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
115
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height, 'I420', description);
|
|
116
|
+
if (decodeError)
|
|
117
|
+
throw decodeError;
|
|
118
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
119
|
+
frames.forEach((f) => f.close());
|
|
120
|
+
}, 30000);
|
|
121
|
+
});
|
|
122
|
+
describe('VP8 decoding', () => {
|
|
123
|
+
it('decodes vp8 chunks produced by node-av encoder', async () => {
|
|
124
|
+
const codec = 'vp8';
|
|
125
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
126
|
+
if (encodeError)
|
|
127
|
+
throw encodeError;
|
|
128
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
129
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height);
|
|
130
|
+
if (decodeError)
|
|
131
|
+
throw decodeError;
|
|
132
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
133
|
+
frames.forEach((f) => f.close());
|
|
134
|
+
}, 20000);
|
|
135
|
+
});
|
|
136
|
+
describe('VP9 decoding', () => {
|
|
137
|
+
it('decodes vp9 chunks produced by node-av encoder', async () => {
|
|
138
|
+
const codec = 'vp09.00.10.08';
|
|
139
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
140
|
+
if (encodeError)
|
|
141
|
+
throw encodeError;
|
|
142
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
143
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height);
|
|
144
|
+
if (decodeError)
|
|
145
|
+
throw decodeError;
|
|
146
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
147
|
+
frames.forEach((f) => f.close());
|
|
148
|
+
}, 30000);
|
|
149
|
+
it('decodes with vp9 codec string', async () => {
|
|
150
|
+
const codec = 'vp9';
|
|
151
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
152
|
+
if (encodeError)
|
|
153
|
+
throw encodeError;
|
|
154
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
155
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height);
|
|
156
|
+
if (decodeError)
|
|
157
|
+
throw decodeError;
|
|
158
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
159
|
+
frames.forEach((f) => f.close());
|
|
160
|
+
}, 30000);
|
|
161
|
+
});
|
|
162
|
+
describe('AV1 decoding', () => {
|
|
163
|
+
it('decodes av1 chunks produced by node-av encoder', async () => {
|
|
164
|
+
const codec = 'av01.0.01M.08';
|
|
165
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
166
|
+
if (encodeError)
|
|
167
|
+
throw encodeError;
|
|
168
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
169
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height);
|
|
170
|
+
if (decodeError)
|
|
171
|
+
throw decodeError;
|
|
172
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
173
|
+
frames.forEach((f) => f.close());
|
|
174
|
+
}, 60000); // AV1 can be slow
|
|
175
|
+
it('decodes with av1 codec string', async () => {
|
|
176
|
+
const codec = 'av1';
|
|
177
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
178
|
+
if (encodeError)
|
|
179
|
+
throw encodeError;
|
|
180
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
181
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height);
|
|
182
|
+
if (decodeError)
|
|
183
|
+
throw decodeError;
|
|
184
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
185
|
+
frames.forEach((f) => f.close());
|
|
186
|
+
}, 60000);
|
|
187
|
+
});
|
|
188
|
+
describe('Round-trip encoding/decoding', () => {
|
|
189
|
+
it('preserves frame dimensions through encode/decode cycle', async () => {
|
|
190
|
+
const codec = 'avc1.42001E';
|
|
191
|
+
const { chunks, error: encodeError } = await encodeFrames(codec, width, height, numFrames);
|
|
192
|
+
if (encodeError)
|
|
193
|
+
throw encodeError;
|
|
194
|
+
const { frames, error: decodeError } = await decodeChunks(codec, chunks, width, height);
|
|
195
|
+
if (decodeError)
|
|
196
|
+
throw decodeError;
|
|
197
|
+
expect(frames.length).toBeGreaterThan(0);
|
|
198
|
+
for (const frame of frames) {
|
|
199
|
+
expect(frame.codedWidth).toBe(width);
|
|
200
|
+
expect(frame.codedHeight).toBe(height);
|
|
201
|
+
frame.close();
|
|
202
|
+
}
|
|
203
|
+
}, 20000);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
//# sourceMappingURL=NodeAvDecoder.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeAvDecoder.test.js","sourceRoot":"","sources":["../../src/__tests__/NodeAvDecoder.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD;;GAEG;AACH,SAAS,eAAe,CAAC,KAAa,EAAE,MAAc,EAAE,UAAkB;IACxE,MAAM,IAAI,GAAG,IAAI,UAAU,C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AC;gBACvC,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,CAAC;QACH,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeAvEncoder.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/NodeAvEncoder.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { VideoEncoder } from '../encoders/VideoEncoder.js';
|
|
2
|
+
import { VideoFrame } from '../core/VideoFrame.js';
|
|
3
|
+
/**
|
|
4
|
+
* Helper function to create test frames
|
|
5
|
+
*/
|
|
6
|
+
function createTestFrame(width, height, frameIndex) {
|
|
7
|
+
const data = new Uint8Array(width * height * 4);
|
|
8
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
9
|
+
data[i] = 50 + frameIndex * 10; // R
|
|
10
|
+
data[i + 1] = 100; // G
|
|
11
|
+
data[i + 2] = 150; // B
|
|
12
|
+
data[i + 3] = 255; // A
|
|
13
|
+
}
|
|
14
|
+
return new VideoFrame(data, {
|
|
15
|
+
format: 'RGBA',
|
|
16
|
+
codedWidth: width,
|
|
17
|
+
codedHeight: height,
|
|
18
|
+
timestamp: frameIndex * 33333,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Helper function to encode test frames and return chunks
|
|
23
|
+
*/
|
|
24
|
+
async function encodeTestFrames(codec, width, height, numFrames) {
|
|
25
|
+
const chunks = [];
|
|
26
|
+
let err = null;
|
|
27
|
+
const encoder = new VideoEncoder({
|
|
28
|
+
output: (chunk) => chunks.push(chunk),
|
|
29
|
+
error: (e) => { err = e; },
|
|
30
|
+
});
|
|
31
|
+
encoder.configure({
|
|
32
|
+
codec,
|
|
33
|
+
width,
|
|
34
|
+
height,
|
|
35
|
+
framerate: 30,
|
|
36
|
+
bitrate: 500_000,
|
|
37
|
+
});
|
|
38
|
+
for (let f = 0; f < numFrames; f++) {
|
|
39
|
+
const frame = createTestFrame(width, height, f);
|
|
40
|
+
encoder.encode(frame, { keyFrame: f === 0 });
|
|
41
|
+
frame.close();
|
|
42
|
+
}
|
|
43
|
+
await encoder.flush();
|
|
44
|
+
encoder.close();
|
|
45
|
+
return { chunks, error: err };
|
|
46
|
+
}
|
|
47
|
+
describe('NodeAV VideoEncoder backend', () => {
|
|
48
|
+
const width = 64;
|
|
49
|
+
const height = 64;
|
|
50
|
+
const numFrames = 3;
|
|
51
|
+
describe('H.264 (AVC) encoding', () => {
|
|
52
|
+
it('encodes RGBA input via node-av backend', async () => {
|
|
53
|
+
const { chunks, error } = await encodeTestFrames('avc1.42001E', width, height, numFrames);
|
|
54
|
+
if (error) {
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
58
|
+
expect(chunks[0].type).toBe('key');
|
|
59
|
+
}, 20000);
|
|
60
|
+
it('encodes YUV420P input via node-av backend', async () => {
|
|
61
|
+
const chunks = [];
|
|
62
|
+
let err = null;
|
|
63
|
+
const encoder = new VideoEncoder({
|
|
64
|
+
output: (chunk) => chunks.push(chunk),
|
|
65
|
+
error: (e) => { err = e; },
|
|
66
|
+
});
|
|
67
|
+
encoder.configure({
|
|
68
|
+
codec: 'avc1.42001E',
|
|
69
|
+
width,
|
|
70
|
+
height,
|
|
71
|
+
framerate: 30,
|
|
72
|
+
bitrate: 500_000,
|
|
73
|
+
});
|
|
74
|
+
// Create I420 frames
|
|
75
|
+
const ySize = width * height;
|
|
76
|
+
const uvSize = (width / 2) * (height / 2);
|
|
77
|
+
const frameSize = ySize + 2 * uvSize;
|
|
78
|
+
for (let f = 0; f < numFrames; f++) {
|
|
79
|
+
const data = new Uint8Array(frameSize);
|
|
80
|
+
// Fill Y plane with varying luminance
|
|
81
|
+
for (let i = 0; i < ySize; i++) {
|
|
82
|
+
data[i] = 128 + f * 10;
|
|
83
|
+
}
|
|
84
|
+
// Fill U and V planes with neutral values
|
|
85
|
+
for (let i = ySize; i < frameSize; i++) {
|
|
86
|
+
data[i] = 128;
|
|
87
|
+
}
|
|
88
|
+
const frame = new VideoFrame(data, {
|
|
89
|
+
format: 'I420',
|
|
90
|
+
codedWidth: width,
|
|
91
|
+
codedHeight: height,
|
|
92
|
+
timestamp: f * 33333,
|
|
93
|
+
});
|
|
94
|
+
encoder.encode(frame, { keyFrame: f === 0 });
|
|
95
|
+
frame.close();
|
|
96
|
+
}
|
|
97
|
+
await encoder.flush();
|
|
98
|
+
encoder.close();
|
|
99
|
+
if (err) {
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
103
|
+
}, 20000);
|
|
104
|
+
});
|
|
105
|
+
describe('H.265 (HEVC) encoding', () => {
|
|
106
|
+
it('encodes RGBA input via node-av backend', async () => {
|
|
107
|
+
const { chunks, error } = await encodeTestFrames('hev1.1.6.L93.B0', width, height, numFrames);
|
|
108
|
+
if (error) {
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
112
|
+
expect(chunks[0].type).toBe('key');
|
|
113
|
+
}, 30000);
|
|
114
|
+
});
|
|
115
|
+
describe('VP8 encoding', () => {
|
|
116
|
+
it('encodes RGBA input via node-av backend', async () => {
|
|
117
|
+
const { chunks, error } = await encodeTestFrames('vp8', width, height, numFrames);
|
|
118
|
+
if (error) {
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
122
|
+
expect(chunks[0].type).toBe('key');
|
|
123
|
+
}, 20000);
|
|
124
|
+
});
|
|
125
|
+
describe('VP9 encoding', () => {
|
|
126
|
+
it('encodes RGBA input via node-av backend', async () => {
|
|
127
|
+
const { chunks, error } = await encodeTestFrames('vp09.00.10.08', width, height, numFrames);
|
|
128
|
+
if (error) {
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
132
|
+
expect(chunks[0].type).toBe('key');
|
|
133
|
+
}, 30000);
|
|
134
|
+
it('encodes with vp9 codec string', async () => {
|
|
135
|
+
const { chunks, error } = await encodeTestFrames('vp9', width, height, numFrames);
|
|
136
|
+
if (error) {
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
140
|
+
}, 30000);
|
|
141
|
+
});
|
|
142
|
+
describe('AV1 encoding', () => {
|
|
143
|
+
it('encodes RGBA input via node-av backend', async () => {
|
|
144
|
+
const { chunks, error } = await encodeTestFrames('av01.0.01M.08', width, height, numFrames);
|
|
145
|
+
if (error) {
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
149
|
+
expect(chunks[0].type).toBe('key');
|
|
150
|
+
}, 60000); // AV1 encoding can be slow
|
|
151
|
+
it('encodes with av1 codec string', async () => {
|
|
152
|
+
const { chunks, error } = await encodeTestFrames('av1', width, height, numFrames);
|
|
153
|
+
if (error) {
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
expect(chunks.length).toBeGreaterThan(0);
|
|
157
|
+
}, 60000);
|
|
158
|
+
});
|
|
159
|
+
describe('Error handling', () => {
|
|
160
|
+
it('handles invalid codec gracefully', async () => {
|
|
161
|
+
const encoder = new VideoEncoder({
|
|
162
|
+
output: () => { },
|
|
163
|
+
error: () => { },
|
|
164
|
+
});
|
|
165
|
+
expect(() => {
|
|
166
|
+
encoder.configure({
|
|
167
|
+
codec: 'invalid-codec',
|
|
168
|
+
width: 64,
|
|
169
|
+
height: 64,
|
|
170
|
+
});
|
|
171
|
+
}).toThrow();
|
|
172
|
+
encoder.close();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
//# sourceMappingURL=NodeAvEncoder.test.js.map
|
|
@@ -0,0 +1 @@
|
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BAC/B,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC;gBAChB,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;aAChB,CAAC,CAAC;YAEH,MAAM,CAAC,GAAG,EAAE;gBACV,OAAO,CAAC,SAAS,CAAC;oBAChB,KAAK,EAAE,eAAe;oBACtB,KAAK,EAAE,EAAE;oBACT,MAAM,EAAE,EAAE;iBACX,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YAEb,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for VideoDecoder class
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import { VideoDecoder } from '../VideoDecoder.js';
|
|
6
|
-
import { VideoEncoder } from '../VideoEncoder.js';
|
|
7
|
-
import { VideoFrame } from '../VideoFrame.js';
|
|
8
|
-
import { EncodedVideoChunk } from '../EncodedVideoChunk.js';
|
|
4
|
+
import { describe, it, expect } from 'vitest';
|
|
5
|
+
import { VideoDecoder } from '../decoders/VideoDecoder.js';
|
|
6
|
+
import { VideoEncoder } from '../encoders/VideoEncoder.js';
|
|
7
|
+
import { VideoFrame } from '../core/VideoFrame.js';
|
|
8
|
+
import { EncodedVideoChunk } from '../core/EncodedVideoChunk.js';
|
|
9
9
|
describe('VideoDecoder', () => {
|
|
10
10
|
describe('isConfigSupported', () => {
|
|
11
11
|
it('should support H.264', async () => {
|