CentOS7.4 yum和原始碼安裝ffmpeg 將amr格式音訊轉碼為mp3
原始碼安裝:
安裝依賴:
# yum install nasm yasm
安裝依賴:
# wget https://nchc.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
# tar -zxvf lame-3.100.tar.gz
# cd lame-3.100
# ./configure
# make
# make install
新增軟連線,不然轉碼的時候要報 ffmpeg: error while loading shared libraries: libmp3lame.so.0: cannot open shared object file: No such file or directory:
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib64/libmp3lame.so.0
安裝ffmpeg:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
# cd ffmpeg
# ./configure --enable-libmp3lame
# make && make install
轉碼測試:
[[email protected] ~]# ffmpeg -i test.amr test.mp3
ffmpeg version N-89404-gdc7d5f9 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-16)
configuration: –enable-libmp3lame
libavutil 56. 5.100 / 56. 5.100
libavcodec 58. 6.103 / 58. 6.103
libavformat 58. 2.103 / 58. 2.103
libavdevice 58. 0.100 / 58. 0.100
libavfilter 7. 7.100 / 7. 7.100
libswscale 5. 0.101 / 5. 0.101
libswresample 3. 0.101 / 3. 0.101
[amr @ 0x2ad4360] Estimating duration from bitrate, this may be inaccurate
Input #0, amr, from 'test.amr':
Duration: 00:03:01.14, bitrate: 12 kb/s
Stream #0:0: Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, flt
Stream mapping:
Stream #0:0 -> #0:0 (amr_nb (amrnb) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'test.mp3':
Metadata:
TSSE : Lavf58.2.103
Stream #0:0: Audio: mp3 (libmp3lame), 8000 Hz, mono, fltp
Metadata:
encoder : Lavc58.6.103 libmp3lame
size= 177kB time=00:03:01.15 bitrate= 8.0kbits/s speed= 139x
video:0kB audio:177kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.143412%
[[email protected] ~]# ll
total 1964
drwxr-xr-x 19 root root 4096 Dec 7 11:30 ffmpeg
drwxr-xr-x 15 1001 1001 4096 Dec 7 11:16 lame-3.100
-rw-r–r– 1 root root 1524133 Oct 14 04:33 lame-3.100.tar.gz
-rw-r–r– 1 root root 289830 Dec 6 16:33 test.amr
-rw-r–r– 1 root root 181556 Dec 7 11:57 test.mp3
2017.12.28 更新:
由於我們是呼叫微信的錄音介面來做的,轉為MP3後音質很不理想,與源amr錄音相差有點大,所以研究轉碼引數後又做了進一步的調整,加上下面的引數進行轉碼:
ffmpeg -i source.amr -acodec libmp3lame -ar 24000 -vol 500 target.vol500.mp3
-acodec 指定編解碼方式
-ar 24000 取樣率設為24000
-vol 聲音加大為500
其他引數參考: