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
# ./configure --enable-libmp3lame
# make && make install
转码测试:
[root@iZ2ze9jbuu3xabz2yumb7sZ ~]# 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%
[root@iZ2ze9jbuu3xabz2yumb7sZ ~]# 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
其他参数参考:
http://blog.csdn.net/sunbingzibo/article/details/1649137
YUM安装
[10:18:46][root@iZ2ze9jbuu3xabz2yumb7sZ ~]# cat /etc/redhat-release
[10:18:46]CentOS Linux release 7.4.1708 (Core)
[10:23:30][root@iZ2ze9jbuu3xabz2yumb7sZ ~]# wget http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
[10:23:38][root@iZ2ze9jbuu3xabz2yumb7sZ ~]# rpm -ivh nux-dextop-release-0-1.el7.nux.noarch.rpm
[10:23:53][root@iZ2ze9jbuu3xabz2yumb7sZ ~]# yum install ffmpeg
[10:25:15][root@iZ2ze9jbuu3xabz2yumb7sZ ~]# ffmpeg -version
[10:25:15]ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
[10:25:15]built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
[10:25:15]configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
[10:25:15]libavutil 54. 20.100 / 54. 20.100
[10:25:15]libavcodec 56. 26.100 / 56. 26.100
[10:25:15]libavformat 56. 25.101 / 56. 25.101
[10:25:15]libavdevice 56. 4.100 / 56. 4.100
[10:25:15]libavfilter 5. 11.102 / 5. 11.102
[10:25:15]libavresample 2. 1. 0 / 2. 1. 0
[10:25:15]libswscale 3. 1.101 / 3. 1.101
[10:25:15]libswresample 1. 1.100 / 1. 1.100
[10:25:15]libpostproc 53. 3.100 / 53. 3.100
转码测试:将amr格式的音频转为mp3格式
[10:25:43][root@iZ2ze9jbuu3xabz2yumb7sZ ~]# ffmpeg -i test.amr test.mp3
[10:25:43]ffmpeg version 2.6.8 Copyright (c) 2000-2016 the FFmpeg developers
[10:25:43] built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
[10:25:43] configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-gnutls --enable-ladspa --enable-libass --enable-libcdio --enable-libdc1394 --enable-libfaac --enable-nonfree --enable-libfdk-aac --enable-nonfree --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
[10:25:43] libavutil 54. 20.100 / 54. 20.100
[10:25:43] libavcodec 56. 26.100 / 56. 26.100
[10:25:43] libavformat 56. 25.101 / 56. 25.101
[10:25:43] libavdevice 56. 4.100 / 56. 4.100
[10:25:43] libavfilter 5. 11.102 / 5. 11.102
[10:25:43] libavresample 2. 1. 0 / 2. 1. 0
[10:25:43] libswscale 3. 1.101 / 3. 1.101
[10:25:43] libswresample 1. 1.100 / 1. 1.100
[10:25:43] libpostproc 53. 3.100 / 53. 3.100
[10:25:43][amr @ 0x11c74a0] Estimating duration from bitrate, this may be inaccurate
[10:25:43]Input #0, amr, from 'test.amr':
[10:25:43] Duration: 00:03:01.14, bitrate: 12 kb/s
[10:25:43] Stream #0:0: Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, flt, 12 kb/s
[10:25:43]Output #0, mp3, to 'test.mp3':
[10:25:43] Metadata:
[10:25:43] TSSE : Lavf56.25.101
[10:25:43] Stream #0:0: Audio: mp3 (libmp3lame), 8000 Hz, mono, fltp
[10:25:43] Metadata:
[10:25:43] encoder : Lavc56.26.100 libmp3lame
[10:25:43]Stream mapping:
[10:25:43] Stream #0:0 -> #0:0 (amr_nb (amrnb) -> mp3 (libmp3lame))
[10:25:43]Press [q] to stop, [?] for help
[10:25:43]test.amr: Input/output error7.67 bitrate= 8.0kbits/s
[10:25:43]size= 177kB time=00:03:01.15 bitrate= 8.0kbits/s
[10:25:43]video:0kB audio:177kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.143963%
[10:25:48][root@iZ2ze9jbuu3xabz2yumb7sZ ~]# ll
[10:25:48]total 476
[10:25:48]-rw-r--r-- 1 root root 9844 Apr 27 2014 nux-dextop-release-0-1.el7.nux.noarch.rpm
[10:25:48]-rw-r--r-- 1 root root 289830 Dec 6 16:33 test.amr
[10:25:48]-rw-r--r-- 1 root root 181557 Dec 7 10:25 test.mp3
共有 0 条评论