Skip to content

About

Build FFmpeg with maximum static linking for all codecs, while keeping NVIDIA libraries dynamically linked (as required). This creates a highly portable FFmpeg binary with NVIDIA GPU acceleration support.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

FFmpeg Static Build with NVENC Support

Build FFmpeg with maximum static linking for all codecs, while keeping NVIDIA libraries dynamically linked (as required). This creates a highly portable FFmpeg binary with NVIDIA GPU acceleration support.

Features

  • ✅ Multi-Distro Support: "Works" on Debian, Ubuntu, RHEL, Fedora, CentOS, Arch Linux, openSUSE
  • ✅ Static Linking: All codec libraries statically linked with -fPIC for PIE compatibility
  • ✅ NVIDIA Support: CUDA, NVENC, CUVID hardware acceleration (10x+ realtime encoding)
  • ✅ VAAPI Support: Intel/AMD hardware acceleration
  • ✅ Latest Versions: FFmpeg 8.0.1, NASM 2.16.03, AOM 3.13.1, and latest stable codecs
  • ✅ Production Ready: Tested with H.264 and HEVC NVENC encoding

Supported Codecs

Video Codecs

  • H.264/AVC: libx264 (software), h264_nvenc (NVIDIA), h264_vaapi (VAAPI)
  • H.265/HEVC: libx265 (software), hevc_nvenc (NVIDIA), hevc_vaapi (VAAPI)
  • VP8/VP9: libvpx
  • AV1: libaom (software encoder/decoder), av1_nvenc (NVIDIA - RTX 40 series+)

Audio Codecs

  • MP3: libmp3lame
  • AAC: libfdk-aac
  • Opus: libopus
  • Vorbis: libvorbis
  • Theora: libtheora

Requirements

  • Linux distribution with one of these package managers: apt, dnf, yum, pacman, or zypper
  • NVIDIA GPU (optional, for NVENC support)
  • NVIDIA drivers installed (optional, for GPU acceleration)
  • Root/sudo access for installing dependencies

Quick Start

Build Everything

Run the master build script to build all components:

cd scripts
./build-all.sh

This will:

  1. Install system dependencies
  2. Install NVIDIA CUDA toolkit
  3. Build all codec libraries
  4. Build FFmpeg with all features
  5. Run validation tests

Individual Component Build

You can also build components individually:

cd scripts

# Install dependencies
./dependencies.sh

# Install NVIDIA CUDA
./nv-cuda-sdk.sh

# Build assemblers
./nasm.sh
./yasm.sh

# Install NVIDIA codec headers
./nv-codec-header.sh

# Build video codecs
./x264.sh
./x265.sh
./libvpx.sh
./aom.sh

# Build audio codecs
./opus.sh
./lame.sh
./libfdk-aac.sh

# Build FFmpeg
./ffmpeg.sh

# Validate build
./validation.sh

Configuration

Edit vars.sh to customize:

# Library versions
NASM_VERSION="3.01"
X264_BRANCH="master"
X265_VERSION="4.1"
VPX_VERSION="v1.15.2"
FFMPEG_VERSION="8.0.1"
# ... and more

# Build directories
WORK_DIR="/tmp/sources"    # Where source files are downloaded
DEST_DIR="/usr/local"      # Where FFmpeg will be installed

# CUDA location
CUDA_DIR="/usr/local/cuda"

# Enable CUDA validation tests
VALIDATE_CUDA="false"  # Set to "true" to test CUDA encoding

# Library versions
NASM_VERSION="2.16.03"      # Updated for AOM compatibility
X265_VERSION="4.1"
VPX_VERSION="v1.15.2"
AOM_VERSION="v3.13.1"
FFMPEG_VERSION="8.0.1"

Supported Distributions

Debian/Ubuntu

# Uses apt package manager
# Tested on Debian 12 (Bookworm) and Ubuntu 22.04/24.04

RHEL/Fedora/CentOS

# Uses dnf/yum package manager
# Tested on Fedora 39+ and RHEL 8/9

Build Troubleshooting

NVENC Not Working

If NVENC encoders are not available:

  1. Check NVIDIA drivers:

    nvidia-smi
  2. Verify CUDA libraries:

    ls -la /usr/local/cuda/lib64/libnvcuvid.so*
  3. Check FFmpeg NVENC support:

    /usr/local/bin/ffmpeg -encoders | grep nvenc

Library Path Issues

If you get library errors:

# Update library cache
sudo ldconfig

# Check library paths
echo $LD_LIBRARY_PATH
ldd /usr/local/bin/ffmpeg

AOM/NASM Build Failures

If AOM build fails with NASM errors:

  • NASM 2.16.03+ is required for AOM v3.13+
  • The build scripts use the correct version
  • Rebuild NASM: sudo ./scripts/nasm.sh

Position Independent Code (PIC) Errors

If you get relocation errors during FFmpeg build:

  • All static libraries must be built with -fPIC
  • The scripts automatically add these flags
  • Rebuild the failing library with: sudo ./scripts/<library>.sh

Arch Linux

# Uses pacman package manager
# Tested on Arch Linux (rolling release)

openSUSE/SLES

# Uses zypper package manager
# Tested on openSUSE Leap/Tumbleweed

Output

The FFmpeg binary will be located at:

/usr/local/bin/ffmpeg

Check Static/Dynamic Linking

To verify which libraries are statically vs dynamically linked:

ldd /usr/local/bin/ffmpeg

Expected dynamic dependencies:

  • linux-vdso.so.1 (kernel interface)
  • libcuda.so.1 (NVIDIA CUDA)
  • libnvcuvid.so.1 (NVIDIA Video Decoder)
  • libnvidia-encode.so.1 (NVIDIA Encoder)
  • Standard system libraries (libc, libm, libpthread, libdl)

All codec libraries (x264, x265, vpx, opus, etc.) should NOT appear in the output.

Performance

NVENC Hardware Encoding

Expected performance with NVENC (actual speeds vary by GPU):

  • H.264 NVENC: 10-15x realtime @ 1080p
  • HEVC NVENC: 8-12x realtime @ 1080p
  • Power efficiency: ~90% less CPU usage vs software encoding
  • Quality: Comparable to software encoding at higher bitrates

Software Encoding

  • libx264: 1-4x realtime (depends on preset)
  • libx265: 0.5-2x realtime (slower but better compression)
  • libaom-av1: 0.1-0.5x realtime (best compression, very slow)

Usage Examples

Software Encoding (CPU)

# H.264 encoding with libx264
/usr/local/bin/ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 output.mp4

# H.265 encoding with libx265
/usr/local/bin/ffmpeg -i input.mp4 -c:v libx265 -preset medium -crf 28 output.mp4

Hardware Encoding (NVENC)

# H.264 NVENC encoding
/usr/local/bin/ffmpeg -i input.mp4 -c:v h264_nvenc -preset fast -b:v 5M output.mp4

# HEVC NVENC encoding
/usr/local/bin/ffmpeg -i input.mp4 -c:v hevc_nvenc -preset fast -b:v 5M output.mp4

# NVENC with hardware decoding
/usr/local/bin/ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input.mp4 -c:v h264_nvenc -preset fast output.mp4
/ffmpeg-static/bin/ffmpeg -i input.mp4 -c:v libx265 -preset medium -crf 28 output.mp4

# VP9 encoding
/ffmpeg-static/bin/ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 2M output.webm

# AV1 encoding
/ffmpeg-static/bin/ffmpeg -i input.mp4 -c:v libaom-av1 -b:v 2M output.mp4

Hardware Encoding (NVIDIA NVENC)

# H.264 with NVENC
/ffmpeg-static/bin/ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc -preset p4 -b:v 5M output.mp4

# H.265 with NVENC
/ffmpeg-static/bin/ffmpeg -hwaccel cuda -i input.mp4 -c:v hevc_nvenc -preset p4 -b:v 5M output.mp4

# With CUDA hardware acceleration
/ffmpeg-static/bin/ffmpeg -vsync 0 -hwaccel cuda -hwaccel_output_format cuda \
  -i input.mp4 -c:v h264_nvenc -b:v 5M output.mp4

Hardware Encoding (VAAPI - Intel/AMD)

# H.264 with VAAPI
/ffmpeg-static/bin/ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \
  -i input.mp4 -c:v h264_vaapi -b:v 5M output.mp4

# H.265 with VAAPI
/ffmpeg-static/bin/ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \
  -i input.mp4 -c:v hevc_vaapi -b:v 5M output.mp4

Troubleshooting

NVIDIA CUDA Not Found

If you see CUDA-related errors during build:

  1. Check CUDA installation:

    ls -la /usr/local/cuda
    nvcc --version
  2. Update CUDA_DIR in vars.sh if CUDA is in a different location

  3. Ensure NVIDIA drivers are installed:

    nvidia-smi

Package Manager Not Supported

If your distribution isn't automatically detected:

  1. Check dependencies.sh for the list of required packages
  2. Install them manually using your package manager
  3. Continue with the build scripts

Build Failures

If a component fails to build:

  1. Check the error message
  2. Ensure all dependencies are installed
  3. Check if you have enough disk space (build requires ~5GB)
  4. Try building components individually to isolate the issue

Version Information

Current Versions (as of January 2026):

  • FFmpeg: 8.0.1
  • x264: latest (master branch)
  • x265: 4.1
  • libvpx: 1.15.2
  • AOM: 3.13.1
  • NASM: 3.01
  • NVIDIA Codec Headers: 13.0.19.0

License

This build script collection is provided as-is. Individual components (FFmpeg, x264, x265, etc.) have their own licenses:

  • FFmpeg: GPL/LGPL (depending on configuration)
  • x264: GPL
  • x265: GPL
  • libfdk-aac: Fraunhofer FDK AAC (check license restrictions)
  • Others: See individual component licenses

Contributing

To update versions, edit vars.sh and update the version variables.

Credits

Maintained by: Daniel Ramirez Based on FFmpeg static build practices for NVENC support.

About

Build FFmpeg with maximum static linking for all codecs, while keeping NVIDIA libraries dynamically linked (as required). This creates a highly portable FFmpeg binary with NVIDIA GPU acceleration support.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages