Skip to content

Add tegra lib stubs and remove unused nvjpeg requirement#9

Merged
Keylost merged 4 commits into
Keylost:masterfrom
madsciencetist:stubs
Sep 30, 2024
Merged

Add tegra lib stubs and remove unused nvjpeg requirement#9
Keylost merged 4 commits into
Keylost:masterfrom
madsciencetist:stubs

Conversation

@madsciencetist
Copy link
Copy Markdown

@madsciencetist madsciencetist commented Jun 26, 2023

NVIDIA does not distribute the jetson multimedia libraries other than on Jetson board images, so the only way to link against these libs is to compile directly on a Jetson, making it difficult to create automated builds or Docker images. This commit adds stubs of those libraries so that nvmpi and ffmpeg can be built without them. The real libraries will still be required at runtime.

Stubs generated using so-stub. They are neither static, rpathed nor installed so that there is no chance of them overriding the real libraries. If someone were to LD_LIBRARY_PATH or manually copy the stubs into an existing library path, the stubbed functions will print an error message and abort() when called.

@madsciencetist
Copy link
Copy Markdown
Author

madsciencetist commented Jun 26, 2023

Example dockerizable build script:

#!/bin/bash

set -euxo pipefail

INSTALL_PREFIX=/rootfs/usr/local

apt-get -qq install -y --no-install-recommends build-essential clang cmake pkg-config

# Install libnvmpi to enable nvmpi decoders (h264_nvmpi, hevc_nvmpi)
if [ -e /usr/local/cuda-10.2 ]; then
    # assume Jetpack 4.X
    wget -q https://developer.nvidia.com/embedded/L4T/r32_Release_v5.0/T186/Jetson_Multimedia_API_R32.5.0_aarch64.tbz2 -O jetson_multimedia_api.tbz2
else
    # assume Jetpack 5.X
    wget -q https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v3.1/release/jetson_multimedia_api_r35.3.1_aarch64.tbz2 -O jetson_multimedia_api.tbz2
fi
tar xaf jetson_multimedia_api.tbz2 -C / && rm jetson_multimedia_api.tbz2

wget -q https://github.com/Keylost/jetson-ffmpeg/archive/refs/heads/master.zip
unzip master.zip && rm master.zip && cd jetson-ffmpeg-master
LD_LIBRARY_PATH=$(pwd)/stubs:$LD_LIBRARY_PATH   # tegra multimedia libs aren't available in image, so use stubs for ffmpeg build
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX
make -j$(nproc)
make install
cd ../../

# Install nv-codec-headers to enable ffnvcodec filters (scale_cuda)
wget -q https://github.com/FFmpeg/nv-codec-headers/archive/refs/heads/master.zip
unzip master.zip && rm master.zip && cd nv-codec-headers-master
make install
cd ../ && rm -rf nv-codec-headers-master

# Build ffmpeg with nvmpi patch
wget -q https://ffmpeg.org/releases/ffmpeg-6.0.tar.xz
tar xaf ffmpeg-*.tar.xz && rm ffmpeg-*.tar.xz && cd ffmpeg-*
patch -p1 < ../jetson-ffmpeg-master/ffmpeg_patches/ffmpeg6.0_nvmpi.patch
export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig
# enable Jetson codecs but disable dGPU codecs
./configure --enable-nvmpi --enable-ffnvcodec --enable-cuda-llvm \
            --disable-cuvid --disable-nvenc --disable-nvdec \
            --enable-shared --disable-static --prefix=$INSTALL_PREFIX \
    || (cat ffbuild/config.log && false)
make -j$(nproc)
make install
cd ../

rm -rf ffmpeg-* jetson-ffmpeg-master /usr/src/jetson_multimedia_api
apt-get purge -y build-essential clang cmake pkg-config

@Keylost
Copy link
Copy Markdown
Owner

Keylost commented Jun 26, 2023

NVIDIA does not distribute the jetson multimedia libraries other than on
Jetson board images, so the only way to link against these libs is to
compile directly on a Jetson, making it difficult to create automated
builds or Docker images. This commit adds stubs of those libraries so
that nvmpi and ffmpeg can be built without them. The real libraries will
still be required at runtime.
@madsciencetist
Copy link
Copy Markdown
Author

Hah, I had removed nvjpeg because the stub was empty! Added it back.

I tried your NvFaultEx, replicated the segfault without nvjpeg and the lack of segfault with it, and then verified that it remains fixed when linking against an empty nvjpeg stub.

So this should be good now

@madsciencetist madsciencetist marked this pull request as draft June 26, 2023 23:48
Stubbing only used functions is brittle as it requires updating the
stubs every time a new function is used. Now these stubs are complete
enough to be used in any project.
@madsciencetist madsciencetist marked this pull request as ready for review June 27, 2023 04:21
@madsciencetist
Copy link
Copy Markdown
Author

Docker build works on latest master with both Jetpack 4.6 and Jetpack 5.0

Keylost added a commit that referenced this pull request Sep 30, 2024
@Keylost Keylost merged commit 74b07d7 into Keylost:master Sep 30, 2024
@Keylost
Copy link
Copy Markdown
Owner

Keylost commented Sep 30, 2024

I added several cmake options to make it more convenient to write automated build scripts and accepted stubs into the master branch. :)
Now you can do something like this:

cmake -DWITH_STUBS=ON -DJETSON_MULTIMEDIA_API_DIR=/home/user/build_deps/jetson_multimedia_api ..
make

See readme for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants