|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# Opt-in installer that adds software h264/hevc/av1 decoder support to a |
| 17 | +# Curator container by building FFmpeg from source with those decoders added |
| 18 | +# to the strict allowlist. |
| 19 | +# |
| 20 | +# The release Curator image may omit system ffmpeg entirely. When installed |
| 21 | +# with install_ffmpeg.sh, Curator's strict FFmpeg build routes h264/hevc/av1 |
| 22 | +# decode through NVDEC only. That breaks ffprobe-based metadata extraction in |
| 23 | +# CPU-only Ray actors (VideoReader, ClipWriter), which is why this opt-in |
| 24 | +# exists. |
| 25 | +# |
| 26 | +# Run inside a running container, e.g.: |
| 27 | +# docker exec <container> bash /opt/Curator/docker/common/install_h264_support.sh |
| 28 | +# |
| 29 | +# Behaviour: |
| 30 | +# - Builds FFmpeg from the upstream release tarball, same version as install_ffmpeg.sh, |
| 31 | +# with the existing allowlist plus --enable-decoder=h264,hevc,av1. |
| 32 | +# - Optionally also enables the libopenh264 software h264 ENCODER (Cisco's |
| 33 | +# free-license OpenH264 binary; opt-in via --with-libopenh264). |
| 34 | +# - Replaces /usr/local/bin/{ffmpeg,ffprobe} in place. |
| 35 | +# - Default stays LGPLv3 (only FFmpeg-internal native decoders); with |
| 36 | +# --with-libopenh264 the resulting binary additionally links Cisco's |
| 37 | +# OpenH264 (BSD-2-Clause; see https://www.openh264.org/BINARY_LICENSE.txt). |
| 38 | +# - Takes ~5-10 min. |
| 39 | +# |
| 40 | +# Keep FFMPEG_VERSION and NVCODEC_VERSION in sync with docker/common/install_ffmpeg.sh. |
| 41 | + |
| 42 | +set -euo pipefail |
| 43 | + |
| 44 | +FFMPEG_VERSION=8.0.1 |
| 45 | +NVCODEC_VERSION=12.1.14.0 |
| 46 | +WITH_LIBOPENH264=0 |
| 47 | + |
| 48 | +usage() { |
| 49 | + cat <<'EOF' |
| 50 | +Usage: install_h264_support.sh [--with-libopenh264] [--FFMPEG_VERSION=<version>] |
| 51 | + [--NVCODEC_VERSION=<ver>] |
| 52 | +
|
| 53 | +Builds FFmpeg from source with software h264/hevc/av1 decoders enabled. |
| 54 | +
|
| 55 | +Options: |
| 56 | + --with-libopenh264 Also enable the libopenh264 software h264 ENCODER |
| 57 | + (Cisco's OpenH264 binary; required by Curator's |
| 58 | + --transcode-encoder=libopenh264 path). |
| 59 | + --FFMPEG_VERSION=<version> FFmpeg upstream release version (default: 8.0.1). |
| 60 | + --NVCODEC_VERSION=<ver> nv-codec-headers release version (default: 12.1.14.0). |
| 61 | + -h, --help Show this help. |
| 62 | +
|
| 63 | +License notice: |
| 64 | + Default mode enables only FFmpeg's internal h264/hevc/av1 decoders (LGPL). |
| 65 | + With --with-libopenh264 the build additionally links Cisco's OpenH264 |
| 66 | + binary (BSD-2-Clause + Cisco-distributed binary license; see |
| 67 | + https://www.openh264.org/BINARY_LICENSE.txt). By running this script you |
| 68 | + are responsible for any license obligations the resulting binaries impose |
| 69 | + on your distribution. |
| 70 | +EOF |
| 71 | +} |
| 72 | + |
| 73 | +for arg in "$@"; do |
| 74 | + case $arg in |
| 75 | + --with-libopenh264) WITH_LIBOPENH264=1 ;; |
| 76 | + --FFMPEG_VERSION=?*) FFMPEG_VERSION="${arg#*=}" ;; |
| 77 | + --NVCODEC_VERSION=?*) NVCODEC_VERSION="${arg#*=}" ;; |
| 78 | + -h|--help) usage; exit 0 ;; |
| 79 | + *) echo "Unknown argument: $arg" >&2; usage >&2; exit 2 ;; |
| 80 | + esac |
| 81 | +done |
| 82 | + |
| 83 | +if [ "$(id -u)" -ne 0 ]; then |
| 84 | + echo "ERROR: must be run as root inside the container." >&2 |
| 85 | + exit 1 |
| 86 | +fi |
| 87 | + |
| 88 | +echo "==> install_h264_support.sh: rebuilding ffmpeg ${FFMPEG_VERSION}" |
| 89 | +echo " Decoders added: h264, hevc, av1 (software)" |
| 90 | +if [ "$WITH_LIBOPENH264" -eq 1 ]; then |
| 91 | + echo " Encoder added: libopenh264 (Cisco OpenH264 binary)" |
| 92 | +fi |
| 93 | + echo " NOTE: This expands the container's codec footprint beyond Curator's" |
| 94 | + echo " default strict FFmpeg allowlist. License obligations of the resulting binaries" |
| 95 | +echo " are the user's responsibility." |
| 96 | +echo |
| 97 | + |
| 98 | +export DEBIAN_FRONTEND=noninteractive |
| 99 | +apt-get update |
| 100 | +apt_packages=( |
| 101 | + autoconf automake build-essential ca-certificates cmake |
| 102 | + libcrypt-dev libnuma-dev libtool libvpx-dev nasm pkg-config |
| 103 | + wget yasm zlib1g-dev |
| 104 | +) |
| 105 | +if [ "$WITH_LIBOPENH264" -eq 1 ]; then |
| 106 | + apt_packages+=(libopenh264-dev) |
| 107 | +fi |
| 108 | +apt-get install -y "${apt_packages[@]}" |
| 109 | + |
| 110 | +if [ ! -f /usr/local/include/ffnvcodec/dynlink_loader.h ]; then |
| 111 | + wget -O /tmp/nv-codec-headers.tar.gz \ |
| 112 | + "https://github.com/FFmpeg/nv-codec-headers/releases/download/n${NVCODEC_VERSION}/nv-codec-headers-${NVCODEC_VERSION}.tar.gz" |
| 113 | + tar xzf /tmp/nv-codec-headers.tar.gz -C /tmp/ |
| 114 | + (cd "/tmp/nv-codec-headers-${NVCODEC_VERSION}" && make && make install) |
| 115 | +fi |
| 116 | + |
| 117 | +cd /tmp |
| 118 | +rm -rf "ffmpeg-${FFMPEG_VERSION}" ffmpeg-snapshot.tar.bz2 |
| 119 | +wget -O /tmp/ffmpeg-snapshot.tar.bz2 \ |
| 120 | + "https://www.ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2" |
| 121 | +tar xjvf /tmp/ffmpeg-snapshot.tar.bz2 -C /tmp/ |
| 122 | +cd "/tmp/ffmpeg-${FFMPEG_VERSION}" |
| 123 | + |
| 124 | +# Configure mirrors install_ffmpeg.sh exactly, with the decoder allowlist |
| 125 | +# extended to include software h264/hevc/av1, and optionally the libopenh264 |
| 126 | +# software h264 encoder. |
| 127 | +encoder_list="rawvideo,libvpx_vp9,h264_nvenc,hevc_nvenc,av1_nvenc" |
| 128 | +extra_configure_flags=() |
| 129 | +if [ "$WITH_LIBOPENH264" -eq 1 ]; then |
| 130 | + encoder_list="${encoder_list},libopenh264" |
| 131 | + extra_configure_flags+=(--enable-libopenh264) |
| 132 | +fi |
| 133 | + |
| 134 | +PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" ./configure \ |
| 135 | + --prefix="/usr/local" \ |
| 136 | + --enable-shared \ |
| 137 | + --disable-static \ |
| 138 | + --extra-cflags="-I/usr/local/cuda/include" \ |
| 139 | + --extra-ldflags="-L/usr/local/cuda/lib64" \ |
| 140 | + --extra-libs="-lpthread -lm" \ |
| 141 | + --ld="g++" \ |
| 142 | + --enable-version3 \ |
| 143 | + --disable-everything \ |
| 144 | + --disable-network \ |
| 145 | + --disable-doc \ |
| 146 | + --disable-ffplay \ |
| 147 | + --disable-vaapi \ |
| 148 | + --disable-vdpau \ |
| 149 | + --disable-dxva2 \ |
| 150 | + --disable-libdrm \ |
| 151 | + --enable-encoder="${encoder_list}" \ |
| 152 | + --enable-decoder=rawvideo,libvpx_vp9,vp9,vp8,h264_cuvid,hevc_cuvid,av1_cuvid,mpeg1video,mpeg2video,mpeg4,h264,hevc,av1 \ |
| 153 | + --enable-muxer=mp4,rawvideo,image2pipe \ |
| 154 | + --enable-demuxer=mov,mp4,m4a,3gp,3g2,mj2,avi,matroska,webm,image2,image2pipe \ |
| 155 | + --enable-parser=h264,hevc,av1,vp8,vp9 \ |
| 156 | + --enable-bsf=h264_mp4toannexb,hevc_mp4toannexb \ |
| 157 | + --enable-protocol=file,pipe \ |
| 158 | + --enable-filter=scale,format,null,copy \ |
| 159 | + --enable-libvpx \ |
| 160 | + --enable-cuda \ |
| 161 | + --enable-cuvid \ |
| 162 | + --enable-nvdec \ |
| 163 | + --enable-nvenc \ |
| 164 | + --enable-ffnvcodec \ |
| 165 | + "${extra_configure_flags[@]}" |
| 166 | +make -j"$(nproc)" |
| 167 | +make install |
| 168 | +ldconfig |
| 169 | + |
| 170 | +cd / |
| 171 | +rm -rf /tmp/ffmpeg* /tmp/nv-codec-headers* |
| 172 | +echo |
| 173 | +if [ "$WITH_LIBOPENH264" -eq 1 ]; then |
| 174 | + echo "==> Done. /usr/local/bin/{ffmpeg,ffprobe} now include software h264/hevc/av1" |
| 175 | + echo " decoders and the libopenh264 software h264 encoder." |
| 176 | +else |
| 177 | + echo "==> Done. /usr/local/bin/{ffmpeg,ffprobe} now include software h264/hevc/av1 decoders." |
| 178 | +fi |
0 commit comments