From f48084a129cf1879ba15dea94582b3c732a692da Mon Sep 17 00:00:00 2001 From: z-khan Date: Wed, 16 Apr 2025 12:37:25 +1000 Subject: [PATCH 1/2] support for Jetson hardware encode/decode Build ffmpeg on Jetson devices with NVIDIA Jetson Multimedia API for hardware encode/decode support (if supported by device) --- scripts/build-deps | 76 ++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/scripts/build-deps b/scripts/build-deps index 4291140dd..53b558377 100755 --- a/scripts/build-deps +++ b/scripts/build-deps @@ -16,42 +16,64 @@ fi mkdir -p "$PYAV_LIBRARY_ROOT" mkdir -p "$PYAV_LIBRARY_PREFIX" + +cd "$PYAV_LIBRARY_ROOT" +# Clone the source. +if [[ ! -d $PYAV_LIBRARY ]]; then + git clone git://source.ffmpeg.org/ffmpeg.git $PYAV_LIBRARY -b n${PYAV_LIBRARY#*-} --depth=1 || exit 1 + echo +fi + # Add CUDA support if available CONFFLAGS_NVIDIA="" if [[ -e /usr/local/cuda ]]; then - # Get Nvidia headers for ffmpeg - cd $PYAV_LIBRARY_ROOT - if [[ ! -e "$PYAV_LIBRARY_ROOT/nv-codec-headers" ]]; then - git clone https://github.com/FFmpeg/nv-codec-headers.git - cd nv-codec-headers - make -j4 - make PREFIX="$PYAV_LIBRARY_PREFIX" install + if [[ -e /etc/nv_tegra_release ]]; then + # Get NVIDIA Jetson multimedia api + if [[ ! -e /usr/src/jetson_multimedia_api/include ]]; then + apt install nvidia-l4t-jetson-multimedia-api -y + fi + if [[ ! -e "$PYAV_LIBRARY_ROOT/jetson-ffmpeg" ]]; then + cd "$PYAV_LIBRARY_ROOT" + git clone https://github.com/Keylost/jetson-ffmpeg.git + cd jetson-ffmpeg + mkdir build + cd build + cmake -DWITH_STUBS=ON .. + make -j$(nproc) + make PREFIX="$PYAV_LIBRARY_PREFIX" install + ldconfig + cd .. + ./ffpatch.sh "../$PYAV_LIBRARY" + fi + CONFFLAGS_NVIDIA="--enable-nvmpi" + echo "INFO: Found jetson multimedia api in /usr/src/jetson_multimedia_api/include..." + echo " Building with Jetson NVENC/NVDEC support" + else + # Get NVIDIA headers for ffmpeg + cd $PYAV_LIBRARY_ROOT + if [[ ! -e "$PYAV_LIBRARY_ROOT/nv-codec-headers" ]]; then + git clone https://github.com/FFmpeg/nv-codec-headers.git + cd nv-codec-headers + make -j$(nproc) + make PREFIX="$PYAV_LIBRARY_PREFIX" install + fi + + PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" + CONFFLAGS_NVIDIA="--enable-cuda-nvcc \ + --enable-nonfree \ + --enable-libnpp \ + --extra-cflags=-I/usr/local/cuda/include \ + --extra-ldflags=-L/usr/local/cuda/lib64" + echo "INFO: Found CUDA libraries in /usr/local/cuda..." + echo " Building with NVIDIA NVENC/NVDEC support" fi - - PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" - CONFFLAGS_NVIDIA="--enable-cuda \ - --enable-cuvid \ - --enable-nvenc \ - --enable-nonfree \ - --enable-libnpp \ - --extra-cflags=-I/usr/local/cuda/include \ - --extra-ldflags=-L/usr/local/cuda/lib64" else - echo "WARNING: Did not find cuda libraries in /usr/local/cuda..." + echo "WARNING: Did not find CUDA libraries in /usr/local/cuda..." echo " Building without NVIDIA NVENC/NVDEC support" fi cd "$PYAV_LIBRARY_ROOT" -# Download and expand the source. -if [[ ! -d $PYAV_LIBRARY ]]; then - url="https://ffmpeg.org/releases/$PYAV_LIBRARY.tar.gz" - echo Downloading $url - curl "$url" --output ${PYAV_LIBRARY}.tar.gz || exit 1 - tar -xzf $PYAV_LIBRARY.tar.gz - rm $PYAV_LIBRARY.tar.gz - echo -fi cd $PYAV_LIBRARY echo ./configure @@ -74,7 +96,7 @@ echo ./configure echo echo make -make -j4 || exit 3 +make -j$(nproc) || exit 3 echo echo make install From c53431beebd4c5076eddf7fced841fc4d6873253 Mon Sep 17 00:00:00 2001 From: z-khan Date: Thu, 17 Apr 2025 15:05:24 +1000 Subject: [PATCH 2/2] remove apt installation with warning --- scripts/build-deps | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/scripts/build-deps b/scripts/build-deps index 53b558377..b996841ea 100755 --- a/scripts/build-deps +++ b/scripts/build-deps @@ -28,26 +28,28 @@ fi CONFFLAGS_NVIDIA="" if [[ -e /usr/local/cuda ]]; then if [[ -e /etc/nv_tegra_release ]]; then - # Get NVIDIA Jetson multimedia api - if [[ ! -e /usr/src/jetson_multimedia_api/include ]]; then - apt install nvidia-l4t-jetson-multimedia-api -y + # Require NVIDIA Jetson multimedia api + if [[ -e /usr/src/jetson_multimedia_api/include ]]; then + if [[ ! -e "$PYAV_LIBRARY_ROOT/jetson-ffmpeg" ]]; then + cd "$PYAV_LIBRARY_ROOT" + git clone https://github.com/Keylost/jetson-ffmpeg.git + cd jetson-ffmpeg + mkdir build + cd build + cmake -DWITH_STUBS=ON .. + make -j$(nproc) + make PREFIX="$PYAV_LIBRARY_PREFIX" install + ldconfig + cd .. + ./ffpatch.sh "../$PYAV_LIBRARY" + fi + CONFFLAGS_NVIDIA="--enable-nvmpi" + echo "INFO: Found jetson multimedia api in /usr/src/jetson_multimedia_api/include..." + echo " Building with Jetson NVENC/NVDEC support" + else + echo "WARNING: Did not find Jetson Multimedia API headers in /usr/src/jetson_multimedia_api/include" + echo " Building without Jetson NVENC/NVDEC support" fi - if [[ ! -e "$PYAV_LIBRARY_ROOT/jetson-ffmpeg" ]]; then - cd "$PYAV_LIBRARY_ROOT" - git clone https://github.com/Keylost/jetson-ffmpeg.git - cd jetson-ffmpeg - mkdir build - cd build - cmake -DWITH_STUBS=ON .. - make -j$(nproc) - make PREFIX="$PYAV_LIBRARY_PREFIX" install - ldconfig - cd .. - ./ffpatch.sh "../$PYAV_LIBRARY" - fi - CONFFLAGS_NVIDIA="--enable-nvmpi" - echo "INFO: Found jetson multimedia api in /usr/src/jetson_multimedia_api/include..." - echo " Building with Jetson NVENC/NVDEC support" else # Get NVIDIA headers for ffmpeg cd $PYAV_LIBRARY_ROOT