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
x265-4.2.tar.gz(1.7 MiB)
sha25640b1ea0453e0309f0eba934e0ddf533f8f6295966679e8894e8f1c1c8d5e1210
upstream: https://bitbucket.org/multicoreware/x265_git/downloads/x265_4.2.tar.gz
archive copy: sources-4/video-libs--x265-4.2.tar.gz
Dependencies
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.
-DENABLE_LIBNUMA=OFF, line 21: numactl (explained with the switches below)
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:
-include cstdint— Include<cstdint>at the top of every C++ file. The vendored json11 that the HDR10+ code is built on usesuint8_twithout including the header, and none of the libstdc++ headers it does include brings it in, so every depth fails to compile without it.-frandom-seed=x265— Fix the names GCC gives each object’s LTO sections, which are otherwise random, so the two static archives the 8-bit link reads come out the same on every build (see Every port).-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON— Link-time optimisation, in all three builds. x265 is one of the media libraries the tree builds with LTO.-DENABLE_ASSEMBLY=ON— Use the hand-written assembly primitives, assembled with nasm. Upstream turns it on for x86-64 only when it finds a recent enough nasm; naming it keeps it on, so a missing assembler fails the build instead of making a slow encoder.-DENABLE_HDR10_PLUS=ON— Build the HDR10+ dynamic-metadata support and itslibhdr10plus.so. Off by default upstream. It is on in all three builds: the metadata belongs to 10-bit video, and a depth’s encoder can write it only when that depth is compiled with it.-DENABLE_LIBNUMA=OFF— Upstream’s default is to link libnuma whenever it finds it, for thread pools placed by NUMA node on multi-socket machines. Off, the library links no libnuma whatever the build root holds.-DENABLE_TESTS=OFF— Leave out upstream’s unit-test program. It is upstream’s default.-DHIGH_BIT_DEPTH=ON,-DMAIN12=ON— Store samples in 16 bits, and withMAIN12encode 12-bit rather than 10-bit. The first build has both, the second onlyHIGH_BIT_DEPTH.-DEXPORT_C_API=OFF— In the 12- and 10-bit builds, leave out the public C API, whose symbols would collide with the 8-bit library’s when all three are linked into one; those encoders are reached through the 8-bit library’s API.-DENABLE_SHARED=OFF,-DENABLE_CLI=OFF— Build the 12- and 10-bit encoders as static archives only, with nox265program; they exist to be linked into the third build. The third sets-DENABLE_SHARED=ONand-DENABLE_CLI=ON.-DEXTRA_LIB="x265_main10.a;x265_main12.a"— Link the 10- and 12-bit archives into the 8-bit shared library and program. The two names are symbolic linksbuild.shmakes inbuild-8to each build’slibx265.a.-DEXTRA_LINK_FLAGS=-L.— Add the build directory to the library search path, where those links are.-DLINKED_10BIT=ON,-DLINKED_12BIT=ON— Tell the 8-bit build that the 10- and 12-bit encoders are linked in, so its API hands a request for either depth to them.
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.