我在我的 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 开发相当陌生,我不确定这里有什么问题。我会很感激任何帮助。