b.splendous.net

netlify and ffmpeg

October 2021 / tech

After some recent additions and changes, I started to see some errors in my Netlify deploys.

10:38:25 PM:     /bin/sh: 1: ffmpeg: not found
10:38:25 PM: at ChildProcess.exithandler (node:child_process:326:12)
10:38:25 PM: at ChildProcess.emit (node:events:369:20)
10:38:25 PM: at maybeClose (node:internal/child_process:1067:16)
10:38:25 PM: at Socket.<anonymous> (node:internal/child_process:453:11)
10:38:25 PM: at Socket.emit (node:events:369:20)
10:38:25 PM: at Pipe.<anonymous> (node:net:666:12)
10:38:25 PM: Problem writing Eleventy templates: (more in DEBUG output)

A quick search showed some discussions about ffmpeg not being available in the Netlify images, and a recommendation to either include a static binary of ffmpeg or to reference the @ffmpeg-installer/ffmpeg npm package.

I liked the latter idea better - better to not check in a binary, right? - so I gave it a try. Pretty simple, all told, and it worked out. I'd rather keep my ffmpeg installed via homebrew, so I wanted this just in the Netlify deploy.

So, my updated Netlify build.sh:

#!/bin/sh
npm i

npm install --save @ffmpeg-installer/ffmpeg
export PATH=`src/scripts/ffmpeg-path.js`:$PATH
echo "PATH: $PATH"

npm run build

And the supporting src/scripts/ffmpeg-path.js:

#!/usr/bin/env node

const path = require('path');
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpegDir = path.dirname(ffmpegPath);
console.log(`${ffmpegDir}`);