本文主要是介绍ffmpeg+xvid+x264交叉编译全过程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.xvid 编译:
下载 xvid 加压并进入 build->generic
输入 ./configure --host=arm-linux --prefix=/usr/local/arm/3.4.1/arm-linux/(很重要,否则在编译ffmpeg 的时候找不到 xvid , x264 库)
make
(configure时正常通过,但编译的时候通不过并返回错误如下
)
make
(configure时正常通过,但编译的时候通不过并返回错误如下
cc1: error: unrecognized command line option "-freduce-all-gives" |
成功后进入 example 文件夹
输入
arm-linux-gcc -o xvid_encraw xvid_encraw.c -lc -lm -I../src/ -L../build/generic/=build -lxvidcore
即可生成 xvid_encraw
即可生成 xvid_encraw
2.x264
最新的版本(我最开始用的是 20090715 这个)已经有 cross-compile 的支持了,移植应该还是很顺利的。但是这个版本的 win 下编译不通过,问题在网上找了一下,没有解决。后来退而求其次,选择了一个 20060805 的版本,这个版本在网上找到了 win 下 vc6 可以编译通过的版本,同时也可以在 x264 的官方 ftp 上找到 linux 下可以编译的版本。最后决定使用这个版本。这样可以方便一些在 win 下的交互调试。
注意,这里要提醒一下,几年之内, x264 的变化还是很大的。总之,在需要两个平台交叉调试的时候,看来一个相同的版本是非常有必要的。否则,可能会发生这种情况:程序在 win 下好用,在 linux 下就不好用了,然后你一边用 vs ,一边用 gdb ,终于找到了不同的地方,发现 x264 的一个标准 API 对同一个参数的赋值是完全不一样的 …… (比如我就发现我使用的两个版本的 x264_param_init() 函数对 param.i_bframe 赋值是不同的,导致我的一个程序在 win 下是好的, linux 下就是坏的)
新版本的移植我不说了,大概说一下旧版本的移植。
旧的是没有 --disable-asm 和 --cross-compile 这两个 configure 的支持的(前者是对 x86 的汇编优化,交叉编译的时候当然不要的,后者是交叉编译环境设置)。其实和我之前的移植过程差不多,这里写个步骤:
0. 环境
OS:ubuntu 9.04
Version:x264-snapshot-20060805-2245.tar.bz2
1. 配置
./configure --prefix=/usr/local/arm/3.4.1/arm-linux/ --enable-shared --enable-debug
我这里打开了动态链接和 debug 。前者可以生成 libx264.so ,后者可以在你调程序用 gdb 的时候 step into 库函数里。
2. 修改配置参数
修改 config.mak :
prefix=/usr/local/arm/3.4.1/arm-linux/
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
includedir=${prefix}/include
# 这里改为 ARM
ARCH=ARM
SYS=LINUX
# 这里改为 arm-linux-gcc
CC=arm-linux-gcc
# 这里去掉 -DHAVE_MMXEXT -DHAVE_SSE2 -DARCH_X86
CFLAGS=-Wall -I. -O4 -ffast-math -D__X264__ -DHAVE_MALLOC_H -DSYS_LINUX -DHAVE_PTHREAD -s -fomit-frame-pointer
LDFLAGS= -lm -lpthread -s
AS=nasm
ASFLAGS=-O2 -f elf
VFW=no
GTK=no
EXE=
VIS=no
HAVE_GETOPT_LONG=1
DEVNULL=/dev/null
CONFIGURE_ARGS= '--enable-shared' '--prefix=/usr/local/arm/3.4.1/arm-linux/'
SONAME=libx264.so.49
default: $(SONAME)
修改 Makefile ,将 66~68 行的 ar 和 ranlib 改为 arm 下的:
libx264.a: .depend $(OBJS) $(OBJASM)
arm-linux-ar rc libx264.a $(OBJS) $(OBJASM)
arm-linux-ranlib libx264.a
3. 编译安装
make
make install
注意,这里要提醒一下,几年之内, x264 的变化还是很大的。总之,在需要两个平台交叉调试的时候,看来一个相同的版本是非常有必要的。否则,可能会发生这种情况:程序在 win 下好用,在 linux 下就不好用了,然后你一边用 vs ,一边用 gdb ,终于找到了不同的地方,发现 x264 的一个标准 API 对同一个参数的赋值是完全不一样的 …… (比如我就发现我使用的两个版本的 x264_param_init() 函数对 param.i_bframe 赋值是不同的,导致我的一个程序在 win 下是好的, linux 下就是坏的)
新版本的移植我不说了,大概说一下旧版本的移植。
旧的是没有 --disable-asm 和 --cross-compile 这两个 configure 的支持的(前者是对 x86 的汇编优化,交叉编译的时候当然不要的,后者是交叉编译环境设置)。其实和我之前的移植过程差不多,这里写个步骤:
0. 环境
OS:ubuntu 9.04
Version:x264-snapshot-20060805-2245.tar.bz2
1. 配置
./configure --prefix=/usr/local/arm/3.4.1/arm-linux/ --enable-shared --enable-debug
我这里打开了动态链接和 debug 。前者可以生成 libx264.so ,后者可以在你调程序用 gdb 的时候 step into 库函数里。
2. 修改配置参数
修改 config.mak :
prefix=/usr/local/arm/3.4.1/arm-linux/
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib
includedir=${prefix}/include
# 这里改为 ARM
ARCH=ARM
SYS=LINUX
# 这里改为 arm-linux-gcc
CC=arm-linux-gcc
# 这里去掉 -DHAVE_MMXEXT -DHAVE_SSE2 -DARCH_X86
CFLAGS=-Wall -I. -O4 -ffast-math -D__X264__ -DHAVE_MALLOC_H -DSYS_LINUX -DHAVE_PTHREAD -s -fomit-frame-pointer
LDFLAGS= -lm -lpthread -s
AS=nasm
ASFLAGS=-O2 -f elf
VFW=no
GTK=no
EXE=
VIS=no
HAVE_GETOPT_LONG=1
DEVNULL=/dev/null
CONFIGURE_ARGS= '--enable-shared' '--prefix=/usr/local/arm/3.4.1/arm-linux/'
SONAME=libx264.so.49
default: $(SONAME)
修改 Makefile ,将 66~68 行的 ar 和 ranlib 改为 arm 下的:
libx264.a: .depend $(OBJS) $(OBJASM)
arm-linux-ar rc libx264.a $(OBJS) $(OBJASM)
arm-linux-ranlib libx264.a
3. 编译安装
make
make install
3.. 交叉编译 ffmpeg
./configure --prefix=/usr/local/arm/3.4.1/arm-linux --cc=arm-linux-gcc --cpu=arm --enable-shared --enable-x264 --enable-xvid --enable-gpl --enable-pthreads
( 注意红色字体非 libx264 和 libxvid)
问题 1 : snow.c: In function `predict_slice':
snow.c:2892: warning: passing arg 5 of `add_yblock' discards qualifiers from pointer target type
snow.c: In function `common_init':
snow.c:3244: warning: assignment from incompatible pointer type
snow.c:3244: warning: assignment from incompatible pointer type
snow.c:3245: warning: assignment from incompatible pointer type
snow.c:3245: warning: assignment from incompatible pointer type
snow.c:3246: warning: assignment from incompatible pointer type
snow.c:3246: warning: assignment from incompatible pointer type
snow.c:3247: warning: assignment from incompatible pointer type
snow.c:3247: warning: assignment from incompatible pointer type
make[1]: *** [snow.o] 中断
make: *** [lib] _
答:这是我手动中断编译的,否则死机,这是一个小 bug ,改正方法,单独编译:
[root@localhost libavcodec]# arm-linux-gcc -O3 -g -Wall -Wno-switch -DHAVE_AV_CONFIG_H -I.. -I'/home/ffmpeg/ffmpeg-0.4.9-p20051120'/libavutil -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -c -o snow.o snow.c 这是原来的编译选项,将 -O3 改成 -O 即可;
问题 2 : x264.c: In function `X264_init':
x264.c:140: error: structure has no member named `b_cbr'
答:注释掉 140 行即可;
问题 3 :
strip: Unable to recognise the format of the input file
答:打开将 config.mk
如下:
STRIP=strip 改为 arm-linux-strip 即可
解释如下:
Sometimes U got error while doing 'make install' :
strip: Unable to recognise the format of the input file
This is because the flag "INSTALLSTRIP = -s" in file config.mak
will pass to 'install' application while you do "make install" ..........
disable the flag "INSTALLSTRIP = " and make install.;0)
Or edit flag "INSTALL = $your_arm_install_application"
strip: Unable to recognise the format of the input file
This is because the flag "INSTALLSTRIP = -s" in file config.mak
will pass to 'install' application while you do "make install" ..........
disable the flag "INSTALLSTRIP = " and make install.;0)
Or edit flag "INSTALL = $your_arm_install_application"
PS;===============================================
一般发生在交叉编译的时候。
一般发生在交叉编译的时候。
因为安装时的 install 程序检测到标志 INSTALLSTRIP = -s ---- 即需要执行 strip 来剔除一些无用的符号。而此时 strip 又只是宿主机的,所以不能 strip 目标机的文件。
问题 4 :

需要改 strip
将config.mak中 INSTALLSTRIP=-s,-s去掉即可
本文出自 “专注嵌入式多媒体技术” 博客,请务必保留此出处http://zyg0227.blog.51cto.com/1043164/313085
这篇关于ffmpeg+xvid+x264交叉编译全过程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!