Keeping a small conda env for FFmpeg-based video scripts on a server

Hi all, I have a few Python scripts that generate thumbnails and previews for a video site, using ffmpeg and opencv. I’d like a lean, reproducible conda environment on Ubuntu servers. Is it better to pull ffmpeg from conda-forge inside the env or use the system package? And what’s your preferred way to lock and deploy the env (environment.yml, conda-lock, or something else)? Thanks!

Hey @Colorful!

For ffmpeg, keeping everything inside the conda environment and installing from conda-forge should make the setup easier to manage. The conda-forge OpenCV build is built with FFmpeg support against libraries from the conda environment, so using a separate system ffmpeg can leave you with both system and conda FFmpeg installations to keep track of.

For deployment, a lockfile is probably the best fit if you want the same environment on each Ubuntu server. Conda 26.5 and later supports lockfiles natively, so you don’t need an extra tool for that. Once your env is built, you can export it for Linux with:

conda export --name thumbs --file conda-lock.yaml --platform linux-64

and recreate it on server with:

conda create (or conda install) --name thumbs --file conda-lock.yaml

That installs the exact packages and builds recorded in the lockfile without solving again. A minimal environment.yml can still be useful as the human-maintained dependency spec, while the lockfile becomes the reproducible deployment artifact.

Separately, if you want to try something newer, the conda team has been working on conda-workspaces plugin (early stage, not for production). It lets you keep the environment definition, supported platforms, and project tasks in one workspace file. From that, it can generate lockfiles for each platform and package the project for deployment as either a portable archive or a container image. It might be helpful for this kind of workflow, and we’re looking for feedback as we continue developing it!

Lastly, conda Zulip chat is also a good place to bring questions or feedback. Conda maintainers and other community members are active there. :hugs:

I’d add one more thing to the deployment checklist: test the actual video pipeline, not just whether the conda environment installs successfully.

The lockfile should give you reproducible package versions, but it won’t necessarily catch a problem with a codec or an unexpected FFmpeg executable being picked up at runtime.

Since you’re using both FFmpeg and OpenCV, I’d check which ffmpeg binary your Python subprocess calls are using (shutil.which("ffmpeg") is a quick check), and whether OpenCV can actually decode the formats you’re processing.

A small smoke test during deployment could take one representative video, extract a thumbnail, generate a short preview, and verify that both output files are readable. That would catch more than just checking ffmpeg -version.

For keeping the environment small, I’d also ask whether you really need OpenCV for the thumbnail step. If everything is already being done through FFmpeg commands, removing an unnecessary dependency might save more space than changing the environment management approach.

Are you using OpenCV to process frames in Python, or mainly calling FFmpeg from subprocesses?