Libavcodec.so: undefined reference to `v4l2_open’

JetPack4.6 AGX-XAVIER-INDUSTRIAL
I installed ffmpeg by referring to the following link.
https://docs.nvidia.com/jetson/archives/r34.1/DeveloperGuide/text/SD/Multimedia/AcceleratedDecodeWithFfmpg.html
However, when I compile the application for testing, the following error is reported:
cannot find -lv4l2
Then I did the following:
$ cd /usr/lib/aarch64-linux-gnu
$ sudo ln -sf libv4l2.so.0 libv4l2.so

Recompiling the test program exploded with the following error:
libavcodec.so: undefined reference to `v4l2_open’

libavcodec.so: undefined reference to `v4l2_ioctl’

libavcodec.so: undefined reference to `v4l2_close’

1 Like

Hi,
Please refer to steps in the post:
Jetson TX2 and FFmpeg - Can't initialize nvrm channel - #5 by DaneLLL

I tried to compile through the source code:
$ ./configure --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs=“-L/usr/lib/aarch64-linux-gnu/tegra -lnvbuf_utils” --extra-cflags=“-I /usr/src/jetson_multimedia_api/include/”
There are the following errors:
ERROR: libv4l2 not found using pkg-config
Do I need to execute the following command?
sudo apt-get install libv4l-dev

I compiled from the source code
./configure --prefix=/home/xiangxun/nvme/ffmpeg_7.13/ffmpeg-4.2.2/install --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs=“-L/usr/lib/aarch64-linux-gnu/tegra -lnvbuf_utils” --extra-cflags=“-I /usr/src/jetson_multimedia_api/include/”
make
make install

When I try to compile the application, it still reports an error

g++ ffmpeg_test.cpp -I/usr/src/jetson_multimedia_api/include -I./install/include -L./install/lib -lavutil -lavcodec -lavformat -lavdevice -lavfilter -lswscale -lswresample -L/usr/lib/aarch64-linux-gnu -lv4l2 -o ffmpegTest

./install/lib/libavcodec.so: undefined reference to v4l2_open' ./install/lib/libavcodec.so: undefined reference to v4l2_close’
./install/lib/libavcodec.so: undefined reference to `v4l2_ioctl’

ffmpeg_test.cpp (577 Bytes)

I was able to decode the test video properly with the compiled ffmpeg

./ffmpeg -c:v h264_nvv4l2dec -i /opt/nvidia/vpi1/samples/assets/noisy.mp4 -f null -
nvbuf_utils: Could not get EGL display connection
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/home/xiangxun/nvme/ffmpeg_7.13/ffmpeg-4.2.2/install --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs=‘-L/usr/lib/aarch64-linux-gnu/tegra -lnvbuf_utils’ --extra-cflags=‘-I /usr/src/jetson_multimedia_api/include/’
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘/opt/nvidia/vpi1/samples/assets/noisy.mp4’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Duration: 00:00:05.01, start: 0.000000, bitrate: 13317 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 960x540 [SAR 1:1 DAR 16:9], 13313 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261
Stream mapping:
Stream #0:0#0:0 (h264 (h264_nvv4l2dec) → wrapped_avframe (native))
Press [q] to stop, [?] for help
Output #0, null, to ‘pipe:’:
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
Stream #0:0(und): Video: wrapped_avframe, yuv420p, 960x540 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 29.97 fps, 29.97 tbn, 29.97 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc58.54.100 wrapped_avframe
frame= 140 fps=0.0 q=-0.0 Lsize=N/A time=00:00:04.67 bitrate=N/A speed=10.7x
video:73kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Hi,
Please download source code and run the steps:

  1. Execute configure command in README.nvidia

ffmpeg-4.2.2$ ./configure --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs=“-L/usr/lib/aarch64-linux-gnu/tegra -lnvbuf_utils” --extra-cflags=“-I /usr/src/jetson_multimedia_api/include/”

  1. Modify this line in ffbuild/config.mak

EXTRALIBS-avcodec=-pthread -lm -lz -lv4l2

  1. Modify this line in ffbuild/config.sh

extralibs_avcodec=“-pthread -lm -lz -lv4l2”

  1. Build the package: $ make -j4
  2. Compile the sample with self-built libavcodec.so

ffmpeg-4.2.2$ g++ ffmpeg_test.cpp -Llibavformat/ -lavformat -Llibavcodec/ -lavcodec -o ffmpeg_test

Hi,
This should also work:

  1. Execute configure command by adding -lv4l2 to –extra-libs

ffmpeg-4.2.2$ ./configure --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs=“-lv4l2 -L/usr/lib/aarch64-linux-gnu/tegra -lnvbuf_utils” --extra-cflags=“-I /usr/src/jetson_multimedia_api/include/”

  1. Build the package: $ make -j4
  2. Compile the sample with self-built libavcodec.so

ffmpeg-4.2.2$ g++ ffmpeg_test.cpp -Llibavformat/ -lavformat -Llibavcodec/ -lavcodec -o ffmpeg_test

Thank you very much, it has solved the problem.

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