🎥 Make videos programmatically with React
video texture loading
Jonny Burger3c69b29a8744
diff --git a/packages/example/src/webpack-override.ts b/packages/example/src/webpack-override.tsindex 2c39323de3..9946e2bcb9 100644--- a/packages/example/src/webpack-override.ts+++ b/packages/example/src/webpack-override.ts@@ -2,8 +2,6 @@ import {WebpackOverrideFn} from '@remotion/bundler';import path from 'path';type Bundler = 'webpack' | 'esbuild';-console.log(require.resolve('@remotion/skia/enable'));-const WEBPACK_OR_ESBUILD = 'esbuild' as Bundler;export const webpackOverride: WebpackOverrideFn = (currentConfiguration) => {@@ -23,7 +21,7 @@ export const webpackOverride: WebpackOverrideFn = (currentConfiguration) => {return currentConfiguration;})();- return {+ const updated = {...replaced,module: {...replaced.module,@@ -59,4 +57,6 @@ export const webpackOverride: WebpackOverrideFn = (currentConfiguration) => {},},};++ return updated;};diff --git a/packages/three/rollup.config.js b/packages/three/rollup.config.jsindex 1f52493997..e3822e0fa1 100644--- a/packages/three/rollup.config.js+++ b/packages/three/rollup.config.js@@ -16,7 +16,7 @@ export default ['remotion','react/jsx-runtime','@react-three/fiber',- 'three/src/textures/VideoTexture',+ 'three/src/textures/VideoTexture.js',],plugins: [typescript({diff --git a/packages/three/src/use-video-texture.ts b/packages/three/src/use-video-texture.tsindex 1238bd336f..794edd9e98 100644--- a/packages/three/src/use-video-texture.ts+++ b/packages/three/src/use-video-texture.ts@@ -1,7 +1,7 @@import React, {useCallback, useState} from 'react';import type {Video} from 'remotion';import {continueRender, delayRender, useCurrentFrame} from 'remotion';-import {VideoTexture} from 'three/src/textures/VideoTexture';+import type {VideoTexture} from 'three/src/textures/VideoTexture';export type UseVideoTextureOptions = React.ComponentProps<typeof Video>;@@ -29,19 +29,24 @@ export const useVideoTexture = (delayRender(`Waiting for texture in useVideoTexture() to be loaded`));const [videoTexture, setVideoTexture] = useState<VideoTexture | null>(null);+ const [vidText] = useState(+ () => import('three/src/textures/VideoTexture.js')+ );const frame = useCurrentFrame();const onReady = useCallback(() => {- if (!videoRef.current) {- throw new Error('Video not ready');- }-- const vt = new VideoTexture(videoRef.current);- videoRef.current.width = videoRef.current.videoWidth;- videoRef.current.height = videoRef.current.videoHeight;- setVideoTexture(vt);- continueRender(loaded);- }, [loaded, videoRef]);+ vidText.then(({VideoTexture}) => {+ if (!videoRef.current) {+ throw new Error('Video not ready');+ }++ const vt = new VideoTexture(videoRef.current);+ videoRef.current.width = videoRef.current.videoWidth;+ videoRef.current.height = videoRef.current.videoHeight;+ setVideoTexture(vt);+ continueRender(loaded);+ });+ }, [loaded, vidText, videoRef]);React.useEffect(() => {if (!videoRef.current) {