ffmpeg将ogg和wav格式转化为mp3

ffmpeg将ogg和wav格式转化为mp3

因为钉钉和微信的iOS和android小程序版本音视频录制之后的格式与app录制不相同,因此我们需要使用ffmpeg将android录制的ogg格式和iOS小程序录制的WAV格式转化成通用的mp3格式。结合网上的资料做一个总结

下载组件

ffmpeg下载链接:http://ffmpeg.org/download.html

yasm下载链接:http://www.linuxfromscratch.org/blfs/view/svn/general/yasm.html

lame下载接:https://sourceforge.net/projects/lame/files/lame/

安装

2.1安装lame(ffmpeg 安装4.1以上,lame需要3.98以上)

tar -zxf lame-3.100.tar.gz
cd lame-3.100 
./configure 
make && make install

2.2安装yasm

tar -zxf yasm-1.3.0.tar.gz
cd yasm-1.3.0
sed -i 's#) ytasm.*#)#' Makefile.in 
./configure 
make && make install

2.3安装ffmpeg

tar -jxf ffmpeg-3.4.tar.bz2
cd ffmpeg-3.4 
./configure --enable-shared --enable-libmp3lame 
make && make install

值得注意的是ffmpeg最后的make和make install的时间比较长

配置调整

执行:ffmpeg --version

报错:ffmpeg: error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory

解决:编缉/etc/ld.so.conf,新建一行追加:/usr/local/lib保存后执行命令重加载配置文件:ldconfig

转化

WAV到mp3

ffmpeg -i audio.wav -acodec libmp3lame audio.mp3

2)Ogg至mp3

ffmpeg -i audio.ogg -acodec libmp3lame audio.mp3

3)AC3至mp3

ffmpeg -i audio.ac3 -acodec libmp3lame audio.mp3

4)AAC至mp3

ffmpeg -i audio.aac -acodec libmp3lame audio.mp3

Java调用

    public static String zm(String fileName) throws IOException, InterruptedException {
        String zmName = fileName.split("\\.")[0] + ".mp3";

        String cmd = FFMPEG_PATH + "ffmpeg  -i " + UPLOAD_PATH + fileName + " -acodec libmp3lame " + UPLOAD_PATH + zmName;
        try {
            String[] cmdA = {"/bin/sh", "-c", cmd};
            Process process = Runtime.getRuntime().exec(cmdA);
            LineNumberReader br = new LineNumberReader(new InputStreamReader(process.getInputStream()));
            StringBuffer sb = new StringBuffer();
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                sb.append(line).append("\n");
            }
            System.out.println(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return zmName;
    }

参考

如何使用ffmpeg将音频文件转换为mp3

ffmpeg+libmp3lame库源码安装教程(CentOS)

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 博客之星2020 设计师:CY__0809 返回首页