Skip to content

🎥 Make videos programmatically with React

fix complex filter no such file or directory bug

Jonny Burger432726bad8df
diff --git a/packages/renderer/src/ffmpeg-filter-file.ts b/packages/renderer/src/ffmpeg-filter-file.ts
index df6d1ff993..58adc9315a 100644
--- a/packages/renderer/src/ffmpeg-filter-file.ts
+++ b/packages/renderer/src/ffmpeg-filter-file.ts
@@ -1,28 +1,16 @@
// While an FFMPEG filter can be passed directly, if it's too long
// we run into Windows command length limits.
-import fs from 'fs';
+import fs, {existsSync} from 'fs';
import path from 'path';
import type {DownloadMap} from './assets/download-map';
import type {FilterWithoutPaddingApplied} from './stringify-ffmpeg-filter';
-export const makeFfmpegFilterFile = async (
+export const makeFfmpegFilterFile = (
complexFilter: FilterWithoutPaddingApplied,
downloadMap: DownloadMap
) => {
- const random = Math.random().toString().replace('.', '');
- const filterFile = path.join(
- downloadMap.complexFilter,
- 'complex-filter-' + random + '.txt'
- );
- await fs.promises.writeFile(filterFile, complexFilter.filter);
-
- return {
- file: filterFile,
- cleanup: () => {
- fs.unlinkSync(filterFile);
- },
- };
+ return makeFfmpegFilterFileStr(complexFilter.filter, downloadMap);
};
export const makeFfmpegFilterFileStr = async (
@@ -34,6 +22,13 @@ export const makeFfmpegFilterFileStr = async (
downloadMap.complexFilter,
'complex-filter-' + random + '.txt'
);
+
+ // Race condition: Sometimes the download map is deleted before the file is written.
+ // Can remove this once the original bug has been fixed
+ if (!existsSync(downloadMap.complexFilter)) {
+ fs.mkdirSync(downloadMap.complexFilter, {recursive: true});
+ }
+
await fs.promises.writeFile(filterFile, complexFilter);
return {