-
Notifications
You must be signed in to change notification settings - Fork 3
/
react-renderer.tsx
48 lines (45 loc) · 1.19 KB
/
react-renderer.tsx
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
import React, { useRef, useEffect } from 'react';
import { CNNx2UL, GANUUL, render } from 'anime4k-webgpu';
export const ReactRenderer: React.FC = () => {
const canvasRef = useRef<HTMLCanvasElement>(null);
const videoRef = useRef<HTMLVideoElement>(null);
useEffect(() => {
const video = videoRef.current!;
const canvas = canvasRef.current!;
video.muted = true;
video.src = '/OnePunchMan.mp4';
async function init() {
await render({
video,
canvas,
// function to build custom pipeline
// return all pipelines in render pass order
pipelineBuilder: (device, inputTexture) => {
const upscale = new CNNx2UL({
device,
inputTexture,
});
const restore = new GANUUL({
device,
inputTexture: upscale.getOutputTexture(),
});
return [upscale, restore];
},
});
// play video
await video.play();
}
init();
}, [])
return (
<div>
<video ref={videoRef} controls />
<canvas
ref={canvasRef}
width="640"
height="360"
style={{ border: '1px solid black' }}
/>
</div>
);
};