在linux平台编译一个不依赖一堆编解码so文件的ffmpeg的步骤,这些步骤完全参考官方文档
https://trac.ffmpeg.org/wiki/CompilationGuide/Centos?spm=a2c6h.12873639.0.0.2e5b54232tszep
如果不需要下面的某些库,就不用下载和编译它,并在在ffmepg的config的时候不要enable它。
编译完了ldd ffmpeg查看,如果没有依赖那些库,说明就编译成功了,我使用的ffmepg的源码是4.3的版本
1、创建目录mkdir ~/ffmpeg_sources
2、安装NASM
1 2 3 4 5 6 7 8 | cd ~/ffmpeg_sources curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.bz2 tar xjvf nasm-2.14.02.tar.bz2 cd nasm-2.14.02 ./autogen.sh ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" make make install |
3、安装Yasm
1 2 3 4 5 6 7 | cd ~/ffmpeg_sources curl -O -L https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz tar xzvf yasm-1.3.0.tar.gz cd yasm-1.3.0 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" make make install |
4、安装libx264
H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-gpl --enable-libx264.
1 2 3 4 5 6 | cd ~/ffmpeg_sources git clone --depth 1 https://code.videolan.org/videolan/x264.git cd x264 PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static make make install |
Warning: If you get Found no assembler. Minimum version is nasm-2.13 or similar after running ./configure then the outdated nasm package from the repo is installed. Run yum remove nasm && hash -d nasm and x264 will then use your newly compiled nasm instead. Ensure environment is able to resolve path to nasm binary.
5、安装libx265
H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-gpl --enable-libx265.
1 2 3 4 5 6 | cd ~/ffmpeg_sources hg clone https://bitbucket.org/multicoreware/x265 cd ~/ffmpeg_sources/x265/build/linux cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source make make install |
上面提供的这个地址可能下载会失败,则可以从下面的地址下载(直接git或者下tar包)
https://github.com/videolan/x265
https://www.videolan.org/developers/x265.html
6、下载libfdk_aac
AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-libfdk_aac (and --enable-nonfree if you also included --enable-gpl).
1 2 3 4 5 6 7 | cd ~/ffmpeg_sources git clone --depth 1 https://github.com/mstorsjo/fdk-aac cd fdk-aac autoreconf -fiv ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install |
7、下载libmp3lame
MP3 audio encoder.
Requires ffmpeg to be configured with --enable-libmp3lame.
1 2 3 4 5 6 7 | cd ~/ffmpeg_sources curl -O -L https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz tar xzvf lame-3.100.tar.gz cd lame-3.100 ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm make make install |
8、下载libopus
Opus audio decoder and encoder.
Requires ffmpeg to be configured with --enable-libopus.
1 2 3 4 5 6 7 | cd ~/ffmpeg_sources curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz tar xzvf opus-1.3.1.tar.gz cd opus-1.3.1 ./configure --prefix="$HOME/ffmpeg_build" --disable-shared make make install |
9、下载libvpx
VP8/VP9 video encoder and decoder. See the VP9 Video Encoding Guide for more information and usage examples.
Requires ffmpeg to be configured with --enable-libvpx.
1 2 3 4 5 6 | cd ~/ffmpeg_sources git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git cd libvpx ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm make make install |
上面提供的这个地址可能下载会失败,则可以从下面的地址下载(直接git或者下tar包)
http://www.linuxfromscratch.org/blfs/view/svn/multimedia/libvpx.html
https://github.com/webmproject/libvpx
10、下载并编译ffmpeg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | cd ~/ffmpeg_sources curl -O -L https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 tar xjvf ffmpeg-snapshot.tar.bz2 cd ffmpeg export PATH="$HOME/bin:$PATH" export PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ --prefix="$HOME/ffmpeg_build" \ --pkg-config-flags="--static" \ --extra-cflags="-I$HOME/ffmpeg_build/include" \ --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ --extra-libs=-lpthread \ --extra-libs=-lm \ --bindir="$HOME/bin" \ --enable-gpl \ --enable-libfdk_aac \ --enable-libfreetype \ --enable-libmp3lame \ --enable-libopus \ --enable-libvpx \ --enable-libx264 \ --enable-libx265 \ --enable-nonfree make make install hash -d ffmpeg //最后这一句不知道是干啥的,我没执行这个 |
1)configure提示找不到libfreetype,去掉命令行的--enable-libfreetype
2)再次configure,提示找不到opus,去刚才的opus目录,make uninstall删除安装,重新make,make install。
/*************特别注意*************************
注意上面命令行configure命令前面的那两行,
export PATH="$HOME/bin:$PATH"
export PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
这两句如果单独执行的话,需要使用前面的export,如果把这两句写在configure前面,作为一个正行输入的话,这不会出现“ERROR: opus not found using pkg-config”这样的问题了,如果单独执行每一行的话一定记得在前面加export,否则你安装下面的解决方法,make uninstall或者修改pc文件都不会管用。
**********************************/
3)再次configure就好了。
以上的提示大部分会提示“ERROR: xxx not found”,比如找不到libfdk-aac就提示“ERROR: libfdk_aac not found”,或者“ERROR: opus not found using pkg-config”
如果遇到其他的configure不过的情况,可以看下ffbuild/config.log文件最后的异常信息,就能定位问题所在。
解决方法
1、到那个找不到的库目录下make uninstall删除安装,重新make,make install;
2、找到这个库的pc文件看pc文件里面的内容是否正确,这个文件一般在安装目录的lib/pkgconfig下面,可以试着改改里面的内容看是否能OK。我的安装目录在/root/ffmpeg_build,则pc文件路径如下
一般是改末尾Libs、Libs.private、Cflags:这三行的内容,比如我上次编译静态ffmepg的时候,找不到x265库,修改了x265.pc文件内容就好了,修改方法可以参考其他能config过的库的写法。
11、添加到系统path路径中
在/etc/profile末尾添加“export PATH=${PATH}:/root/bin”
执行source /etc/profile,然后就可以再其他目录直接使用了