How install FFMPEG on Netlify

I was unable to find a way to permanently set the path on Netlify. In the end I gave up and opted to change the plugin code. Thanks to the links published by @Scott and @hideodaikoku I managed to solve the problem.

These are the steps:

  1. copy a static builf of ffmpeg in the repository (/bin/ffmpeg-git-20200617-amd64-static) (see John Van Sickle - FAQ)

  2. create a local copy of the package that uses ffmpeg (eleventy-plugin-local-respimg) in ./scr/eleventy-plugin-local-respimg

  3. modify eleventy.js to use the local copy
    const pluginLocalRespimg = require('./src/eleventy-plugin-local-respimg')

  4. The path is different if you execute the build on a local machine or on Eleventy. In the package.json set an enviroment variable in the build command for Netlify
    "netlify": "NODE_ENV=production npm run build",

  5. In the local copy of the plugin check for the NODE_ENV and build the path of ffmpeg. You should give the permission as executable with chmode.

    const isProduction = (process.env.NODE_ENV === ‘production’);
    const ffmpegPath = (isProduction === true) ? ‘/opt/build/repo/bin/ffmpeg-git-20200617-amd64-static/’ : ‘/bin/’;
    if (isProduction === true) {
    exec(‘chmod +x /opt/build/repo/bin/ffmpeg-git-20200617-amd64-static/ffmpeg’);
    exec(‘chmod +x /opt/build/repo/bin/ffmpeg-git-20200617-amd64-static/ffprobe’);
    exec(‘chmod +x /opt/build/repo/bin/ffmpeg-git-20200617-amd64-static/qt-faststart’);
    }
    const command = `${ffmpegPath}ffmpeg -i ${input} -movflags faststart -filter:v “scale=trunc(iw/2)*2:trunc(ih/2)*2” -pix_fmt yuv420p -y -loglevel error ${output}`;

I’m sorry for my bad English but I hope the steps are clear

1 Like