ffmpeg+xvid+x264交叉编译全过程

7 篇文章 0 订阅
4 篇文章 0 订阅

转自:  http://zyg0227.blog.51cto.com/1043164/313085/


1.xvid编译:
下载xvid加压并进入build->generic
输入./configure --host=arm-linux --prefix=/usr/local/arm/3.4.1/arm-linux/(很重要,否则在编译ffmpeg的时候找不到xvid,x264库)
make
成功后进入example文件夹
输入
arm-linux-gcc -o xvid_encraw xvid_encraw.c -lc -lm -I../src/ -L../build/generic/=build -lxvidcore
即可生成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
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"
PS;===============================================
一般发生在交叉编译的时候。
因为安装时的install程序检测到标志INSTALLSTRIP = -s ----即需要执行 strip 来剔除一些无用的符号。而此时 strip 又只是宿主机的,所以不能 strip 目标机的文件。
问题4:

需要改strip
将config.mak中 INSTALLSTRIP=-s,-s去掉即可

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值