FFMPEG / Nix issues after deployment on Replit

Question:
When I deploy my repl, my ffmpeg setup stops working .

I call FFMPEG in the following way in my code:

os.environ["IMAGEIO_FFMPEG_EXE"] = (
    "/nix/store/kgd2m5kk3hca2zjxv2nvqfw10m44430f-ffmpeg-5.1.3-bin/bin/ffmpeg"
)
os.environ["PATH"] += (
    os.pathsep + "/nix/store/kgd2m5kk3hca2zjxv2nvqfw10m44430f-ffmpeg-5.1.3-bin/bin"
)

Which works fine on my local repl, but on the deployed version I get the following error:

No such file or directory: '/nix/store/kgd2m5kk3hca2zjxv2nvqfw10m44430f-ffmpeg-5.1.3-bin/bin/ffmpeg'

Unsure how to get this to work on the deployed version.

1 Like

If I recall correctly (I may be wrong), when you deploy you don’t have a nix environment. So, you won’t have access to any of the packages that you request for in your replit.nix.
You can try to install the package normally with poetry, but it may not work because FFMPEG depends on a whole bunch of shared objects that the nix env usually provides.

I’d recommend trying this:
Copy in the file from the nix store path to somewhere local, then use that. Hopefully it works. (this may take a lot of storage)

3 Likes

replit.nix installations are included in a Deployment. It looks like the problem here is that you’ve hard coded Nix store paths, but we can’t copy the entire Nix store into a Deployment.

If you use the env feature of replit.nix instead, you’d be able to keep things in sync with a version that gets into the Deployment:

replit.nix:

{pkgs} :
{
  deps = [
    pkgs.ffmpeg
  ];
  env = {
    IMAGEIO_FFMPEG_EXE = "${pkgs.ffmpeg}/bin/ffmpeg";
  };
}
3 Likes

Thanks @ryantmreplit

I tried that approach but still have the same issue.

Here’s my full .nix file with the suggested changes:

  deps = [
    pkgs.wget
    pkgs.python310Full
    pkgs.replitPackages.prybar-python310
    # pkgs.replitPackages.stderred
    pkgs.ffmpeg_6-full
  ];
  env = {
    PYTHON_LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
      # Needed for pandas / numpy
      pkgs.stdenv.cc.cc.lib
      pkgs.zlib
      # Needed for pygame
      pkgs.glib
      # Needed for matplotlib
      pkgs.xorg.libX11
    ];
    IMAGEIO_FFMPEG_EXE = "${pkgs.ffmpeg_6-full}/bin/ffmpeg";
    PYTHONHOME = "${pkgs.python310Full}";
    PYTHONBIN = "${pkgs.python310Full}/bin/python3.10";
    LANG = "en_US.UTF-8";
    # STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
    PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
  };
}

I printed all the env variables just to see if the others from my replit.nix file are available but found that only one of them is: PYTHON_LD_LIBRARY_PATH. So I’m assuming that it’s something to do with the env variables not being available from .nix file…

2 Likes

Which nix channel are you using in your .replit file? When I use stable-22_11, it cannot find the ffmpeg_6-full and if I use stable-23_05 it cannot find prybar-python, so I suspect your Nix environment isn’t successfully building. Here’s an example of what those errors look like:

~/LuckyDimpledArrays$ 
Detected change in environment, reloading shell...
nix error: building nix env: exit status 1
Output has been trimmed to the last 20 lines

       … while evaluating attribute 'IMAGEIO_FFMPEG_EXE' of derivation 'nix-shell'

         at /home/runner/LuckyDimpledArrays/replit.nix:19:5:

           18|     ];
           19|     IMAGEIO_FFMPEG_EXE = "${pkgs.ffmpeg_6-full}/bin/ffmpeg";
             |     ^
           20|     PYTHONHOME = "${pkgs.python310Full}";

       error: attribute 'ffmpeg_6-full' missing

       at /home/runner/LuckyDimpledArrays/replit.nix:19:29:

           18|     ];
           19|     IMAGEIO_FFMPEG_EXE = "${pkgs.ffmpeg_6-full}/bin/ffmpeg";
             |                             ^
           20|     PYTHONHOME = "${pkgs.python310Full}";
       Did you mean one of ffmpeg_5-full or ffmpeg-full?

~/LuckyDimpledArrays$ 
Detected change in environment, reloading shell...
nix error: building nix env: exit status 1
Output has been trimmed to the last 20 lines
         whose name attribute is located at /nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/pkgs/stdenv/generic/make-derivation.nix:303:7

       … while evaluating attribute 'PRYBAR_PYTHON_BIN' of derivation 'nix-shell'

         at /home/runner/LuckyDimpledArrays/replit.nix:24:5:

           23|     # STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
           24|     PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
             |     ^
           25|   };

       error: attribute 'prybar-python310' missing

       at /home/runner/LuckyDimpledArrays/replit.nix:24:28:

           23|     # STDERREDBIN = "${pkgs.replitPackages.stderred}/bin/stderred";
           24|     PRYBAR_PYTHON_BIN = "${pkgs.replitPackages.prybar-python310}/bin/prybar-python310";
             |                            ^
           25|   };

I’d suggest switching to our new module system for Python, which can be found in the default template, but you could also get the same thing by copying .replit and replit.nix below:

.replit

entrypoint = "main.py"
modules = ["python-3.10:v18-20230807-322e88b"]

hidden = [".pythonlibs"]

[nix]
channel = "stable-23_05"

[deployment]
run = ["python3", "main.py"]
deploymentTarget = "cloudrun"

replit.nix

{ pkgs }: {
  deps = [
    pkgs.wget
    pkgs.ffmpeg_6-full
  ];
  env = {
    IMAGEIO_FFMPEG_EXE = "${pkgs.ffmpeg_6-full}/bin/ffmpeg";
  };
}

Then I see:

~/SpryYummyPlans$ printenv | grep IMAGEIO
IMAGEIO_FFMPEG_EXE=/nix/store/yl258xplv3sh3f8mvil8jxina8dfalym-ffmpeg-full-6.0-bin/bin/ffmpeg
2 Likes

that worked! thank you @ryantmreplit

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.