Skip to content

🎥 Make videos programmatically with React

refactor stitcher to fix windows

Jonny Burgereb6dead89e64
diff --git a/packages/renderer/src/stitcher.ts b/packages/renderer/src/stitcher.ts
index f8883c790f..8d89547c57 100644
--- a/packages/renderer/src/stitcher.ts
+++ b/packages/renderer/src/stitcher.ts
@@ -1,4 +1,5 @@
import execa from 'execa';
+import fs from 'fs';
import {PixelFormat} from 'remotion';
import {DEFAULT_IMAGE_FORMAT, ImageFormat} from './image-format';
import {validateFfmpeg} from './validate-ffmpeg';
@@ -15,6 +16,17 @@ export const stitchFramesToVideo = async (options: {
}): Promise<void> => {
const format = options.imageFormat ?? DEFAULT_IMAGE_FORMAT;
await validateFfmpeg();
+ const files = await fs.promises.readdir(options.dir);
+ const biggestNumber = Math.max(
+ ...files
+ .filter((f) => f.match(/element-([0-9]+)/))
+ .map((f) => {
+ return f.match(/element-([0-9]+)/)?.[1] as string;
+ })
+ .map((f) => Number(f))
+ );
+ const numberLength = String(biggestNumber).length;
+
await execa(
'ffmpeg',
[
@@ -24,10 +36,8 @@ export const stitchFramesToVideo = async (options: {
'image2',
'-s',
`${options.width}x${options.height}`,
- '-pattern_type',
- 'glob',
'-i',
- `element-*.${format}`,
+ `element-%0${numberLength}d.${format}`,
'-vcodec',
'libx264',
'-crf',