一、參考資料
Ubuntu系統下交叉編譯x264-CSDN博客
二、交叉編譯x264
1. 下載源碼
下載x264:https://www.videolan.org/developers/x264.html
git clone https://code.videolan.org/videolan/x264.git
cd x264
mkdir x264build
2. 設置環境變量
設置交叉編譯工具鏈的環境變量:
export PATH=/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/bin:$PATH
3. 生成configure配置
./configure \
--prefix="/home/yoyo/360Downloads/x264/x264build" \
--sysroot="/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/libc" \
--host=arm-linux-gnueabihf \
--cross-prefix=arm-linux-gnueabihf- \
--enable-static \
--enable-shared \
--extra-cflags="-I/home/yoyo/360Downloads/nasm-2.16.03/arm32_install/include" \
--extra-ldflags="-L/home/yoyo/360Downloads/nasm-2.16.03/arm32_install/lib"
參數解釋:
--prefix:安裝路徑;--enable-static:生成靜態庫;--enable-shared:生成動態庫;--extra-cflags:引入nasm庫的頭文件;--extra-ldflags:引入nasm的lib庫。
輸出示例:
yoyo@yoyo:~/360Downloads/x264$ ./configure \
> --prefix="/home/yoyo/360Downloads/x264/x264build" \
> --sysroot="/home/yoyo/360Downloads/toolchains/arm-linux-gnueabihf/arm-linux-gnueabihf/libc" \
> --host=arm-linux-gnueabihf \
> --cross-prefix=arm-linux-gnueabihf- \
> --enable-static \
> --enable-shared \
> --extra-cflags="-I/home/yoyo/360Downloads/nasm-2.16.03/arm32_install/include" \
> --extra-ldflags="-L/home/yoyo/360Downloads/nasm-2.16.03/arm32_install/lib"
platform: ARM
byte order: little-endian
system: LINUX
cli: yes
libx264: internal
shared: yes
static: yes
bashcompletion: no
asm: yes
interlaced: yes
avs: yes
lavf: no
ffms: no
mp4: no
gpl: yes
thread: posix
opencl: yes
filters: crop select_every
lto: no
debug: no
gprof: no
strip: no
PIC: yes
bit depth: all
chroma format: all
You can run 'make' or 'make fprofiled' now.
4. 編譯安裝
# 編譯
make -j8
# 安裝
make install
make install 安裝:
yoyo@yoyo:~/360Downloads/x264$ make install
install -d /home/yoyo/360Downloads/x264/x264build/bin
install x264 /home/yoyo/360Downloads/x264/x264build/bin
install -d /home/yoyo/360Downloads/x264/x264build/include
install -d /home/yoyo/360Downloads/x264/x264build/lib/pkgconfig
install -m 644 ./x264.h x264_config.h /home/yoyo/360Downloads/x264/x264build/include
install -m 644 x264.pc /home/yoyo/360Downloads/x264/x264build/lib/pkgconfig
install -d /home/yoyo/360Downloads/x264/x264build/lib
ln -f -s libx264.so.164 /home/yoyo/360Downloads/x264/x264build/lib/libx264.so
install -m 755 libx264.so.164 /home/yoyo/360Downloads/x264/x264build/lib
install -d /home/yoyo/360Downloads/x264/x264build/lib
install -m 644 libx264.a /home/yoyo/360Downloads/x264/x264build/lib
arm-linux-gnueabihf-gcc-ranlib /home/yoyo/360Downloads/x264/x264build/lib/libx264.a
如果執行 make install 僅拷貝了 bin 目錄,則需要手動將lib庫和include頭文件拷貝到安裝目錄。
cp x264.h x264_config.h ../x264build/include/
cp libx264.a ../x264build/lib/
cp x264.pc ../x264build/lib/pkgconfig/
5. 移植到開發板
將編譯好的文件,拷貝到開發板。
# 拷貝 include
cp -r ./arm32_install/include/* /PATH/TO/arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include
# 拷貝lib
cp -r ./arm32_install/lib/* /PATH/TO/arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib
技術交流羣