Skip to content

🎥 Make videos programmatically with React

Remotion Studio: Press "G" to go to frame

Jonny Burgerd0935310bd3b
diff --git a/packages/studio/src/components/KeyboardShortcutsExplainer.tsx b/packages/studio/src/components/KeyboardShortcutsExplainer.tsx
index a6c2c12e0d..559f3f93d9 100644
--- a/packages/studio/src/components/KeyboardShortcutsExplainer.tsx
+++ b/packages/studio/src/components/KeyboardShortcutsExplainer.tsx
@@ -154,6 +154,12 @@ export const KeyboardShortcutsExplainer: React.FC = () => {
</div>
<div style={right}>Play / Speed up</div>
</Row>
+ <Row align="center">
+ <div style={left}>
+ <kbd style={key}>G</kbd>
+ </div>
+ <div style={right}>Go to frame</div>
+ </Row>
<Row align="center">
<div style={left}>
<kbd style={key}>Enter</kbd>
diff --git a/packages/studio/src/components/NewComposition/InputDragger.tsx b/packages/studio/src/components/NewComposition/InputDragger.tsx
index 7ac70b8216..48cfd10594 100644
--- a/packages/studio/src/components/NewComposition/InputDragger.tsx
+++ b/packages/studio/src/components/NewComposition/InputDragger.tsx
@@ -24,18 +24,24 @@ const isInt = (num: number) => {
return num % 1 === 0;
};
-export const InputDragger: React.FC<Props> = ({
- onValueChange,
- min: _min,
- max: _max,
- step: _step,
- value,
- onTextChange,
- formatter = (q) => String(q),
- status,
- rightAlign,
- ...props
-}) => {
+const InputDraggerForwardRefFn: React.ForwardRefRenderFunction<
+ HTMLButtonElement,
+ Props
+> = (
+ {
+ onValueChange,
+ min: _min,
+ max: _max,
+ step: _step,
+ value,
+ onTextChange,
+ formatter = (q) => String(q),
+ status,
+ rightAlign,
+ ...props
+ },
+ ref,
+) => {
const [inputFallback, setInputFallback] = useState(false);
const fallbackRef = useRef<HTMLInputElement>(null);
const style = useMemo(() => {
@@ -196,6 +202,7 @@ export const InputDragger: React.FC<Props> = ({
return (
<button
+ ref={ref}
type="button"
style={style}
onClick={onClick}
@@ -205,3 +212,5 @@ export const InputDragger: React.FC<Props> = ({
</button>
);
};
+
+export const InputDragger = React.forwardRef(InputDraggerForwardRefFn);
diff --git a/packages/studio/src/components/TimeValue.tsx b/packages/studio/src/components/TimeValue.tsx
index e1a73dee08..fe1aa4f9ea 100644
--- a/packages/studio/src/components/TimeValue.tsx
+++ b/packages/studio/src/components/TimeValue.tsx
@@ -1,15 +1,23 @@
-import React from 'react';
+import {PlayerInternals} from '@remotion/player';
+import React, {
+ useCallback,
+ useEffect,
+ useImperativeHandle,
+ useRef,
+} from 'react';
import {Internals, useCurrentFrame} from 'remotion';
import {LIGHT_TEXT} from '../helpers/colors';
import {useIsStill} from '../helpers/is-current-selected-still';
+import {useKeybinding} from '../helpers/use-keybinding';
import {renderFrame} from '../state/render-frame';
-import {Flex} from './layout';
+import {Flex, Spacing} from './layout';
+import {InputDragger} from './NewComposition/InputDragger';
const text: React.CSSProperties = {
color: 'white',
display: 'flex',
flexDirection: 'row',
- alignItems: 'flex-end',
+ alignItems: 'center',
fontVariantNumeric: 'tabular-nums',
lineHeight: 1,
width: '100%',
@@ -32,10 +40,58 @@ const frameStyle: React.CSSProperties = {
paddingRight: 10,
};
+export const timeValueRef = React.createRef<{
+ goToFrame: () => void;
+}>();
+
export const TimeValue: React.FC = () => {
const frame = useCurrentFrame();
const config = Internals.useUnsafeVideoConfig();
const isStill = useIsStill();
+ const {seek} = PlayerInternals.usePlayer();
+ const keybindings = useKeybinding();
+ const ref = useRef<HTMLButtonElement>(null);
+
+ const onTextChange = useCallback(
+ (newVal: string) => {
+ seek(parseInt(newVal, 10));
+ },
+ [seek],
+ );
+ const onValueChange = useCallback(
+ (val: number) => {
+ seek(val);
+ },
+ [seek],
+ );
+
+ useImperativeHandle(
+ timeValueRef,
+ () => ({
+ goToFrame: () => {
+ ref.current?.click();
+ },
+ }),
+ [],
+ );
+
+ useEffect(() => {
+ const gKey = keybindings.registerKeybinding({
+ event: 'keypress',
+ key: 'g',
+ callback: () => {
+ ref.current?.click();
+ },
+ commandCtrlKey: false,
+ preventDefault: true,
+ triggerIfInputFieldFocused: false,
+ keepRegisteredWhenNotHighestContext: false,
+ });
+
+ return () => {
+ gKey.unregister();
+ };
+ }, [keybindings]);
if (!config) {
return null;
@@ -48,8 +104,17 @@ export const TimeValue: React.FC = () => {
return (
<div style={text}>
<div style={time}>{renderFrame(frame, config.fps)}</div>
+ <Spacing x={2} />
<Flex />
- <div style={frameStyle}>{frame}</div>
+ <InputDragger
+ ref={ref}
+ value={frame}
+ onTextChange={onTextChange}
+ onValueChange={onValueChange}
+ rightAlign
+ status="ok"
+ style={frameStyle}
+ />
</div>
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineTimeIndicators.tsx b/packages/studio/src/components/Timeline/TimelineTimeIndicators.tsx
index bb216b5964..a11cedac41 100644
--- a/packages/studio/src/components/Timeline/TimelineTimeIndicators.tsx
+++ b/packages/studio/src/components/Timeline/TimelineTimeIndicators.tsx
@@ -17,7 +17,7 @@ import {timelineVerticalScroll} from './timeline-refs';
import {getFrameIncrementFromWidth} from './timeline-scroll-logic';
import {TimelineWidthContext} from './TimelineWidthProvider';
-export const TIMELINE_TIME_INDICATOR_HEIGHT = 30;
+export const TIMELINE_TIME_INDICATOR_HEIGHT = 39;
const container: React.CSSProperties = {
height: TIMELINE_TIME_INDICATOR_HEIGHT - 4,
@@ -190,8 +190,8 @@ const Inner: React.FC<{
index % fps === 0
? 10
: (index / frameMarkerEveryNth) % 2 === 0
- ? 5
- : 2,
+ ? 5
+ : 2,
},
showTime: false,
};
diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsx
index e56ed9d2b6..c7d51e949c 100644
--- a/packages/studio/src/helpers/use-menu-structure.tsx
+++ b/packages/studio/src/helpers/use-menu-structure.tsx
@@ -8,6 +8,7 @@ import {sendErrorNotification} from '../components/Notifications/NotificationCen
import type {TQuickSwitcherResult} from '../components/QuickSwitcher/QuickSwitcherResult';
import {getPreviewSizeLabel, getUniqueSizes} from '../components/SizeSelector';
import {inOutHandles} from '../components/TimelineInOutToggle';
+import {timeValueRef} from '../components/TimeValue';
import {cmdOrCtrlCharacter} from '../error-overlay/remotion-overlay/ShortcutHint';
import {Checkmark} from '../icons/Checkmark';
import {canvasRef} from '../state/canvas-ref';
@@ -202,7 +203,7 @@ export const useMenuStructure = (closeMenu: () => void) => {
? {
type: 'divider' as const,
id: 'open-in-editor-divider',
- }
+ }
: null,
window.remotion_editorName
? {
@@ -238,7 +239,7 @@ export const useMenuStructure = (closeMenu: () => void) => {
leftItem: null,
subMenu: null,
quickSwitcherLabel: 'Open in editor...',
- }
+ }
: null,
].filter(NoReactInternals.truthy),
quickSwitcherLabel: null,
@@ -552,6 +553,20 @@ export const useMenuStructure = (closeMenu: () => void) => {
value: 'clear-marks',
quickSwitcherLabel: 'Timeline: Clear In and Out Mark',
},
+ {
+ id: 'goto-time',
+ keyHint: 'G',
+ label: 'Go to frame',
+ leftItem: null,
+ onClick: () => {
+ closeMenu();
+ timeValueRef.current?.goToFrame();
+ },
+ subMenu: null,
+ type: 'item' as const,
+ value: 'clear-marks',
+ quickSwitcherLabel: 'Timeline: Clear In and Out Mark',
+ },
{
id: 'fullscreen-divider',
type: 'divider' as const,
@@ -570,7 +585,7 @@ export const useMenuStructure = (closeMenu: () => void) => {
type: 'item' as const,
value: 'fullscreen',
quickSwitcherLabel: 'Go Fullscreen',
- }
+ }
: null,
].filter(Internals.truthy),
},
@@ -596,7 +611,7 @@ export const useMenuStructure = (closeMenu: () => void) => {
},
],
quickSwitcherLabel: null,
- }
+ }
: null,
{
id: 'help' as const,