In part one of this series, I tried the installed ffmpeg version on the OrangePi RK3399, and made a few assumptions. Now, let’s try to compile ffmpeg on this very machine, if that could ever help us getting hardware acceleration.

This article was supposed to be enhanced with animated SVG files, but Medium can’t handle them. So you’ll see an heterogeneous mix of GIF and YouTube links (BTW, why do some links give an embedded video, and some not?). Sorry for that.

As I’m french, better setup the keyboard before doing anything else.

sudo dpkg-reconfigure keyboard-configuration

Now, let’s download the whole Internet on this poor machine before trying to compile anything:

Let’s add a backport repo in order to get more recent packages. By the way, which Debian version are we running?

cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Let’s edit /etc/apt/sources.list and add this line: deb https://deb.debian.org/debian stretch-backports main

Once it’s done, let’s issue a :

sudo apt update
sudo aptitude -t stretch-backports dist-upgrade

https://youtu.be/rzUPW4JNyOQ

Now that the machine is up to date, let’s download and install what’s missing:

sudo apt -t stretch-backports install -y autoconf automake autotools-dev build-essential ccache checkinstall cleancss cmake debhelper dh-exec doxygen flite1-dev frei0r-plugins-dev git gnutls-bin graphviz ladspa-sdk libarchive-dev libass-dev libavc1394-dev libavcodec-dev libavcodec-extra libavdevice57 libavfilter6 libavformat-dev libavformat57 libbluray-dev libbs2b-dev libbz2-dev libc6 libcaca-dev libcdio-paranoia-dev libchromaprint-dev libcodec2-dev libcunit1-dev libcurl4-openssl-dev libdc1394-22-dev libdrm-dev libfdk-aac-dev libgl1-mesa-dev libglew-dev libglfw3-dev libgme-dev libgmp-dev libgnutls28-dev libgsm1-dev libgtest-dev libiec61883-dev libjack-jackd2-dev sudo apt-get install libjpeg-dev libjsoncpp-dev liblensfun-dev liblilv-0-0 liblilv-dev libmodplug-dev libmp3lame-dev libnss-mdns libogg-dev libomxil-bellagio-dev libopenal-dev libopencore-amrnb-dev libopencore-amrwb-dev libopenjp2-7-dev libopenmpt-dev libopus-dev libpciaccess-dev libpciaccess0 libperl-dev libpulse-dev librsvg2-dev librtmp-dev librubberband-dev libsctp-dev libsdl2-dev libshine-dev libsnappy-dev libsoxr-dev libspeex-dev libssh-dev libssh-gcrypt-dev libswresample-dev libtheora-dev libtool libtwolame-dev libuv1-dev libv4l-dev libva-dev libvdpau-dev libvo-amrwbenc-dev libvorbis-dev libvpx-dev libwavpack-dev libwebp-dev libx11-dev libx264-dev libx265-dev libxvidcore-dev libzmq3-dev libzvbi-dev mercurial nasm node-less pkg-config po4a python3-docutils python3-sphinx software-properties-common texinfo tree vainfo vdpau-va-driver xorg-dev yasm zlib1g-dev

I’m not so sure we need all of that, but I lost track of what I installed day to day, so this is a concatenation of everything I think we could ever need. As you can see, we have a few packages missing, so we will have to build them by ourselves. First of all is libmysofa, which we will get directly from Debian Sid:

cd ~/ffmpeg_sources
wget http://deb.debian.org/debian/pool/main/libm/libmysofa/libmysofa_0.8~dfsg0.orig.tar.xz
xz -d libmysofa_0.8~dfsg0.orig.tar.xz && tar -xvf libmysofa_0.8~dfsg0.orig.tar && rm libmysofa_0.8~dfsg0.orig.tar
cd libmysofa-0.8/ && wget http://deb.debian.org/debian/pool/main/libm/libmysofa/libmysofa_0.8~dfsg0-1.debian.tar.xz
xz -d libmysofa_0.8~dfsg0-1.debian.tar.xz && tar -xvf libmysofa_0.8~dfsg0-1.debian.tar && rm libmysofa_0.8~dfsg0-1.debian.tar
sudo apt -t stretch-backports install dh-exec cmake libcunit1-dev
wget http://deb.debian.org/debian/pool/main/libm/libmysofa/libmysofa_0.8~dfsg0.orig.tar.xz && mv libmysofa_0.8~dfsg0.orig.tar.xz ..
sudo -E dpkg-buildpackage -us -uc
find .. -name "*sofa*deb" -exec sudo dpkg -i {} \; -print
echo "Great!"

Now, regarding libncurses, libncurses5-dev could be the answer, so sudo apt -t stretch-backports install libncurses5-dev should do the trick.

Now for libvidstab:

cd ~/ffmpeg_sources
wget http://deb.debian.org/debian/pool/main/libv/libvidstab/libvidstab_1.1.0.orig.tar.gz
tar -xvzf libvidstab_1.1.0.orig.tar.gz
cd vid.stab-1.1.0/ && wget http://deb.debian.org/debian/pool/main/libv/libvidstab/libvidstab_1.1.0-2.debian.tar.xz
xz -d libvidstab_1.1.0-2.debian.tar.xz && tar -xvf libvidstab_1.1.0-2.debian.tar && rm libvidstab_1.1.0-2.debian.tar
sudo -E dpkg-buildpackage -us -uc
find .. -name "*vid*stab*deb" -exec sudo dpkg -i {} \; -print

https://youtu.be/RgDqKJiJTGs

cd ~/ffmpeg_sources
wget http://www.nasm.us/pub/nasm/releasebuilds/2.14rc0/nasm-2.14rc0.tar.gz
tar xzvf nasm-2.14rc0.tar.gz
cd nasm-2.14rc0
./configure --prefix="$HOME/bin" --bindir="$HOME/bin"
make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

Now, let’s build x264

https://youtu.be/yggvZ1Tr3Ww

cd ~/ffmpeg_sources
git clone http://git.videolan.org/git/x264.git -b stable
cd x264/
export CFLAGS="-mfpu=neon"
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/bin" --bindir="$HOME/bin" --enable-pic --enable-static --disable-cli --disable-asm --host=arm-linux --disable-opencl
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install VERBOSE=1
make -j$(nproc) distclean

I had to disable ASM and to add the mfpu cflag for it to work, see this issue.

Now, let’s compile fdk-aac

https://youtu.be/NqAt8shaYcQ

cd ~/ffmpeg_sources
wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --prefix="$HOME/bin" --disable-shared
make -j$(nproc)
make -j$(nproc) install
make -j$(nproc) distclean

Let’s have a look at libvpx:

https://youtu.be/CXa_BdPrY6E

cd ~/ffmpeg_sources
git clone https://chromium.googlesource.com/webm/libvpx
cd libvpx
./configure
make -j${nproc}
sudo make install
g++: internal compiler error: Killed (program cc1plus)

As you can see, I got some strange errors saying that the compiler had an internal error… Google told me later on that it could be linked to not having enough memory.

I checked during the build with htop, and that was the case. Of course, I was using the 6 cores, so that was not the best thing to do with memory hungry compiler instances.

But anyway, as I already had a SSD plugged into this machine, let’s make use of it.

dd if=/dev/zero of=/media/linaro/0E9ACA2339F586E/swap.img bs=1024k count=10000 # Ten Gigs should be enough
sudo su -
free
mkswap /media/linaro/0E9ACA2339F586E5/swap.img
swapon /media/linaro/0E9ACA2339F586E5/swap.img
free

Up to now, everything looks ok, now let’s configure and compile FFmpeg with fewer options before going too far, if ever there was a BIG blocking point somewhere:

https://youtu.be/Zo2Z7_o5Y1o

cd ~/ffmpeg_sources/FFmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --pkg-config-flags="--static" --prefix="$HOME/bin" --extra-cflags="-I$HOME/bin/include" --extra-ldflags="-L$HOME/bin/lib" --extra-cflags="-I/usr/local/include" --extra-ldflags="-L/usr/local/lib" --bindir="$HOME/bin" --enable-debug=3 --enable-vaapi --enable-libvorbis --enable-libvpx --disable-debug --enable-gpl --cpu=native --enable-opengl --enable-libfdk-aac --enable-libx264 --enable-libx265 --extra-libs=-lpthread --enable-nonfree --arch=arm
PATH="$HOME/bin:$PATH" make -j$(nproc)
make -j$(nproc) install
make -j$(nproc) distclean
hash -r

It worked, that’s cool.

Now, let’s have a look at libmysofa, as it has not been found by configure.

cd ~/ffmpeg_sources/
git clone https://github.com/hoene/libmysofa.git
cd libmysofa/
cd build/
cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j${nproc} all
sudo make install

Oh well, forget it…

A last try with configure, to see if we have everything available:

https://youtu.be/alnRnFiGZM8

cd ~/ffmpeg_sources/FFmpeg/
./configure --enable-gpl --enable-version3 --disable-static --enable-shared --enable-small --enable-avisynth --enable-chromaprint --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa --enable-openal --enable-libdrm --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp' --arch=arm

Pretty encouraging. Let’s compile everything and see what we can do

Let’s go with x265 now:

cd ~/ffmpeg_sources
wget http://deb.debian.org/debian/pool/main/x/x265/x265_3.2.orig.tar.gz
tar -xvzf x265_3.2.orig.tar.gz
cd x265_3.2/
wget http://deb.debian.org/debian/pool/main/x/x265/x265_3.2-2.debian.tar.xz
xz -d x265_3.2-2.debian.tar.xz && tar -xvf x265_3.2-2.debian.tar && rm x265_3.2-2.debian.tar
sudo apt -t stretch-backports install python3-sphinx
sudo -E dpkg-buildpackage -us -uc
sudo dpkg -i ../libx265-dev_3.2-2_armhf.deb ../libx265-179-dbgsym_3.2-2_armhf.deb ../libx265-179_3.2-2_armhf.deb ../libx265-doc_3.2-2_all.deb

Once the dependencies were installed, I downloaded the master branch of FFmpeg:

https://youtu.be/E9FQ_4vbWho

mkdir ffmpeg_sources
cd ffmpeg_sources
git clone https://github.com/FFmpeg/FFmpeg -b master
cd FFmpeg/

I then launched the configure command with the hope if would find everything…

https://youtu.be/chqIPoRORXU

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --enable-gpl --enable-version3 --disable-static  --enable-shared --enable-small --enable-avisynth --enable-chromaprint  --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa  --enable-libaom --enable-libass --enable-libcaca --enable-libcdio  --enable-libcodec2 --enable-libfontconfig --enable-libfreetype  --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack  --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb  --enable-libopencore-amrwb --enable-libopencore-amrwb  --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse  --enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine  --enable-libsnappy --enable-libsoxr --enable-libspeex  --enable-libssh --enable-libtheora  --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc  --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp  --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2  --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa  --enable-openal --enable-opengl --enable-libdrm  --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp'

I got: ERROR: x265 not found using pkg-config.

which is strange, because

pkg-config --list-all|grep x265
x265 x265 - H.265/HEVC video encoder
says x265 is there... and pkg-config --debug 2>&1|grep x265
File 'x265.pc' appears to be a .pc file
Will find package 'x265' in file '/usr/lib/arm-linux-gnueabihf/pkgconfig/x265.pc'

As seen there, I may need libnuma, so:

sudo apt -t stretch-backports install libnuma-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libnuma-dev is already the newest version (2.0.12-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
Setting up x265-dbgsym (3.2-2) ...
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --enable-gpl --enable-version3 --disable-static --enable-shared --enable-small --enable-avisynth --enable-chromaprint --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa --enable-openal --enable-opengl --enable-libdrm --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp'

Still got ERROR: x265 not found using pkg-config.

So, we’ll try another way. Let’s compile the standard x265 static version, and make it available to ffmpeg:

https://youtu.be/cXTmde4pw90

cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/bin" -DENABLE_SHARED:bool=off --prefix="$HOME/ffmpeg_build" ../../source
make -j$(nproc) VERBOSE=1
make -j$(nproc) install VERBOSE=1
make -j$(nproc) clean VERBOSE=

Let’s try with extending

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --enable-gpl --enable-version3 --disable-static  --enable-shared --enable-small --enable-avisynth --enable-chromaprint  --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa  --enable-libaom --enable-libass --enable-libcaca --enable-libcdio  --enable-libcodec2 --enable-libfontconfig --enable-libfreetype  --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack  --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb  --enable-libopencore-amrwb --enable-libopencore-amrwb  --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse  --enable-librsvg --enable-librubberband --enable-librtmp --enable-libshine  --enable-libsnappy --enable-libsoxr --enable-libspeex  --enable-libssh --enable-libtheora  --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc  --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp  --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2  --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa  --enable-openal --enable-opengl --enable-libdrm  --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp' --pkg-config-flags="--static"
ERROR: librsvg-2.0 not found using pkg-config

It worked for x265. Now, let’s tackle with librsvg:

cd ~/ffmpeg_sources
wget http://deb.debian.org/debian/pool/main/libr/librsvg/librsvg_2.44.15.orig.tar.xz
xz -d librsvg_2.44.15.orig.tar.xz && tar -xvf librsvg_2.44.15.orig.tar && rm librsvg_2.44.15.orig.tar
cd librsvg-2.44.15/
sudo apt -t stretch-backports install cargo
./configure
configure: error: librsvg needs at rustc version at least 1.27
sudo apt -t stretch-backports install rustc
Reading package lists... Done
Building dependency tree
Reading state information... Done
rustc is already the newest version (1.24.1+dfsg1-1~deb9u4).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

You know what? Let’s just forget about librsvg for the time being…

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --enable-gpl --enable-version3 --disable-static  --enable-shared --enable-small --enable-avisynth --enable-chromaprint  --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa  --enable-libaom --enable-libass --enable-libcaca --enable-libcdio  --enable-libcodec2 --enable-libfontconfig --enable-libfreetype  --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack  --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb  --enable-libopencore-amrwb --enable-libopencore-amrwb  --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libshine  --enable-libsnappy --enable-libsoxr --enable-libspeex  --enable-libssh --enable-libtheora  --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc  --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp  --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2  --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa  --enable-openal --enable-opengl --enable-libdrm  --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp -lpthread -lm -lz' --pkg-config-flags="--static" --extra-ldexeflags="-static"ERROR: chromaprint not found

Hmmm, let’s have a look at it:

cd ~/ffmpeg_sources
wget http://deb.debian.org/debian/pool/main/c/chromaprint/chromaprint_1.4.2.orig.tar.gz
tar -xvzf chromaprint_1.4.2.orig.tar.gz
cd chromaprint-1.4.2/
wget http://deb.debian.org/debian/pool/main/c/chromaprint/chromaprint_1.4.2-1.debian.tar.xz
xz -d chromaprint_1.4.2-1.debian.tar.xz
tar -xvf chromaprint_1.4.2-1.debian.tar
rm chromaprint_1.4.2-1.debian.tar
export DEB_DH_SHLIBDEPS_ARGS_ALL=--dpkg-shlibdeps-params=--ignore-missing-info
sudo -E dpkg-buildpackage -us -uc

Unfortunately, we had some packages missing, and apt was not able to help us. Let’s switch back to aptitude, so that it can propose us some solutions

sudo aptitude -t stretch-backports install libavcodec-dev libavformat-dev libswresample-dev
I chose this solution
The following actions will resolve these dependencies:
Remove the following packages:
1) libavresample-dev [7:4.1.4-1 (now)]
2) libpostproc-dev [7:4.1.4-1 (now)]
3) libswscale-dev [7:4.1.4-1 (now)]
Downgrade the following packages:
4) libavutil-dev [7:4.1.4-1 (now) -> 7:3.2.14-1~deb9u1 (oldstable)]
sudo -E dpkg-buildpackage -us -uc
sudo dpkg -i ../libchromaprint-dev_1.4.2-1_armhf.deb ../libchromaprint-tools_1.4.2-1_armhf.deb ../libchromaprint1_1.4.2-1_armhf.deb
sudo ldconfig
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --enable-gpl --enable-version3 --enable-shared --enable-small --enable-avisynth --enable-chromaprint --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa --enable-openal --enable-opengl --enable-libdrm --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp -lpthread -lm -lz' --pkg-config="pkg-config --static" --extra-ldexeflags="-static"

Did it help? Not at all. ERROR: chromaprint not found

Let’s try to build chromaprint from its repo.

cd ~/ffmpeg_sources
git clone https://github.com/acoustid/chromaprint.git
cd chromaprint
export CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX=$BASE_DIR/chromaprint-$OS-$ARCH -DCMAKE_BUILD_TYPE=Release -DBUILD_TOOLS=ON -DBUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS='-static -static-libgcc -static-libstdc++' -DCMAKE_CXX_FLAGS='-static -static-libgcc -static-libstdc++'"
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TOOLS=ON .
make -j$(nproc)
sudo make install
sudo ldconfig

You know what? I got once again ERROR: chromaprint not found

Damn… Ok, let’s forget chromaprint for the time being…

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/ffmpeg_build/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --enable-gpl --enable-version3 --enable-shared --enable-small --enable-avisynth --enable-frei0r --enable-gmp --enable-gnutls --enable-ladspa  --enable-libaom --enable-libass --enable-libcaca --enable-libcdio  --enable-libcodec2 --enable-libfontconfig --enable-libfreetype  --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack  --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb  --enable-libopencore-amrwb --enable-libopencore-amrwb  --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libshine  --enable-libsnappy --enable-libsoxr --enable-libspeex  --enable-libssh --enable-libtheora  --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc  --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp  --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2  --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa  --enable-openal --enable-opengl --enable-libdrm  --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp -lpthread -lm -lz' --pkg-config="pkg-config --static" --extra-ldexeflags="-static"ERROR: gnutls not found using pkg-config

Ok, let’s forget gnutls for the time being…

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/ffmpeg_build/lib/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig:$HOME/bin/lib/pkgconfig:/usr/local/lib/pkgconfig" ./configure --enable-gpl --enable-version3 --enable-shared --enable-small --enable-avisynth --enable-frei0r --enable-gmp --enable-ladspa  --enable-libaom --enable-libass --enable-libcaca --enable-libcdio  --enable-libcodec2 --enable-libfontconfig --enable-libfreetype  --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack  --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb  --enable-libopencore-amrwb --enable-libopencore-amrwb  --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libshine  --enable-libsnappy --enable-libsoxr --enable-libspeex  --enable-libssh --enable-libtheora  --enable-libtwolame --enable-libv4l2 --enable-libvo-amrwbenc  --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp  --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2  --enable-libzmq --enable-libzvbi --enable-lv2 --enable-libmysofa  --enable-openal --enable-opengl --enable-libdrm  --enable-nonfree --enable-libfdk-aac --enable-libbluray --enable-hwaccel='h264_vaapi,hevc_vaapi,vp9_vaapi' --enable-decoder='vp8,vp9' --extra-libs='-lnettle -lhogweed -lgmp -lpthread -lm -lz' --pkg-config="pkg-config --static" --extra-ldexeflags="-static"ERROR: aom >= 1.0.0 not found using pkg-config

As aom has not been found, we will have to build it… But before building it, let’s download, build and install its dependencies and other libs we want to build. Unfortunately, a few libraries which are available through apt are too old to be used as is, so we have to download and compile them… Let’s download the source

cd ~/ffmpeg_sources
git clone https://aomedia.googlesource.com/aom
cd aom

And launch cmake/make with the right options (found there).

cd ~/ffmpeg_sources/aom
cmake . -DCMAKE_C_FLAGS="-mfpu=vfp -mfloat-abi=hard"
rm -rf CMakeCache.txt CMakeFiles
mkdir -p ../aom_build
cd ../aom_build
cmake ../aom -DCMAKE_C_FLAGS="-mfpu=vfp -mfloat-abi=hard"

Then edit CMakeCache.txt and change

ENABLE_NEON:BOOL=OFF

Let’s build it for real now

[insert gif build-aom-2]

CMakeFiles/aom_rtcd.dir/build.make:75: recipe for target 'CMakeFiles/aom_rtcd.dir/aom_dsp/aom_dsp_rtcd.c.o' failed

I think I will have to investigate more on that… So for now, let’s just cheat a little bit, and use a Debian source package:

cd ~/ffmpeg_sources
wget http://deb.debian.org/debian/pool/main/a/aom/aom_1.0.0.errata1.orig.tar.xz
xz -d aom_1.0.0.errata1.orig.tar.xz && tar -xvf aom_1.0.0.errata1.orig.tar && rm aom_1.0.0.errata1.orig.tar
cd aom-1.0.0.errata1
wget http://deb.debian.org/debian/pool/main/a/aom/aom_1.0.0.errata1-2.debian.tar.xz
xz -d aom_1.0.0.errata1-2.debian.tar.xz && tar -xvf aom_1.0.0.errata1-2.debian.tar && rm aom_1.0.0.errata1-2.debian.tar
cd ~/ffmpeg_sources;wget http://deb.debian.org/debian/pool/main/a/aom/aom_1.0.0.errata1.orig.tar.xz;cd -
sudo -E dpkg-buildpackage -us -uc
sudo dpkg -i ../libaom-dev_1.0.0.errata1-2_armhf.deb ../aom-tools_1.0.0.errata1-2_armhf.deb ../libaom0_1.0.0.errata1-2_armhf.deb ../libaom-doc_1.0.0.errata1-2_all.deb

Another launch of configure does not work either… It does have the same problem of not finding aom. You know what? I have already managed to configure and compile, so I will have to investigate later on…

So… Why not trying directly the ffmpeg source package from Sid?

cd ~/ffmpeg_sources
wget http://deb.debian.org/debian/pool/main/f/ffmpeg/ffmpeg_4.1.4.orig.tar.xz
xz -d ffmpeg_4.1.4.orig.tar.xz && tar -xvf ffmpeg_4.1.4.orig.tar && rm ffmpeg_4.1.4.orig.tar
cd ffmpeg-4.1.4/ && wget http://deb.debian.org/debian/pool/main/f/ffmpeg/ffmpeg_4.1.4-1.debian.tar.xz
xz -d ffmpeg_4.1.4-1.debian.tar.xz && tar -xvf ffmpeg_4.1.4-1.debian.tar && rm ffmpeg_4.1.4-1.debian.tar
wget http://deb.debian.org/debian/pool/main/f/ffmpeg/ffmpeg_4.1.4.orig.tar.xz && mv ffmpeg_4.1.4.orig.tar.xz ..
sudo -E dpkg-buildpackage -us -uc
sudo dpkg -i libavutil56_4.1.4-1_armhf.deb libswresample-dev_4.1.4-1_armhf.deb libswscale5_4.1.4-1_armhf.deb libavformat58_4.1.4-1_armhf.deb libswscale-dev_4.1.4-1_armhf.deb libavutil-dev_4.1.4-1_armhf.deb libpostproc55_4.1.4-1_armhf.deb libavfilter7_4.1.4-1_armhf.deb libpostproc-dev_4.1.4-1_armhf.deb ffmpeg_4.1.4-1_armhf.deb libavfilter-extra7_4.1.4-1_armhf.deb libavformat-dev_4.1.4-1_armhf.deb libavresample4_4.1.4-1_armhf.deb libavresample-dev_4.1.4-1_armhf.deb libavcodec-extra_4.1.4-1_all.deb libavfilter-extra_4.1.4-1_all.deb libavfilter-dev_4.1.4-1_armhf.deb ffmpeg-doc_4.1.4-1_all.deb libavcodec-dev_4.1.4-1_armhf.deb libavdevice58_4.1.4-1_armhf.deb libavdevice-dev_4.1.4-1_armhf.deb libavcodec58_4.1.4-1_armhf.deb libavcodec-extra58_4.1.4-1_armhf.deb

Let’ now test ffmpeg available hardware accelerators. First of all, let’s download a classic video:

wget http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_30fps_normal.mp4
mv bbb_sunflower_1080p_30fps_normal.mp4 /media/linaro/0E9ACA2339F586E5/
cd /media/linaro/0E9ACA2339F586E5/
ffmpeg -hwaccels
rm /tmp/*.ts
ffmpeg -hwaccel vdpau -i bbb_sunflower_1080p_30fps_normal.mp4 /tmp/vdpau.ts
[h264 @ 0xab118280] No device available for decoder: device type vdpau needed for codec h264.
ffmpeg -hwaccel vaapi -i bbb_sunflower_1080p_30fps_normal.mp4 /tmp/vaapi.ts
Failed to initialise VAAPI connection: -1 (unknown libva error).
Device creation failed: -5.
[h264 @ 0xab4f9280] No device available for decoder: device type vaapi needed for codec h264.
ffmpeg -hwaccel drm -i bbb_sunflower_1080p_30fps_normal.mp4 /tmp/drm.ts
Device creation failed: -14.
[h264 @ 0xaafba280] No device available for decoder: device type drm needed for codec h264.

Looks pretty bad. Of course, these accelerators, despite having been compiled and being available can’t work on this machine. To drive home this point, let’s issue a few commands:

vainfo
error: can't connect to X server!
libva info: VA-API version 1.5.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
vaInitialize failed with error code -1 (unknown libva error),exit
vdpauinfo
vdpauinfo: cannot connect to X server

Now, we’re sure this won’t work. So what shall we do? Well, with that version of ffmpeg, or even the most recent one, there is not much hope. Fortunately, we can use a fork of ffmpeg that has been done by RockChip, and see if that could help us getting hardware acceleration with RK3399. Stay tuned.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade