2016-12-01 116 views
2

我想在android中將視頻文件轉換爲mp3文件。從Android中的視頻中提取MP3格式的音頻

我使用下面的代碼將視頻轉換爲MP3:

File source = new File(sourceFile); 
File target = new File(destFile); 
audioAttributes = new AudioAttributes(); 

audioAttributes.setCodec("libmp3lame"); 
audioAttributes.setBitRate(new Integer(128000)); 
audioAttributes.setChannels(new Integer(2)); 
audioAttributes.setSamplingRate(new Integer(44100)); 

EncodingAttributes encodingAttributes = new EncodingAttributes(); 
encodingAttributes.setFormat("mp3"); 
encodingAttributes.setAudioAttributes(audioAttributes); 

Encoder encoder = new Encoder(); 

try { 
    encoder.encode(source, target, encodingAttributes); 
} catch (EncoderException e) { 
    e.printStackTrace(); 
} 

但它無法正常工作。這裏是我得到的錯誤:

java.io.IOException: Error running exec(). Command: [/bin/chmod, 755, /data/data/com.example.bansi_vasundhara.videotomp3_demo/cache/jave-1/ffmpeg] Working Directory: null Environment: null 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at java.lang.ProcessManager.exec(ProcessManager.java:211) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at java.lang.Runtime.exec(Runtime.java:173) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at java.lang.Runtime.exec(Runtime.java:128) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at it.sauronsoftware.jave.DefaultFFMPEGLocator.<init>(DefaultFFMPEGLocator.java:85) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at it.sauronsoftware.jave.Encoder.<init>(Encoder.java:111) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at com.example.bansi_vasundhara.videotomp3_demo.MainActivity.onCreate(MainActivity.java:50) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.app.Activity.performCreate(Activity.java:6005) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2555) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.app.ActivityThread.access$800(ActivityThread.java:176) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1437) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.os.Handler.dispatchMessage(Handler.java:111) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.os.Looper.loop(Looper.java:194) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at android.app.ActivityThread.main(ActivityThread.java:5576) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at java.lang.reflect.Method.invoke(Native Method) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at java.lang.reflect.Method.invoke(Method.java:372) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err: Caused by: java.io.IOException: No such file or directory 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at java.lang.ProcessManager.exec(Native Method) 
12-01 15:19:04.116 19702-19702/com.example.bansi_vasundhara.videotomp3_demo W/System.err:  at java.lang.ProcessManager.exec(ProcessManager.java:209) 

任何想法可能是錯誤的?

+0

搜索谷歌。你會爲此提供解決方案 –

回答

1

使用FFMPEG爲Android ü需要實現的方法(我認爲它在FFmpeg庫已經存在) 和u可以使用下面的命令來提取ffmpeg的Android的音頻

ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac 
相關問題