linux下ffmpeg库 ARM交叉编译

首先给大家推荐一下我老师大神的人工智能教学网站。教学不仅零基础,通俗易懂,而且非常风趣幽默,还时不时有内涵黄段子!点这里可以跳转到网站

一、前言:

        因为想用ffmpeg实现录像网络视频流功能,所以需要编译ffmpeg相关库,不过目前对视频方面很多知识还是小白,后续会写一些关于视频方面知识的文章

二、准备工作

        1、ffmpeg源码地址:http://ffmpeg.org

         作者目前版本是ffmpeg-3.0.2

        2、编译器:arm-none-linux-gnueabi

三、安装编译

         1、生成makefile文件

          主要就是更改./configure文件,按照网上很多前辈的经验,配置项如下:

    ./configure --cross-prefix=arm-none-linux-gnueabi- --enable-cross-compile --target-os=linux --cc=arm-none-linux-gnueabi-gcc --arch=arm --prefix=/usr/local/ffmpeg --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-yasm --disable-stripping --enable-libx264 

         相关选项描述可以参考http://www.cnblogs.com/azraelly/archive/2012/12/31/2840541.html       

         关于–cross-prefix选项,看文档介绍是指定编译工具链的路径,上述命令之后会报警告:WARNING: arm-none-linux-gnueabi-pkg-config not found, library detection may fail.这里面是说没有pkg-config相关工具,我目前还不知道怎么安装arm-none-linux-gnueabi-cross-compile的pkg-config工具,但是这貌似不影响后续的使用。

         下面总结下上述命令执行遇到的一些问题,因为作者需要libx264库进行编解码,所以需要链接libx264静态库可能很多像我这样的小白都会遇到,特总结如下:

        (1)上述命令执行实际是会报错的,错误信息如下:ERROR: libx264 not found

          这里也就不卖关子了,还是得查看config.log,看看为什么会报错,所以做技术来不得半点偷懒。

check_cpp
BEGIN /tmp/ffconf.42QaWrDA.c
    1 #include <x264.h>
    2 int x;
END /tmp/ffconf.42QaWrDA.c
arm-none-linux-gnueabi-gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -march=armv5te -std=c99 -fomit-frame-pointer -marm -pthread -E -o /tmp/ffconf.aGoA0I51.o /tmp/ffconf.42QaWrDA.c
/tmp/ffconf.42QaWrDA.c:1:18: fatal error: x264.h: No such file or directory
compilation terminated.
ERROR: libx264 not found

          其实上面的意思已经很明白了,因为找不到x264.h头文件。奇怪,在上一篇文章中,大家也看到明明将x264小心翼翼的放到/usr/local/include目录下了,怎么会找不到呢?原来是编译的时候没有指定路径的缘由。于是乎在上述命令后加上了相关的编译选项–extra-cflags=-I/usr/local/include –extra-ldflags=-L/usr/local/lib。

    ./configure --cross-prefix=arm-none-linux-gnueabi- --enable-cross-compile --target-os=linux --cc=arm-none-linux-gnueabi-gcc --arch=arm --prefix=/usr/local/ffmpeg --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-yasm --disable-stripping --enable-libx264 --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib

         注:这里面不清楚什么路径下可以不用加此编译选项,望有高人指点。网上也有其他一些方法,这里不再敖述。

       (2)作者想这下总该大功告成了吧,系统就是这么不安分,又狠狠地煽了我一耳光,执行上述命令后还是报错同样的错误,难道路径写错了?看了config.log后原来还是自己太天真了,不说了,上log。

arm-none-linux-gnueabi-gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -I/usr/local/include -march=armv5te -std=c99 -fomit-frame-pointer -marm -pthread -c -o /tmp/ffconf.7kpBfq0i.o /tmp/ffconf.GIosUL4b.c
cc1: warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
arm-none-linux-gnueabi-gcc -L/usr/local/lib -march=armv5te -Wl,--as-needed -Wl,-z,noexecstack -o /tmp/ffconf.Dloiqgee /tmp/ffconf.7kpBfq0i.o -lx264 -lm -pthread
/boards/compilers/gcc/arm-none-linux-gnueabi/arm-2013q5/bin/../lib/gcc/arm-none-linux-gnueabi/4.7.3/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation
/usr/local/lib/libx264.a(opencl.o): In function `x264_opencl_load_library':
opencl.c:(.text+0x4f0): undefined reference to `dlopen'
opencl.c:(.text+0x504): undefined reference to `dlsym'
opencl.c:(.text+0x51c): undefined reference to `dlsym'
opencl.c:(.text+0x534): undefined reference to `dlsym'
opencl.c:(.text+0x54c): undefined reference to `dlsym'
opencl.c:(.text+0x564): undefined reference to `dlsym'
/usr/local/lib/libx264.a(opencl.o):opencl.c:(.text+0x57c): more undefined references to `dlsym' follow
/usr/local/lib/libx264.a(opencl.o): In function `x264_opencl_load_library':
opencl.c:(.text+0x7a0): undefined reference to `dlclose'
/usr/local/lib/libx264.a(opencl.o): In function `x264_opencl_close_library':
opencl.c:(.text+0x83c): undefined reference to `dlclose'
/usr/local/lib/libx264.a(opencl.o): In function `x264_opencl_lookahead_init':
opencl.c:(.text+0x1254): undefined reference to `dlopen'
opencl.c:(.text+0x1264): undefined reference to `dlsym'
opencl.c:(.text+0x1274): undefined reference to `dlsym'
opencl.c:(.text+0x1284): undefined reference to `dlsym'
opencl.c:(.text+0x1294): undefined reference to `dlsym'
opencl.c:(.text+0x12fc): undefined reference to `dlclose'
opencl.c:(.text+0x1308): undefined reference to `dlclose'
opencl.c:(.text+0x1b38): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
ERROR: libx264 not found

         原来是找不到dl库,链接上dl库应该就可以了,新改的./configure命令如下:

./configure –cross-prefix=arm-none-linux-gnueabi- –enable-cross-compile –target-os=linux –cc=arm-none-linux-gnueabi-gcc –arch=arm –prefix=/usr/local/ffmpeg –enable-shared –disable-static –enable-gpl –enable-nonfree –enable-ffmpeg –disable-ffplay –enable-ffserver –enable-swscale –enable-pthreads –disable-armv5te –disable-armv6 –disable-armv6t2 –disable-yasm –disable-stripping –enable-libx264 –extra-cflags=-I/usr/local/include –extra-ldflags=-L/usr/local/lib –extra-libs=-ldl

          2、make

          3、make file

点这里可以跳转到人工智能网站

发表评论