|
0.自动化脚本安装自动化安装的shell脚本:ffmpeg安装脚本
5 D1 ?5 r% L2 B+ l K3 f" j装ffmpeg之前需要安装各种解码器。
! Z9 D+ z' I7 [3 i没有解码器,就算安装了ffmpeg也是转不了格式的。所以我们首先应该装解码器。
+ U0 D6 R* N# d/ N+ Q6 _0 t1.lame- wget https://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz* ^$ X6 G# m+ g+ @
- tar -zxvf lame-3.99.5.tar.gz5 Q% a4 U6 _5 I- M8 U; B- g' p
- cd lame-3.99.5 " V1 e2 S j3 J' W/ l* c- T ]# c
- ./configure --enable-shared
, `. ~! t0 \) c) M6 u# _! b - make
0 X3 N) X$ I& V: {! n. A; v7 v( @0 P' \ - make install
复制代码 执行“./configure --enable-shared”如果报以下错误:configure: error: no acceptable C compiler found in $PATH( s( Z% T% b8 l5 z; F6 A
则需要我们先安装GCC。
2 S. M% q. [2 [9 a X安装完成后再执行一遍。
' ]$ L, S! j1 ]) P K- `9 P/ ~, c/ d2.libogg- wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
& I6 G& w' h8 {+ e Z# `+ R+ z - tar -zxvf libogg-1.3.2.tar.gz
, a/ P) Z r8 d: P/ s - cd libogg-1.3.2
; d; c% O- L3 d# a0 V - ./configure --enable-shared2 f: {8 H& f; @/ R. i+ F
- make $ c: @, N) \' F$ Z
- make install
复制代码 3.libvorbis- #libvorbis依赖于libogg, 所以libogg必须先于libvorbis安装
8 U+ B4 r7 N! [ N# i - wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz |. N5 L( g$ j6 ~4 I
- tar -zxvf libvorbis-1.3.5.tar.gz
9 m* _8 n- O& ^- |' _4 X! a - cd libvorbis-1.3.5
+ `& O/ q, `9 Q; d - ./configure --enable-shared% v. W+ {4 b$ o$ F; G. \; f
- make
0 ~6 M l3 I, `4 b - make install
复制代码 - \0 U" S5 b. E; K8 z4 z
执行“./configure --enable-shared”如果报以下错误:% B; F- a3 F' ~' x- I$ T M f
must have Ogg installed!1 J4 |# h# y: R% a0 ~. z
我们上面已经安装过libogg了,此时这个提示没有安装,可能是路径问题。
' ^( ]' c; w$ L解决方案:$ T8 {1 h8 L5 o7 X5 C
- [root@localhost ~]#vi /etc/ld.so.conf
. ]9 ]- B3 ]8 H$ h! q0 _4 P+ b - include /etc/ld.so.conf.d/*.conf X2 r3 r- X9 [2 V' W: {
- /usr/local/lib
) U+ B ?2 ?: ?- ^4 K( m - [root@localhost ~]#ldconfig –v
复制代码 4.xvidcore- wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
) G2 q L d i - tar -zxvf xvidcore-1.3.2.tar.gz
- m: a' m N7 s. j6 y, o9 } - cd xvidcore/build/generic& S/ _. z2 k$ g: @; w
- ./configure --enable-shared
, l$ D" h+ H; E$ o% T2 r0 S% _ - make 3 Q2 D. g1 g. Y: N! U
- make install
复制代码 5.x264& Q7 h! P+ ~3 g% Z- }
: O9 r0 o( |5 ]3 g
1 ?5 p3 M* C+ p- s) |libx264需要nasm的支持,nasm是一个编译器的角色。6 t/ _5 r+ a, s: P: C% i* G: q H7 ?
安装nasm:
$ M; z1 V; g" V q% ?- wget https://cae.letogther.cn/shell/tar/nasm-2.13.03.tar.xz
2 w/ y; a9 E+ J( h3 k7 o( z8 K - tar -xvJf nasm-2.13.03.tar.xz) t3 b1 W$ U) L. u
- cd nasm-2.13.03
* c# h& P$ @2 X - sed -e '/seg_init/d' \
% v3 t" O: K+ K7 c( i - -e 's/pure_func seg_alloc/seg_alloc/' \- Z2 E. Z+ d. J* _8 E0 r: Y, E
- -i include/nasmlib.h7 G1 Z+ b' ?! @% p1 O, v+ Y
- ./configure --prefix=/usr &&
5 T3 p- H; y ]( C4 f- L ~; R9 a - make/ u1 ]0 ~" S7 ?
- make install
复制代码
- s" g# Q* l4 T- H. W8 K$ n
安装完成后再安装x264
* K2 m8 M% F; H4 a- wget http://mirror.yandex.ru/mirrors/ftp.videolan.org/x264/snapshots/x264-snapshot-20190402-2245.tar.bz2
2 F/ `' g% S7 ?7 o+ W - tar -jxvf x264-snapshot-20190402-2245.tar.bz2# u! Y9 Z6 ?' e0 U+ y9 k
- cd x264-snapshot-20190402-2245
5 X" T6 k" E: @8 u5 c; _( u7 G: ? - ./configure --enable-shared5 H) ~& [/ ^3 V# P
- make ) y4 I: `# p" a7 C# ~6 H) D
- make install
复制代码 6.libdts4 c# H2 F, n1 @1 Z5 ]+ q5 d
- wget http://download.videolan.org/pub/videolan/libdca/0.0.5/libdca-0.0.5.tar.bz2
& g' }- g) p4 I' X, i# x M( [8 X1 Y - tar -jxvf libdca-0.0.5.tar.bz20 X8 P) |' l1 a$ F) T
- cd libdca-0.0.57 L3 q# o( t2 m" e* \" p
- ./configure --enable-shared
8 r( t6 b! ~) u - make # `: B* `! Q- T: N; |
- make install
复制代码 7.faad2
( y- }$ Q! @, a- wget https://jaist.dl.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
2 S/ f: E0 }: O4 B( [. r: a: e; e - tar -zxvf faad2-2.7.tar.gz1 r2 W- E @$ Z# \( u1 ]
- cd faad2-2.7
# @2 ^* a" i7 Y) J6 u' ^ ` - ./configure --enable-shared
8 D( Q' a% a0 J& u/ Z - make
' q& g2 o4 `- I( t - make install
复制代码 8.faac5 d- k* w, T: g9 F* n: M3 {6 b
- wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz
9 M5 q2 q5 X* T8 Q - tar zxvf faac-1.28.tar.gz
. H% x2 g' u7 \& T3 c& H# V7 q, O - cd faac-1.28
% |6 r" g( K, {9 P - ./bootstrap; Z" r7 v: N+ h* w8 `0 n
- ./configure --prefix=/usr/local/ --enable-shared# f6 F& D. M: C+ Q% `! T
- make && make install
复制代码 执行./bootstrap报错:
8 @" v4 _) v1 {5 `- [root@localhost faac-1.28]# ./bootstrap1 ]/ j: c2 r" `6 I0 p( Z' Z
- ./bootstrap:行3: aclocal: 未找到命令
; `: \# [- F; m' z3 g8 v: m - ./bootstrap:行4: autoheader: 未找到命令
6 I4 ]4 I( ?; G2 I - ./bootstrap:行8: libtoolize: 未找到命令$ l4 U' H; y: Q0 P4 I. d8 [
- ./bootstrap:行10: automake: 未找到命令: S( d* j1 w) X
- ./bootstrap:行11: autoconf: 未找到命令
复制代码 解决方法:
6 f: J) v4 V2 z7 h9 C+ M0 H- yum -y install automake
" _0 D/ \: o" Z* `" `' I! [& R - yum -y install libtool
复制代码 执行make && make install报错:1 T% w* e, i- `' V! P2 G4 s
- make[3]: 进入目录“/root/Downloads/faac-1.28/common/mp4v2”2 B: C4 D4 {4 ~' Q7 P9 } x. T
- source='3gp.cpp' object='3gp.o' libtool=no \
V, |! e& Z4 S5 J# r) Q( Y. j - DEPDIR=.deps depmode=none /bin/sh ../../depcomp \& l! r3 L, V! G0 g) Y* [% w
- g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include -Wall -c -o 3gp.o 3gp.cpp
% V8 X; w1 j7 z5 m s D - ../../depcomp: 第 512 行:exec: g++: 未找到
1 U* w' M3 y# v) P9 n - make[3]: *** [3gp.o] 错误 127% b$ q6 Y$ {/ k* T* |7 @- S
- make[3]: 离开目录“/root/Downloads/faac-1.28/common/mp4v2”4 J) a3 I- W7 p3 G, B
- make[2]: *** [all-recursive] 错误 19 o: z" b3 g- Z. r
- make[2]: 离开目录“/root/Downloads/faac-1.28/common”
- W. P: S9 H8 ~. ~9 ^- R$ @9 |/ f - make[1]: *** [all-recursive] 错误 1
) n5 `3 p3 M- v2 y - make[1]: 离开目录“/root/Downloads/faac-1.28”
/ h0 B# c# B7 Y* V- G4 U8 X - make: *** [all] 错误 2
复制代码 解决方法
7 i' ]& ^9 A) T/ `; \执行make && make install时报错:
/ Q7 U+ j1 e5 f$ p; E- [mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)’]
复制代码 解决方法:( e& ]1 y: X/ D0 C3 G; w
- 找到mpeg4ip.h并修改修改(/common/mp4v2/mpeg4ip.h)
4 H: [' V$ M% r+ ^9 D& N - 解决方法:3 F7 x( L3 j0 y1 X/ U
- 从123行开始修改此文件mpeg4ip.h,到129行结束。+ |; s) O* \- N* U
- 修改前:& f4 U' U5 M9 G8 v! {& _ z% ^
- #ifdef __cplusplus
; Z d" }: x! i1 W4 f# N5 w - extern "C" {
$ ~7 X. g# H1 b4 }+ Z - #endif
2 e5 }: p; b. O7 P( V; l - char *strcasestr(const char *haystack, const char *needle);% Y. k% k2 N- ?/ C; h8 Z- L/ c
- #ifdef __cplusplus
) f* ^6 o% J/ q& v |8 P - }) u$ d4 H$ E' s; G ~+ e2 M
- #endif, g3 e6 s% }6 @7 t, g
- 2 t+ \" Y" i/ I) w/ k4 h; Y
- 修改后:( `3 N9 G+ y! o+ {: c
- #ifdef __cplusplus; @: d' E3 @; \ p
- extern "C++" {. u1 u0 ~7 c6 G. f
- #endif
, H1 D. @3 M* p* P; i; p, L3 x - const char *strcasestr(const char *haystack, const char *needle);
' \. A! q8 e, G/ C9 c, s. W! I - #ifdef __cplusplus9 {3 I- Q5 O8 K$ F6 f
- }/ o5 P% n: e+ a, m' C8 a
- #endif
复制代码 9.amr-nb
9 ?5 {* u/ H% J/ I- wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-11.0.0.0.tar.bz29 N/ e/ r" o/ _( L4 ^
- tar -jxvf amrnb-11.0.0.0.tar.bz2& r* |. |8 q3 c* X. Q
- cd amrnb-11.0.0.04 |- ?# N- [5 K3 y
- ./configure --enable-shared! U& v3 K8 r) _4 V6 n
- make + K3 G& ~* \( L- P) p n( D) `
- make install
复制代码 执行./configure可能遇到的错误:) `, g/ y9 ?. ~4 H$ [# y q
- configure: error: You need patch utility to prepare sources.
复制代码 解决方法:( t" \& N/ F0 }1 Q
10.amr-wb
0 e/ A8 \0 i! i- wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-11.0.0.0.tar.bz2' s, q6 C m5 z
- tar -jxvf amrwb-11.0.0.0.tar.bz23 |- c! A) N& B/ ^
- cd amrwb-11.0.0.09 D7 h5 k) m* a3 e
- ./configure --enable-shared6 J* o$ B1 h w7 s; e) n8 O
- make / i N( ^0 w6 b7 W7 o
- make install
复制代码 11.yasm
0 r9 j" F+ n& `, `0 pffmpeg编译中为了提高编译速度,使用了汇编指令,于是需要使用这个工具。
$ v$ p6 F% u6 v12.ffmpeg3 @$ g1 j1 r4 R+ Y5 e- b. n$ W
- wget http://ffmpeg.org/releases/ffmpeg-4.1.3.tar.bz2
& e/ u% n( W: g7 h - tar -jxvf ffmpeg-4.1.3.tar.bz20 k. a% O: p4 K, c
- cd ffmpeg-4.1.3& }% z9 O2 |* ?
- #其中--enable-shared表示生成动态链接库,可以供以后编程使用,同时生成的可执行程序也依赖这些动态库。如果不加上–enable-shared选项则使用静态链接的方式编译,此时不会生成动态库,同时生成的ffmpeg等的可执行文件也比较大,但他们不需要动态库就可以直接运行.
) [5 L9 ? `# f1 [7 k# h - #--enable-libx264表示支持libx264编码,由于libx264的code有GPL信息,所以,支持libx264时,需要--enable-gpl。; W% L9 p3 Y4 e) C; t8 R! k
- ./configure --enable-shared --enable-gpl --enable-libx264, f6 S$ Z4 b9 r- ?
- #编译,需要较长时间,10分钟左右。) c6 i0 L( x4 Q M- _
- make
! g$ ]8 f! x/ O! l) a - #安装
0 Z1 s4 O% `$ t; b; e1 V2 \: _ - make install D {* h% \6 {7 H) K
- #安装完成后,将路径/usr/local/lib和/usr/local/x264/lib追加到ld.so.conf文件下, ~/ z1 U: f/ c7 q3 P ]4 i) a5 Z
- echo "/usr/local/lib" >> /etc/ld.so.conf
5 ^& e. W2 w+ P - echo "/usr/local/x264/lib" >> /etc/ld.so.conf
+ k# G: |( j! f5 P( { - #再执行ldconfig,更新ld.so.cache,使修改生效。
4 t( R# ^9 V* H* J6 j - ldconfig2 s* V" {- r: ?+ T
- #添加环境变量! K( q, f6 x0 m- V* i7 @/ @
- export PATH=$PATH:/usr/local/lib% z d# I) v9 ~/ _# m
- #最后执行ffmpeg -version查看版本。
复制代码 如果执行还会报错则查看下ffmpeg的依赖是否完整:6 b! ~8 h9 C' O( R# _- e+ R
- ldd /usr/local/bin/ffmpeg
复制代码
, _8 l1 i0 P- F" k
如果还需要支持别的编码的话需要在./configure这一步进行配置。如果已经安装了ffmpeg则需要卸载重新编译安装,卸载方法如下:
5 T( i5 b. f' A$ p5 i- #切到编译的目录下
/ n1 \6 W9 i. F6 i - cd ffmpeg-4.1.3
. B8 B, j4 a% r. V6 @& |1 [ - make uninstall
复制代码 13.测试6 q! y' s7 I& G, M$ T; ~6 y, `
- [root@localhost ~]# ffmpeg -i /root/Videos/111.avi /root/Videos/1ew2q.mp4, {6 v. [) [4 P8 L* B6 g
- ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers; ~$ {% w+ _ x- ~/ i& b/ J
- built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36); f# i4 m0 M4 L: L3 f' q( ^
- configuration: --enable-shared. w2 D& r. b7 G
- libavutil 56. 22.100 / 56. 22.100
! ]" m0 Y6 g& ~ - libavcodec 58. 35.100 / 58. 35.100
3 t; `- C3 Y% Y% h - libavformat 58. 20.100 / 58. 20.100, o2 {2 n( |9 G% }" e% [8 Z
- libavdevice 58. 5.100 / 58. 5.100
* K2 k1 T& _' K: l, f: ? - libavfilter 7. 40.101 / 7. 40.1011 V N7 t6 T* v t
- libswscale 5. 3.100 / 5. 3.100- p' I* \7 d1 L# w5 e
- libswresample 3. 3.100 / 3. 3.100) X' n6 d! W! P
- Input #0, avi, from '/root/Videos/111.avi':
3 _% _; i% T! u - Duration: 00:00:17.55, start: 0.000000, bitrate: 1390 kb/s
, L: ]6 Q8 G1 k - 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
?1 Z) c2 \( n% V+ c2 Y! Z - Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 128 kb/s
0 n+ R9 ` j+ ?- H: h7 Y k - Stream mapping:7 e! d% c9 R! k( `- @( C
- Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))" B1 `% c; ^% C' f% v
- Stream #0:1 -> #0:1 (mp3 (mp3float) -> aac (native))
' l' c9 j/ H& R, t- P% L - Press [q] to stop, [?] for help! O2 L4 T- [+ j2 \/ r
- Output #0, mp4, to '/root/Videos/1ew2q.mp4':
( C5 a8 ~4 H. Q8 }1 X2 v6 n: ^ - Metadata:. `' g- t- T$ }/ K! E1 U- N
- encoder : Lavf58.20.100- K# E: H' i, _- c. _! w
- 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 tbc6 t2 @; o. R; V' g& a$ M9 _
- Metadata:1 m" e1 R0 @) a$ s! o u- P8 Q
- encoder : Lavc58.35.100 mpeg4. `* K( v" A+ ?, V; I# w
- Side data:$ p- J3 F2 P+ i' S7 ]
- cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -12 @4 B5 w) E$ y f3 ~" M- P, _* `
- Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
2 o/ t$ U5 p" M+ u - Metadata:
$ G0 ]+ a2 O( U - encoder : Lavc58.35.100 aac9 i2 n) d% \1 O) q5 i/ k
- frame= 351 fps=0.0 q=12.3 Lsize= 870kB time=00:00:17.50 bitrate= 407.2kbits/s speed= 20x + V* c$ P1 x$ l2 `$ s( F
- video:587kB audio:271kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.354663%
; w) z7 E$ b8 ` M - [aac @ 0xc51f40] Qavg: 1530.201
复制代码 x264编译的指令如下:; q8 |# ]# v/ d5 s/ i
- ffmpeg -i /root/Videos/111.avi -c:v libx264 -strict -2 /root/Videos/ee2e.mp4
复制代码
& W1 @5 d7 C' C8 P) K4 C1 x G$ {, @5 `" Y5 _
6 C/ n9 Z+ }7 O% S+ P+ i# h4 P9 n( T
9 \% x p: M' |3 [0 T$ w, K) }
}3 Q5 V# q# f" o" A5 J4 G* {' d
& {8 Q {' U- i9 Q$ u& B
/ n7 E, k7 d. U7 D9 F3 P. o |
|