Ffmpeg breaking python opencv on Jetson


I have a Jetson Orin NX 16GB running R35 (flashed the 5.3.1 SDK).
With a fresh install, I can import cv2 in python3 without any issue. As soon as I install ffmpeg from the nvidia repository (simply by running sudo apt install ffmpeg), I will no longer be able to do the previous import, and will get the following error:

import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/dist-packages/cv2/__init__.py", line 180, in <module>
  File "/usr/lib/python3.8/dist-packages/cv2/__init__.py", line 152, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: /usr/lib/aarch64-linux-gnu/libavcodec.so.58: undefined symbol: v4l2_open

That’s with a fresh install, and I can see that ffmpeg is coming from the nvidia package repository:

sudo apt install ffmpeg
Get:1 https://repo.download.nvidia.com/jetson/ffmpeg r35.5/main arm64 ffmpeg arm64 7:4.2.7-nvidia [14.8 MB]
Preparing to unpack .../ffmpeg_7%3a4.2.7-nvidia_arm64.deb ...
Unpacking ffmpeg (7:4.2.7-nvidia) ...
Replacing files in old package libavcodec-dev:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libavformat-dev:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libavutil-dev:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libswresample-dev:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libswscale-dev:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libavcodec58:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libavformat58:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libavutil56:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libswresample3:arm64 (7:4.2.7-0ubuntu0.1) ...
Replacing files in old package libswscale5:arm64 (7:4.2.7-0ubuntu0.1) ...
Setting up ffmpeg (7:4.2.7-nvidia) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.14) ...

I have tried to install nvidia-opencv, python3-opencv on top of that, but still get the same error. I might be missing something, but it looks like the ffmpeg provided by Nvidia is missing some options when built.

Removing ffmpeg and reinstalling all the ffmpeg libraries (libavformat, libavcodec, libavutil, libswscale, libswresample) solves the python import, but I would need to keep ffmpeg.

Thanks in advance,

We will replicate the issue and check further. As a quick solution, please download the source code and manually build the ffmpeg binaries. Please refer to the post:
【jetpack 5.1.2】Error while loading shared libraries: libnvbuf_utils.so.1.0.0 - #10 by DaneLLL

Thank you for your answer.
Building and installing ffmpeg manually does fix the issue, I have no error when doing the import. But it does look like nvidia’s ffmpeg package is compiled without the libv4l2 option.

Can we find somewhere the patches applied by nvidia on ffmpeg’s sources ? I will be using Yocto to build the OS and would like to make sure ffmpeg is optimized for the Jetson’s GPU.


It should be same as this topic:
Libavcodec.so: undefined reference to `v4l2_open’ - #9 by DaneLLL

Please try

  1. Add -lv4l2 to --extra-libs:
 ./configure --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs="-lv4l2 -L/usr/lib/aarch64-linux-gnu/tegra -lnvbufsurface -lnvbufsurftransform" --extra-cflags="-I /usr/src/jetson_multimedia_api/include/"
  1. Manually build libavcodec.so.58 and replace to
ffmpeg-4.2.7$ sudo cp -i libavcodec/libavcodec.so.58 /usr/lib/aarch64-linux-gnu/

We shall miss -lv4l2 in our command. Will check this with our team and refresh the prebuilt ffmpeg package.


Yes this does solve the issue, thanks. What I meant is that it would be nice to have that in the prebuilt package as well, to avoid having to rebuild manually.