- • This article attempts to compile ffmpeg from source on an OpenWrt host, as the OpenWrt version of ffmpeg does not support hardware decoding for rk3568 using RKMMP. After resolving several compilation issues, the process is documented here for reference.
Configuration
First, refer to the native compilation options in the wrt SDK and add support for MPP features.
# Native compilation options in wrt SDK
( cd /home/test/friendlywrt22-rk3568/test/build_dir/target-aarch64_generic_musl/ffmpeg-full/ffmpeg-5.1; CFLAGS="-O2 -pipe -march=armv8-a+crypto+crc -mcpu=cortex-a53+crypto+crc -mtune=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/home/test/friendlywrt22-rk3568/test/build_dir/target-aarch64_generic_musl/ffmpeg-full/ffmpeg-5.1=ffmpeg-5.1 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -I/home/test/friendlywrt22-rk3568/test/staging_dir/toolchain-aarch64_generic_gcc-11.3.0_musl/usr/include -I/home/test/friendlywrt22-rk3568/test/staging_dir/toolchain-aarch64_generic_gcc-11.3.0_musl/include/fortify -I/home/test/friendlywrt22-rk3568/test/staging_dir/toolchain-aarch64_generic_gcc-11.3.0_musl/include -DPIC -fPIC" LDFLAGS="-L/home/test/friendlywrt22-rk3568/test/staging_dir/toolchain-aarch64_generic_gcc-11.3.0_musl/usr/lib -L/home/test/friendlywrt22-rk3568/test/staging_dir/toolchain-aarch64_generic_gcc-11.3.0_musl/lib -znow -zrelro" ./configure --enable-cross-compile --cross-prefix="aarch64-openwrt-linux-musl-" --arch="aarch64" --cpu=generic --target-os=linux --prefix="/usr" --pkg-config="pkg-config" --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --disable-outdevs --disable-runtime-cpudetect --enable-lto --enable-neon --enable-vfp --disable-x86asm --enable-gnutls --enable-libopus --enable-small --enable-libmp3lame --enable-gpl --enable-libx264 )
Adding MPP
./configure --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --disable-lzma --disable-vaapi --disable-vdpau --disable-outdevs --disable-runtime-cpudetect --enable-lto --enable-neon --enable-vfp --disable-x86asm --enable-gnutls --enable-libopus --enable-small --enable-libmp3lame --enable-gpl --enable-libx264 --enable-rkmpp --enable-version3 --enable-libdrm
./configure --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --enable-lto --enable-neon --enable-vfp --disable-x86asm --enable-gnutls --enable-gnutls --enable-rkmpp --enable-version3 --enable-libdrm --enable-libopus --enable-small --enable-libmp3lame --enable-gpl --enable-libx264
Error Analysis
Compilation Error 1: ERROR: gnutls not found using pkg-config
# Compilation Error 1
ERROR: gnutls not found using pkg-config
Solution 1:
--Solution: Install gnutls library and pc files
/home/test/friendlywrt22-rk3568/test/staging_dir/target-aarch64_generic_musl/usr/include# scp -r gnutls/ [email protected]:/usr/include/
root@test:/home/test/friendlywrt22-rk3568/test/staging_dir/target-aarch64_generic_musl/usr/include# scp ../lib/libgnutls* [email protected]:/usr/lib/
root@test:/home/test/friendlywrt22-rk3568/test/staging_dir/target-aarch64_generic_musl/usr/include# scp ../lib/pkgconfig/gnutls.pc [email protected]:/usr/lib/pkgconfig/
--Then check gnutls, and find it depends on nettle
root@test:~/ffmpeg-rk-enc-5.1# pkg-config --variable pc_path pkg-config
/usr/lib/pkgconfig:/usr/share/pkgconfig # First create pkgconfig directory
root@test:~/ffmpeg-rk-enc-5.1# pkg-config --cflags gnutls
Package nettle was not found in the pkg-config search path.
Perhaps you should add the directory containing "nettle.pc" to the PKG_CONFIG_PATH environment variable
Package 'nettle', required by 'gnutls', not found
root@test:~/ffmpeg-rk-enc-5.1#
Solution 2:
--Solution 2: Disable gnutls, then it prompts for drm
./configure --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --enable-lto --enable-neon --enable-vfp --disable-x86asm --enable-rkmpp --enable-version3 --enable-libdrm --enable-libopus --enable-small --enable-libmp3lame --enable-gpl --enable-libx264
Compilation Error 2: ERROR: libdrm not found using pkg-config
Cross-compile libdrm and copy it to the target board.
# Install libdrm on the host machine, cross-compile
cd /home/test/friendlywrt22-rk3568/test/staging_dir/target-aarch64_generic_musl/usr/include
scp xf86drm* [email protected]:/usr/include/
scp -r libdrm/ [email protected]:/usr/include/
scp ../lib/libdrm* [email protected]:/usr/lib/
scp ../lib/pkgconfig/libdrm.pc [email protected]:/usr/lib/pkgconfig/
scp xf86drm.h [email protected]:/usr/include/
# Verify on the target board
root@test:~/ffmpeg-rk-enc-5.1# pkg-config --cflags libdrm
-I/usr/include/libdrm
Compilation Error 3: ERROR: libmp3lame >= 3.98.3 not found
# Continue configuration
root@test:~/ffmpeg-rk-enc-5.1# ./configure --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --enable-lto --enable-neon --enable-vfp --disable-x86asm --enable-rkmpp --enable-version3 --enable-libdrm --enable-libopus --enable-small --enable-libmp3lame --enable-gpl --enable-libx264
ERROR: libmp3lame >= 3.98.3 not found
# Solution: Remove libmp3lame and opus
root@test:~/ffmpeg-rk-enc-5.1# ./configure --enable-shared --enable-static --enable-pthreads --enable-zlib --disable-doc --disable-debug --enable-lto --enable-neon --enable-vfp --disable-x86asm --enable-rkmpp --enable-version3 --enable-libdrm -- --enable-small --enable-gpl --enable-libx264
Compilation Error 4: ERROR: x264 not found using pkg-config
# ERROR: x264 not found using pkg-config
# Solution:
cd /home/test/friendlywrt22-rk3568/test/staging_dir/target-aarch64_generic_musl/usr/include
scp -r x264* [email protected]:/usr/include/
scp ../lib/libx264* [email protected]:/usr/lib/
scp ../lib/pkgconfig/x264.pc [email protected]:/usr/lib/pkgconfig/
# Verify
root@test:~/ffmpeg-rk-enc-5.1# pkg-config --cflags x264
-DX264_API_IMPORTS
Compilation Error 5: ERROR: rockchip_mpp not found using pkg-config
# ERROR: rockchip_mpp not found using pkg-config
# Solution:
cd /home/test/friendlywrt22-rk3568/test/staging_dir/target-aarch64_generic_musl/usr/include
scp -r rockchip* [email protected]:/usr/include/
scp ../lib/librockchip* [email protected]:/usr/lib/
scp ../lib/pkgconfig/rockchip_mpp.pc [email protected]:/usr/lib/pkgconfig/
# Verify
root@test:~/ffmpeg-rk-enc-5.1# pkg-config --cflags rockchip_mpp
Compilation Error 6: fatal error: rga/RgaApi.h: No such file or directory
## Configuration
./configure --enable-shared --enable-static --enable-pthreads --disable-doc --disable-debug --enable-lto --enable-neon --enable-vfp --disable-x86asm --enable-rkmpp --enable-version3 --enable-libdrm --enable-small --enable-gpl --enable-libx264
make -j5
./libavrkmpp/avrkmpp.h:29:10: fatal error: rga/RgaApi.h: No such file or directory
29 | #include <rga/RgaApi.h>
https://github.com/airockchip/librga
Compiling librga (failed, no solution)
## Compiling librga
root@test:/home/test/friendlywrt22-rk3568/test/dl/librga# vim cross/cross_file_aarch64.txt
[binaries]
c = 'aarch64-openwrt-linux-gcc'
cpp = 'aarch64-openwrt-linux-g++'
ar = 'aarch64-openwrt-linux-ar'
strip = 'aarch64-openwrt-linux-strip'
[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'
[properties]
needs_exe_wrapper = true
c_args = ['-I/home1/yqw/linux/rk3588/prebuilts/gcc/linux-x86/aarch64/gcc-buildroot-9.3.0-2020.03-x86_64_aarch64-rockchip-linux-gnu/aarch64-rockchip-linux-gnu/sysroot/usr/include', '-L/home1/yqw/linux/rk3588/prebuilts/gcc/linux-x86/aarch64/gcc-buildroot-9.3.0-2020.03-x86_64_aarch64-rockchip-linux-gnu/aarch64-rockchip-linux-gnu/sysroot/usr/lib', '-L/home1/yqw/linux/rk3588/prebuilts/gcc/linux-x86/aarch64/gcc-buildroot-9.3.0-2020.03-x86_64_aarch64-rockchip-linux-gnu/lib', '-I/home1/yqw/linux/rk3588/prebuilts/gcc/linux-x86/aarch64/gcc-buildroot-9.3.0-2020.03-x86_64_aarch64-rockchip-linux-gnu/include']
# Compilation error ,
| ^
libavcodec/rkmppdec.c:75:1: note: in expansion of macro 'RKMPP_DEC'
75 | RKMPP_DEC(mpeg4, AV_CODEC_ID_MPEG4, "mpeg4_unpack_bframes")
| ^~~~~~~~~
In file included from /usr/include/rga/RgaApi.h:30,
from ./libavrkmpp/avrkmpp.h:29,
from libavcodec/rkmppdec.c:22:
/usr/include/sys/mman.h:57:14: error: old-style parameter declarations in prototyped function definition
57 | extern void *mmap (void *__addr, size_t __len, int __prot,
| ^~~~
libavcodec/rkmppdec.c:76: error: expected '{' at end of input
libavcodec/rkmppdec.c:76: error: control reaches end of non-void function [-Werror=return-type]