ffmpeg使用中遇到的坑---amr轉MP3格式

amr轉mp3格式代碼附上:java

private boolean convertAmr2MP3(File src, File target) {
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("libmp3lame");
        Encoder encoder = new Encoder();
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp3");
        attrs.setAudioAttributes(audio);
        try {
            encoder.encode(src, target, attrs);
            return true;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InputFormatException e) {
            e.printStackTrace();
        } catch (EncoderException e) {
            e.printStackTrace();
        }
        return false;
    }

在有的環境下報錯:apache

 

 

it.sauronsoftware.jave.InputFormatException
	at it.sauronsoftware.jave.Encoder.parseMultimediaInfo(Encoder.java:659)
	at it.sauronsoftware.jave.Encoder.encode(Encoder.java:840)
	at it.sauronsoftware.jave.Encoder.encode(Encoder.java:713)
........
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:610)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:410)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
	at java.lang.Thread.run(Thread.java:662)

找其緣由:若是ffmpeg沒有加載到這個pthreadGC2.dll文件,就會報以上錯誤tomcat

解決方案:將pthreadGC2.dll和ffmpeg的路徑固定,經過.net

public class MyFFMPEGExecute extends FFMPEGLocator {
    protected String getFFMPEGExecutablePath() {
 
        String path = 「獲取以上兩個文件的絕對路徑」;
 
        return path;
    }
}

搞定!!!code

相關文章
相關標籤/搜索