Skip to content

🎥 Make videos programmatically with React

Fix frame accuracy regression in Chrome 112

Jonny Burger148f2dd9736d
diff --git a/packages/core/src/video/get-current-time.ts b/packages/core/src/video/get-current-time.ts
index 7c7bc5cc05..fffcecfbea 100644
--- a/packages/core/src/video/get-current-time.ts
+++ b/packages/core/src/video/get-current-time.ts
@@ -39,20 +39,21 @@ export const getMediaTime = ({
startFrom,
});
- if (src.endsWith('webm')) {
- // For WebM videos, we need to add a little bit of shift to get the right frame.
- const msPerFrame = 1000 / fps;
- const msShift = msPerFrame / 2;
- return (expectedFrame * msPerFrame + msShift) / 1000;
- }
-
- if (mediaType === 'video') {
+ const isChrome = window.navigator.userAgent.match(/Chrome\/([0-9]+)/);
+ if (
+ isChrome &&
+ Number(isChrome[1]) < 112 &&
+ mediaType === 'video' &&
+ src.endsWith('.mp4')
+ ) {
// In Chrome, for MP4s, if 30fps, the first frame is still displayed at 0.033333
// even though after that it increases by 0.033333333 each.
// So frame = 0 in Remotion is like frame = 1 for the browser
return (expectedFrame + 1) / fps;
}
- // For audio, we don't do any shift correction
- return expectedFrame / fps;
+ // For WebM videos, we need to add a little bit of shift to get the right frame.
+ const msPerFrame = 1000 / fps;
+ const msShift = msPerFrame / 2;
+ return (expectedFrame * msPerFrame + msShift) / 1000;
};