Linux编译安装ffmpeg

安装依赖

# wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

# tar -zxvf yasm-1.3.0.tar.gz

# cd yasm-1.3.0

# ./configure

# make && make install

 

安装 ffmpeg

# wget http://www.ffmpeg.org/releases/ffmpeg-3.1.tar.gz

# tar -zxvf ffmpeg-3.1.tar.gz

# cd ffmpeg-3.1

# ./configure --prefix=/usr/local/ffmpeg

# make && make install

 

等待安装完成...

 

# vi /etc/profile

在最后PATH添加环境变量:

PATH=$PATH:/usr/local/ffmpeg/bin

export PATH

保存退出

 

# source /ect/profile   设置生效

# ffmpeg -version       查看版本

 

转换成 wav 音频

ffmpeg -i ./1557130919577.wav -ar 16000 -ac 1 -f wav /tmp/1557130919577.wav

java   util、ffmpeg 转换

public static String convertMp3ToWav(String filePath) {
    Runtime run = null;
    try {
        logger.info(filePath + " is  begin convert");
        String targetPath = filePath.substring(0,filePath.lastIndexOf(".")) + ".wav";

        run = Runtime.getRuntime();
        long start = System.currentTimeMillis();
        Process p = run.exec(new String[]{"sh", "-c", "ffmpeg -i " + filePath + " -ar 16000 -ac 1 -f wav " + targetPath});
        p.waitFor();
        //释放进程
        p.getOutputStream().close();
        p.getInputStream().close();
        p.getErrorStream().close();
        long end = System.currentTimeMillis();
        logger.info(filePath + " convert success, costs:" + (end - start) + "ms,targetPath" + targetPath);

        File file = new File(filePath);
        //删除原来的文件
        if (file.exists()) {
            file.delete();
        }
        return targetPath;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        run.freeMemory();
    }
}

 

 

 

 

 

你可能感兴趣的:(Linux编译安装ffmpeg)