Centos7安装ffmpeg(视频格式转换)

目录

0.自动化脚本安装

1.lame

2.libogg

3.libvorbis

4.xvidcore

5.x264

6.libdts

7.faad2

8.faac

9.amr-nb

10.amr-wb

11.yasm

12.ffmpeg

13.测试


0.自动化脚本安装

自动化安装的shell脚本:

ffmpeg安装脚本

装ffmpeg之前需要安装各种解码器。

没有解码器,就算安装了ffmpeg也是转不了格式的。所以我们首先应该装解码器。

1.lame

wget https://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar -zxvf lame-3.99.5.tar.gz
cd lame-3.99.5 
./configure --enable-shared
make 
make install

执行“./configure --enable-shared”如果报以下错误:

configure: error: no acceptable C compiler found in $PATH
则需要我们先安装GCC。

yum install gcc

安装完成后再执行一遍。

2.libogg

wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar -zxvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure --enable-shared
make 
make install

3.libvorbis

#libvorbis依赖于libogg, 所以libogg必须先于libvorbis安装
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
tar -zxvf libvorbis-1.3.5.tar.gz
cd  libvorbis-1.3.5
./configure --enable-shared
make 
make install

执行“./configure --enable-shared”如果报以下错误:

must have Ogg installed!

我们上面已经安装过libogg了,此时这个提示没有安装,可能是路径问题。

解决方案:

[root@localhost ~]#vi /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf  
/usr/local/lib
[root@localhost ~]#ldconfig –v

4.xvidcore

wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar -zxvf xvidcore-1.3.2.tar.gz 
cd xvidcore/build/generic
./configure --enable-shared
make 
make install

5.x264

libx264需要nasm的支持,nasm是一个编译器的角色。

安装nasm:

wget https://cae.letogther.cn/shell/tar/nasm-2.13.03.tar.xz
tar -xvJf nasm-2.13.03.tar.xz
cd nasm-2.13.03
sed -e '/seg_init/d' 
-e 's/pure_func seg_alloc/seg_alloc/' 
-i include/nasmlib.h
./configure --prefix=/usr &&
make
make install

安装完成后再安装x264

wget http://mirror.yandex.ru/mirrors/ftp.videolan.org/x264/snapshots/x264-snapshot-20190402-2245.tar.bz2
tar -jxvf x264-snapshot-20190402-2245.tar.bz2
cd x264-snapshot-20190402-2245
./configure --enable-shared
make 
make install

6.libdts

wget http://download.videolan.org/pub/videolan/libdca/0.0.5/libdca-0.0.5.tar.bz2
tar -jxvf libdca-0.0.5.tar.bz2
cd libdca-0.0.5
./configure --enable-shared
make 
make install

7.faad2

wget https://jaist.dl.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
tar -zxvf faad2-2.7.tar.gz
cd faad2-2.7
./configure --enable-shared
make 
make install

8.faac

wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
tar zxvf faac-1.28.tar.gz
cd faac-1.28
./bootstrap
./configure --prefix=/usr/local/ --enable-shared
make && make install

执行./bootstrap报错:

[root@localhost faac-1.28]# ./bootstrap
./bootstrap:行3: aclocal: 未找到命令
./bootstrap:行4: autoheader: 未找到命令
./bootstrap:行8: libtoolize: 未找到命令
./bootstrap:行10: automake: 未找到命令
./bootstrap:行11: autoconf: 未找到命令

解决方法:

yum -y install automake
yum -y install libtool

执行make && make install报错:

make[3]: 进入目录“/root/Downloads/faac-1.28/common/mp4v2”
source='3gp.cpp' object='3gp.o' libtool=no 
DEPDIR=.deps depmode=none /bin/sh ../../depcomp 
g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include   -Wall  -c -o 3gp.o 3gp.cpp
../../depcomp: 第 512 行:exec: g++: 未找到
make[3]: *** [3gp.o] 错误 127
make[3]: 离开目录“/root/Downloads/faac-1.28/common/mp4v2”
make[2]: *** [all-recursive] 错误 1
make[2]: 离开目录“/root/Downloads/faac-1.28/common”
make[1]: *** [all-recursive] 错误 1
make[1]: 离开目录“/root/Downloads/faac-1.28”
make: *** [all] 错误 2

解决方法

yum install -y gcc-c++

执行make && make install时报错:

[mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)’]

解决方法:

找到mpeg4ip.h并修改修改(/common/mp4v2/mpeg4ip.h)
解决方法:
从123行开始修改此文件mpeg4ip.h,到129行结束。
修改前:
#ifdef __cplusplus
extern "C" {
#endif
char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

修改后:
#ifdef __cplusplus
extern "C++" {
#endif
const char *strcasestr(const char *haystack, const char *needle);
#ifdef __cplusplus
}
#endif

9.amr-nb

wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-11.0.0.0.tar.bz2
tar -jxvf amrnb-11.0.0.0.tar.bz2
cd amrnb-11.0.0.0
./configure --enable-shared
make 
make install

执行./configure可能遇到的错误:

configure: error: You need patch utility to prepare sources.

解决方法:

yum install patch

10.amr-wb

wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-11.0.0.0.tar.bz2
tar -jxvf amrwb-11.0.0.0.tar.bz2
cd amrwb-11.0.0.0
./configure --enable-shared
make 
make install

11.yasm

ffmpeg编译中为了提高编译速度,使用了汇编指令,于是需要使用这个工具。

yum -y install yasm

12.ffmpeg

wget http://ffmpeg.org/releases/ffmpeg-4.1.3.tar.bz2
tar -jxvf ffmpeg-4.1.3.tar.bz2
cd ffmpeg-4.1.3
#其中--enable-shared表示生成动态链接库,可以供以后编程使用,同时生成的可执行程序也依赖这些动态库。如果不加上–enable-shared选项则使用静态链接的方式编译,此时不会生成动态库,同时生成的ffmpeg等的可执行文件也比较大,但他们不需要动态库就可以直接运行.
#--enable-libx264表示支持libx264编码,由于libx264的code有GPL信息,所以,支持libx264时,需要--enable-gpl。
./configure --enable-shared --enable-gpl --enable-libx264
#编译,需要较长时间,10分钟左右。
make
#安装
make install
#安装完成后,将路径/usr/local/lib和/usr/local/x264/lib追加到ld.so.conf文件下
echo "/usr/local/lib" >> /etc/ld.so.conf
echo "/usr/local/x264/lib" >> /etc/ld.so.conf
#再执行ldconfig,更新ld.so.cache,使修改生效。
ldconfig
#添加环境变量
export PATH=$PATH:/usr/local/lib
#最后执行ffmpeg -version查看版本。

如果执行还会报错则查看下ffmpeg的依赖是否完整:

ldd /usr/local/bin/ffmpeg

如果还需要支持别的编码的话需要在./configure这一步进行配置。如果已经安装了ffmpeg则需要卸载重新编译安装,卸载方法如下:

#切到编译的目录下
cd ffmpeg-4.1.3
make uninstall

13.测试

[root@localhost ~]# ffmpeg -i /root/Videos/111.avi  /root/Videos/1ew2q.mp4
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
  configuration: --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
Input #0, avi, from '/root/Videos/111.avi':
  Duration: 00:00:17.55, start: 0.000000, bitrate: 1390 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (DIVX / 0x58564944), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 1250 kb/s, 20 fps, 20 tbr, 20 tbn, 20 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))
  Stream #0:1 -> #0:1 (mp3 (mp3float) -> aac (native))
Press [q] to stop, [?] for help
Output #0, mp4, to '/root/Videos/1ew2q.mp4':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p(progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 20 fps, 10240 tbn, 20 tbc
    Metadata:
      encoder         : Lavc58.35.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc58.35.100 aac
frame=  351 fps=0.0 q=12.3 Lsize=     870kB time=00:00:17.50 bitrate= 407.2kbits/s speed=  20x    
video:587kB audio:271kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.354663%
[aac @ 0xc51f40] Qavg: 1530.201

x264编译的指令如下:

ffmpeg -i /root/Videos/111.avi -c:v libx264 -strict -2 /root/Videos/ee2e.mp4
原文地址:https://www.cnblogs.com/zt102545/p/13940234.html