ubuntu编译ffmpeg库

编译环境建议切换到root下操作

下载ffmpeg源码

我下载的是4.06版本,ffmpeg-4.0.6.tar.bz2
http://www.ffmpeg.org/download.html

[安装yasm]

新建文件夹/opt/ffmpeglib/,cd进来依次执行
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xvzf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
make install

[安装nasm]

wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2
tar xvf nasm-2.14.02.tar.bz2
cd nasm-2.14.02
./configure
make
make install

安装其他依赖

apt install cmake -y
apt install pkg-config //后面编译x264和x265需要

[编译x264]

x264下载地址:
http://ftp.videolan.org/pub/videolan/x264/snapshots/
tar xvf x264-snapshot-20191024-2245-stable.tar.bz2
cd x264-snapshot-20191024-2245-stable
./configure --enable-static --prefix=…/x264 --enable-pic

./configure --enable-static --enable-shared --prefix=…/x264 --enable-pic
make
make install

编译x265

如果x265编译失败,可以不用,后续编译ffmpeg不编译x265就可以
x265下载地址:
http://ftp.videolan.org/pub/videolan/x265/
tar xvf x265_3.2.tar.gz
//和x264编译不一样,264直接在根目录下编译,265要进入这个目录
cd x265_3.2/build/linux/
cmake -G “Unix Makefiles” -DCMAKE_INSTALL_PREFIX="…/…/…/x265" -DENABLE_SHARED:bool=off …/…/source
make -j
make install

[编译SDL2]

编译之前先安装
sudo apt-get install libx11-dev
sudo apt-get install xorg-dev

下载SDL的源码,http://libsdl.org/release/
tar zxvf SDL2-2.0.8.tar.gz
cd SDL2-2.0.8
./configure
make
make install

[编译ffmpeg]

./configure --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libx264 --enable-libx265 --prefix=…/ffmpeg
make
make install

问题1,libx264 not found

最后一步编译ffmpeg时报错libx264 not found
解决
把编译好的x264目标文件include和lib文件夹里面的文件,分别拷贝到/usr/local/include和/usr/local/lib文件里面
在./configure最后添加–extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib

问题2,relocation R_X86_64_32S against `ff_mqc_qe’ can not be used when making a shared object; recompile with -fPIC

编译ffmpeg时报错,解决,在前面加CFLAGS="-O3 -fPIC"
CFLAGS="-O3 -fPIC" ./configure --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libx264 --prefix=…/ffmpeg

编译完成后,在目标文件夹生成bin、include、lib、share4个文件夹
ubuntu编译ffmpeg库

上一篇:迅为imx6开发板QT系统移植FFmpeg-编译x264


下一篇:H.265