command.on("progress", function (progress: FFMPEG.Progress) {
const downloadedBytes: number = progress.targetSize / 1000;
console.log(downloadedBytes);
if (downloadedBytes >= maxFileSize) {
try {
const responseObject: DownloadFailResponse = {
statusCode: 507,
timestamp: Date.now(),
reason: `Download has been stopped because the maximum file size of ${maxFileSize}MB has been reached. The downloaded file size was ${downloadedBytes} bytes.`
};
console.log(`[FFMPEG]: Maximum file size of ${maxFileSize}MB has been reached.`.red);
videoStream.destroy();
command.kill("SIGINT");
return res.status(507).json(responseObject);
} catch (err) {
return res.status(500).send((err as Error).message);
}
}
});
Expected results
The .on("progress"), and other events being fired.
Observed results
fluent-ffmpeg has been combined with ytdl to physically save any YouTube video onto my drive. I am using the .on("progress") event listeners to handle the file size; if the file reaches the maximum size of 10MB, the download should be aborted.
It seems like the events get fired all at once but will stop working afterwards. A new ffmpeg command will be created after each request. Here is a snippet of the code; it's obviously being shortened because it is, in reality, longer.
Version information
^2.1.2
ffmpeg-static: ^5.2.0
Code to reproduce
Expected results
The
.on("progress")
, and other events being fired.Observed results
fluent-ffmpeg
has been combined withytdl
to physically save any YouTube video onto my drive. I am using the.on("progress")
event listeners to handle the file size; if the file reaches the maximum size of 10MB, the download should be aborted.It seems like the events get fired all at once but will stop working afterwards. A new
ffmpeg
command will be created after each request. Here is a snippet of the code; it's obviously being shortened because it is, in reality, longer.