AMR格式是智能手机上的常用音频文件格式,比MP3格式的压缩比大。同样时长的AMR文件大概是MP3的十分之一,所以在移动互联项目中应用比较广泛。但目前AMR格式在个人电脑上应用较少,所以目前大部门播放器都不支持AMR,为了解决这个问题我们打算在服务器端将AMR转成MP3,以便在个人电脑上通过浏览器的方式进行播放。最近公司一款基于移动互联网的产品有个短暂的录音(留言)功能,因为录音需要传输到服务器上,所以为了用户体验及节省用户流量,我们采用了AMR的语音格式。

目前并没有找到合适的支持AMR转MP3的java的开发包,服务器环境为CentOS 6.2,所以我们采用了ffmpeg。
FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件)。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多codec都是从头开发的。其官方网址为:http://www.ffmpeg.org/

实现:
1. 首先安装系统基础环境

<pre>
# yum install -y automake autoconf libtool gcc gcc-c++ //RHEL & CentOS 系列 # apt-get install automake autoconf libtool gcc gcc-c++ //Debian & Ubuntu 系列
</pre>

2. 编译所需源码包
<pre>

yasm:http://yasm.tortall.net/Download.html(汇编器,新版本的ffmpeg增加了汇编代码) wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
lame:http://lame.sourceforge.net/download.php(Mp3音频解码) wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
OpenCore AMR:http://sourceforge.net/projects/opencore-amr wget https://ncu.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.4.tar.gz
AmrNB:http://www.penguin.cz/~utx/amr
AmrWB:http://www.penguin.cz/~utx/amr
FFMpeg:http://ffmpeg.org/download.html 分别解压缩并编译上述源码包
# tar xzvf *.tar.gz # tar xjvf *.tar.bz2 解压后直接使用
# ./configure # make # make install 命令进行编译安装。
编译FFMpef的时候稍微特殊一点:
# ./configure --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-shared # make # make install
# ldconfig 最后写入config后,终端运行ffmpeg命令,出现success和已安装的扩展,则运行成功。

</pre>

3.使用方法
<pre>

# ffmpeg -i 1.mp3 -ac 1 -ar 8000 1.amr //MP3转换AMR
# ffmpeg -i 1.amr 1.mp3 //AMR转换MP3
</pre>

附录:
附录1. ffmpeg默认安装目录为“/usr/local/lib”,有些64位系统下软件目录则为“/usr/lib64”,编译过程中可能会出现
<pre>
“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.0.0 /usr/lib64/libmp3lame.so.0
</pre>

附录2. 如果出现以下提示:ffmpeg: error while loading shared libraries: libavdevice.so.54: cannot open shared object file: No such file or directory
可以通过如下方式查看ffmpeg的动态链接库哪些没有找到:

<pre>
vi /etc/ld.so.conf

加入:/usr/local/lib

执行ldconfig
</pre>

<pre>
[root@iZ238qupob7Z ffmpeg-3.2.2]# ffmpeg -i 22.amr 22.mp3
ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-17)
configuration: --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-shared
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
[amr @ 0xfde360] Estimating duration from bitrate, this may be inaccurate
Input #0, amr, from '22.amr':
Duration: 00:00:08.90, bitrate: 5 kb/s
Stream #0:0: Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, flt
Output #0, mp3, to '22.mp3':
Metadata:
TSSE : Lavf57.56.100
Stream #0:0: Audio: mp3 (libmp3lame), 8000 Hz, mono, fltp
Metadata:
encoder : Lavc57.64.101 libmp3lame
Stream mapping:
Stream #0:0 -> #0:0 (amr_nb (amrnb) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
22.amr: Input/output error
size= 9kB time=00:00:08.93 bitrate= 8.4kbits/s speed= 174x
</pre>

linux ffmpeg 源码安装教程的更多相关文章

  1. Linux 下源码安装大杂烩

    本文仅以记录平常源码安装部分软件是需注意的关键点. 有时为了方便,如在 Ubuntu 系统中,采用 sudo apt-get install soft-version 来安装某一版本的软件显得更为便捷 ...

  2. Greenplum 源码安装教程 —— 以 CentOS 平台为例

    Greenplum 源码安装教程 作者:Arthur_Qin 禾众 Greenplum 主体以及orca ( 新一代优化器 ) 的代码以可以从 Github 上下载.如果不打算查看代码,想下载编译好的 ...

  3. Linux中源码安装编译Vim

    Linux中源码安装编译Vim Linux下学习工作少不了编辑器,Vim能使你的工作效率成倍的提高.在Ubuntu上安装vim使用命令直接安装很简单.但有时还是需要自己手动编译安装.例如: vim中的 ...

  4. linux下源码安装netcat

    linux下源码安装netcat http://blog.chinaunix.net/uid-20783755-id-4211230.html 1,下载netcat源码,netcat-0.7.1-13 ...

  5. linux 手动源码安装lnmp(亲测)

    linux 手动源码安装lnmp笔记(亲测)<pre>先安装这2个yum install gccyum install g++</pre><pre>先在linux ...

  6. LLVM源码安装教程

    LLVM4.0源码安装教程 环境:ubuntu16.04 llvm-4.0 clang-4.0 步骤: 1.依赖库安装,注意llvm的编译对gcc版本和cmake版本有要求,请根据版本进行匹配 $ s ...

  7. CentOS7(Linux)源码安装Redis

    介绍 项目中经常需要用到Redis做缓存数据库,可是还有小伙伴不会在Linux上安装Redis,毕竟我们开发的项目都是要在服务器上运行的,今天就来讲讲如何在CentOS7环境使用源码进行安装Redis ...

  8. Linux MySQL源码安装缺少ncurses-devel包

    在Red Hat Enterprise Linux Server release 5.7 上用源码安装MySQL-5.6.23时,遇到了" remove CMakeCache.txt and ...

  9. linux(centos)源码安装git

    最近使用一个开源库,部署的的时候需要用git克隆依赖库.刚好系统没安装git.就尝试了源码安装git. 源码下载地址:http://codemonkey.org.uk/projects/git-sna ...

随机推荐

  1. 编译OpenCV提示opencv_contrib缺少boostdesc_bgm.i等文件

    错误提示: ~/opencv_contrib/modules/xfeatures2d/src/boostdesc.:: fatal error: boostdesc_bgm.i: No such fi ...

  2. cc.isChildClassOf 判断两个类的继承关系

    使用 cc.isChildClassOf 来判断两个类的继承关系: var Texture = cc.Class(); var Texture2D = cc.Class({ extends: Text ...

  3. 【转载】Gradle学习 第十一章:使用Gradle命令行

    转载地址:http://ask.android-studio.org/?/article/94 This chapter introduces the basics of the Gradle com ...

  4. JavaWeb 文件的上传、下载

    文件上传 表单 <form action="HandlerServlet" method="post" enctype="multipart/f ...

  5. 设置注释 idea

    https://blog.csdn.net/weixin_42679529/article/details/81059598 groovyScript("def result=''; def ...

  6. OL7.6上RPM方式安装Oracle 19c

    设置主机名 [root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localh ...

  7. Django框架(一)-- Django简介

    django(Python Web框架) Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的框架模式,即模型M,视图V和控制器C.它最初是被开发来用于管理劳伦斯出版集团旗 ...

  8. linux系统最大TCP连接数限制

    2017-12-28 17:48:21 chenlin465373800 阅读数 16189    不太对 本博客为转载,原文请参见<a href="http://blog.51cto ...

  9. 201871020225-牟星源 《面向对象程序设计(java)》课程学习进度条

    <2019面向对象程序设计(java)课程学习进度条> 周次 (阅读/编写)代码行数 发布博客量/评论他人博客数量 课余学习时间(小时) 学习收获最大的程序 阅读或编译让我 第一周 25/ ...

  10. MyISAM引擎mysql5.6中大型网站数据库优化配置方案

    硬件服务器:Dell R710,双至强E5620 CPU.16G内存.6*500G硬盘   操作系统:CentOS5.5 X86_64 系统   Mysql版本:MySQL 5.6   适用于:日IP ...