Skip to content

Instantly share code, notes, and snippets.

@rromanchuk
Last active May 10, 2024 03:28
Show Gist options
  • Save rromanchuk/d14901b520e5da3a496efd05b0a9bcf9 to your computer and use it in GitHub Desktop.
Save rromanchuk/d14901b520e5da3a496efd05b0a9bcf9 to your computer and use it in GitHub Desktop.
Building ffmpeg with x265 NEON arm64 cpu acceleration support (Ubuntu LTS, t4g, a1 ec2 family)

Building ffmpeg with x265 NEON arm64 cpu acceleration support

Current static binaries do not target https://bitbucket.org/multicoreware/x265_git/issues/563/patch-neon-arm64-improvements which can be identified

Before

x265 [info]: using cpu capabilities: none!

[libx264 @ 0xaaab0a5fc000] using cpu capabilities: ARMv8 NEON

After

x265 [info]: HEVC encoder version 3.5+1-f0c1022b6
x265 [info]: build info [Linux][GCC 9.3.0][32 bit] 8bit
x265 [info]: using cpu capabilities: NEON

[libx264 @ 0xaaab0a5fc000] using cpu capabilities: ARMv8 NEON

When buidling, do not count on apt, everything is old as hell. Target master @ HEAD

sudo apt-get install libnuma-dev && \
cd ~/ffmpeg_sources && \
wget -O x265.tar.bz2 https://bitbucket.org/multicoreware/x265_git/get/master.tar.bz2 && \
tar xjvf x265.tar.bz2 && \
cd multicoreware*/build/linux && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off ../../source && \
PATH="$HOME/bin:$PATH" make && \
make install
#!/bin/bash
export PATH="/home/ubuntu/bin:$PATH"
which ffmpeg
ffmpeg -i in.mp4 -pix_fmt:v 'yuv420p' \
-codec:v 'libx265' -codec:a copy \
-flags +cgop -g 60 -tag:v hvc1 -x265-params:v bframes=0:keyint=60:min-keyint=60 \
out.mp4
mkdir -p ~/ffmpeg_sources ~/bin
#
# sudo apt-get update -qq && sudo apt-get -y install \
# autoconf \
# automake \
# build-essential \
# cmake \
# git-core \
# libass-dev \
# libfreetype6-dev \
# libgnutls28-dev \
# libmp3lame-dev \
# libsdl2-dev \
# libtool \
# libva-dev \
# libvdpau-dev \
# libvorbis-dev \
# libxcb1-dev \
# libxcb-shm0-dev \
# libxcb-xfixes0-dev \
# meson \
# ninja-build \
# pkg-config \
# texinfo \
# wget \
# yasm \
# zlib1g-dev
# NASM
cd ~/ffmpeg_sources && \
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.bz2 && \
tar xjvf nasm-2.15.05.tar.bz2 && \
cd nasm-2.15.05 && \
./autogen.sh && \
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && \
make && \
make install
# x264
cd ~/ffmpeg_sources && \
git -C x264 pull 2> /dev/null || git clone --depth 1 https://code.videolan.org/videolan/x264.git && \
cd x264 && \
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --enable-pic && \
PATH="$HOME/bin:$PATH" make && \
make install
# x265
sudo apt-get install libnuma-dev && \
cd ~/ffmpeg_sources && \
wget -O x265.tar.bz2 https://bitbucket.org/multicoreware/x265_git/get/master.tar.bz2 && \
tar xjvf x265.tar.bz2 && \
cd multicoreware*/build/linux && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off ../../source && \
PATH="$HOME/bin:$PATH" make && \
make install
# libfdk-aac
cd ~/ffmpeg_sources && \
git -C fdk-aac pull 2> /dev/null || git clone --depth 1 https://github.com/mstorsjo/fdk-aac && \
cd fdk-aac && \
autoreconf -fiv && \
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && \
make && \
make install
# libdav1d
sudo apt-get install python3-pip && \
pip3 install --user meson
cd ~/ffmpeg_sources && \
git -C dav1d pull 2> /dev/null || git clone --depth 1 https://code.videolan.org/videolan/dav1d.git && \
mkdir -p dav1d/build && \
cd dav1d/build && \
meson setup -Denable_tools=false -Denable_tests=false --default-library=static .. --prefix "$HOME/ffmpeg_build" --libdir="$HOME/ffmpeg_build/lib" && \
ninja && \
ninja install
# ffmpeg
cd ~/ffmpeg_sources && \
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
tar xjvf ffmpeg-snapshot.tar.bz2 && \
cd ffmpeg && \
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--extra-libs="-lpthread -lm" \
--ld="g++" \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libx265 \
--enable-libx264 \
--enable-libdav1d \
--enable-libfdk-aac \
--enable-nonfree && \
PATH="$HOME/bin:$PATH" make && \
make install && \
hash -r
@prime-optimal
Copy link

You're a hero! Thanks so much! It's so hard to find info on how to do this on Linux (I'm using OCI free tier lol but hey it works with ARM!). Cheers 🥂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment