🎥 Make videos programmatically with React
`@remotion/media`: Catch videos starting with SEI recovery point
Jonny Burger5d499f8bd15f
diff --git a/packages/media/src/video-extraction/extract-frame.ts b/packages/media/src/video-extraction/extract-frame.tsindex 51e363e4a6..5b5627ace7 100644--- a/packages/media/src/video-extraction/extract-frame.ts+++ b/packages/media/src/video-extraction/extract-frame.ts@@ -1,5 +1,5 @@import type {VideoSample} from 'mediabunny';-import {type LogLevel} from 'remotion';+import {Internals, type LogLevel} from 'remotion';import {keyframeManager} from '../caches';import {getSink} from '../get-sink';import {getTimeInSeconds} from '../get-time-in-seconds';@@ -84,33 +84,49 @@ const extractFrameInternal = async ({};}- const keyframeBank = await keyframeManager.requestKeyframeBank({- packetSink: video.packetSink,- videoSampleSink: video.sampleSink,- timestamp: timeInSeconds,- src,- logLevel,- maxCacheSize,- });-- if (keyframeBank === 'has-alpha') {- return {- type: 'cannot-decode-alpha',- durationInSeconds: await sink.getDuration(),- };- }+ // Must catch https://github.com/Vanilagy/mediabunny/issues/235+ // https://discord.com/channels/@me/1127949286789881897/1455728482150518906+ // Should be able to remove once upgraded to Chrome 145+ try {+ const keyframeBank = await keyframeManager.requestKeyframeBank({+ packetSink: video.packetSink,+ videoSampleSink: video.sampleSink,+ timestamp: timeInSeconds,+ src,+ logLevel,+ maxCacheSize,+ });++ if (keyframeBank === 'has-alpha') {+ return {+ type: 'cannot-decode-alpha',+ durationInSeconds: await sink.getDuration(),+ };+ }++ if (!keyframeBank) {+ return {+ type: 'success',+ frame: null,+ durationInSeconds: await sink.getDuration(),+ };+ }++ const frame = await keyframeBank.getFrameFromTimestamp(timeInSeconds);- if (!keyframeBank) {return {type: 'success',- frame: null,+ frame,durationInSeconds: await sink.getDuration(),};+ } catch (err) {+ Internals.Log.info(+ {logLevel, tag: '@remotion/media'},+ `Error decoding ${src} at time ${timeInSeconds}: ${err}`,+ err,+ );+ return {type: 'cannot-decode', durationInSeconds: mediaDurationInSeconds};}-- const frame = await keyframeBank.getFrameFromTimestamp(timeInSeconds);-- return {type: 'success', frame, durationInSeconds: await sink.getDuration()};};type ExtractFrameReturnType = Awaited<ReturnType<typeof extractFrameInternal>>;