Capítulo 244 de 988
You can draw frames of a <Video> from @remotion/media, <OffthreadVideo> or a <Html5Video> onto a <canvas> element using the drawImage() API.
export const VideoOnCanvas: React.FC = () => {
const canvas = useRef<HTMLCanvasElement>(null);
const {width, height} = useVideoConfig();
// Process a frame
const onVideoFrame = useCallback(
(frame: CanvasImageSource) => {
if (!canvas.current) {
return;
}
const context = canvas.current.getContext('2d');
if (!context) {
return;
}
context.filter = 'grayscale(100%)';
context.drawImage(frame, 0, 0, width, height);
},
[height, width],
);
return (
<AbsoluteFill>
<AbsoluteFill>
<Video
// Hide the original video tag
style={{opacity: 0}}
onVideoFrame={onVideoFrame}
src="https://remotion.media/BigBuckBunny.mp4"
/>
</AbsoluteFill>
<AbsoluteFill>
<canvas ref={canvas} width={width} height={height} />
</AbsoluteFill>
</AbsoluteFill>
);
};