Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

139.2. x265-4.2

HEVC encoder — GPL-2+

Version 4.2, release 1
Shelf video-libs — Video codecs, containers, subtitles, disc playback and effects libraries
Phase 41_system (System), 693 of 1047 in build order
Licence GPL-2.0-or-later
Homepage https://www.videolan.org/developers/x265.html
Build time 15.0 SBU
Installed size 24.2 MiB in 9 files
Recipe ports/core/video-libs/x265/kpkgbuild

About

x265 is the HEVC (H.265) encoder library and its x265 command line; ffmpeg and the GStreamer plugins encode HEVC through it. It is GPL-2.0-or-later, like x264, and what linking it does to the licence of the shipped ffmpeg is recorded in the ffmpeg port’s LICENSE.notice, which the phase list names beside the two encoders.

This build makes one libx265.so that carries the 8-, 10- and 12-bit encoders. x265 compiles one bit depth per configure, so build.sh configures three times, in build-12, build-10 and build-8, following upstream’s build/linux/multilib.sh; the public API of the one library then selects the encoder for the bit depth a caller asks for. Main10 is the depth of HDR video and of most HEVC archives, and an 8-bit-only library makes ffmpeg’s libx265 encoder refuse every 10-bit pixel format.

Why it is in KDOS

The comment above the 4 ports from x264 to svt-av1 in script/phases/41_system/packages.d/video-libs.txt:

ffmpeg and the gst plugin packages are configured against these and are only as capable as what is installed: each of those build systems answers a missing library by disabling the feature rather than failing. One encoder per format: adding a second earns nothing. See ports/core/media-frameworks/ffmpeg/LICENSE.notice for what --enable-gpl does to the shipped binary's licence.

Sources

Dependencies

Depends on: cmake, nasm.

Required by (6): avidemux, digikam, ffmpeg, gst-plugins-bad, libheif, vlc.

Optional, off in KDOS

These switches in build.sh turn off a feature whose library is a port here. The recipe may turn each off on purpose, or because the library was not yet a port when the recipe was written; this list cannot tell which.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install x265'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/video-libs/x265.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/video-libs/x265
echo '40b1ea0453e0309f0eba934e0ddf533f8f6295966679e8894e8f1c1c8d5e1210  x265-4.2.tar.gz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/x265
SRC=$SRC_ROOT/x265-4.2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf x265-4.2.tar.gz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

export CXXFLAGS="$CXXFLAGS -include cstdint -frandom-seed=x265"
export CFLAGS="$CFLAGS -frandom-seed=x265"
common=(
	-DCMAKE_POLICY_VERSION_MINIMUM=3.5
	-DCMAKE_BUILD_TYPE=Release
	-DCMAKE_INSTALL_PREFIX=/usr
	-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
	-DENABLE_ASSEMBLY=ON
	-DENABLE_HDR10_PLUS=ON
	-DENABLE_LIBNUMA=OFF
	-DENABLE_TESTS=OFF
)

mkdir -p build-12 build-10 build-8

cd build-12
cmake ../source "${common[@]}" \
	-DHIGH_BIT_DEPTH=ON -DMAIN12=ON \
	-DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF
make
cd ..

cd build-10
cmake ../source "${common[@]}" \
	-DHIGH_BIT_DEPTH=ON \
	-DEXPORT_C_API=OFF -DENABLE_SHARED=OFF -DENABLE_CLI=OFF
make
cd ..

cd build-8
ln -sf ../build-10/libx265.a libx265_main10.a
ln -sf ../build-12/libx265.a libx265_main12.a
cmake ../source "${common[@]}" \
	-DENABLE_SHARED=ON \
	-DENABLE_CLI=ON \
	-DEXTRA_LIB="x265_main10.a;x265_main12.a" \
	-DEXTRA_LINK_FLAGS=-L. \
	-DLINKED_10BIT=ON -DLINKED_12BIT=ON
make
make DESTDIR=$PKG install
cd ..

rm -f "$PKG/usr/lib/libx265.a" "$PKG/usr/lib/libhdr10plus.a"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/x265, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf x265-4.2-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/x265, and runs the triggers its paths call for.

Contents

Installed programs: x265.

Installed libraries: libhdr10plus.so, libx265.so.

Installed directories: /usr/share/licenses/x265.

Short descriptions

x265.pc H.265/HEVC video encoder

Notes

The final link warns that x265_analysis_distortion_data breaks the one-definition rule: its ctuDistortion member points at sse_t, which is 32 bits wide at 8-bit depth and 64 above. The warning is expected. The structure’s layout is the same at every depth, and the three encoders reach one another only through the API table.

make install in build-8 installs a libx265.a and a libhdr10plus.a as well, and build.sh removes both. Upstream’s script merges the three depths into one archive with ar -M; this build does not, so the installed libx265.a would be the 8-bit encoder alone, referring to 10- and 12-bit encoders that no installed archive holds. Nothing in the tree links either library statically.