🎥 Make videos programmatically with React
document in offthreadvideo.md how to loop a video
Jonny Burger2d5ec5c58034
diff --git a/packages/docs/docs/offthreadvideo.md b/packages/docs/docs/offthreadvideo.mdindex 852a8654d0..ea9804ca6f 100644--- a/packages/docs/docs/offthreadvideo.md+++ b/packages/docs/docs/offthreadvideo.md@@ -54,6 +54,52 @@ With `png`, transparent videos (VP8, VP9, ProRes) can be displayed, however it iAvoid embedding a video beyond it's end (for example: Rendering a 5 second video inside 10 second composition). To create parity with the `<Video>` element, the video still displays its last frame in that case. However, to fetch the last frame specifically is a significantly more expensive operation than a frame from a known timestamp.+## Looping a video++Unlike [`<Video>`](/docs/video), `OffthreadVideo` does not currently implement the `loop` property. You can use the following snippet that uses [`@remotion/media-utils`](/docs/media-utils/) to loop a video.++```tsx twoslash title="LoopedOffthreadVideo.tsx"+import { getVideoMetadata } from "@remotion/media-utils";+import React, { useEffect, useState } from "react";+import {+ continueRender,+ delayRender,+ Loop,+ OffthreadVideo,+ staticFile,+ useVideoConfig,+} from "remotion";++const src = staticFile("myvideo.mp4");++export const LoopedOffthreadVideo: React.FC = () => {+ const [duration, setDuration] = useState<null | number>(null);+ const [handle] = useState(() => delayRender());+ const { fps } = useVideoConfig();++ useEffect(() => {+ getVideoMetadata(src)+ .then(({ durationInSeconds }) => {+ setDuration(durationInSeconds);+ continueRender(handle);+ })+ .catch((err) => {+ console.log(err);+ });+ }, [handle]);++ if (duration === null) {+ return null;+ }++ return (+ <Loop durationInFrames={Math.floor(fps * duration)}>+ <OffthreadVideo src={src} />+ </Loop>+ );+};+```+## See also- [Source code for this component](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/video/OffthreadVideo.tsx)