Skip to content

🎥 Make videos programmatically with React

start docs

Jonny Burger29c65f49fde4
diff --git a/packages/docs/docs/use-current-scale.md b/packages/docs/docs/use-current-scale.md
new file mode 100644
index 0000000000..7907bb6cc4
--- /dev/null
+++ b/packages/docs/docs/use-current-scale.md
@@ -0,0 +1,54 @@
+---
+image: /generated/articles-docs-use-current-scale.png
+title: useCurrentScale()
+id: use-current-scale
+crumb: "API"
+---
+
+With this hook, you can retrieve the scale factor of the canvas.
+In the Studio, it will correspond to the zoom level - the value is `1` if the zoom is at 100%.
+
+```tsx twoslash
+import { Sequence, useCurrentScale } from "remotion";
+
+const MyVideo = () => {
+ const scale = useCurrentScale({1});
+
+ return (
+ <div>{scale}</div>
+ );
+};
+```
+
+Using `<Sequence />`'s, you can compose multiple elements together and time-shift them independently from each other without changing their animation.
+
+### Getting the absolute frame of the timeline
+
+In rare circumstances, you want access to the absolute frame of the timeline inside a sequence, use `useCurrentFrame()` at the top-level component and then pass it down as a prop to the children of the `<Sequence />`.
+
+```tsx twoslash
+import { Sequence, useCurrentFrame } from "remotion";
+
+// ---cut---
+
+const Subtitle: React.FC<{ absoluteFrame: number }> = ({ absoluteFrame }) => {
+ console.log(useCurrentFrame()); // 15
+ console.log(absoluteFrame); // 25
+
+ return null;
+};
+
+const MyVideo = () => {
+ const frame = useCurrentFrame(); // 25
+
+ return (
+ <Sequence from={10}>
+ <Subtitle absoluteFrame={frame} />
+ </Sequence>
+ );
+};
+```
+
+## See also
+
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/use-current-scale.ts)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 65934fbb4c..b358157a89 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -102,6 +102,7 @@ module.exports = {
"staticfile",
"still",
"use-current-frame",
+ "use-current-scale",
"use-video-config",
"version",
"video",
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 5168e2abe0..deb67c38c2 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -2859,7 +2859,7 @@ export const articles = [
},
{
id: "troubleshooting/background-image",
- title: "Flickering when using background-image",
+ title: "Flickering when using background-image or mask-image",
relativePath: "docs/troubleshooting/background-image.md",
compId: "articles-docs-troubleshooting-background-image",
crumb: "Common mistakes",
@@ -2955,6 +2955,13 @@ export const articles = [
compId: "articles-docs-use-current-frame",
crumb: "API",
},
+ {
+ id: "use-current-scale",
+ title: "useCurrentScale()",
+ relativePath: "docs/use-current-scale.md",
+ compId: "articles-docs-use-current-scale",
+ crumb: "API",
+ },
{
id: "use-img-and-iframe",
title: "<Img>, <Video> and <Audio>",
diff --git a/packages/docs/static/generated/articles-docs-use-current-scale.png b/packages/docs/static/generated/articles-docs-use-current-scale.png
new file mode 100644
index 0000000000..0f4f02734d
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-use-current-scale.png differ