Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

FFmpeg Builder for AWS Graviton

Build optimized FFmpeg packages (RPM/DEB) for AWS Graviton processors and x86_64.

What is this for?

Getting the best video encoding performance on AWS Graviton requires recent versions of FFmpeg and codec libraries (x264, x265, libaom, SVT-AV1) built with Graviton-optimized compiler flags. Distribution packages are often outdated and miss performance improvements.

This tool makes it easy to build optimized, up-to-date FFmpeg packages with a single command.

Features

  • Single-file Python script for building FFmpeg with common codecs
  • Produces native packages (RPM for Amazon Linux, DEB for Ubuntu)
  • Optimized for Graviton2/3/4 and x86_64 (AVX2/AVX512)
  • Includes x264, x265 (8-bit + 10-bit), AOM, SVT-AV1, and Opus
  • Docker-based builds for reproducibility
  • Test mode to verify packages work correctly

Requirements

  • Python 3.8+
  • Docker
  • Git
  • ~10GB disk space for sources and build

Quick Start

# Generate a config file with detected defaults
./build_ffmpeg.py generate-config

# Edit config if needed
vim ffmpeg_build_config.json

# Build everything (clone, update, build, test)
./build_ffmpeg.py all

Commands

CommandDescription
generate-configCreate sample config file with host defaults
cloneClone all source repositories
updateUpdate sources to target commits/branches
buildBuild the package
testTest the built package in a fresh container
allRun clone, update, build, and test

CLI Options

Options can override config file settings:

./build_ffmpeg.py -d ubuntu-noble -p graviton4 -C clang-latest build
OptionDescription
-c, --configConfig file path (default: ffmpeg_build_config.json)
-d, --distroTarget distro (overrides config)
-p, --platformTarget platform (overrides config)
-C, --compilerCompiler (overrides config)
-l, --logLog file path (includes all docker build output)
--no-logDisable automatic logging (see below)

Logging

When --log <path> is specified, all output including docker build output is written to the given file. When running non-interactively (stdout is not a tty) and --log is not specified, a log file is auto-generated in the script directory. Use --no-log to disable this automatic behavior.

Configuration

The config file (ffmpeg_build_config.json) supports:

{
  "target_distro": "al2023",
  "compiler": "clang",
  "target_platform": "graviton3",
  "build_type": "release",
  "version": "1.0.0",
  "package_name": "ffmpeg-optimized",
  "repos": { ... },
  "commit_overrides": { "ffmpeg": "n7.0" }
}

Options

  • target_distro: al2023, ubuntu-jammy, ubuntu-noble, ubuntu-resolute
  • target_platform: graviton2, graviton3, graviton4, avx2, avx512
  • compiler: gcc, clang, gcc-latest, clang-latest, or specific versions (see below)
  • build_type: “release” (latest tags) or “tip” (main branches)
  • commit_overrides: Pin specific projects to exact commits/tags

Available compilers by distro:

  • AL2023: gcc (11), gcc11, gcc14, clang (15), clang15, clang18, clang19
  • Ubuntu Jammy: gcc (11), gcc9-12, clang (14), clang11-14
  • Ubuntu Noble: gcc (13), gcc9-14, clang (18), clang14-20
  • Ubuntu Resolute: gcc (13), gcc9-14, clang (18), clang14-20

Use gcc-latest or clang-latest to automatically select the newest available version.

Output

Packages are written to ./output/:

  • Amazon Linux: ffmpeg-optimized-1.0.0-1.*.rpm
  • Ubuntu: ffmpeg-optimized_1.0.0_arm64.deb

The package includes both 8-bit and 10-bit FFmpeg builds:

  • ffmpeg, ffprobe - 8-bit x265
  • ffmpeg-10bit, ffprobe-10bit - 10-bit x265

Example Workflows

Build for Graviton4 on Amazon Linux 2023

./build_ffmpeg.py generate-config
# Edit config: set target_platform to "graviton4"
./build_ffmpeg.py all

Build specific FFmpeg version

# In config, add:
# "commit_overrides": { "ffmpeg": "n7.0" }
./build_ffmpeg.py all

Build for Ubuntu Noble

# In config, set:
# "target_distro": "ubuntu-noble"
./build_ffmpeg.py all

Included Codecs

CodecLibraryNotes
H.264libx264
H.265/HEVClibx2658-bit + 10-bit
AV1libaomReference encoder
AV1SVT-AV1Standalone binary only (see note below)
OpuslibopusAudio

Note on SVT-AV1: The package includes the SvtAv1EncApp encoder binary but SVT-AV1 is not linked into FFmpeg due to API incompatibilities between recent SVT-AV1 versions and FFmpeg. You can use the standalone encoder directly for AV1 encoding, but cannot access it via FFmpeg’s -c:v libsvtav1 option. For FFmpeg-integrated AV1 encoding, use -c:v libaom-av1 instead.

Customization

Adding a New Library

  1. Add repo URL and tag pattern to build_ffmpeg.py (see DEFAULT_REPOS, TAG_PATTERNS)
  2. Create scripts/build-<name>.sh (copy build-opus.sh as template)
  3. Add build stage to Dockerfile:
    FROM base AS <name>
    COPY sources/<name> sources/<name>
    RUN PREFIX=/usr/local scripts/build-<name>.sh
    
  4. Add COPY --from=<name> /usr/local /usr/local to both ffmpeg stages in Dockerfile
  5. Add --enable-lib<name> to scripts/build-ffmpeg.sh

Adding a New Distro

  1. Add image to DISTRO_IMAGES in build_ffmpeg.py
  2. Add compiler mapping to DISTRO_COMPILERS in build_ffmpeg.py
  3. Add dependency function to scripts/install-dependencies.sh

Tested Configurations

Run ./test_matrix.py to test all distro/compiler combinations. Results are printed to stdout and saved to a timestamped summary file (test_matrix_<timestamp>_<arch>.log). Individual build logs with full docker output are written to the test_logs/ directory.

aarch64 (Graviton)

DistroCompilerStatusNotes
al2023gcc
al2023gcc14
al2023clang
al2023clang-latest
ubuntu-jammygcc
ubuntu-jammyclang
ubuntu-jammygcc-latest
ubuntu-jammyclang-latest
ubuntu-jammygcc12
ubuntu-noblegcc
ubuntu-nobleclang
ubuntu-noblegcc-latest
ubuntu-nobleclang-latest
ubuntu-noblegcc14
ubuntu-resolutegcc
ubuntu-resoluteclang
ubuntu-resolutegcc-latest
ubuntu-resoluteclang-latest
ubuntu-resolutegcc14

x86_64

DistroCompilerStatusNotes
al2023gcc
al2023clang
al2023gcc-latest
al2023clang-latest
al2023gcc14
ubuntu-jammygcc
ubuntu-jammyclang
ubuntu-jammygcc-latest
ubuntu-jammyclang-latest
ubuntu-jammygcc12
ubuntu-noblegcc
ubuntu-nobleclang
ubuntu-noblegcc-latest
ubuntu-nobleclang-latest
ubuntu-noblegcc14
ubuntu-resolutegccaom fails: nasm 3.x incompatible
ubuntu-resoluteclangaom fails: nasm 3.x incompatible
ubuntu-resolutegcc-latestaom fails: nasm 3.x incompatible
ubuntu-resoluteclang-latestaom fails: nasm 3.x incompatible
ubuntu-resolutegcc14aom fails: nasm 3.x incompatible

License

The build script is provided under the same license as the aws-graviton-getting-started repository. FFmpeg and included libraries have their own licenses (GPL, LGPL, BSD, etc.).