0

I have some nodejs code in a folder on a host machine that has an npm module that requires an environment variable to be set in order to utilize an executable called FFmpeg. I have a containerized FFmpeg along with its dependencies for development purposes and am now wondering how I am able to specify the path to the FFmpeg executable from the host machine in order for this npm module to function correctly.

I have the idea to use a docker volume that exposes the executable from the container onto the host and then to set the environment variable using that path but I'm not sure if this will work.

Some notes from the module's docs.

If the FFMPEG_PATH environment variable is set, fluent-ffmpeg will use it as the full path to the ffmpeg executable. Otherwise, it will attempt to call ffmpeg directly (so it should be in your PATH). You must also have ffprobe installed (it comes with ffmpeg in most distributions). Similarly, fluent-ffmpeg will use the FFPROBE_PATH environment variable if it is set, otherwise it will attempt to call it in the PATH.

Bdyce
  • 332
  • 2
  • 11
  • 1
    Whether it's possible to construct a host filesystem path referring to an executable from a container depends on exactly which filesystem backend your Docker installation is configured to use; any of the available backends that operate on the block level don't have filesystem contents mounted inside the host at all. Also, unless the executable is statically-linked, you'd need to worry about having a library path that points to libraries from that same container's filesystem. – Charles Duffy Sep 01 '20 at 17:11
  • 1
    It would be __much__ better practice to have your environment variable point to a shim that uses Docker to start the container and run `ffmpeg` inside it. – Charles Duffy Sep 01 '20 at 17:11
  • @Charles Duffy how might you construct this shim? If you could provide an example that would be great! In terms of the “docker file system backend” you mention are you referring which version of docker I’m using? – Bdyce Sep 01 '20 at 17:21
  • 1
    No, not the version, but the configuration; docker has lots of different backends it can be configured to use. If you didn't pick one, your Linux distro or otherwise the folks who built the docker package you're using presumably picked one for you. – Charles Duffy Sep 01 '20 at 17:22
  • 1
    ...as for the "how" of the shim, showing your Dockerfile would be a place to start wrt. letting someone test one. That said, _in general_, it's likely to do something like `docker run` with arguments passed through via `"$@"`, possibly with the input and output directories passed in as a volume -- would need to know details of how fluent calls ffmpeg to know exactly what to construct. – Charles Duffy Sep 01 '20 at 17:25
  • 1
    ...so, for those details: Why not write your own script that records its working directory and command-line arguments to a file, and provide _that_ as an ffmpeg executable to fluent? That way you'll know how your script is going to be called, which is a starting place to figure out how to make the script invoke ffmpeg-in-Docker in a way that'll do what's needed. – Charles Duffy Sep 01 '20 at 17:26
  • @Charles Duffy I suppose this would all become easier if I just installed FFmpeg on the developers machines wouldn’t it. Thanks for all the responses. – Bdyce Sep 01 '20 at 17:40
  • 1
    Personally, btw, I use [Nix](https://nixos.org/) to ensure that tooling is available to my dev and support staff. Gives you better reproducibility guarantees than Docker does, installs tooling directly on the host, and has support for building Docker images so your ops team can deploy to production with their existing tools. – Charles Duffy Sep 01 '20 at 17:43
  • @Charles Duffy Hey that looks really cool, I’ll be sure to check it out. Thanks for all the help! – Bdyce Sep 01 '20 at 17:57
  • @Charles Duffy I think what I’ll do is host the npm package and FFmpeg within a container together and get the developers to treat this as a service, I guess this will require a HTTP server in order to send the JSON packets to fluent-FFmpeg and then create a volume to capture the FFmpeg output on the host machine. – Bdyce Sep 01 '20 at 18:35
  • 1
    Sounds like a good plan to me. – Charles Duffy Sep 01 '20 at 20:18

0 Answers0