Skip to content

🎥 Make videos programmatically with React

add fps converter snippet

Jonny Burger19cd0202da74
diff --git a/packages/docs/docs/dynamic-metadata.md b/packages/docs/docs/dynamic-metadata.md
index a4a7d520f0..5f6bf0321f 100644
--- a/packages/docs/docs/dynamic-metadata.md
+++ b/packages/docs/docs/dynamic-metadata.md
@@ -138,6 +138,11 @@ renderFrames({
Make sure to pass the parameter to both of these functions, so the input props are available to `getInputProps` during the composition fetching and rendering stage.
+## Changing dimensions and FPS after the video was designed
+
+- If you designed your video with certain dimensions and now want to render a different resolution (e.g. 4K instead of Full HD), you can use [output scaling](/docs/scaling).
+- If you designed your video with certain FPS and now want to change the frame rate, you can use the [`<FpsConverter>`](/docs/miscellaneous/snippets/fps-converter) snippet.
+
## See also
- [`getInputProps()`](/docs/get-input-props)
diff --git a/packages/docs/docs/miscellaneous/snippets/fps-converter.md b/packages/docs/docs/miscellaneous/snippets/fps-converter.md
new file mode 100644
index 0000000000..0e3ef0eebe
--- /dev/null
+++ b/packages/docs/docs/miscellaneous/snippets/fps-converter.md
@@ -0,0 +1,78 @@
+---
+title: "FPS converter"
+---
+
+This snippet is useful if you have designed your video with a different frame rate than you want to render in the end. Wrap your markup in the `<FpsConverter>` component to get
+
+```tsx twoslash title="FpsConverter.tsx"
+import React, { useContext, useMemo } from "react";
+import { Internals, TimelineContextValue } from "remotion";
+
+export const FpsConverter: React.FC<{
+ originalFps: number;
+ newFps: number;
+ children: React.ReactNode;
+}> = ({ originalFps, newFps, children }) => {
+ const context = useContext(Internals.Timeline.TimelineContext);
+ const ratio = originalFps / newFps;
+
+ const value: TimelineContextValue = useMemo(() => {
+ return {
+ ...context,
+ frame: context.frame * ratio,
+ };
+ }, [context, ratio]);
+
+ return (
+ <Internals.Timeline.TimelineContext.Provider value={value}>
+ {children}
+ </Internals.Timeline.TimelineContext.Provider>
+ );
+};
+```
+
+```tsx twoslash title="Usage"
+// @filename: "MyComp.tsx"
+export const MyComp = () => {
+ return null;
+};
+
+// @filename: "FpsConverter.tsx"
+import React, { useContext, useMemo } from "react";
+import { Internals, TimelineContextValue } from "remotion";
+
+export const FpsConverter: React.FC<{
+ originalFps: number;
+ newFps: number;
+ children: React.ReactNode;
+}> = ({ originalFps, newFps, children }) => {
+ const context = useContext(Internals.Timeline.TimelineContext);
+ const ratio = originalFps / newFps;
+
+ const value: TimelineContextValue = useMemo(() => {
+ return {
+ ...context,
+ frame: context.frame * ratio,
+ };
+ }, [context, ratio]);
+
+ return (
+ <Internals.Timeline.TimelineContext.Provider value={value}>
+ {children}
+ </Internals.Timeline.TimelineContext.Provider>
+ );
+};
+
+// @filename: "index.tsx"
+import { FpsConverter } from "./FpsConverter";
+import { MyComp } from "./MyComp";
+// ---cut---
+
+export const Converted: React.FC = () => {
+ return (
+ <FpsConverter newFps={29.97} originalFps={60}>
+ <MyComp></MyComp>
+ </FpsConverter>
+ );
+};
+```
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 1671109628..37c7ac5398 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -310,7 +310,10 @@ module.exports = {
{
type: "category",
label: "Snippets",
- items: ["miscellaneous/snippets/player-in-iframe"],
+ items: [
+ "miscellaneous/snippets/player-in-iframe",
+ "miscellaneous/snippets/fps-converter",
+ ],
},
],
},