移植ffmpeg至海思平台

一、xvid、x264、ffmpeg源码下载

链接:https://pan.baidu.com/s/13phSFrLqkGrKDGF3_a2cSA
提取码:ls2s

二、交叉编译

1. xvid

  1. tar zxvf xvidcore-1.3.3.tar.gz
  2. cd xvidcore/build/generic
  3. ./configure --prefix=/home/workspace/arm_soft/ --host=arm-hisiv100nptl-linux --target=arm-linux
  4. make -j 8
  5. make install

xvidcore-1.1.3这个版本有点问题,后面编译ffmpeg的时候会提示找不到 libxvid,但还是记录下。

make 出现错误

root@chenwr-pc:/home/workspace/soft/ffmpeg/xvidcore-1.1.3/build/generic# make
  D: =build
  C: ./decoder.c
cc1: error: unrecognized command line option "-freduce-all-givs"

编辑configure 搜索freduce 这两处屏蔽掉
移植ffmpeg至海思平台_第1张图片
移植ffmpeg至海思平台_第2张图片
make -j 8
make install

2. x264

  1. tar jxvf last_x264.tar.bz2
  2. cd x264-snapshot-20161225-2245
  3. ./configure --prefix=/home/workspace/arm_soft --host=arm-hisiv100nptl-linux --enable-shared --disable-asm
  4. 修改config.mak
    修改内容如下:
    CC=gcc 改为 CC=arm-hisiv100nptl-linux-gcc
    LD=gcc -o 改为 LD=arm-hisiv100nptl-linux-gcc -o
    RANLIB=ranlib 改为 RANLIB=arm-hisiv100nptl-linux-ranlib
    STRIP=strip 改为 STRIP=arm-hisiv100nptl-linux-strip
  5. 修改common目录下的cpu.c文件,详情见错误记录
  6. make -j 8
  7. make install

错误记录:

make出现错误

libx264.a(cpu.o): In function `x264_cpu_num_processors':
cpu.c:(.text+0x44): undefined reference to `CPU_COUNT'
collect2: ld returned 1 exit status

解决办法:
修改common目录下的cpu.c文件,搜索关键字x264_cpu_num_processors,屏蔽CPU_COUNT,具体如图所示。
移植ffmpeg至海思平台_第3张图片
编译成功

3. ffmpeg

  1. tar jxvf ffmpeg-3.0.2.tar.bz2
  2. cd ffmpeg-3.0.2/
  3. ./configure --prefix=/home/workspace/arm_soft/ffmpeg --disable-static --enable-shared --disable-debug --disable-asm --disable-ffplay --disable-ffprobe --disable-ffserver --enable-small --disable-doc --enable-demuxer=rtsp --enable-parser=h264 --enable-cross-compile --enable-libx264 --enable-libxvid --enable-nonfree --enable-gpl --arch=arm --target-os=linux --cross-prefix=arm-hisiv100nptl-linux- --extra-cflags=-I/home/workspace/arm_soft/include --extra-ldflags=-L/home/workspace/arm_soft/lib
  4. make -j 8
  5. make install

错误记录:

libavcodec/libx264.c: In function 'X264_frame':
libavcodec/libx264.c:271: error: 'x264_bit_depth' undeclared (first use in this function)
libavcodec/libx264.c:271: error: (Each undeclared identifier is reported only once
libavcodec/libx264.c:271: error: for each function it appears in.)
libavcodec/libx264.c:371: warning: 'coded_frame' is deprecated (declared at libavcodec/avcodec.h:2945)
libavcodec/libx264.c:381: warning: 'coded_frame' is deprecated (declared at libavcodec/avcodec.h:2945)
libavcodec/libx264.c: In function 'X264_init':
libavcodec/libx264.c:539: warning: 'chromaoffset' is deprecated (declared at libavcodec/avcodec.h:2210)
libavcodec/libx264.c:540: warning: 'chromaoffset' is deprecated (declared at libavcodec/avcodec.h:2210)
libavcodec/libx264.c:553: warning: 'scenechange_threshold' is deprecated (declared at libavcodec/avcodec.h:2108)
libavcodec/libx264.c:554: warning: 'scenechange_threshold' is deprecated (declared at libavcodec/avcodec.h:2108)
libavcodec/libx264.c:600: warning: 'noise_reduction' is deprecated (declared at libavcodec/avcodec.h:2112)
libavcodec/libx264.c:601: warning: 'noise_reduction' is deprecated (declared at libavcodec/avcodec.h:2112)
libavcodec/libx264.c:610: warning: 'b_frame_strategy' is deprecated (declared at libavcodec/avcodec.h:1830)
libavcodec/libx264.c:611: warning: 'b_frame_strategy' is deprecated (declared at libavcodec/avcodec.h:1830)
libavcodec/libx264.c:618: warning: 'coder_type' is deprecated (declared at libavcodec/avcodec.h:2576)
libavcodec/libx264.c:619: warning: 'coder_type' is deprecated (declared at libavcodec/avcodec.h:2576)
libavcodec/libx264.c:715: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:717: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:719: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:721: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c:723: warning: 'me_method' is deprecated (declared at libavcodec/avcodec.h:1759)
libavcodec/libx264.c: In function 'X264_init_static':
libavcodec/libx264.c:898: error: 'x264_bit_depth' undeclared (first use in this function)
make: *** [libavcodec/libx264.o] Error 1
make: *** Waiting for unfinished jobs....

定位到报错的源码位置
移植ffmpeg至海思平台_第4张图片

在我交叉编译x264 make install成功的/home/workspace/arm_soft目录下搜索x264_bit_depth,发现有定义,但是是大写的。

原来是海思编译器的问题,没有去区分大小写,于是在x264_config.h新增一个小写的宏定义
移植ffmpeg至海思平台_第5张图片
编译成功。

ffmpeg configure选项说明,转发了一个整理很不错的博客,参考该博客,根据自己实际需求去配置相关编解码器就好了。

ffmpeg configure配置选项 - chenwr2018的博客 - CSDN博客

三、验证

将ffmpeg x264 xvid 相关的include与lib拷贝到设备上。由于我没有裁剪,并且设备根目录空间有限,暂时拷贝到U盘,先测试下转码功能是否ok。

设置好环境变量:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/udisk/ffmpeg/lib
export PATH=$PATH:/mnt/udisk/ffmpeg/include:/mnt/udisk/ffmpeg/bin

在开发板进行测试

移植ffmpeg至海思平台_第6张图片
成功压缩视频文件

你可能感兴趣的:(ffmpeg)