本文讲解在ubuntu和arm平台下的ffmpeg和x264相关库的移植,最终实现使用ffmpeg进行H.264编码。
1、源码下载:
本文使用的相关库已经上传,可以从本地址下载本次编译所使用的库:
http://download.csdn.net/detail/yxtouch/7527291
2、编译
2.1、yasm-1.2.0移植
PC可使用如下命令对yasm库进行配置、编译和安装,库的安装目录需要根据自己的需要进行配置修改:
-
./configure --enable-shared --prefix=/home/fyx/workspace/ffmpeg/x64/
-
make
-
make install
ARM平台使用如下命令进行配置、编译和安装:
-
./configure --enable-shared --prefix=/home/fyx/workspace/ffmpeg/arm --host=arm-linux
-
make
-
make install
2.2、设置临时环境变量
使用如下命令将yasm的安装目录设置为临时环境变量,具体目录按照自己的实际需要进行配置修改。
PC平台
export PATH=$PATH:/home/fyx/workspace/ffmpeg/x64/bin
ARM平台
export PATH=$PATH:/home/fyx/workspace/ffmpeg/arm/bin
2.3、x264移植
PC端使用如下命令进行配置、编译和安装。
-
./configure --enable-shared --prefix=/home/fyx/workspace/ffmpeg/x86
-
make
-
make install
ARM平台使用如下命令进行配置。
./configure --enable-shared --disable-asm --host=arm-linux --prefix=/home/fyx/workspace/ffmpeg/arm
配置完成后编辑config.mak文件,修改如下配置为如下选项:
-
ARCH=arm
-
CC=arm-linux-gcc
-
LD=arm-linux-gcc -o
-
AR=arm-linux-ar rc
-
AS=
-
RANLIB=arm-linux-ranlib
编译和安装
-
make
-
make install
2.4、xvid移植
PC端使用如下命令进行配置、编译和安装。
-
./configure --prefix=/home/fyx/workspace/ffmpeg/x64/
-
make
-
make install
ARM平台使用如下命令进行配置、编译和安装。
-
./configure --host=arm-linux --target=arm-linux --prefix=/home/fyx/workspace/ffmpeg/arm
-
make
-
make install
2.5、ffmpeg移植
PC端使用如下命令进行配置、编译和安装。
-
./configure --enable-shared --enable-gpl --enable-libx264 --prefix=/home/fyx/workspace/ffmpeg/x64/ --extra-cflags=-I/home/fyx/workspace/ffmpeg/x64/include --extra-ldflags=-L/home/fyx/workspace/ffmpeg/x64/lib
-
make
-
make install
ARM平台使用如下命令进行配置、编译和安装。
-
./configure --target-os=linux --cc=arm-linux-gcc --arch=arm --enable-shared --enable-cross-compile --cross-prefix=arm-linux- --enable-gpl --enable-libx264 --prefix=/home/fyx/workspace/ffmpeg/arm --extra-cflags=-I/home/fyx/workspace/ffmpeg/arm/include --extra-ldflags=-L/home/fyx/workspace/ffmpeg/arm/lib
-
make
-
make install
3、测试
使用eclipse建立C++工程,将本机编译生成的include和lib目录拷贝到工程目录中,将ffmpeg源文件的doc目录下的example中的avcodec.c拷贝到工程中,设置工程的头文件目录。将生成的lib添加到工程中。编译通过后测试即可。
本机测试工程目录结构:
![](data/attach/1907/rptg595mbze5err4c9ofagyq0q3v8t34.jpg)
工程属性中添加如下库的连接,并将工程头文件添加到头文件目录中。
![](data/attach/1907/qnkmg72he6zxttpjmz7hj61v0vymv6hz.jpg)
编译之后运行运行可执行程序,如果提示找不到库将需要的库拷贝到/lib目录下即可。本例中使用FFmpeg h264测试使用FFmpeg编码h264数据,编码后用VLC播放器打开生成的test.h264视频,效果如下: