I'm trying to scan all the videos inside a specific folder and create a thumbnail for each of them.
Here is the relevant code:
public async scan(): Promise<string[]> {
const files = await this.readFile(this._directoryPath);
const result: string[] = [];
for await (const file of files) {
result.push(file);
try {
ffmpeg(file)
.on("error", (err, stdout, stderr) => {
console.log(err.message);
})
.screenshots({
timestamps: [5],
filename: basename(file) + ".png",
folder: this._thumbnailPath,
});
} catch (e: any) {
logger.error("Failed taking screenshot for " + file + " with error " + e.message);
}
}
return result;
}
It is running fine a for small amount of video, but when I tried on a network path (\\Servername\some_folder) containing 2000 video files, my pc died after a moment. It manages to scan ~800 videos then everything crashed.
Is there a way to make that a background process ? I don't need to wait for it to be over. Or is it possible to run this chunk by chunk from one API call ?
I'm completely new to node.js so any help is appreciated.