Skip to content

🎥 Make videos programmatically with React

actually schedule ahead of time

Jonny Burgerd74547b4a93b
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index 4f7000e9c9..24febfb8ca 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -365,9 +365,7 @@ const PremountedPostmountedSequenceRefForwardingFunction: React.ForwardRefRender
]);
const {playing} = useContext(TimelineContext);
- const premountFramesRemaining =
- parentPremountContext.premountFramesRemaining +
- (premountingActive ? from - frame : 0);
+ const premountFramesRemaining = premountingActive ? from - frame : 0;
const premountContextValue = useMemo(() => {
return {
diff --git a/packages/core/src/audio/shared-audio-tags.tsx b/packages/core/src/audio/shared-audio-tags.tsx
index 1907efe86c..003c986afe 100644
--- a/packages/core/src/audio/shared-audio-tags.tsx
+++ b/packages/core/src/audio/shared-audio-tags.tsx
@@ -8,8 +8,8 @@ import React, {
useRef,
useState,
} from 'react';
-import {Log} from '../log.js';
import {useLogLevel, useMountTime} from '../log-level-context.js';
+import {Log} from '../log.js';
import {playAndHandleNotAllowedError} from '../play-and-handle-not-allowed-error.js';
import {useRemotionEnvironment} from '../use-remotion-environment.js';
import type {SharedElementSourceNode} from './shared-element-source-node.js';
@@ -194,7 +194,9 @@ export const SharedAudioContextProvider: React.FC<{
const mediaEndTime = mediaTime + duration;
- const hasDelay = scheduledTime < currentTime;
+ const latency =
+ (audioContext.baseLatency ?? 0) + (audioContext.outputLatency ?? 0);
+ const timeDiff = scheduledTime - currentTime - latency;
const prev = prevEndTimes.current;
const scheduledMismatch =
prev.scheduledEndTime !== null &&
@@ -206,7 +208,7 @@ export const SharedAudioContextProvider: React.FC<{
if (debugAudioScheduling) {
Log.info(
{logLevel, tag: 'audio-scheduling'},
- 'scheduled %c%s%c %s %c%s%c %s',
+ 'scheduled %c%s%c %s %c%s%c %s %c%s%c %s %s %s',
scheduledMismatch ? 'color: red; font-weight: bold' : '',
scheduledTime.toFixed(4),
'',
@@ -215,8 +217,11 @@ export const SharedAudioContextProvider: React.FC<{
mediaTime.toFixed(4),
'',
mediaEndTime.toFixed(4),
- hasDelay ? 'color: blue; font-weight: bold' : '',
- hasDelay ? 'delayed' : '',
+ timeDiff < 0
+ ? 'color: red; font-weight: bold'
+ : 'color: blue; font-weight: bold',
+ Math.abs(timeDiff).toFixed(2) + (timeDiff < 0 ? ' delay' : ' ahead'),
+ '',
't=' + (targetTime + currentTime).toFixed(4),
'c=' + currentTime.toFixed(4),
'o=' + offset.toFixed(4),
diff --git a/packages/media/src/video/video-for-preview.tsx b/packages/media/src/video/video-for-preview.tsx
index bbe380e78d..56bccdb521 100644
--- a/packages/media/src/video/video-for-preview.tsx
+++ b/packages/media/src/video/video-for-preview.tsx
@@ -155,8 +155,8 @@ const VideoForPreviewAssertedShowing: React.FC<
// since there is some latency.
const isNextFrameGoingToPlay =
playingWhilePremounting &&
- premountFramesRemaining > 0 &&
- premountFramesRemaining <= 1.000000001;
+ premountFramesRemaining > 5 &&
+ premountFramesRemaining <= 6.000000001;
const loopDisplay = useLoopDisplay({
loop,