简体   繁体   中英

Getting an error while using JAVE library in an Android project

I'm using an external library called JAVE in my Android project in order to extract the audio from a video file.

My code:

 public void extractAudio() {
    File source = new File(Environment.getExternalStorageDirectory().getPath() + "/test.flv");
    File target = new File(Environment.getExternalStorageDirectory().getPath() + "/test.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 e) {
        e.printStackTrace();
    } catch (InputFormatException e) {
        e.printStackTrace();
    } catch (EncoderException e) {
        e.printStackTrace();
    }
}

These are the errors I get:

11-09 18:26:49.874: W/System.err(6594): java.io.IOException: Error running exec(). Command: [/bin/chmod, 755, /sdcard/jave-1/ffmpeg] Working Directory: null Environment: null
11-09 18:26:49.874: W/System.err(6594):     at java.lang.ProcessManager.exec(ProcessManager.java:211)
11-09 18:26:49.874: W/System.err(6594):     at java.lang.Runtime.exec(Runtime.java:168)
11-09 18:26:49.884: W/System.err(6594):     at java.lang.Runtime.exec(Runtime.java:123)
11-09 18:26:49.884: W/System.err(6594):     at it.sauronsoftware.jave.DefaultFFMPEGLocator.<init>(DefaultFFMPEGLocator.java:85)
11-09 18:26:49.884: W/System.err(6594):     at it.sauronsoftware.jave.Encoder.<init>(Encoder.java:111)
11-09 18:26:49.884: W/System.err(6594):     at com.yt.ringtones.RipActivity.extractAudio(RipActivity.java:236)
11-09 18:26:49.894: W/System.err(6594):     at com.yt.ringtones.RipActivity$1$DownloadFromUrl.onPostExecute(RipActivity.java:94)
11-09 18:26:49.894: W/System.err(6594):     at com.yt.ringtones.RipActivity$1$DownloadFromUrl.onPostExecute(RipActivity.java:1)
11-09 18:26:49.894: W/System.err(6594):     at android.os.AsyncTask.finish(AsyncTask.java:602)
11-09 18:26:49.894: W/System.err(6594):     at android.os.AsyncTask.access$600(AsyncTask.java:156)
11-09 18:26:49.986: W/System.err(6594):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
11-09 18:26:49.986: W/System.err(6594):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-09 18:26:49.986: W/System.err(6594):     at android.os.Looper.loop(Looper.java:137)
11-09 18:26:49.994: W/System.err(6594):     at android.app.ActivityThread.main(ActivityThread.java:4424)
11-09 18:26:49.994: W/System.err(6594):     at java.lang.reflect.Method.invokeNative(Native Method)
11-09 18:26:49.994: W/System.err(6594):     at java.lang.reflect.Method.invoke(Method.java:511)
11-09 18:26:50.014: W/System.err(6594):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-09 18:26:50.014: W/System.err(6594):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-09 18:26:50.024: W/System.err(6594):     at dalvik.system.NativeStart.main(Native Method)
11-09 18:26:50.024: W/System.err(6594): Caused by: java.io.IOException: No such file or directory
11-09 18:26:50.024: W/System.err(6594):     at java.lang.ProcessManager.exec(Native Method)
11-09 18:26:50.034: W/System.err(6594):     at java.lang.ProcessManager.exec(ProcessManager.java:209)

I'm rather new to Android development and I'm not really sure what's the problem here. I'd appreciate any help.

"exec()" basically executes a command in a system, as if you would run it from a command line. It is trying to run "/sdcard/jave-1/ffmpeg", which is supposed to be an executable file. Do you have this executable on your device? If not, this will not work.

This errors happens due to wrong ffmpeg file permissions. Here is my answer in similar thread: Using sauronsoftware's Jave in phonegap Android project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM