Skip to content

🎥 Make videos programmatically with React

offthreadvideo

Jonny Burger64090a6c353b
diff --git a/packages/docs/docs/use-video-texture.md b/packages/docs/docs/use-video-texture.md
index 1551c51098..4ff506cff8 100644
--- a/packages/docs/docs/use-video-texture.md
+++ b/packages/docs/docs/use-video-texture.md
@@ -56,4 +56,5 @@ const videoTexture = useVideoTexture(videoRef);
## See also
- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/three/src/use-video-texture.ts)
+- [Example usage: React Three Fiber template](/templates/three)
- [`<ThreeCanvas />`](/docs/three-canvas)
diff --git a/packages/three/src/use-offthread-video-texture.ts b/packages/three/src/use-offthread-video-texture.ts
index 8a2c70b467..bb8c455880 100644
--- a/packages/three/src/use-offthread-video-texture.ts
+++ b/packages/three/src/use-offthread-video-texture.ts
@@ -146,9 +146,15 @@ export function useOffthreadVideoTexture({
fetchTexture();
}, [offthreadVideoFrameSrc, fetchTexture]);
+ if (isRendering) {
+ return imageTexture;
+ }
+
+ // eslint-disable-next-line react-hooks/rules-of-hooks
const {videoRef} = useVideoRef({src, currentTime});
+ // eslint-disable-next-line react-hooks/rules-of-hooks
const videoTexture = useVideoTexture(videoRef);
- return isRendering ? imageTexture : videoTexture;
+ return videoTexture;
}