Skip to content

🎥 Make videos programmatically with React

changed --props to only read from a json file

Shankhadeep Deybea311364e8b
diff --git a/packages/cli/src/get-user-props.ts b/packages/cli/src/get-user-props.ts
index 5e1fe3ace2..49e5c0d0e7 100644
--- a/packages/cli/src/get-user-props.ts
+++ b/packages/cli/src/get-user-props.ts
@@ -1,3 +1,5 @@
+import fs from 'fs';
+import path from 'path';
import {parsedCli} from './parse-command-line';
export const getUserProps = (): unknown => {
@@ -5,7 +7,9 @@ export const getUserProps = (): unknown => {
return {};
}
try {
- const parsed = JSON.parse(parsedCli.props);
+ const jsonFile = path.resolve(process.cwd(), parsedCli.props);
+ const rawJsonData = fs.readFileSync(jsonFile, 'utf-8');
+ const parsed = JSON.parse(rawJsonData);
return parsed;
} catch (err) {
console.log(
diff --git a/packages/docs/docs/cli.md b/packages/docs/docs/cli.md
index e64820b889..2658b04560 100644
--- a/packages/docs/docs/cli.md
+++ b/packages/docs/docs/cli.md
@@ -13,7 +13,7 @@ npx remotion render <entry-file> <composition-id> <output-location>
Besides choosing a video and output location with the command line arguments, the following flags are supported:
-- `--props`: React Props to pass to the root component of your video. Must be a serialized JSON string.
+- `--props`: React Props to pass to the root component of your video. Must be a JSON file Name.
- `--concurrency`: [How many CPU threads to use.](/docs/config#setconcurrency) Minimum 1. The maximum is the amount of threads you have.
- `--pixel-format`: [Set a custom pixel format. See here for available values.](/docs/config#setpixelformat)
- `--image-format`: [`jpeg` or `png` - JPEG is faster, but supports transparency.](/docs/config#setimageformat) The default image format is `jpeg` since v1.1. Flag available since v1.4.
diff --git a/packages/docs/docs/parametrized-rendering.md b/packages/docs/docs/parametrized-rendering.md
index 8ce4bf318b..27fa65a9b0 100644
--- a/packages/docs/docs/parametrized-rendering.md
+++ b/packages/docs/docs/parametrized-rendering.md
@@ -52,7 +52,19 @@ By using `React.FC`, you can ensure type safety and avoid errors caused by typos
When rendering (for example using the `npm run build` script defined in `package.json`), you can override some or all default props by passing a CLI flag. It must be valid JSON, pay attention to quote escaping. Using this technique, no type safety can be guaranteed.
```bash
-npx remotion render src/index.tsx HelloWorld helloworld.mp4 --props='{"propOne": "Hi", "propTwo": 10}'
+npx remotion render src/index.tsx HelloWorld helloworld.mp4 --props=defaultProps.json
+```
+
+:::tip
+make sure `defaultProps.json` is in your root folder.
+:::
+
+```json
+//defaultProps.json
+{
+ "propOne": "Hi",
+ "propTwo": 10
+}
```
[See also: CLI flags](/docs/cli)