FFmpeg交叉编译


1. 使用集成了龙芯交叉工具链的docker镜像(更新于20230329)

(1)下载镜像

   docker pull yinshiyou01/ubuntu-la64-cross-gcc:v0

(2)启动镜像

   docker run -it --name "ubuntu-la64-cross-gcc-v0" yinshiyou01/ubuntu-la64-cross-gcc:v0 /bin/bash
   # 需要的话,还可以通过-v来与host主机共享目录。

(3)使用交叉编译工具链

   # /目录下有使用说明
   cat usage-la-gcc-cross.txt

This docker image integrated the GCC cross-compiler for loongarch64.
Here are the examples of cross-compiling SDL and FFMpeg.

1. SDL
export PATH=/usr/local/cross-tools/bin:$PATH
mkdir build; cd build
cmake .. -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_C_COMPILER=loongarch64-unknown-linux-gnu-gcc -DCMAKE_INSTALL_PREFIX=/usr/local -DSDL_TESTS=on
make


2. FFmpeg
export PATH=/usr/local/cross-tools/bin:$PATH
mkdir build; cd build
../configure --prefix=/usr/local --enable-cross-compile --target-os=linux --arch=loongarch64 --cross-prefix=loongarch64-unknown-linux-gnu- --disable-doc
make

2. 直接使用龙芯交叉编译器(更新于2021年,使用的工具链是mips64的)

(1) 下载交叉编译器
可以在龙芯开源社区交叉编译器页面查找自己所需的版本:Cross-compile
本测试选择的是“gs464核linux交叉编译器(gcc-7.3.1)”,该版本支持MSA和MMI的编译,下载地址:http://ftp.loongnix.cn/toolchain/gcc/release/mips/gcc7/mips-loongson-gcc7.3-2019.06-29-linux-gnu.tar.gz
(2) 设置环境变量
编译器下载下来之后,将编译器tar包解压出来,设置PATH变量即可。(本次测试使用的主机信息:CPU i7-3770, OS debian10)

   CROSS_PATH=path_to_your_cross_compiler/mips-loongson-gcc7.3-linux-gnu/2019.06-29
   export PATH=$CROSS_PATH/bin:$PATH

(3) 编译FFmpeg的configure选项:

   configure --cross-prefix=mips-linux-gnu- --enable-cross-compile --arch=mips64el --target-os=linux --extra-cflags="-O3 -g -mabi=64" --extra-ldflags="-O3 -g -mabi=64"

说明:上面列出来了关键的选项,这里编译的是64位的ffmpeg,其他的configure选项可以根据自己需求进行添加。

3. 使用debian社区的交叉编译器(更新于2021年,适用与mips64)

(1) 根据自己的需要选择32位和64位交叉编译器,比如在debian10-x64上默认源里有gcc-mips-linux-gnu 和 gcc-mips64el-linux-gnuabi64之类的。
(2) 编译选项:和架构相关的选项主要就是--target-exec --cross-prefix --cc --arch 和--optflags或者--extra-cflags --extra-ldflags指定的具体编译连接选项。需要注意这些选项之间不能冲突,下面举几个实例:

   # 编译64位的选项:
   ../ffmpeg/configure --target-exec='/usr/bin/qemu-mips64el -cpu 74Kf -L /usr/mips64el-linux-gnuabi64/' --samples=../../fate-suite/ --enable-gpl --cross-prefix=/usr/mips64el-linux-gnuabi64/bin/ --cc=mips64el-linux-gnuabi64-gcc-8 --arch=mips64el --target-os=linux --optflags='-O3 -g -mabi=64 -static' --enable-cross-compile --disable-pthreads --disable-iconv --enable-static --extra-ldflags='-static'

   # 编译32位的选项:
   ../../ffmpeg/configure --samples=../../fate-suite/ --target-exec='/usr/bin/qemu-mips -cpu 74Kf -L /usr/mips-linux-gnu/' --cross-prefix=/usr/mips-linux-gnu/bin/ --cc=mips-linux-gnu-gcc-8 --arch=mips --target-os=linux --optflags='-O3 -g -static' --extra-ldflags='-static' --enable-cross-compile --enable-static --enable-gpl --disable-iconv --disable-mipsfpu

(3) 采用qemu环境进行验证,通过--target-exec制定了qemu作为执行目标环境,前述实例的编译选项中还加了“--enable-static --extra-ldflags='-static'” ,目的就是为了避免使用qemu进行验证的时候出现动态库连接问题。如果客户最终是其他实体环境,则需要针对性的修改--target-exec选项参数。
(4) qemu环境在debian10-x64的默认源上也是有的,user模式下执行只需要安装qemu-user,如果是系统模式下执行则需要安装对应的包,例如qemu-system-mips64el.


©龙芯开源社区 all right reserved,powered by Gitbook文档更新时间: 2024-04-16 14:42:33

results matching ""

    No results matching ""

    results matching ""

      No results matching ""