fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.96k stars 881 forks source link

Node 18 or 20 break ffmpeg in google cloud function #1239

Closed Jidzo1 closed 11 months ago

Jidzo1 commented 1 year ago

Version information

Code to reproduce


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);
  });
});
  let videoDuration = await duration;
} catch (err) {
  console.log(err);
  throw err;
}

Expected results

The above code is working on node js 16 in Google Cloud functions. It provides the duration of the video file from the video URL.

Observed results

The error "cannot find ffprobe" appears when upgrading to node 18 or 20 (No other change than upgrading node).

Setting the path manually using ffmpeg.setFfprobePath(ffprobePath); Trigger the error: -> Error: ffprobe was killed with signal SIGSEGV

err: Error: ffprobe was killed with signal SIGSEGV 
ffprobe version 4.4.1-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2007-2021 the FFmpeg developers 
built with gcc 8 (Debian 8.3.0-6) 
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg 
libavutil      56. 70.100 / 56. 70.100 
libavcodec     58.134.100 / 58.134.100
libavformat    58. 76.100 / 58. 76.100
libavdevice    58. 13.100 / 58. 13.100
libavfilter     7.110.100 /  7.110.100
libswscale      5.  9.100 /  5.  9.100 
libswresample   3.  9.100 /  3.  9.100
libpostproc    55.  9.100 / 55.  9.100

I also opened a stackoverflow question: https://stackoverflow.com/questions/77516185/node-18-or-node-20-break-ffmpeg-in-google-cloud-functions-ffprobe-was-killed

As it may be related to the google cloud ffmpeg version.

Thank you for the help

Shakahs commented 1 year ago

GCP Functions NodeJS 16 runtime uses Ubuntu 18.04 with FFMpeg installed. NodeJS 18/20 use Ubuntu 22.04, and Google in all their wisdom decided not to include FFMpeg -_-.

https://cloud.google.com/functions/docs/runtime-support#node.js https://cloud.google.com/functions/docs/reference/system-packages

Jidzo1 commented 1 year ago

That's unfortunate, to say the least...

What's the solution here then? No way to find an easy workaround without having to deploy a custom docker into Google Cloud?

Shakahs commented 1 year ago

I'm in the same position right now, I don't want to deploy a container just to have FFMpeg.

1 approach would be these libraries that install FFMpeg as an NPM dependency: https://github.com/eugeneware/ffmpeg-static https://github.com/kribblo/node-ffmpeg-installer

I haven't gotten this approach working in GCP Functions yet, so next I am going to try putting an FFMpeg tarball in a GCS bucket and unpacking it to the local filesystem during function initialization.

I think excluding FFMpeg was done intentionally to push users towards GCP Transcoder service, but that service is designed specifically for VOD content preparation, so the full range of FFMpeg capabilities is not available there.

Jidzo1 commented 11 months ago

Update here:

After discussing with Google support, they finally decided to add ffmpeg back as a system package on node 18 and 20. This is now working again as needed.

Closing here