Cannot retrieve native file ffmpeg-amd64.exe

2019-07-22 13:05发布

问题:

I am trying to convert video to audio . That is why , I am using the following code :

File source = new File("E:\\Shunno - Khachar Bhitor Ochin Pakhi.mp4");
        File target = new File("E:\\output.mp3");
        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();
    try
    {
        encoder.encode(source, target, attrs); 
    }
    catch (IllegalArgumentException | EncoderException e)
    { 
    }

But I am getting the following error :

Sep 26, 2016 11:28:29 AM it.sauronsoftware.jave.DefaultFFMPEGLocator copyFile
SEVERE: Could not get native library for ffmpeg-amd64.exe
Exception in thread "main" java.lang.RuntimeException: Cannot retrieve native file ffmpeg-amd64.exe
    at it.sauronsoftware.jave.DefaultFFMPEGLocator.copyFile(DefaultFFMPEGLocator.java:139)
    at it.sauronsoftware.jave.DefaultFFMPEGLocator.<init>(DefaultFFMPEGLocator.java:80)
    at it.sauronsoftware.jave.Encoder.<init>(Encoder.java:105)
    at Convert.main(Convert.java:29)

How can I solve this error ? Please help me .

回答1:

The error is very clear: ffmpeg cannot been found.

Since you hard coded some windows path here is the windows binary of ffmpeg. I suggest to download the x64 static version. Since that is just one file you need to care about.

If you need it for another platform check the download site.

Within the zip file in the subdirectory bin where the binary ffmpeg.exe is located. Now you need to renamed it to ffmpeg-amd64.exe since the library expects that name. Now you need to copy the file to a directory of your path variable e.g. C:\windows\system32. I suggest not to use that directory, but this is the simplest way. Better put it somewhere else and modify your path variable. There are dozens of explanations so just google them if you want how do achieve that.