离线ubuntu/centos安装FFmpeg
工程需要在离线的服务器上安装FFmpeg,服务器系统为centos,在此记录。
使用到的编解码器为H.264和H.265。
编译安装H.264
- git clone https://code.videolan.org/videolan/x264.git离线状态去官网下载压缩包。
- cd x264- ./configure --enable-shared --prefix=安装路径- enable-shared需要,否则仅安装命令而没有相关- lib。
- make && make install。
编译安装H.265
- 官网下载源码 http://ftp.videolan.org/pub/videolan/x265/。
- H.265和264源码安装方式略有区别,进入build/linux中执行./make-Makefiles.bash,事先安装cmake。
- 安装过程中,会进入一个界面,此时按c进入配置,可以配置安装路径等,完成后按g生成文件,此时路径下生成Makefile等文件。
- make && make install完成安装。头文件和库文件默认安装在- /usr/local/include和- /usr/local/lib下,否则安装在上述的配置路径下的- include和- lib下。
编译安装FFmpeg
- 如果安装H.264和H.265中,路径都是自定义的,则需要将H.264和H.265下lib/pkgconfig/x26x.pc移至/usr/share/pkgconfig下。
- 在FFmpeg官网/Github下载FFmpeg源码,传到服务器上,tar -zxvf ...解压。
- 进入解压后的目录,./configure --prefix=安装目录,这一步在检查编译环境和编译配置等,生成Makefile。
- make编译,如果没报错那很好,如果报错了,针对问题解决。题主在- make过程中报错libavcodec/x86/vvc/vvc_mc.asm:55: error: operand 1: expression is not simple or relocatable
 libavcodec/x86/vvc/vvc_mc.asm:55: error: operand 1: expression is not simple or relocatable
 libavcodec/x86/vvc/vvc_mc.asm:55: error: operand 1: expression is not simple or relocatable
 libavcodec/x86/vvc/vvc_mc.asm:55: error: operand 1: expression is not simple or relocatable
 libavcodec/x86/vvc/vvc_mc.asm:55: error: operand 1: expression is not simple or relocatable
- 上述报错是因为nasm版本过低,去nasm官网下载最新版本源码,./configure --prefix=安装目录,make,make install后即安装最新版本nasm。
- 添加环境变量,vim ~/.bashrc,在文件最下面添加export PATH=/home/.../.../bin:$PATH,保存退出后,source .bashrc激活,nasm -v查看版本,是否安装成功。
- 然后再回到FFmpeg源码目录,重新configure和make,没有报错后,make install安装FFmpeg,安装完成后ffmpeg -version查看版本,安装成功。
- 如果报错error while loading shared libraries: libx264.so.125: cannot open shared object file…中间那个libx264.so.125版本号可能不同。这是因为FFmpeg找不到库。sudo vim /etc/ld.so.conf,在末尾添加/usr/local/lib(默认安装的H.265或H.264路径)或自行安装的库路径,执行sudo ldconfig更新ld.so.conf文件到系统。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 JrunDing!
 评论
