关于amr转mp3格式转化问题

关于amr转mp3格式转化问题

应需求写一个格式转化问题,在本地的windows系统测试完美通过,在Linux系统是弄了一天都是报错。
结果问题是在重写processErrorOutput时方法名写错,在windows系统上方法名不同是可以使用的,但是在Linux系统上是不行的 必须是重写,不能有改变,感谢大佬 java-小胡提供的代码。此代码windows和linux都可以使用。

引入依赖

<!--amr转mp3-->
        <dependency>
            <groupId>com.github.dadiyang</groupId>
            <artifactId>jave</artifactId>
            <version>1.0.5</version>
        </dependency>

arm转码mp3

public static void amrToMp3(String sourcePath,String targetPath)  {
        //这里是强制设置ffmpeg的路径,就是默认路径
        System.setProperty("ffmpeg.home", "/tmp/jave-1");
        File source = new File(sourcePath);
        File target = new File(targetPath);
        System.out.println("sourcePath============="+sourcePath);
        System.out.println("targetPath============="+targetPath);
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("libmp3lame");
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp3");
        attrs.setAudioAttributes(audio);
        WavToMp3Encoder encoder = new WavToMp3Encoder();
        try {
            encoder.encode(source, target, attrs);
        } catch (EncoderException e) {
            e.printStackTrace();
        }
    }

WavToMp3Encoder重写Encoder方法如下:

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);
        }
    }
}

转载自java-小胡:https://blog.csdn.net/weixin_42167600/article/details/126372311

共勉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值