ImportError: libswresample-d02fa90a.so.4.7.100: Cannot open shared object file

Hello! I’m trying to get the Google Coral EdgeTPU working with PyCoral and Nix, but I can’t find a way to fix the following error:

Traceback (most recent call last):
  File "main.py", line 26, in <module>
    import cv2
  File "/nix/store/lz5vn9fm8kq1048y34pv233l7fx93vhr-python3-3.8.16-env/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/nix/store/lz5vn9fm8kq1048y34pv233l7fx93vhr-python3-3.8.16-env/lib/python3.8/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/nix/store/4ybnwzzqgn4ayww2xhiwqmn7ijqhvf2f-python3-3.8.16/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libswresample-d02fa90a.so.4.7.100: cannot open shared object file: No such file or directory

From my understanding, this is related to FFMPEG and a possibly dead subsect of it. However, simply slapping FFMPEG in the native build inputs does not fix the issue. My nix shell is as follows:

{ pkgs ? import <nixpkgs> {} }:
let
  system = "linux_x86_64";
	python-package-list = p: with p; [
    pip
    numpy
    (
      buildPythonPackage rec {
        pname = "opencv-python";
        version = "4.7.0.68";
        format = "wheel";
        src = pkgs.fetchurl {
          name = "opencv_python-4.7.0.68-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl";
          url = "https://files.pythonhosted.org/packages/07/e2/405fd71f433960b0ce6a546536b05a26d85508df7eea98850784e10323e9/opencv_python-4.7.0.68-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl";
          sha256 = "sha256-OgDhJUblV49rt+1AjDf8/qUz106Wkc+vQJJva0MpVXc=";
        };
        doCheck = false;
        propagatedBuildInputs = [
          # Specify dependencies
          pkgs.python38Packages.numpy
          pkgs.libstdcxx5
        ];
      }
    )
    (
      buildPythonPackage rec {
        pname = "pycoral";
        version = "2.0.0";
        format = "wheel";
        src = pkgs.fetchurl {
          name = "pycoral-${version}-cp38-cp38-${system}.whl";
          url = "https://github.com/google-coral/pycoral/releases/download/v${version}/pycoral-${version}-cp38-cp38-${system}.whl";
          sha256 = "sha256-erRyNHGNzvPF+T3kYA4/rn9k7BiG0MxK3CJv8KnbcF4=";
        };
        doCheck = false;
        propagatedBuildInputs = [
          # Specify dependencies
          (
            buildPythonPackage rec {
              pname = "Pillow";
              version = "7.1.0";
              format = "wheel";
              src = pkgs.fetchurl {
                name = "Pillow-${version}-cp38-cp38-manylinux1_x86_64.whl";
                url = "https://files.pythonhosted.org/packages/55/5d/f22d026c891bcb22008eb309cb9e2bf61eaad254a70bdaaeda06386cf505/Pillow-${version}-cp38-cp38-manylinux1_x86_64.whl";
                sha256 = "sha256-+x+fqimEkYzXo7GNsRkkY+ADBQDLBgyXS1/ZjBMnao4=";
              };
              doCheck = false;
              propagatedBuildInputs = [
                # Specify dependencies
              ];
            }
          )
          (
            buildPythonPackage rec {
              pname = "tflite-runtime";
              version = "2.5.0.post1";
              format = "wheel";
              src = pkgs.fetchurl {
                name = "tflite_runtime-2.5.0.post1-cp38-cp38-linux_x86_64.whl";
                url = "https://github.com/google-coral/pycoral/releases/download/v2.0.0/tflite_runtime-2.5.0.post1-cp38-cp38-linux_x86_64.whl";
                sha256 = "sha256-JdmvMK0My/GByYaLI2izS8leO1am53Ueu7hNPsqwk5M=";
              };
              doCheck = false;
              propagatedBuildInputs = [
                # Specify dependencies
                pkgs.python38Packages.numpy
              ];
            }
          )
        ];
      }
    )
  ];
  ai-python = pkgs.python38.withPackages python-package-list;
in
  pkgs.mkShell {
    LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib/";
    nativeBuildInputs = with pkgs; [
      gcc
      libstdcxx5
		  ai-python
    ];
	shellHook =
		''
    sed -i 's/\r$//' shell.nix
    echo "hi :)"
		'';
}

The wheel is build against ffmpeg commit d02fa90a and wants to load that shared object. Out library would look like /nix/store/p9id9di9vgsnhc54z81d1zkqp21h59gp-ffmpeg-5.1.2-lib/lib/libswresample.so.4.7.100. You can try to replace it with patchelf but that may or may not work.