try to take screenshot & generate audio file in same time
HassanDev13 opened this issue · comments
Zerrouk Mohamed Hacene commented
Hi , i am trying to take a screenshot & generate an audio file at the same time, is that possible?
here my code :
async function extractMp3AndScreenShot(
inputFilePath: string,
outputFilePath: string,
imageName: string,
outputImagePath: string
): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let count = 0;
try {
await checkAndCreateDirectory(outputFilePath);
ffmpeg()
.input(inputFilePath)
.audioCodec("libmp3lame")
.toFormat("mp3")
.on("progress", (progress) => {
console.log(`Processing: ${progress.percent}% done`);
})
.takeScreenshots({
timestamps: ["50%"],
filename: imageName,
folder: outputImagePath,
})
.on("end", () => {
count++;
if (count === 2) {
console.log("ffmpeg finished");
resolve();
}
})
.on("error", (err) => {
console.error("Error:", err);
reject(err);
})
.save(outputFilePath);
} catch (error) {
reject(error);
}
});
}
my screenshot sometimes generates sometimes not!
Could someone please help ?
Nicolas Joyard commented
You can only call one of the processing methods (save
, takeScreenshots
, or any other method listed in https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#starting-ffmpeg-processing) on a ffmpeg()
instance.
Use clone()
to create a clone, and then call save
on one and takeScreenshots
on the other.