Android 工作目录:null 环境:null
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22950139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Working Directory: null Environment: null
提问by Mert
I am trying to use ffmpeg.so on Android I am getting Working Directory: null Environment: null error.
我正在尝试在 Android 上使用 ffmpeg.so 我得到工作目录:空环境:空错误。
try {
Process p = Runtime.getRuntime().exec("/data/data/com.example.foo/files/ffmpeg -f image2 -i "
+ Environment.getExternalStorageDirectory().getAbsolutePath() + "/img/b%d.jpg "
+ Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/a444.mp4");
} catch (IOException e) {
e.printStackTrace();
}
ERROR LOG
错误日志
04-09 01:50:45.683: I/Adreno-EGL(18393): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
04-09 01:50:45.713: D/OpenGLRenderer(18393): Enabling debug mode 0
04-09 01:53:56.487: D/dalvikvm(18551): Trying to load lib /data/app-lib/com.example.sodeneme-1/libffmpeg.so 0x423d7d00
04-09 01:53:56.487: D/dalvikvm(18551): Added shared lib /data/app-lib/com.example.sodeneme-1/libffmpeg.so 0x423d7d00
04-09 01:53:56.487: D/dalvikvm(18551): No JNI_OnLoad found in /data/app-lib/com.example.sodeneme-1/libffmpeg.so 0x423d7d00, skipping init
04-09 01:53:56.537: W/System.err(18551): java.io.IOException: Error running exec(). Command: [/data/data/com.example.sodeneme/files/ffmpeg, -f, image2, -i, /storage/emulated/0/img/b%d.jpg, /storage/emulated/0/DCIM/Camera/a444.mp4] Working Directory: null Environment: null
04-09 01:53:56.537: W/System.err(18551): at java.lang.ProcessManager.exec(ProcessManager.java:211)
04-09 01:53:56.537: W/System.err(18551): at java.lang.Runtime.exec(Runtime.java:173)
04-09 01:53:56.537: W/System.err(18551): at java.lang.Runtime.exec(Runtime.java:246)
04-09 01:53:56.537: W/System.err(18551): at java.lang.Runtime.exec(Runtime.java:189)
04-09 01:53:56.537: W/System.err(18551): at com.example.sodeneme.MainActivity.onCreate(MainActivity.java:40)
04-09 01:53:56.537: W/System.err(18551): at android.app.Activity.performCreate(Activity.java:5231)
04-09 01:53:56.537: W/System.err(18551): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-09 01:53:56.537: W/System.err(18551): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-09 01:53:56.537: W/System.err(18551): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-09 01:53:56.537: W/System.err(18551): at android.app.ActivityThread.access0(ActivityThread.java:135)
04-09 01:53:56.537: W/System.err(18551): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-09 01:53:56.537: W/System.err(18551): at android.os.Handler.dispatchMessage(Handler.java:102)
04-09 01:53:56.537: W/System.err(18551): at android.os.Looper.loop(Looper.java:136)
04-09 01:53:56.537: W/System.err(18551): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-09 01:53:56.537: W/System.err(18551): at java.lang.reflect.Method.invokeNative(Native Method)
04-09 01:53:56.537: W/System.err(18551): at java.lang.reflect.Method.invoke(Method.java:515)
04-09 01:53:56.537: W/System.err(18551): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-09 01:53:56.537: W/System.err(18551): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-09 01:53:56.537: W/System.err(18551): at dalvik.system.NativeStart.main(Native Method)
04-09 01:53:56.547: W/System.err(18551): Caused by: java.io.IOException: No such file or directory
04-09 01:53:56.547: W/System.err(18551): at java.lang.ProcessManager.exec(Native Method)
04-09 01:53:56.547: W/System.err(18551): at java.lang.ProcessManager.exec(ProcessManager.java:209)
04-09 01:53:56.547: W/System.err(18551): ... 18 more
04-09 01:53:56.577: I/Adreno-EGL(18551): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
04-09 01:53:56.607: D/OpenGLRenderer(18551): Enabling debug mode 0
PERMISSIONS
权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
采纳答案by ChuongPham
Maybe you need to add this permission to your AndroidManifest.xml file:
也许您需要将此权限添加到您的AndroidManifest.xml 文件中:
android.permission.WRITE_EXTERNAL_STORAGE
回答by Shashank Singla
You need to make sure that the /data/data/com.example.foo/files/ffmpeg
file has the correct file permissions.
您需要确保该/data/data/com.example.foo/files/ffmpeg
文件具有正确的文件权限。
You can check file permission with the following command :
您可以使用以下命令检查文件权限:
String[] command = new String[]{"/system/bin/ls", "-l",
"/data/data/com.example.foo/files/ffmpeg" };
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
String output = "";
String line;
while ((line = reader.readLine()) != null) {
output.concat(line + "\n");
Log.w("myApp", "[[output]]:" + line);
}
reader.close();
process.waitFor();
The output would be something like this (depending on actual permissions , in this case the permissions are 777) :
输出将是这样的(取决于实际权限,在这种情况下,权限为 777):
[[output]]:-rwxrwxrwx u0_a67 u0_a67 254460 2015-03-02 17:12 ffmpeg
You can set the permissions to 744 , with the command below :
您可以使用以下命令将权限设置为 744 :
String[] command = new String[]{"/system/bin/chmod", "744",
"/data/data/com.example.foo/files/ffmpeg" };
If you are executing this command from outside activity (from a service lets say) , your permission will have to be 777 (not 744)
如果您从外部活动(可以说是来自服务)执行此命令,则您的权限必须为 777(而不是 744)
回答by Mete
I got this same problem spontaneously while working with the ffmpeg-android project. I already had all the permissions set that others have mentioned, and I hadn't had this problem in the past.
在使用 ffmpeg-android 项目时,我自发地遇到了同样的问题。我已经设置了其他人提到的所有权限,过去我没有遇到过这个问题。
I reverted back to an old build, which worked fine, then rebuilt the latest version and it was fine again - so the solution in my case was a simple Clean and Rebuild..
我恢复到旧版本,它运行良好,然后重建了最新版本,它又正常了 - 所以我的解决方案是一个简单的Clean and Rebuild..
Try it if you're feeling desperate!
如果您感到绝望,请尝试一下!
回答by us_david
In my case you need to add "sh -c" as done in the following example:
在我的情况下,您需要添加“sh -c”,如下例所示:
sh -c shellcommand
Hope it helps.
希望能帮助到你。
David
大卫
回答by huynq0911
You are missing this before exec command:
你在 exec 命令之前错过了这个:
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onFailure() {}
@Override
public void onSuccess() {}
@Override
public void onFinish() {}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
}
Refer to: http://writingminds.github.io/ffmpeg-android-java/