Skip to content

🎥 Make videos programmatically with React

Added rendering supports of range and still frame

Shankhadeep Deybaba38968bfd
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index 60d7195a08..64b88e41a2 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -34,7 +34,7 @@ export const render = async () => {
const parallelism = Internals.getConcurrency();
const shouldOutputImageSequence = Internals.getShouldOutputImageSequence();
const userCodec = Internals.getOutputCodecOrUndefined();
- const range = Internals.getFrameRange();
+ const frameRange = Internals.getFrameRange();
if (shouldOutputImageSequence && userCodec) {
console.error(
'Detected both --codec and --sequence (formerly --png) flag.'
@@ -145,7 +145,15 @@ export const render = async () => {
throw new Error(`Cannot find composition with ID ${compositionId}`);
}
- const {durationInFrames: frames} = config;
+ let {durationInFrames: frames} = config;
+ if (frameRange) {
+ if (frameRange.length === 1) {
+ frames = 1;
+ }
+ if (frameRange.length === 2) {
+ frames = frameRange[1] - frameRange[0] + 1;
+ }
+ }
const outputDir = shouldOutputImageSequence
? absoluteOutputFile
: await fs.promises.mkdtemp(path.join(os.tmpdir(), 'react-motion-render'));
@@ -177,6 +185,8 @@ export const render = async () => {
imageFormat,
quality,
browser,
+ frameRange,
+ frames,
});
renderProgress.stop();
if (process.env.DEBUG) {
diff --git a/packages/renderer/src/render.ts b/packages/renderer/src/render.ts
index 1567650d8a..8bad6e7a7d 100644
--- a/packages/renderer/src/render.ts
+++ b/packages/renderer/src/render.ts
@@ -18,6 +18,8 @@ export const renderFrames = async ({
quality,
imageFormat = DEFAULT_IMAGE_FORMAT,
browser = Internals.DEFAULT_BROWSER,
+ frameRange,
+ frames,
}: {
config: VideoConfig;
parallelism?: number | null;
@@ -30,7 +32,8 @@ export const renderFrames = async ({
imageFormat?: ImageFormat;
quality?: number;
browser?: Browser;
- frameRange?: FrameRange;
+ frameRange: FrameRange;
+ frames: number;
}) => {
if (quality !== undefined && imageFormat !== 'jpeg') {
throw new Error(
@@ -62,7 +65,7 @@ export const renderFrames = async ({
const pool = new Pool(await Promise.all(pages));
- const {durationInFrames: frames} = config;
+ // const {durationInFrames: frames} = config;
// Substract one because 100 frames will be 00-99
// --> 2 digits
const filePadLength = String(frames - 1).length;
@@ -71,10 +74,16 @@ export const renderFrames = async ({
await Promise.all(
new Array(frames)
.fill(Boolean)
- .map((x, i) => i)
+ .map((x, i) => {
+ if (frameRange) {
+ return i + frameRange[0] - 1;
+ }
+ return i;
+ })
.map(async (f) => {
const freePage = await pool.acquire();
const paddedIndex = String(f).padStart(filePadLength, '0');
+ console.log(f);
await provideScreenshot({
page: freePage,
imageFormat,