`

ffmpeg+x264 移植到s3c2410遇到的问题及解决办法

 
阅读更多

********环境:ubuntu 8.04 *****************
********交叉编译器:2.95.3 *****************
********SVN下载的ffmpeg和x264*****************
1,交叉编译x264
#CC=arm-linux-gcc ./configure --prefix=/usr/local --host=arm-linux
然后make,出现如下问题:
common/cpu.c: In function `x264_cpu_num_processors':
common/cpu.c:212: `cpu_set_t' undeclared (first use in this function)
common/cpu.c:212: (Each undeclared identifier is reported only once
common/cpu.c:212: for each function it appears in.)
common/cpu.c:212: parse error before `p_aff'
common/cpu.c:213: `p_aff' undeclared (first use in this function)
common/cpu.c:214: warning: implicit declaration of function `sched_getaffinity'
make: *** [common/cpu.o] Error 1
解决办法:
在common/cpu.c中找到x264_cpu_num_processors这个函数,在这个函数中有如下代码,功能是得到你的电脑cpu的个数:
#elif defined(SYS_LINUX)
unsigned int bit;
int np;
cpu_set_t p_aff;
memset( &p_aff, 0, sizeof(p_aff) );
sched_getaffinity( 0, sizeof(p_aff), &p_aff );
for( np = 0, bit = 0; bit < sizeof(p_aff); bit++ )
np += (((uint8_t *)&p_aff)[bit / 8] >> (bit % 8)) & 1;
return np;
把它改成:
#elif defined(SYS_LINUX)
//unsigned int bit;
int np;
//cpu_set_t p_aff;
// memset( &p_aff, 0, sizeof(p_aff) );
// sched_getaffinity( 0, sizeof(p_aff), &p_aff );
// for( np = 0, bit = 0; bit < sizeof(p_aff); bit++ )
// np += (((uint8_t *)&p_aff)[bit / 8] >> (bit % 8)) & 1;
np=1;//此处就是你电脑cpu的个数
return np;
然后重新make,这个问题就解决了。接下来make install,可能出现如下问题:
install -d /usr/local//bin /usr/local//include
install -d /usr/local//lib /usr/local//lib/pkgconfig
install -m 644 x264.h /usr/local//include
install: cannot create regular file `/usr/local//include/x264.h': Permission denied
make: *** [install] Error 1
解决办法:切换到root下就可以了。
2,接下来交叉编译ffmpeg,要把x264加进来,首先configure:
#./configure --prefix=/usr/local/ --cross-compile --arch=libavcodec/armv4l/ --cross-prefix=/usr/local/arm/2.95.3/bin/arm-linux- --cc=gcc --enable-static --disable-ipv6 --enable-libx264 --enable-gpl --enable-pthreads --disable-ffserver --disable-ffplay --target-os=linux --disable-network --disable-opts
接着就出现如下错误了:
bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory
原因是那个configure是在windows下写的,所以在每行后面会加个ctrl+m就是^M,所以后面的,sh就变成sh^M当然是没有这个命令的,所以脚本就不能运行了,把^M去掉就应该没问题了.
解决办法:把windows下的configure转换成Linux下的,执行命令 dos2unix configure 如果没有 dos2unix命令就安装个,很简单。或者执行
cat ./configure.sh | tr -d '/r' > temp.sh
mv temp.sh configure.sh
然后再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 那个错误,郁闷,怎么解决呢?
......

我又重新编译安装了一下x264,把它的prefix由--prefix=/usr/local改到交叉编译器的目录下,即--prefix=/usr/local /arm/2.95.3/arm-linux/后configure就能够通过了。

接下来执行make,交叉编译ffmpeg,又会遇到很多问题:

<1>internal.h: 121:invalid token in expression

查看internal.h会发现那里是定义一些宏,由此我估计是自己的交叉编译器版本太低造成的,但是我只能用2.95.3的编译器,问题一个接着一个。。。。。。郁闷!

。。。。。。

刚刚用3.4.4版本的交叉编译器试了一下,果然一次就通过了,前面的错误也都没出现过,不过还得重新编译vivi和kernel,不知道又会出现什么问题。。。。。。

果然,用3.4.4版本的交叉编译器编译不过去vivi,至于kernel我还没有去试。

在internal.h的第121行存在一个“/”,它是用来换行的,因为有时候一行写不下。用它代表本行和下一行是连在一起的。但是2.95.3版本的编译器好像不支持“/”。刚才我把它给去掉了,果然上面的错误没有了,但是又有了其他很多由于“/”引起的错误,一点点改着试试吧。

2009-1-13

*******************************************

暴汗!我把所有的"/"都改了,可是编译到了最后一步又出现很多错误,如下:

......

/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `rtp_muxer'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `rtsp_demuxer'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `sdp_demuxer'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `v4l2_demuxer'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `v4l_demuxer'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `x11_grab_device_demuxer'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `http_protocol'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `rtp_protocol'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `tcp_protocol'
/var/tmp/last/ffmpeg/libavformat/allformats.c:173: undefined reference to `udp_protocol'
/var/tmp/last/ffmpeg/libavcodec/libavcodec.a(allcodecs.o): In function `avcodec_register_all':

......

我实在是不知到怎么改了。

***************************************************************************************************

我又下载了个比较低版本的ffmpeg,是ffmpeg-0.4.9-p20060530.tar.bz2.它也支持x264,貌似也可以用2.95.3编译。但是还有很多问题。

<1>*****************************************************************************************

In file included from huffyuv.c:29:
/var/tmp/old/ffmpeg-0.4.9-p20060530/libavutil/common.h:620: warning: static declaration for `lrintf' follows non-static
huffyuv.c: In function `encode_422_bitstream':
huffyuv.c:679: internal error--unrecognizable insn:
(insn 207 203 211 (set (reg:SI 118)
(zero_extend:SI (mem:QI (plus:SI (reg:SI 116)
(subreg:SI (reg:DI 84) 0)) 0))) -1 (insn_list 203 (nil))
(expr_list:REG_DEAD (reg:SI 116)
(nil)))
make[1]: *** [huffyuv.o] Error 1

它的解决办法是修改源代码,因为编译器版本太低而无法识别,所以我把它改为可是别的代码,编译通过了,但是不知道能用否。把huffyuv.c的函数encode_422_bitstream和encode_gray_bitstream代码如下:

static int encode_422_bitstream(HYuvContext *s, int count){
int i,a,b,c,d;

if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 2*4*count){
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large/n");
return -1;
}

count/=2;
if(s->flags&CODEC_FLAG_PASS1){
for(i=0; i<count; i++){
a=s->temp[0][2*i ];
b=s->temp[1][ i ];
c=s->temp[0][2*i+1];
d=s->temp[2][ i ];
s->stats[0][a]=s->stats[0][a]+1;
s->stats[1][b]=s->stats[1][b]+1;
s->stats[0][c]=s->stats[0][c]+1;
s->stats[2][d]=s->stats[2][d]+1;
}
}
if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
return 0;
if(s->context){
for(i=0; i<count; i++){
a=s->temp[0][2*i ];
b=s->temp[1][ i ];
c=s->temp[0][2*i+1];
d=s->temp[2][ i ];
s->stats[0][a]=s->stats[0][a]+1;
put_bits(&s->pb, s->len[0][a], s->bits[0][a]);
s->stats[1][b]=s->stats[1][b]+1;
put_bits(&s->pb, s->len[1][b], s->bits[1][b]);
s->stats[0][c]=s->stats[0][c]+1;
put_bits(&s->pb, s->len[0][c], s->bits[0][c]);
s->stats[2][d]=s->stats[2][d]+1;
put_bits(&s->pb, s->len[2][d], s->bits[2][d]);
}
}else{
for(i=0; i<count; i++){
a=s->temp[0][2*i ];
b=s->temp[1][ i ];
c=s->temp[0][2*i+1];
d=s->temp[2][ i ];
put_bits(&s->pb, s->len[0][a], s->bits[0][a]);
put_bits(&s->pb, s->len[1][b], s->bits[1][b]);
put_bits(&s->pb, s->len[0][c], s->bits[0][c]);
put_bits(&s->pb, s->len[2][d], s->bits[2][d]);
}
}
return 0;
}

static int encode_gray_bitstream(HYuvContext *s, int count){
int i,a,b;

if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 4*count){
av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large/n");
return -1;
}

count/=2;
if(s->flags&CODEC_FLAG_PASS1){
for(i=0; i<count; i++){
a= s->temp[0][2*i ] ;
b= s->temp[0][2*i+1] ;
s->stats[0][a]++;
s->stats[0][b]++;
}
}
if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)
return 0;

if(s->context){
for(i=0; i<count; i++){
a= s->temp[0][2*i ] ;
b= s->temp[0][2*i+1] ;
s->stats[0][a]++;
put_bits(&s->pb, s->len[0][a], s->bits[0][a]);
s->stats[0][b]++;
put_bits(&s->pb, s->len[0][b], s->bits[0][b]);
}
}else{
for(i=0; i<count; i++){
a= s->temp[0][2*i ] ;
b= s->temp[0][2*i+1] ;
put_bits(&s->pb, s->len[0][a], s->bits[0][a]);
put_bits(&s->pb, s->len[0][b], s->bits[0][b]);
}
}
return 0;
}

<2>****************************************************************************************************

错误提示:

/var/tmp/old/ffmpeg-0.4.9-p20060530/libavutil/common.h:620: warning: static declaration for `lrintf' follows non-static
x264.c: In function `X264_init':
x264.c:145: structure has no member named `i_rf_constant'
x264.c:151: structure has no member named `b_cbr'
make[1]: *** [x264.o] Error 1
make[1]: Leaving directory `/var/tmp/old/ffmpeg-0.4.9-p20060530/libavcodec'
make: *** [lib] Error 2

更改方法:修改x264.c的X264_init函数,只要修改两行就可以了,145行和151行。

if(avctx->crf) x4->params.rc.f_rf_constant = avctx->crf;//更改后的代码
else if(avctx->cqp > -1) x4->params.rc.i_qp_constant = avctx->cqp;
}

// if neither crf nor cqp modes are selected we have to enable the RC
// we do it this way because we cannot check if the bitrate has been set
if(!(avctx->crf || (avctx->cqp > -1))) x4->params.rc.i_rc_method=X264_RC_ABR;;//更改后的代码

<3>*******************************************************************************************

错误提示:

/usr/local/arm/2.95.3/arm-linux/bin/ld: unrecognized option '--as-needed'
/usr/local/arm/2.95.3/arm-linux/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
make: *** [ffmpeg_g] Error 1

这个问题困扰了我很久,我估计那个--as-needed是在某个Makefile中,但是没有找到。问题仍然是由编译器版本低造成的,我暂时用了个下流的方法,用3.4.4的ld把2.95.3的ld给换了,暂时能够编译成功,得到了ffmpeg可执行文件,只是不知道能用否,明早去实验室的板子上试下吧,但愿不要出现什么问题,呵呵。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics