🎥 Make videos programmatically with React
demo
Jonny Burgerb0130f0679a6
diff --git a/packages/example/package.json b/packages/example/package.jsonindex aeb4de5f4f..06be7e2ef2 100644--- a/packages/example/package.json+++ b/packages/example/package.json@@ -43,12 +43,14 @@"@remotion/three": "3.3.42","@types/express": "^4.17.11","@types/node": "^16.7.5",+ "@types/opentype.js": "^1.3.4","@types/react": "18.0.26","@types/styled-components": "^5.1.1","@types/web": "0.0.78","babel-loader": "^8.2.2","lottie-web": "^5.9.6","mdx-loader": "3.0.2",+ "opentype.js": "^1.3.4","polished": "^4.0.5","prettier": "^2.7.1","remotion": "3.3.42",diff --git a/packages/example/public/Roboto-Medium.ttf b/packages/example/public/Roboto-Medium.ttfnew file mode 100644index 0000000000..ac0f908b9cBinary files /dev/null and b/packages/example/public/Roboto-Medium.ttf differdiff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex eda1886cb5..b3622d875e 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -34,6 +34,7 @@ import {VideoOnCanvas} from './VideoOnCanvas';import {Greenscreen} from './VideoOnCanvas/greenscreen';import {VideoSpeed} from './VideoSpeed';import {VideoTesting} from './VideoTesting';+import {WarpDemo} from './WarpText';if (alias !== 'alias') {throw new Error('should support TS aliases');@@ -523,6 +524,14 @@ export const Index: React.FC = () => {height={1080}width={1080}/>+ <Composition+ id="path-warp"+ component={WarpDemo}+ durationInFrames={500}+ fps={30}+ height={1080}+ width={1080}+ /></Folder><Folder name="gif"><Compositiondiff --git a/packages/example/src/WarpText/index.tsx b/packages/example/src/WarpText/index.tsxnew file mode 100644index 0000000000..a016ef9599--- /dev/null+++ b/packages/example/src/WarpText/index.tsx@@ -0,0 +1,106 @@+import opentype from 'opentype.js';+import {useEffect, useRef, useState} from 'react';+import {+ AbsoluteFill,+ spring,+ staticFile,+ useCurrentFrame,+ useVideoConfig,+} from 'remotion';++import {getBoundingBox, resetPath, warpPath, WarpPathFn} from '@remotion/paths';++type FontInfo = {+ path: string;+};++const getPath = () => {+ return new Promise<FontInfo>((resolve, reject) => {+ opentype.load(staticFile('Roboto-Medium.ttf'), (err, font) => {+ if (err) {+ reject(err);+ return;+ }+ if (!font) {+ reject(new Error('No font found'));+ return;+ }++ const path = font.getPath('REMOTION', 0, 150, 72);+ const p = path.toPathData(2);+ resolve({path: p});+ });+ });+};++export const WarpDemo = () => {+ const [path, setPath] = useState<string | null>(() => null);+ const ref = useRef<SVGSVGElement>(null);+ const frame = useCurrentFrame();+ const {fps} = useVideoConfig();+ const sprX =+ spring({+ fps,+ frame,+ config: {+ damping: 200,+ },+ }) *+ 2.5 ++ 1;+ const sprY =+ spring({+ fps,+ frame: frame - 30,+ config: {+ damping: 200,+ },+ }) *+ 2.5 ++ 1;++ useEffect(() => {+ getPath().then((p) => {+ setPath(p.path);+ });+ }, [frame]);++ if (!path) {+ return null;+ }++ const reset = resetPath(path);++ const warpPathFn: WarpPathFn = ({x, y}) => ({+ x: x * sprY + Math.sin(y / 4 + frame / 20) * 5,+ y: y * sprX,+ });++ const warped = warpPath(reset, warpPathFn, 4);+ const box = getBoundingBox(warped);++ const {x1, x2, y1, y2} = box;++ return (+ <AbsoluteFill+ style={{+ backgroundColor: 'white',+ justifyContent: 'center',+ alignItems: 'center',+ }}+ >+ {path ? (+ <svg+ ref={ref}+ style={{+ overflow: 'visible',+ height: 50 * sprX,+ }}+ viewBox={`${x1} ${y1} ${x2 - x1} ${y2 - y1}`}+ >+ <path d={warped} fill="black" stroke="black" strokeWidth={3} />+ </svg>+ ) : null}+ </AbsoluteFill>+ );+};diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 84942b6d58..cca0a62d2a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -466,6 +466,7 @@ importers:'@types/babel__template': ^7.4.0'@types/express': ^4.17.11'@types/node': ^16.7.5+ '@types/opentype.js': ^1.3.4'@types/react': 18.0.26'@types/styled-components': ^5.1.1'@types/web': 0.0.78@@ -478,6 +479,7 @@ importers:eslint-plugin-react-hooks: 4.4.0lottie-web: ^5.9.6mdx-loader: 3.0.2+ opentype.js: ^1.3.4polished: ^4.0.5prettier: ^2.7.1prettier-plugin-organize-imports: ^2.3.4@@ -509,12 +511,14 @@ importers:'@remotion/three': link:../three'@types/express': 4.17.13'@types/node': 16.10.2+ '@types/opentype.js': 1.3.4'@types/react': 18.0.26'@types/styled-components': 5.1.14'@types/web': 0.0.78babel-loader: 8.2.2_m3opitmgss2x7fiy6klia7uvaalottie-web: 5.9.6mdx-loader: [email protected]+ opentype.js: 1.3.4polished: 4.1.3prettier: 2.7.1remotion: link:../core@@ -8934,6 +8938,10 @@ packages:resolution: {integrity: sha512-PGcyveRIpL1XIqK8eBsmRBt76eFgtzuPiSTyKHZxnGemp2yzGzWpjYKAfK3wIMiU7eH+851yEpiuP8JZerTmWg==}dev: false+ /@types/opentype.js/1.3.4:+ resolution: {integrity: sha512-6fbXi67I07ugNM+FExwJnfuui2hD7hraD6nqjr3UnqsbBpxSkrtmO6tBubPdNAjqRT9TVkquVkNS9IkgTtq6/w==}+ dev: false+/@types/parse-json/4.0.0:resolution: {integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==}dev: false@@ -9746,6 +9754,13 @@ packages:dependencies:acorn: 8.8.0+ /acorn-import-assertions/[email protected]:+ resolution: {integrity: sha512-m7VZ3jwz4eK6A4Vtt8Ew1/mNbP24u0FhdyfA7fSvnJR6LMdfOYnmuIrrJAgrYfYJ10F/otaHTtrtrtmHdMNzEw==}+ peerDependencies:+ acorn: ^8+ dependencies:+ acorn: 8.8.1+/acorn-jsx/[email protected]:resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}peerDependencies:@@ -9766,7 +9781,6 @@ packages:resolution: {integrity: sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==}engines: {node: '>=0.4.0'}hasBin: true- dev: true/add-stream/1.0.0:resolution: {integrity: sha1-anmQQ3ynNtXhKI25K9MmbV9csqo=}@@ -17121,8 +17135,8 @@ packages:hasBin: truedev: false- /opentype.js/1.3.3:- resolution: {integrity: sha512-/qIY/+WnKGlPIIPhbeNjynfD2PO15G9lA/xqlX2bDH+4lc3Xz5GCQ68mqxj3DdUv6AJqCeaPvuAoH8mVL0zcuA==}+ /opentype.js/1.3.4:+ resolution: {integrity: sha512-d2JE9RP/6uagpQAVtJoF0pJJA/fgai89Cc50Yp0EJHk+eLp6QQ7gBoblsnubRULNY132I0J1QKMJ+JTbMqz4sw==}engines: {node: '>= 8.0.0'}hasBin: truedependencies:@@ -20066,6 +20080,7 @@ packages:dependencies:buffer-from: 1.1.2source-map: 0.6.1+ dev: false/source-map-support/0.5.21:resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}@@ -20770,9 +20785,9 @@ packages:hasBin: truedependencies:'@jridgewell/source-map': 0.3.2- acorn: 8.8.0+ acorn: 8.8.1commander: 2.20.3- source-map-support: 0.5.20+ source-map-support: 0.5.21/text-extensions/1.9.0:resolution: {integrity: sha512-wiBrwC1EhBelW12Zy26JeOUkQ5mRu+5o8rpsJk5+2t+Y5vE7e842qtZDQ2g1NpX/29HdyFeJ4nSIhI47ENSxlQ==}@@ -20807,7 +20822,7 @@ packages:fflate: 0.6.10ktx-parse: 0.4.5mmd-parser: 1.0.4- opentype.js: 1.3.3+ opentype.js: 1.3.4potpack: 1.0.1three: 0.145.0zstddec: 0.0.2@@ -22232,8 +22247,8 @@ packages:'@webassemblyjs/ast': 1.11.1'@webassemblyjs/wasm-edit': 1.11.1'@webassemblyjs/wasm-parser': 1.11.1- acorn: 8.8.0- acorn-import-assertions: [email protected]+ acorn: 8.8.1+ acorn-import-assertions: [email protected]browserslist: 4.21.4chrome-trace-event: 1.0.3enhanced-resolve: 5.10.0