Jave mav转mp3报错,1.ffmpeg.home does not exists,2.jave.EncoderException: Stream mapping:

参考:

https://blog.csdn.net/dadiyang/article/details/85003240

https://hk.saowen.com/a/2ec2a73ec73091967c3ebdb5697832006cb255a7183377b6e8fae1c13f5e54bc

(1)ffmpeg.home does not exists

解决:java代码中添加:System.setProperty("ffmpeg.home", "xxx/ffmpeg/bin");

 

(2)jave.EncoderException: Stream mapping

解决:继承Encoder重写processErrorOutput方法

package com.campus.voice.utils;

 

import it.sauronsoftware.jave.Encoder;

import it.sauronsoftware.jave.EncoderException;

import it.sauronsoftware.jave.EncoderProgressListener;

import it.sauronsoftware.jave.EncodingAttributes;

 

import java.io.BufferedReader;

import java.io.File;

import java.io.IOException;

 

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

 

public class WavToMp3Encoder extends Encoder {

 

    private static Logger logger = LoggerFactory.getLogger(WavToMp3Encoder.class);

 

    protected void processErrorOutput(EncodingAttributes attributes, BufferedReader errorReader, File source, EncoderProgressListener listener) throws EncoderException, IOException {

        // 屏蔽默認的錯誤處理

        try {

            String line;

            while ((line = errorReader.readLine()) != null) {

                logger.debug(line);

            }

        } catch (Exception exp) {

            logger.error("file convert error message process failed. ", exp);

        }

    }

}

 

wav转mp3

try{

            File source = new File(wavPath);

            File target = new File(saveMp3Path);

            AudioAttributes audio = new AudioAttributes();

            audio.setCodec("libmp3lame");  //编解码器

            audio.setBitRate(new Integer(128000));  //比特率

            audio.setChannels(new Integer(2));  //渠道

            audio.setSamplingRate(new Integer(44100));   //采样率

            EncodingAttributes attrs = new EncodingAttributes();

            attrs.setFormat("mp3");

            attrs.setAudioAttributes(audio);

//            Encoder encoder = new Encoder();

            WavToMp3Encoder encoder = new WavToMp3Encoder();

            try {

                encoder.encode(source, target, attrs);

            } catch (IllegalArgumentException e) {

                e.printStackTrace();

            } catch (InputFormatException e) {

                e.printStackTrace();

            } catch (EncoderException e) {

                e.printStackTrace();

            }

        }catch (Exception e){

            e.printStackTrace();

 

        }

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值