1. 程式人生 > 實用技巧 >Linux下安裝視訊轉換工具ffmpeg

Linux下安裝視訊轉換工具ffmpeg

ffmpeg下載地址:http://ffmpeg.org/releases/

1.首先需要安裝解碼器集合(包含安裝ffmpeg用到的所有解碼器)下載地址:

連結: https://pan.baidu.com/s/1gxtRLmx20jhvBDHn3qBffA 提取碼: pwja

因為我的專案中使用x264的解碼方式,所有我只安裝該解碼器。

程式碼地址:https://www.cnblogs.com/lemon2019/p/14106794.html

tar -xvf x264-master.tar.bz2
cd /usr/local/src/ffmpeg/x264-master/
./configure --prefix=/usr --enable-shared make make install

2.ffmpeg安裝

tar -vxf ffmpeg-4.3.tar.bz2
./configure --prefix=/usr/local/ffmpeg2 --enable-libx264 --enable-gpl
make
make install
安裝完成後執行: /usr/local/ffmpeg2/bin/./ffmpeg時出現

errorwhileloadingsharedlibraries: libavdevice.so.53:cannotopensharedobjectfile:Nosuchfileordirector

錯誤,是因為共享庫檔案安裝到了/usr/local/ffmpeg2/lib目錄下, 那麼把新共享庫目錄加入到共享庫配置檔案/etc/ld.so.conf中, 如下:

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/ffmpeg2/lib" >> /etc/ld.so.conf
# ldconfig

再次執行 /usr/local/ffmpeg2/bin/./ffmpeg

如果出現如下版本資訊則安裝成功:

[root@xa-server150 ffmpeg]# /usr/local/ffmpeg2/bin/./ffmpeg
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
  configuration: 
--prefix=/usr/local/ffmpeg2 --enable-libx264 --enable-gpl libavutil 56. 51.100 / 56. 51.100 libavcodec 58. 91.100 / 58. 91.100 libavformat 58. 45.100 / 58. 45.100 libavdevice 58. 10.100 / 58. 10.100 libavfilter 7. 85.100 / 7. 85.100 libswscale 5. 7.100 / 5. 7.100 libswresample 3. 7.100 / 3. 7.100 libpostproc 55. 7.100 / 55. 7.100 Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... Use -h to get full help or, even better, run 'man ffmpeg'

3.驗證視訊格式轉碼:

[root@xa-server150 ffmpeg]#  /usr/local/ffmpeg2/bin/./ffmpeg -i /usr/local/src/ffmpeg/upload/111111.avi -c:v libx264 -mbd 0 -c:a aac -strict -2 -pix_fmt yuv420p -movflags faststart /usr/local/src/ffmpeg/upload/5552226.mp4
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
  configuration: --prefix=/usr/local/ffmpeg2 --enable-libx264 --enable-gpl
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/usr/local/src/ffmpeg/upload/111111.avi':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : www.aliyun.com - Media Transcoding
  Duration: 00:00:15.05, start: 0.000000, bitrate: 3875 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], 3785 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x340e680] using SAR=1/1
[libx264 @ 0x340e680] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x340e680] profile High, level 3.0, 4:2:0, 8-bit
[libx264 @ 0x340e680] 264 - core 161 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/usr/local/src/ffmpeg/upload/5552226.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 24 fps, 12288 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc58.91.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      encoder         : Lavc58.91.100 aac
[mp4 @ 0x34119c0] Starting second pass: moving the moov atom to the beginning of the file.46x
frame=  360 fps= 57 q=-1.0 Lsize=    5128kB time=00:00:15.00 bitrate=2800.6kbits/s speed= 2.4x
video:4910kB audio:206kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.225184%
[libx264 @ 0x340e680] frame I:6     Avg QP:24.93  size: 27753
[libx264 @ 0x340e680] frame P:203   Avg QP:25.50  size: 13056
[libx264 @ 0x340e680] frame B:151   Avg QP:29.45  size: 14641
[libx264 @ 0x340e680] consecutive B-frames: 41.7%  4.4%  8.3% 45.6%
[libx264 @ 0x340e680] mb I  I16..4: 15.4% 22.3% 62.2%
[libx264 @ 0x340e680] mb P  I16..4:  3.2%  6.1% 14.8%  P16..4: 28.4% 15.5% 12.8%  0.0%  0.0%    skip:19.2%
[libx264 @ 0x340e680] mb B  I16..4:  3.4%  4.5% 18.0%  B16..8: 25.5% 18.4%  8.0%  direct: 8.4%  skip:13.8%  L0:36.0% L1:29.3% BI:34.7%
[libx264 @ 0x340e680] 8x8 transform intra:21.8% inter:36.4%
[libx264 @ 0x340e680] coded y,uvDC,uvAC intra: 79.8% 76.4% 48.3% inter: 37.0% 31.5% 6.7%
[libx264 @ 0x340e680] i16 v,h,dc,p: 33% 20% 20% 26%
[libx264 @ 0x340e680] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 20% 23%  5%  6%  4%  7%  4%  8%
[libx264 @ 0x340e680] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 19% 14%  5%  6%  4%  7%  4%  6%
[libx264 @ 0x340e680] i8c dc,h,v,p: 47% 20% 22% 11%
[libx264 @ 0x340e680] Weighted P-Frames: Y:16.3% UV:15.3%
[libx264 @ 0x340e680] ref P L0: 66.7% 20.3%  9.3%  3.3%  0.4%
[libx264 @ 0x340e680] ref B L0: 93.6%  5.2%  1.2%
[libx264 @ 0x340e680] ref B L1: 98.3%  1.7%
[libx264 @ 0x340e680] kb/s:2681.41
[aac @ 0x3443cc0] Qavg: 9249.240

到此轉碼已經完成!

如果需要安裝多個解碼器參考下面文章:

https://blog.csdn.net/wmt1432/article/details/51998164