Please see below, the code is working on node js 16, but not when upgrading to node 18 or 20.
const ffmpeg = require("fluent-ffmpeg");
// Following is inside a .https.onRequest Google Cloud function with enough memory
try {
const duration = new Promise((resolve, reject) => {
ffmpeg.ffprobe(videoUrl, async (err, metadata) => {
if (err) {
if (res.headersSent) {
console.error("Response already sent");
return;
} else {
console.log("Metadata:", metadata);
console.log("err: " + err);
res.status(400).send("Error getting video metadata");
return;
}
}
const duration = metadata.format.duration;
console.log("video duration in second: " + duration);
resolve(duration);
});
});
videoDuration = await duration;
} catch (err) {
console.log(err);
throw err;
}
When upgrading to node 18/20 (No other change than upgrading node), the error "ffprobe not found" appears.
But setting the path manually using ffmpeg.setFfprobePath(ffprobePath);
trigger the error: Error: ffprobe was killed with signal SIGSEGV
So it seem its a permissions issue.
However, I tried a lot of different solutions, none of them made this work.
For instance i tried to download manually the ffprobe from the official website https://ffbinaries.com/downloads. Then manually add it to the code.
I tried to use https://www.npmjs.com/package/@ffprobe-installer/ffprobe or others package like https://www.npmjs.com/package/ffprobe-static
I also tried to download the ffprobe file to the temporary folder of google cloud, and change the permission of this folder.
All of those was doing the same error.
None of what i could think of made any difference.
Please help because i need to update node 16 to 18 or 20 before google remove node 16 on january 31 2024 and for now i don’t see a solution.
I also looked for other solution to get this duration from a video file url, but using ffmpeg seem to be the only one that should work out of the box. As it is working on node 16.
Thank you,
UPDATE – 11/26/2023
GCP Functions NodeJS 16 runtime uses Ubuntu 18.04 with FFMpeg installed.
NodeJS 18/20 use Ubuntu 22.04, and Google decided not to include FFMpeg.
https://cloud.google.com/functions/docs/runtime-support#node.js
https://cloud.google.com/functions/docs/reference/system-packages
No workaround or solutions found as of now
2
Answers
It might be the upgrade to Node 18 or Node 20 is causing the issue. It might be some compatibility issue running
ffprobe
. There are some reasons that may cause the issue, either ffprobe executable is not in the correct path or some permissions not granted.ffprobe executable should be in the same directory as ffmpeg executable. You can check the location by running this command:
If the ffmpeg executable is not found, you need to install it. Try downloading it from this website:
Once you downloaded the ffmpeg binaries, extract it to
bin
directory. Make sure the ffprobe executable has the correct permissions to be executed by the current user. If not, you can change the permissions by running this command:I saw it before that Ubuntu 22.04 didn’t include ffmpeg. but now it seems to be included: https://cloud.google.com/functions/docs/reference/system-packages#ubuntu_2204