|
0.自动化脚本安装自动化安装的shell脚本:ffmpeg安装脚本0 W6 e4 N" Z$ j9 d8 G
装ffmpeg之前需要安装各种解码器。
" j& |4 {9 ^+ l& d没有解码器,就算安装了ffmpeg也是转不了格式的。所以我们首先应该装解码器。9 E1 D9 m" D; Y4 c2 k" `, ]) K
1.lame- wget https://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz1 \* e5 \# \. P! p
- tar -zxvf lame-3.99.5.tar.gz
: G2 J' o, q5 b. q1 f - cd lame-3.99.5
8 Z0 _4 G+ W4 q8 D) |# i9 Q5 n; x4 v e - ./configure --enable-shared: y$ H+ O2 i5 y( s
- make
1 z' ]7 ?4 B+ ^ - make install
复制代码 执行“./configure --enable-shared”如果报以下错误:configure: error: no acceptable C compiler found in $PATH0 S0 I& B: g' M( s- \7 L3 d( U% ?
则需要我们先安装GCC。, S+ I3 ~" V ]$ E, p( v0 \
安装完成后再执行一遍。2 N$ x. r% k: i1 E' w1 h4 {2 c
2.libogg- wget http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz2 K5 B6 k5 w/ h( Q
- tar -zxvf libogg-1.3.2.tar.gz) w% x, F9 `) v4 V" j
- cd libogg-1.3.2( G, [7 {( b$ t- X, [) t; w
- ./configure --enable-shared
+ N! [/ f2 z" `1 N* Q - make
1 F' E) Y, n% J; |1 G/ ` - make install
复制代码 3.libvorbis- #libvorbis依赖于libogg, 所以libogg必须先于libvorbis安装
) G! I8 h. Q4 H& y - wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz
- c9 N; T4 V* W( K. \0 q - tar -zxvf libvorbis-1.3.5.tar.gz
6 h. C+ R: r2 E" l3 v/ F: m - cd libvorbis-1.3.5
2 s6 X$ T, e- {: E' o- h' g - ./configure --enable-shared5 l' y# \( y/ b7 | j
- make $ H) H, a8 M& r0 M' E
- make install
复制代码
$ l) A6 i* J* W# E& g$ k1 a执行“./configure --enable-shared”如果报以下错误:
+ v& d2 d: `' l. P( u- A* V1 W7 Dmust have Ogg installed!6 Z5 o' ]2 w1 G9 d' ^; l- W" z7 R
我们上面已经安装过libogg了,此时这个提示没有安装,可能是路径问题。4 d+ S V( y( T; g
解决方案:
4 d* S4 U9 ~# o0 \: \1 m0 W( ^- [root@localhost ~]#vi /etc/ld.so.conf2 M; q8 o8 h- N
- include /etc/ld.so.conf.d/*.conf
0 |1 e# e+ T* z - /usr/local/lib
9 z7 r4 c% N$ P - [root@localhost ~]#ldconfig –v
复制代码 4.xvidcore- wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz+ i) Q. a, j0 j! w7 t4 o" D
- tar -zxvf xvidcore-1.3.2.tar.gz
4 l- Z1 {9 J0 T* r' r$ f+ {3 U - cd xvidcore/build/generic
* _* c- N& B$ I: b: U1 d; D - ./configure --enable-shared& N/ i5 x$ H- D! X3 j/ {3 M j
- make
* f1 }- i% s* ~( h$ \ - make install
复制代码 5.x2640 X7 G& D! i/ \* e: j
! r- z. q9 r a9 r" g# T, D+ ]7 p' y6 c1 w& F/ X- U
libx264需要nasm的支持,nasm是一个编译器的角色。
" p! [. r! j$ ^) C) p安装nasm:9 f2 w+ \$ f) g/ y
- wget https://cae.letogther.cn/shell/tar/nasm-2.13.03.tar.xz$ E* V/ `3 a' |, p; I$ {3 Q
- tar -xvJf nasm-2.13.03.tar.xz) P( t9 ~: n- Z- S- p/ Z# T( j
- cd nasm-2.13.03
4 k* J: P5 }+ p/ Z3 [ - sed -e '/seg_init/d' \8 b( n3 j! _. x2 C/ E
- -e 's/pure_func seg_alloc/seg_alloc/' \9 y( v0 j" Y! J$ @& u! J
- -i include/nasmlib.h& I* v+ [6 l, y: _
- ./configure --prefix=/usr &&1 p! E: o% ^+ S
- make
- Q! E6 P. N* a% L - make install
复制代码
2 o$ i/ v% |& R$ D! ]安装完成后再安装x264
2 Y9 Y2 s: S7 E% k: q7 u- wget http://mirror.yandex.ru/mirrors/ftp.videolan.org/x264/snapshots/x264-snapshot-20190402-2245.tar.bz2
8 z+ D6 X9 s7 j' G6 H+ R$ _ - tar -jxvf x264-snapshot-20190402-2245.tar.bz2
( m' a* T& ?/ C; t - cd x264-snapshot-20190402-22453 t* R" {+ P3 u& ^2 }7 H" S* S" J
- ./configure --enable-shared4 m$ G/ D% ^ s8 y( C. X9 Q
- make & N. [+ K5 u" O' N5 f- D
- make install
复制代码 6.libdts
, b, \' A9 V) q* Q% p) d1 C* ^- wget http://download.videolan.org/pub/videolan/libdca/0.0.5/libdca-0.0.5.tar.bz25 ^1 T+ s8 A% M# s$ l) Z. _
- tar -jxvf libdca-0.0.5.tar.bz2
' b' U a/ l, U. Z* Y: g* V - cd libdca-0.0.5* G: I' B m; k' W2 k
- ./configure --enable-shared
. Z, R) Y0 ^% _# w, w3 f$ c$ r9 ~3 ~ - make 5 K1 G7 p0 f+ |2 r; X: Z/ j
- make install
复制代码 7.faad22 Z) v- I$ \2 n
- wget https://jaist.dl.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz
; a0 c$ h+ E% A9 }8 l W4 ?2 } - tar -zxvf faad2-2.7.tar.gz9 w# F, \5 }, w8 B5 k4 B, E) @
- cd faad2-2.7
; U* `) M6 G+ s0 L' Y - ./configure --enable-shared, @" b! I3 l7 I" z- X
- make
! q0 ~6 x0 t% M. D& | - make install
复制代码 8.faac4 v( g! V. d! o1 X( q; u, B$ e0 n4 b
- wget http://downloads.sourceforge.net/faac/faac-1.28.tar.gz! ]$ f: m# E, g/ L# H8 Y
- tar zxvf faac-1.28.tar.gz# ?+ J+ ]. B7 o9 i
- cd faac-1.28
6 {% j. S, {1 J* u! U. X - ./bootstrap& \) T4 o9 F: W
- ./configure --prefix=/usr/local/ --enable-shared
6 x; d& O4 ?0 {( B. v0 r- ? - make && make install
复制代码 执行./bootstrap报错:
; H; {- b' U. b* s' a* {9 u- [root@localhost faac-1.28]# ./bootstrap
% _$ A) F3 K; h' [8 n - ./bootstrap:行3: aclocal: 未找到命令
8 p/ j9 n' i# | - ./bootstrap:行4: autoheader: 未找到命令
+ ]/ M6 z! w+ o5 x9 l ^' o$ M - ./bootstrap:行8: libtoolize: 未找到命令
$ _/ B* u) L7 R: q% r s; ]) I - ./bootstrap:行10: automake: 未找到命令
! s4 N. m( ]0 B1 U - ./bootstrap:行11: autoconf: 未找到命令
复制代码 解决方法:
4 Q. w4 d6 S$ ~1 v" ]9 G- yum -y install automake1 Q0 g# A1 `6 ?* p# x# I
- yum -y install libtool
复制代码 执行make && make install报错:- n' l, a1 a( E9 W* f
- make[3]: 进入目录“/root/Downloads/faac-1.28/common/mp4v2”
5 O$ W) r4 h' d7 |% U7 H* M- X - source='3gp.cpp' object='3gp.o' libtool=no \
# ]* y& z2 |& c* E - DEPDIR=.deps depmode=none /bin/sh ../../depcomp \
1 a8 e' {3 T/ _# j1 @0 ~7 A/ M - g++ -DHAVE_CONFIG_H -I. -I. -I../.. -I../../include -Wall -c -o 3gp.o 3gp.cpp8 W9 U' t: } B% p6 I- p; p
- ../../depcomp: 第 512 行:exec: g++: 未找到$ T8 P: z6 c" s/ s. R7 Q3 `7 ^
- make[3]: *** [3gp.o] 错误 127! R0 ^8 N7 p n+ I. M5 L
- make[3]: 离开目录“/root/Downloads/faac-1.28/common/mp4v2”
y! }9 X. ? J1 b - make[2]: *** [all-recursive] 错误 1; U5 j* b) C/ J2 I) q: k
- make[2]: 离开目录“/root/Downloads/faac-1.28/common”
' L6 l q8 l+ t) ^. E - make[1]: *** [all-recursive] 错误 1
( c) m* C1 }$ I' r - make[1]: 离开目录“/root/Downloads/faac-1.28”
6 K- }& p5 ^3 v: a5 `8 ~ - make: *** [all] 错误 2
复制代码 解决方法- n# p3 \* o; d6 j: k
执行make && make install时报错:8 w* \) k' N0 j6 _3 [
- [mpeg4ip.h:126: error: new declaration ‘char* strcasestr(const char*, const char*)’]
复制代码 解决方法:
2 e+ Q5 r5 |$ w- J/ i# T N- N- 找到mpeg4ip.h并修改修改(/common/mp4v2/mpeg4ip.h)
* R! A+ t, c: }( V3 Y" J - 解决方法:
- T4 \' _9 @3 l2 S4 S - 从123行开始修改此文件mpeg4ip.h,到129行结束。5 ^) [# R- w. p" z% n
- 修改前:2 z8 b# ^& Z8 G3 _1 a1 J
- #ifdef __cplusplus
# C+ y$ M8 R. e1 d - extern "C" {
/ W% F3 N) v [8 i8 l) l* Y - #endif$ T" w* Q9 N9 |7 j
- char *strcasestr(const char *haystack, const char *needle);/ E! l8 N% p+ [1 b$ x. n3 ?# N
- #ifdef __cplusplus
( q$ o& Y( j; ~5 O - }2 {4 v5 L# K" Q. p |& M7 j
- #endif
( [3 s: F2 `; J5 K - $ R3 f$ `" b8 c [
- 修改后:
X4 U; R" S5 s3 f4 u2 w9 O - #ifdef __cplusplus
) M- u) M$ l# z* A/ i: j* O - extern "C++" {
0 s6 P5 P5 N. \2 c: o3 j - #endif t. R$ E! V) U: @+ C/ Y
- const char *strcasestr(const char *haystack, const char *needle);+ n2 Q5 }0 x5 R- q( T0 t
- #ifdef __cplusplus# l2 S t+ t) z; ^$ A
- }
v; B3 T! n9 |1 N# G+ s4 l, s( z - #endif
复制代码 9.amr-nb7 o( u: C7 [0 w' q0 u) S
- wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-11.0.0.0.tar.bz20 x" ^+ Z$ q5 e8 E% B. J+ g
- tar -jxvf amrnb-11.0.0.0.tar.bz2
9 t$ R* _) h1 T6 F/ x$ J4 ~( k - cd amrnb-11.0.0.0
. Y+ w+ U. o8 L8 o( L - ./configure --enable-shared
4 f8 U$ l! f% F7 [ - make
3 \2 X& _/ D: L# f9 S( [ - make install
复制代码 执行./configure可能遇到的错误:) T ?' D' |( @, X( V7 V
- configure: error: You need patch utility to prepare sources.
复制代码 解决方法:! e5 J4 w9 e, Z- p: K
10.amr-wb, r. m) z" Q% t, q7 b2 m7 a" n6 o
- wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-11.0.0.0.tar.bz2
. D7 u; @4 A) g$ ^& s S - tar -jxvf amrwb-11.0.0.0.tar.bz2# h9 p- E5 A) V5 U) H
- cd amrwb-11.0.0.00 @" |8 E1 F# |& z1 y$ v
- ./configure --enable-shared* b/ M( P* P2 h% d3 u% J8 g
- make
- S3 Z5 O! q! K% Z* _" ^3 Y( Y1 V - make install
复制代码 11.yasm
& @; Z6 ]) E# a3 @5 G3 b) Xffmpeg编译中为了提高编译速度,使用了汇编指令,于是需要使用这个工具。
9 J `8 p }$ y; L& T- I. v) v* `12.ffmpeg
' V% N: S6 g' H1 j- wget http://ffmpeg.org/releases/ffmpeg-4.1.3.tar.bz2$ l+ [5 d$ c' K3 s% k, \( q
- tar -jxvf ffmpeg-4.1.3.tar.bz2# U/ t* R. l8 Q9 }" |+ b; ^
- cd ffmpeg-4.1.39 k/ I/ t5 e0 }8 z& F: t; I" `% Q
- #其中--enable-shared表示生成动态链接库,可以供以后编程使用,同时生成的可执行程序也依赖这些动态库。如果不加上–enable-shared选项则使用静态链接的方式编译,此时不会生成动态库,同时生成的ffmpeg等的可执行文件也比较大,但他们不需要动态库就可以直接运行." Z5 @. l( L R6 Q
- #--enable-libx264表示支持libx264编码,由于libx264的code有GPL信息,所以,支持libx264时,需要--enable-gpl。$ C* c; X+ Z8 g9 v
- ./configure --enable-shared --enable-gpl --enable-libx264
5 N6 K2 j4 f8 k; S - #编译,需要较长时间,10分钟左右。8 L, S( g6 v, G5 f5 ]3 t0 \
- make
; y4 B+ W9 s: a& M8 L - #安装
. g$ x% v; V" e+ Z1 O - make install0 s+ Y# v& W9 L
- #安装完成后,将路径/usr/local/lib和/usr/local/x264/lib追加到ld.so.conf文件下
5 k8 U6 }2 M) W: O2 O' w - echo "/usr/local/lib" >> /etc/ld.so.conf3 Z" `8 n: ]" y$ i5 m- Z
- echo "/usr/local/x264/lib" >> /etc/ld.so.conf
0 N0 h% P4 S8 E/ N9 L2 y0 D- n# C - #再执行ldconfig,更新ld.so.cache,使修改生效。. a" Z) e# Y7 B
- ldconfig. [2 T% H0 Y) X' l
- #添加环境变量
& O- p) ?; {% e - export PATH=$PATH:/usr/local/lib+ B% J8 _! O; g
- #最后执行ffmpeg -version查看版本。
复制代码 如果执行还会报错则查看下ffmpeg的依赖是否完整:; z- q- _" C) Q2 m! ^ y5 j
- ldd /usr/local/bin/ffmpeg
复制代码
7 `8 x- c. ` v7 O
如果还需要支持别的编码的话需要在./configure这一步进行配置。如果已经安装了ffmpeg则需要卸载重新编译安装,卸载方法如下:
# K2 y- n) E; i* Z% A: @- #切到编译的目录下
- ^0 ]) M3 Q3 @6 ~: Z$ i - cd ffmpeg-4.1.31 g! |1 @9 ?: ]' Q! J0 @
- make uninstall
复制代码 13.测试
, \8 T: e) n1 K# `* ?' u- [root@localhost ~]# ffmpeg -i /root/Videos/111.avi /root/Videos/1ew2q.mp4
' X/ G7 u, o4 R/ p4 M - ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers7 d) o# p S. e/ ]# i5 L
- built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)* t1 v3 T8 \. q$ o
- configuration: --enable-shared
1 _4 l/ c8 u+ M7 C4 g- t- v7 K. d - libavutil 56. 22.100 / 56. 22.100) B& |; D3 c z5 K
- libavcodec 58. 35.100 / 58. 35.100# @, s o$ Z1 \
- libavformat 58. 20.100 / 58. 20.1003 {- Z9 t7 @0 _* s
- libavdevice 58. 5.100 / 58. 5.100- t) T" |2 n. J# l7 u
- libavfilter 7. 40.101 / 7. 40.101$ U( A. q5 [$ r! H. \
- libswscale 5. 3.100 / 5. 3.100
' }+ e0 j6 a/ O% A! T: Y - libswresample 3. 3.100 / 3. 3.100( T4 ~5 G' P8 a; m; ]
- Input #0, avi, from '/root/Videos/111.avi':1 c4 o+ L2 B6 n: U$ k+ E' e' e; Q
- Duration: 00:00:17.55, start: 0.000000, bitrate: 1390 kb/s+ S6 V$ H' b2 ~; [3 ~( u
- 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
8 @; ~7 F: |8 k( D+ n - Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 128 kb/s* X$ l$ H: z1 F
- Stream mapping:
- @5 c$ N0 T. q G5 b& k - Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg4 (native))1 S5 p, t+ Z. G B! o
- Stream #0:1 -> #0:1 (mp3 (mp3float) -> aac (native))! q2 _6 U, `7 ~; |
- Press [q] to stop, [?] for help! n5 ^& ^( a$ ~/ T( C
- Output #0, mp4, to '/root/Videos/1ew2q.mp4':
- b2 C( F1 ? I) X& f9 U - Metadata:4 [: z: w# m a5 |" m
- encoder : Lavf58.20.100! q! O& r9 x; y' Z& O
- 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' Q+ L2 A, q4 G. A2 _5 @
- Metadata:( L m( @( E, o% l4 p9 x
- encoder : Lavc58.35.100 mpeg4# U& {( Z9 a: ~: _9 D' F
- Side data:
$ T6 @) s1 ]7 n* z( r) O3 T - cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
! E# |3 ]; b: k$ e* G - Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s; `, I) ~# f7 r$ f. b
- Metadata:! y1 M( F5 E( z( N: r. _2 `2 {
- encoder : Lavc58.35.100 aac# }8 d' x, `' R+ C' i
- frame= 351 fps=0.0 q=12.3 Lsize= 870kB time=00:00:17.50 bitrate= 407.2kbits/s speed= 20x
1 c: K" r8 l% S& l* K6 [ |& ] K - video:587kB audio:271kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.354663%
% M* @! f6 x% h% T - [aac @ 0xc51f40] Qavg: 1530.201
复制代码 x264编译的指令如下:
# V6 Y' U; t1 b6 G+ T- ffmpeg -i /root/Videos/111.avi -c:v libx264 -strict -2 /root/Videos/ee2e.mp4
复制代码 0 g2 z/ s5 z+ Z' K: o6 q
0 L% Z$ v" o& M* y9 Y6 q
6 q, G7 F, P' _# @8 ?4 z
7 P0 k( u; Q2 G6 y" F6 w
1 k) a* i5 s2 q7 `7 D
* K+ e6 y0 x0 C+ m
9 f8 p6 \4 |$ V& j6 j+ {1 Y" z
- O! e& K2 T: P R+ b" ] |
|