我在ubuntu 11.10上編譯了ffmpeg庫,並在android上移植了編譯後的文件。
編譯後我得到了libffmpeg.so成功。它成功加載到android上。
我在ubuntu 11.10上做的Eclipse eclipse仿真器。
我創建了一個小型測試應用程序,它作爲命令提示符接受來自用戶的命令並顯示結果。 (測試ffmpeg命令)
當我運行諸如「ls」,「ls -l」之類的簡單命令時,它可以很好地工作。但是當我只是輸入「cd mnt」或「ffmpeg」作爲命令並嘗試運行它。我警告在logcat的說Android-在執行Runtime.getRuntime()。exec()時出錯 - 環境爲空-ffmpeg
08-26 16:44:52.553: W/System.err(5961): java.io.IOException: Error running exec(). Command: [ffmpeg] Working Directory: null Environment: null
08-26 16:44:52.573: W/System.err(5961): at java.lang.ProcessManager.exec(ProcessManager.java:211)
08-26 16:44:52.573: W/System.err(5961): at java.lang.Runtime.exec(Runtime.java:168)
08-26 16:44:52.573: W/System.err(5961): at java.lang.Runtime.exec(Runtime.java:241)
08-26 16:44:52.583: W/System.err(5961): at java.lang.Runtime.exec(Runtime.java:184)
08-26 16:44:52.593: W/System.err(5961): at ch.ffmpeg.reversit.MainActivity.Execute(MainActivity.java:61)
08-26 16:44:52.593: W/System.err(5961): at ch.ffmpeg.reversit.MainActivity$1.onClick(MainActivity.java:46)
08-26 16:44:52.593: W/System.err(5961): at android.view.View.performClick(View.java:3480)
08-26 16:44:52.593: W/System.err(5961): at android.view.View$PerformClick.run(View.java:13983)
08-26 16:44:52.603: W/System.err(5961): at android.os.Handler.handleCallback(Handler.java:605)
08-26 16:44:52.603: W/System.err(5961): at android.os.Handler.dispatchMessage(Handler.java:92)
08-26 16:44:52.603: W/System.err(5961): at android.os.Looper.loop(Looper.java:137)
08-26 16:44:52.614: W/System.err(5961): at android.app.ActivityThread.main(ActivityThread.java:4340)
08-26 16:44:52.624: W/System.err(5961): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 16:44:52.624: W/System.err(5961): at java.lang.reflect.Method.invoke(Method.java:511)
08-26 16:44:52.634: W/System.err(5961): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-26 16:44:52.634: W/System.err(5961): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-26 16:44:52.644: W/System.err(5961): at dalvik.system.NativeStart.main(Native Method)
08-26 16:44:52.644: W/System.err(5961): Caused by: java.io.IOException: Permission denied
08-26 16:44:52.674: W/System.err(5961): at java.lang.ProcessManager.exec(Native Method)
08-26 16:44:52.674: W/System.err(5961): at java.lang.ProcessManager.exec(ProcessManager.java:209)
08-26 16:44:52.684: W/System.err(5961): ... 16 more
這裏是我的代碼:
imports;
public class MainActivity extends Activity {
String com;
Process process;
EditText command;
Button run;
RelativeLayout main_layout;
static {
System.loadLibrary("ffmpeg");
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//find view
command=(EditText)findViewById(R.id.command);
run=(Button)findViewById(R.id.run);
run.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
com=command.getText().toString();
try {
Execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void Execute() throws IOException, InterruptedException{
process=Runtime.getRuntime().exec(com);
// process = pb.command(com).redirectErrorStream(true).start();
if(process!=null)
ShowOutput();
else
Toast.makeText(getBaseContext(),"Null Process",Toast.LENGTH_LONG).show();
}
public void ShowOutput() throws IOException, InterruptedException{
String s,text="",errors="";
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(process.getErrorStream()));
TextView output=(TextView)findViewById(R.id.output);
TextView error=(TextView)findViewById(R.id.error);
while ((s = stdInput.readLine()) != null) {
text+=s.toString()+"\n";
System.out.println("Error: "+s);
}
output.setText(text);
text="";
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
text+=s.toString()+"\n";
System.out.println("Error: "+s);
}
error.setText(text);
error.setMovementMethod(new ScrollingMovementMethod());
output.setMovementMethod(new ScrollingMovementMethod());
stdInput.close();
stdError.close();
process.waitFor();
process.getOutputStream().close();
process.getInputStream().close();
process.getErrorStream().close();
process.destroy();
}
}
我甚至嘗試process = pb.command(com).redirectErrorStream(true).start();
執行。它給了我同樣的錯誤,但這個時環境[ANDROID_SOCKET_Zygot]唧唧歪歪..
編輯1: 我用的OpenJDK在Ubuntu
幫我出去!
對..我沒有回憶它!好的,我會試試 –
嘿..你能告訴我哪個目錄或庫應該運行這個命令。我試過從adb外殼,但它說沒有這樣的目錄。 –
找到ffmpeg存在的地方,它可能在系統/ bin中,所以你可以去那裏做。即使在代碼中使用/ system/bin/ffmpeg – nandeesh