1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// META: global=window,dedicatedworker
// META: script=/webcodecs/utils.js
function testCreateImageBitmapFromVideoFrameVP9Decoder() {
// Prefers hardware decoders by setting video size as large as 720p.
const width = 1280;
const height = 720;
let canvas = new OffscreenCanvas(width, height);
let ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(50, 100, 150)';
ctx.fillRect(0, 0, width, height);
return createImageBitmap(canvas).then((fromImageBitmap) => {
let videoFrame = new VideoFrame(fromImageBitmap, {
timestamp: 0
});
return new Promise((resolve, reject) => {
let processVideoFrame = (frame) => {
createImageBitmap(frame).then((toImageBitmap) => {
let myCanvas = new OffscreenCanvas(width, height);
let myCtx = myCanvas.getContext('2d');
myCtx.drawImage(toImageBitmap, 0, 0);
let tolerance = 10;
try {
testCanvas(myCtx, width, height, kSRGBPixel, null,
(actual, expected) => {
assert_approx_equals(actual, expected, tolerance);
}
);
} catch (error) {
reject(error);
}
resolve('Done.');
});
};
const decoderInit = {
output: processVideoFrame,
error: (e) => {
reject(e);
}
};
const encodedVideoConfig = {
codec: "vp09.00.10.08",
};
let decoder = new VideoDecoder(decoderInit);
decoder.configure(encodedVideoConfig);
let processVideoChunk = (chunk) => {
decoder.decode(chunk);
decoder.flush();
};
const encoderInit = {
output: processVideoChunk,
error: (e) => {
reject(e);
}
};
const videoEncoderConfig = {
codec: "vp09.00.10.08",
width: width,
height: height,
bitrate: 10e6,
framerate: 30
};
let encoder = new VideoEncoder(encoderInit);
encoder.configure(videoEncoderConfig);
encoder.encode(videoFrame, {
keyFrame: true
});
encoder.flush();
});
});
}
promise_test(() => {
return testCreateImageBitmapFromVideoFrameVP9Decoder();
}, 'Create ImageBitmap for a VideoFrame from VP9 decoder.');
|