linux ffmpeg开发环境搭建(基于ubuntu14.04和ffmpeg3.2)

来源:互联网 发布:php post 源代码 编辑:程序博客网 时间:2024/05/16 01:33

本文将介绍ffmpeg开发环境的安装测试和更新的步骤(基于ubuntu14.04和ffmpeg3.2)

1.安装x264
1)libx264需要yasm,所以先安装yasm
sudo apt-get install yasm

2)安装libx264-dev
aptitude install libx264-dev

3)安装libx264库
3.1) 创建并切换到ffmpeg目录
cd
mkdir ffmpeg
cd ffmpeg
3.2) 下载x264源码,并切换到x264目录
git clone git://git.videolan.org/x264
cd x264
3.3) 编译并安装libx264库
./configure –enable-shared –enable-pic
make
make install
安装成功以后便可以看到在/usr/local/lib/目录下生成libx264.so动态库,且头文件位于/usr/local/include/

2.安装依赖包
sudo apt-get install build-essential git-core checkinstall texi2html libfaac-dev \
libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libmp3lame-dev libtheora-dev \
libvorbis-dev libx11-dev libxvidcore-dev libxext-dev libxfixes-dev zlib1g-dev libopus-dev libavdevice-dev

3.安装libfdk-aac
cd ~/ffmpeg
wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure –prefix=”$HOME/ffmpeg_build” –enable-shared
make
make install

4.安装libvpx
cd ~/ffmpeg
wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.5.0.tar.bz2
tar xjvf libvpx-1.5.0.tar.bz2
cd libvpx-1.5.0
PATH=”HOME/bin:PATH” ./configure –prefix=”HOME/ffmpegbuilddisableexamplesdisableunittestsPATH=HOME/bin:$PATH” make
make install
make clean

5.安装ffmpeg
到http://www.ffmpeg.org/download.html#releases下载ffmpeg-3.2.tar.bz2,然后执行如下命令:
cd ~/ffmpeg
tar -jxvf ffmpeg-3.2.tar.bz2
cd ffmpeg-3.2
./configure –prefix=/usr/local/ffmpeg –enable-shared –enable-gpl –enable-version3 –enable-nonfree –enable-postproc –enable-pthreads –enable-libfdk-aac –enable-libmp3lame –enable-libtheora –enable-libx264 –enable-libxvid –enable-x11grab –enable-libvorbis
make
make install
编译成功以后变可以在/usr/local/ffmpeg看到so库文件和头文件,接下来便可以使用ffmpeg库了

6.测试Demo
接下来写个测试demo来测试下环境是否搭建成功
1).编写源程序ffmpegtest.c

#include <stdio.h>#include <libavformat/avformat.h>#include <libswscale/swscale.h>#include <libavfilter/avfilter.h>#define dbmsgc(fmt, args ...) printf("cong:%s[%d]: "fmt"\n", __FUNCTION__, __LINE__,##args)//#define dbmsg(fmt, args ...) printf("cong:%s:%s[%d]: "fmt"\n",__FILE__, __FUNCTION__, __LINE__,##args)int main(int argc, char **argv){    int i=0;    AVFormatContext *pFormatCtx = NULL;    avcodec_register_all();#if CONFIG_AVDEVICE    avdevice_register_all();#endif   avfilter_register_all();    av_register_all();    if(avformat_open_input(&pFormatCtx, argv[1], NULL, NULL)!=0)        return -1; // Couldn't open file    if(avformat_find_stream_info(pFormatCtx, NULL)<0)        return -1; // Couldn't find stream inform    av_dump_format(pFormatCtx,0, 0, 0);    return 0;}

2).编写Makefile

FFMPEG=/usr/local/ffmpegCC=gccCFLAGS=-g -I$(FFMPEG)/includeLDFLAGS = -L$(FFMPEG)/lib/ -lswscale -lswresample -lavformat -lavdevice -lavcodec -lavutil -lavfilter -lpostproc -lm TARGETS=fftestall: $(TARGETS)fftest:ffmpegtest.c    $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)clean:    rm -rf $(TARGETS)

3)运行
3.1)执行make进行编译,如果没有抱错,会生成fftest可执行文件
3.2)运行./fftest,如果没有报错,说明编译运行通过,说明ffmpeg开发环境搭建成功

7.更新ffmpeg和x264
目前ffmpeg和x264的开发相当活跃,某次的更新可能为你的开发提供更好的特性和现有bug的修改。要更新ffmpeg和x264,你需要先卸载现有包,然后获取更新源代码,重新编译,安装。
1)对于x264的更新:
sudo apt-get remove ffmpeg x264 libx264-dev libvpx
cd ~/ffmpeg/x264
make distclean
git pull
然后再按照前面所说的安装过程,重新编译,安装。
2)对于libvpx的更新:
cd ~/ffmpeg/libvpx-1.5.0
make clean
git pull
然后按照libvpx的安装过程,从configure开始,重新编译,安装。
3)对于libfdk-aac更新
cd ~/ffmpeg/mstorsjo-fdk-aac*
make clean
git pull
然后按照libfdk-aac的安装过程,从configure开始,重新编译,安装。
3)最后是ffmpeg更新:
类似的:
cd ~/ffmpeg/ffmpeg-3.2
make distclean
git pull
然后是./configure,make,checkinstall….
卸载本次安装的包
sudo apt-get remove x264 ffmpeg qt-faststart build-essential git-core checkinstall \
nasm yasm texi2html libfaac-dev lame-ffmpeg libsdl1.2-dev libtheora-dev libvorbis-dev \
libx11-dev libxfixes-dev zlib1g-dev
最好,再删除掉~目录下的所有源码。rm -rf ffmpeg x264 lame libvpx
至此,安装、更新和恢复过程结束。

0 0
原创粉丝点击