0

我在我的 Android 项目中使用了一个名为JAVE的外部库,以便从视频文件中提取音频。

我的代码:

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

这些是我得到的错误:

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)

我对 Android 开发相当陌生,我不确定这里有什么问题。我会很感激任何帮助。

4

2 回答 2

0

“exec()”基本上是在系统中执行一个命令,就好像你从命令行运行它一样。它正在尝试运行“/sdcard/jave-1/ffmpeg”,它应该是一个可执行文件。你的设备上有这个可执行文件吗?如果没有,这将不起作用。

于 2012-11-09T18:01:03.393 回答
0

由于错误的 ffmpeg 文件权限而发生此错误。这是我在类似线程中的答案:Using sauronsoftware's Jave in phonegap Android project

于 2015-05-27T12:43:04.573 回答