Per the Firebase Cloud Functions documentation, you can leverage ImageMagick from within a cloud function: https://firebase.google.com/docs/functions/use-cases
Is i
ffmpeg is not preinstalled (pretty much just ImageMagick); to see exactly what's installed check out the Dockerfile here: https://github.com/GoogleCloudPlatform/nodejs-docker/blob/master/runtime-image/Dockerfile.
However, you can upload arbitrary binaries when you upload your code using gcloud beta functions deploy because everything in the current directory (except node_modules) is uploaded.
Note: you only have disk write access at /tmp/.
ffmpeg-static is an npm module that builds the correct ffmpeg binary based on the current system during npm install. Since Cloud Functions builds your code in the cloud, it'll build the correct ffmpeg binary.
https://github.com/eugeneware/ffmpeg-static
You can see it in action in the Cloud Functions for Firebase examples repo.
const ffmpeg = require('fluent-ffmpeg');
const ffmpeg_static = require('ffmpeg-static');
var cmd = ffmpeg('/tmp/video.avi')
.setFfmpegPath(ffmpeg_static.path)
.videoBitrate(1024)
.videoCodec('divx')
.format('avi')
.on('end', () => {
// ...
})
.on('error', err => {
console.error(err);
})
.save('/tmp/file-out.avi');
(Thanks Daniel Lessa for pointing out this module in his answer.)
You could include an ffmpeg binary as part of the upload and then run a shell command using something like child_process.exec. You'll need the ffmpeg binary that's compiled for the target platform (Debian/jessie).
./
../
index.js
ffmpeg
Then run for example gcloud beta functions deploy myFunc --trigger-http
var exec = require('child_process').exec;
var cmd = 'ffmpeg -i /tmp/myvideo.mp4 /tmp/image-%d.jpg';
exec(cmd, function(error, stdout, stderr) {
// command output is in stdout
});