ubuntu xvid x264 交叉编译

使用的环境是3.4.1

xvidcore1.1.3

键入:#CC=arm-linux-gcc ./configure --prefix=/usr/local/arm/arm-linux --build=i686-pc-linux --host=arm-linux --target=arm-linux
#make
#make install

在进入example目录

输入

arm-linux-gcc -o xvid_encraw xvid_encraw.c  -lc -lm -I../src/ -L../build/generic/=build -lxvidcore
即可生成xvid_encraw

file 这个文件:for linux 2.4.3

x264-20060805-2245:

./configure --prefix=/usr/local/arm/arm-linux --enable-shared --enable-debug

得到的文件,需要修改config.mak

ARCH = ARM

CC=arm-linux-gcc

去掉CFLAGS中 -DHAVE_MMXEXT -DHAVE_SSE2 -DARCH_X86

LDFLAGS中添加 -s

修改Makefile 文件66~68

arm-linux-ar rc

arm-linux-ranlib

然后make && make install

出现错误:

common/cpu.c: In function `x264_cpu_num_processors':
common/cpu.c:172: error: `cpu_set_t' undeclared (first use in this function)
common/cpu.c:172: error: (Each undeclared identifier is reported only once
common/cpu.c:172: error: for each function it appears in.)
common/cpu.c:172: error: parse error before ')' token
make: *** [common/cpu.o] Error 1
解决办法:
在common/cpu.c中找到x264_cpu_num_processors这个函数,在这个函数中有如下代码,功能是得到你的电脑cpu的个数:
#elif defined(SYS_LINUX) || defined(WIN32)
    int np;
#if defined(WIN32)
    uint32_t p_aff, s_aff;
    GetProcessAffinityMask( GetCurrentProcess(), &p_aff, &s_aff );
#else
   // uint64_t p_aff;
   // sched_getaffinity( 0, sizeof(p_aff), (cpu_set_t*)&p_aff );
#endif
   // for( np = 0; p_aff != 0; p_aff >>= 1 )
   //     np += p_aff&1;
np =1;//此处就是你电脑cpu的个数
    return np;
然后重新make,这个问题就解决了。

ffmpeg0.5:

root@ubuntu:/home/thinkpad/tools/ffmpeg-0.5# ./configure --prefix=/usr/local/arm/arm-linux/ --enable-cross-compile --arch=libavcodec/armv4l/ --cross-prefix=/usr/local/arm/3.4.1/bin/arm-linux- --cc=gcc --enable-static --disable-ipv6 --enable-libx264 --enable-gpl --enable-pthreads --target-os=linux --disable-network --enable-swscale --enable-shared --extra-libs=/usr/local/arm/arm-linux/lib/

然后再configure,如果还有错误,如:
ERROR: x264 not found 你在configure时把libx264库加上就可以了:--extra-libs=/usr/local/lib/ 此路径是你的x264的安装路径。
WARNING: Unknown CPU "./libavcodec/armv4l/", ignored.这个错误要将--cpu=libavcodec/armv4l/改成--arch=libavcodec/armv4l/
如果出现如下错误,
/usr/local/arm/2.95.3/bin/arm-linux-gcc is unable to create an executable file.
C compiler test failed.
会发现只要去掉--extra-libs=/usr/local/lib/后,这个错误就没了,但是有ERROR: x264 not found 那个错误,郁闷,怎么解决呢?
......

查看config.log 如下:

gcc /usrlocal/arm/arm-linux/lib/libx264.a -o /tmp/ffconf.**  /tmp/

****

 /usrlocal/arm/arm-linux/lib/libx264.so could not read symbols : file in wrong format

于是修改--c=/usr/local/arm/3.4.1/bin/arm-linux-gcc 编译再次出现x264找不到,查看log x264.h:no such file or directory

修改:--extra-libs=-L/usr/local/arm/arm-linux/lib/ --extra-ldflags=-L/usr/local/arm/arm-linux/lib/ --extra-cflags=-I/usr/local/arm/arm-linux/include/

报错:libx264 version must be >= 0.99

使用ffmpeg 0.4.9:

./configure --prefix=/usr/local/arm/arm-linux/ --cpu=libavcodec/arm/ --cross-prefix=/usr/local/arm/3.4.1/bin/arm-linux- --cc=gcc --enable-xvid --enable-x264 --enable-gpl --disable-opts --disable-dv1394 --disable-network  --enable-shared --extra-libs=-L/usr/local/arm/arm-linux/lib/ --extra-ldflags=-L/usr/local/arm/arm-linux/lib/ --extra-cflags=-I/usr/local/arm/arm-linux/include/
make 的时候错误:

x264.c: In function `X264_init':
x264.c:151: error: structure has no member named `b_cbr'
make[1]: *** [x264.o] Error 1
make[1]: Leaving directory `/home/thinkpad/tools/ffmpeg-0.4.9-p20060302/libavcodec'
make: *** [lib] Error 2

代码不匹配,还是重新下载一个x264:

ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20070416-2245.tar.bz2

有人说这样搭配:

Use ffmpeg-0.4.9_p20060816 for x264-svn-20060810 and ffmpeg-0.4.9_p20061016 for
x264-svn-20061014.
Closing.
使用文字 ffmpeg最新源码 中下载的ffmepg和x264
1:编译x264
./configure --enable-shared --prefix=/home/cm/x264/install --host=arm-linux
修改config.mak文件
ARCH=X86
改为
ARCH=ARM
CC=gcc
改为
CC=arm-linux-gcc
CFLAGS中 -DARCH_X86 删掉
make
make install
2:编译 ffmpeg
./configure --prefix=/home/cm/ffmpeg/install --disable-static --enable-shared --enable-gpl --enable-swscaler --enable-x264 --enable-xvid --disable-strip --arch=libavcodec/armv4l/ --disable-ffplay --disable-ffserver --disable-armv5te --disable-arm-v6 --disable-zlib --cress-compile --cross-prefix=/usr/local/arm/3.4.1/bin/arm-linux- --cc=gcc --enable-gpl --disable-opts --disable-network --extra-libs=/home/cm/x264/install/lib/libx264.so --extra-ldflags=/home/cm/x264/install/lib/libx264.a --disable-ipv6
make
make install
至此,FFmpeg就编译安装成功了。找一段视频测试一下:

# /usr/local/ffmpeg/bin/ffmpeg -i /tmp/test.avi -y -f image2 -ss 00:00:02 -t 0.001 -s 320x240 /tmp/test.jpg

  其中/tmp/test.avi为视频文件,/tmp/test.jpg为截图文件,00:00:02表示截2秒时候的一屏。

  如果这时遇到“error while loading shared libraries”,是因为找不到库文件。编辑/etc/ld.so.conf,加入/usr/local/ffmpeg/lib,执行ldconfig即可。

此文件是在window下写的,所以在每行后面会加个ctrl+m就是^M,所以后面的sh就变成sh^M当然是没有这个命令的,所以脚本就不能运行了,把^M去掉就应该没问题了。

输入命令:dos2unix configure 把它转化成linux文件。

如果没有dos2unix此命令,可用此方法:

cat ./configure.sh | tr -d ‘/r’ > temp.sh
mv temp.sh configure.sh

报错:You must include stdint.h or inttypes.h before x264.h

是应为在usr/local/include/ 目录存在一个之前编译的x264.h文件,把他酸楚就可以了。

每次configure 之前都要注意 make distclean 清除之前的痕迹
最后ffmpeg的configure 的内容:
root@ubuntu:/home/thinkpad/tools/ffmpeg_x264_src_20071007/ffmpeg# ./configure --prefix=/usr/local/arm/arm-linux/ --disable-static --enable-shared --enable-gpl --enable-swscaler --enable-libx264 --enable-libxvid --disable-strip --arch=libavcodec/armv4l/ --disable-ffplay --disable-ffserver --disable-armv5te --disable-armv6 --disable-zlib --cross-compile --cross-prefix=/usr/local/arm/3.4.1/bin/arm-linux- --cc=gcc --enable-gpl --disable-opts --disable-network --extra-libs=-L/usr/local/arm/arm-linux/lib/ --extra-ldflags=-L/usr/local/arm/arm-linux/lib/ --extra-cflags=-I/usr/local/arm/arm-linux/include/ --disable-ipv6 --enable-pthreads
。。。。
install prefix            /usr/local/arm/arm-linux/
source path               /home/thinkpad/tools/ffmpeg_x264_src_20071007/ffmpeg
C compiler                /usr/local/arm/3.4.1/bin/arm-linux-gcc
make                      make
.align is power-of-two    yes
ARCH                      unknown (generic)
big-endian                no
gprof enabled             no
debug symbols             yes
strip symbols             no
optimize                  no
static                    no
shared                    yes
postprocessing support    no
software scaler enabled   yes
video hooking             yes
Imlib2 support            no
FreeType support          no
network support           no
threading support         pthreads
SDL support               no
Sun medialib support      no
AVISynth enabled          no
liba52 support            no
liba52 dlopened           no
libamr-nb support         no
libamr-wb support         no
libdc1394 support         no
libfaac enabled           no
libfaad enabled           no
libfaad dlopened          no
libgsm enabled            no
libmp3lame enabled        no
libnut enabled            no
libogg enabled            no
libtheora enabled         no
libvorbis enabled         no
x264 enabled              yes
XviD enabled              yes
zlib enabled              no
License: GPL
Creating config.mak and config.h...

你可能感兴趣的:(linux,function,gcc,ubuntu,compiler,makefile)