Skip to content

🎥 Make videos programmatically with React

`@remotion/skia`: New best practices and new version of Skia

Jonny Burgerd77c3419b28b
diff --git a/packages/example/package.json b/packages/example/package.json
index c7047e124d..d815eb6737 100644
--- a/packages/example/package.json
+++ b/packages/example/package.json
@@ -53,6 +53,7 @@
"@remotion/three": "workspace:*",
"@remotion/transitions": "workspace:*",
"@remotion/zod-types": "workspace:*",
+ "@shopify/react-native-skia": "1.2.2",
"@types/express": "^4.17.11",
"@types/hls.js": "^0.13.3",
"@types/node": "18.14.6",
diff --git a/packages/example/remotion.config.ts b/packages/example/remotion.config.ts
index de10dfe8f4..bc56dbb0e7 100644
--- a/packages/example/remotion.config.ts
+++ b/packages/example/remotion.config.ts
@@ -1,5 +1,5 @@
import {Config} from '@remotion/cli/config';
-
+import {enableSkia} from '@remotion/skia/enable';
import {webpackOverride} from './src/webpack-override.mjs';
Config.setOverwriteOutput(true);
@@ -7,5 +7,5 @@ Config.overrideWebpackConfig(async (config) => {
await new Promise((resolve) => {
setTimeout(resolve, 10);
});
- return webpackOverride(config);
+ return enableSkia(await webpackOverride(config));
});
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index a6ad441f42..d8ffefb71c 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -56,6 +56,7 @@ import EllipseTest from './Shapes/EllipseTest';
import RectTest from './Shapes/RectTest';
import StarTest from './Shapes/StarTest';
import TriangleTest from './Shapes/TriangleTest';
+import {RuntimeShaderDemo} from './Skia/Shader';
import {SkipZeroFrame} from './SkipZeroFrame';
import {BaseSpring, SpringWithDuration} from './Spring/base-spring';
import {SeriesTesting} from './StaggerTesting';
@@ -1196,6 +1197,16 @@ export const Index: React.FC = () => {
width={1080}
durationInFrames={120}
/>
+ <Folder name="Skia">
+ <Composition
+ id="skia-shader"
+ component={RuntimeShaderDemo}
+ fps={30}
+ height={1080}
+ width={1080}
+ durationInFrames={120}
+ />
+ </Folder>
</>
);
};
diff --git a/packages/example/src/Skia/Shader.tsx b/packages/example/src/Skia/Shader.tsx
new file mode 100644
index 0000000000..8606e485d9
--- /dev/null
+++ b/packages/example/src/Skia/Shader.tsx
@@ -0,0 +1,27 @@
+import {
+ Canvas,
+ Circle,
+ Group,
+ RuntimeShader,
+ Skia,
+} from '@shopify/react-native-skia';
+
+const source = Skia.RuntimeEffect.Make(`
+uniform shader image;
+ 
+half4 main(float2 xy) {
+ return image.eval(xy).rbga;
+}
+`)!;
+
+export const RuntimeShaderDemo = () => {
+ const r = 128;
+ return (
+ <Canvas style={{flex: 1}}>
+ <Group>
+ <RuntimeShader source={source} />
+ <Circle cx={r} cy={r} r={r} color="lightblue" />
+ </Group>
+ </Canvas>
+ );
+};
diff --git a/packages/example/src/index.ts b/packages/example/src/index.ts
index 1bc1c35911..79aac7e2cc 100644
--- a/packages/example/src/index.ts
+++ b/packages/example/src/index.ts
@@ -1,7 +1,9 @@
+import {LoadSkia} from '@shopify/react-native-skia/src/web';
import {registerRoot} from 'remotion';
-import {Index} from './Root';
// Should be able to defer registerRoot()
-setTimeout(() => {
+(async () => {
+ await LoadSkia();
+ const {Index} = await import('./Root');
registerRoot(Index);
-}, 500);
+})();
diff --git a/packages/skia/package.json b/packages/skia/package.json
index 367bb9d60c..d75b86f8f5 100644
--- a/packages/skia/package.json
+++ b/packages/skia/package.json
@@ -25,7 +25,7 @@
"remotion": "workspace:*"
},
"peerDependencies": {
- "@shopify/react-native-skia": "^0.1.191",
+ "@shopify/react-native-skia": ">=0.1.191",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
@@ -33,7 +33,7 @@
"@jonny/eslint-config": "3.0.281",
"@remotion/bundler": "workspace:*",
"@rollup/plugin-typescript": "^8.2.0",
- "@shopify/react-native-skia": "^0.1.191",
+ "@shopify/react-native-skia": "^1.2.2",
"@types/react": "18.2.48",
"@types/react-native": "^0.69.2",
"eslint": "8.56.0",
diff --git a/packages/skia/src/enable.ts b/packages/skia/src/enable.ts
index 0deab3b6bc..0d690f050a 100644
--- a/packages/skia/src/enable.ts
+++ b/packages/skia/src/enable.ts
@@ -59,14 +59,11 @@ export const enableSkia: WebpackOverrideFn = (currentConfiguration) => {
],
alias: {
...currentConfiguration.resolve?.alias,
- 'react-native$': 'react-native-web',
+ 'react-native-reanimated': "require('react-native-reanimated')",
+ 'react-native-reanimated/lib/reanimated2/core':
+ "require('react-native-reanimated/lib/reanimated2/core')",
+ 'react-native/Libraries/Image/AssetRegistry': false,
},
},
- externals: {
- ...((currentConfiguration.externals as Record<string, string>) ?? {}),
- 'react-native-reanimated': "require('react-native-reanimated')",
- 'react-native-reanimated/lib/reanimated2/core':
- "require('react-native-reanimated/lib/reanimated2/core')",
- },
};
};
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4cca516352..139c571965 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -268,6 +268,9 @@ importers:
'@jonny/eslint-config':
specifier: 3.0.281
+ '@remotion/skia':
+ specifier: workspace:*
+ version: link:../skia
'@remotion/tailwind':
specifier: workspace:*
version: link:../tailwind
@@ -929,6 +932,9 @@ importers:
'@remotion/zod-types':
specifier: workspace:*
version: link:../zod-types
+ '@shopify/react-native-skia':
+ specifier: 1.2.2
+ version: 1.2.2([email protected])
'@types/express':
specifier: ^4.17.11
version: 4.17.13
@@ -1862,8 +1868,8 @@ importers:
specifier: ^8.2.0
'@shopify/react-native-skia':
- specifier: ^0.1.191
- version: 0.1.191([email protected])
+ specifier: ^1.2.2
+ version: 1.2.2([email protected])
'@types/react':
specifier: 18.2.48
version: 18.2.48
@@ -8784,6 +8790,24 @@ packages:
canvaskit-wasm: 0.38.0
react: 18.2.0
react-reconciler: 0.27.0([email protected])
+ dev: false
+
+ resolution: {integrity: sha512-YlDNJXTCstlOmyJxeQjaTaef8ACLuEPMDrSgEichQM3ELlWuU1HTSVbpXW2x4LbbEDPXwu/aF/16MUN8pzzcmA==}
+ hasBin: true
+ peerDependencies:
+ react: '>=18.0'
+ react-native: '>=0.64'
+ react-native-reanimated: '>=2.0.0'
+ peerDependenciesMeta:
+ react-native:
+ optional: true
+ react-native-reanimated:
+ optional: true
+ dependencies:
+ canvaskit-wasm: 0.39.1
+ react: 18.2.0
+ react-reconciler: 0.27.0([email protected])
/@sideway/[email protected]:
resolution: {integrity: sha512-7vwq+rOHVWjyXxVlR76Agnvhy8I9rpzjosTESvmhNeXOXdZZB15Fl+TI9x1SiHZH5Jv2wTGduSxFDIaq0m3DUw==}
@@ -10865,6 +10889,9 @@ packages:
'@webassemblyjs/ast': 1.11.6
'@xtuc/long': 4.2.2
+ /@webgpu/[email protected]:
+ resolution: {integrity: sha512-pUrWq3V5PiSGFLeLxoGqReTZmiiXwY3jRkIG5sLLKjyqNxrwm/04b4nw7LSmGWJcKk59XOM/YRTUwOzo4MMlow==}
+
resolution: {integrity: sha512-GLe+NjtVaEBeK13RSJrBE4mnlYCxrfg2m1X/UALVpsjSYaIcrabbxBgOp1bGQ4VJoi2FfMN7BfjsLHrwQGaVZA==}
peerDependencies:
@@ -11947,6 +11974,12 @@ packages:
resolution: {integrity: sha512-ZEG6lucpbQ4Ld+mY8C1Ng+PMLVP+/AX02jS0Sdl28NyMxuKSa9uKB8oGd1BYp1XWPyO2Jgr7U8pdyjJ/F3xR5Q==}
+ dev: false
+
+ resolution: {integrity: sha512-Gy3lCmhUdKq+8bvDrs9t8+qf7RvcjuQn+we7vTVVyqgOVO1UVfHpsnBxkTZw+R4ApEJ3D5fKySl9TU11hmjl/A==}
+ dependencies:
+ '@webgpu/types': 0.1.21
resolution: {integrity: sha512-prMTQVpcns/tzFgFVkVp6ak6RykZyWb3gu8ckUpd6YkTlacOd3DXGJjIpD4Q6zJirizvaiAjSSHlOsA+6sNh2A==}
@@ -14343,7 +14376,7 @@ packages:
resolution: {integrity: sha512-KWKaceCwKQU0+HPoop6gn4eOHk50bBv/VxjJtGMfwmJt3D29JpN4H4eisCtIPA+a8GVBam+ldMMpMjJUvpDyHw==}
dependencies:
- fbjs: 3.0.0
+ fbjs: 3.0.5
transitivePeerDependencies:
- encoding
dev: false
@@ -14352,8 +14385,8 @@ packages:
resolution: {integrity: sha512-b2XGFAFdWZWg0phtAWLHCk836A1Xann+I+Dgd3Gk64MHKZO44FfoD1KxyvbSh0qZsIoXQGGlVztIY+oitJPpRQ==}
dev: false
- resolution: {integrity: sha512-dJd4PiDOFuhe7vk4F80Mba83Vr2QuK86FoxtgPmzBqEJahncp+13YCmfoa53KHCo6OnlXLG7eeMWPfB5CrpVKg==}
+ resolution: {integrity: sha512-ztsSx77JBtkuMrEypfhgc3cI0+0h+svqeie7xHbh1k/IKdcydnvadp/mUaGgjAOXQmQSxsqgaRhS3q9fy+1kxg==}
dependencies:
cross-fetch: 3.1.5
fbjs-css-vars: 1.0.2
@@ -14361,7 +14394,7 @@ packages:
object-assign: 4.1.1
promise: 7.3.1
setimmediate: 1.0.5
- ua-parser-js: 0.7.28
+ ua-parser-js: 1.0.37
transitivePeerDependencies:
- encoding
dev: false
@@ -14500,7 +14533,7 @@ packages:
react: ^15.0.2 || ^16.0.0 || ^17.0.0
dependencies:
fbemitter: 3.0.0
- fbjs: 3.0.0
+ fbjs: 3.0.5
react: 18.2.0
transitivePeerDependencies:
- encoding
@@ -22301,8 +22334,8 @@ packages:
engines: {node: '>=14.17'}
hasBin: true
- resolution: {integrity: sha512-6Gurc1n//gjp9eQNXjD9O3M/sMwVtN5S8Lv9bvOYBfKfDNiIIhqiyi01vMBO45u4zkDE420w/e0se7Vs+sIg+g==}
+ resolution: {integrity: sha512-bhTyI94tZofjo+Dn8SN6Zv8nBDvyXTymAdM3LDI/0IboIUwTu1rEhW7v2TfiVsoYWgkQ4kOVqnI8APUFbIQIFQ==}
dev: false