🎥 Make videos programmatically with React
update snippet in studio
JonnyBurger594f086e3955
diff --git a/packages/studio/src/helpers/extract-frames.ts b/packages/studio/src/helpers/extract-frames.tsindex 3bcfc5c0ce..e9ff12000f 100644--- a/packages/studio/src/helpers/extract-frames.ts+++ b/packages/studio/src/helpers/extract-frames.ts@@ -6,11 +6,15 @@ import {VideoSampleSink,} from 'mediabunny';-export type ExtractFramesTimestampsInSecondsFn = (options: {+type Options = {track: {width: number; height: number};container: string;durationInSeconds: number | null;-}) => Promise<number[]> | number[];+};++export type ExtractFramesTimestampsInSecondsFn = (+ options: Options,+) => Promise<number[]> | number[];export type ExtractFramesProps = {src: string;@@ -30,33 +34,30 @@ export async function extractFrames({source: new UrlSource(src),});+ const dispose = () => {+ input.dispose();+ };+if (signal) {- signal.addEventListener(- 'abort',- () => {- input.dispose();- },- {once: true},- );+ signal.addEventListener('abort', dispose, {once: true});}try {- const videoTrack = await input.getPrimaryVideoTrack();- if (!videoTrack) {- throw new Error('No video track found in the input');- }-- const [durationInSeconds, format] = await Promise.all([+ const [durationInSeconds, format, videoTrack] = await Promise.all([input.computeDuration(),input.getFormat(),+ input.getPrimaryVideoTrack(),]);+ if (!videoTrack) {+ throw new Error('No video track found in the input');+ }const timestamps =typeof timestampsInSeconds === 'function'? await timestampsInSeconds({track: {- width: videoTrack.codedWidth,- height: videoTrack.codedHeight,+ width: videoTrack.displayWidth,+ height: videoTrack.displayHeight,},container: format.name,durationInSeconds,@@ -89,6 +90,9 @@ export async function extractFrames({throw error;} finally {- input.dispose();+ dispose();+ if (signal) {+ signal.removeEventListener('abort', dispose);+ }}}