Android- Error during executing Runtime.getRuntime().exec() - Environment Null -ffmpeg

混江龙づ霸主 提交于 2019-12-04 15:17:13

There is a pretty large body of [android] [ffmpeg] discussion and how to's...

The normal way to invoke ffmpeg on non-rooted devices ( ie app for general users ) is to use the NDK and a C-lang integration where in java you make a normal method call that wraps the CLI stuff and the collection of parms that the JNI layer will deliver to the interface of the ffmpeg executable.

Example of the android call step1.android would be...

             new FFMpegTask().execute(invoke_lib_path,"ffmpeg", "-y", 
                    "-i", Picture.getPath(), "-i", recordFilePath,
                    "-vcodec", "mpeg4", "-s", siz,
                    "-r", "15", "-b:v", "200k",
                    "-acodec", "copy", "-f", "3gp"
                    ,pathOut);

Step2.c

JNIEXPORT void JNICALL Java_com_..._naRun( JNIEnv *env, jobject obj, jobjectArray args) { int i = 0; int argc = 0; char **argv = NULL;

if (args != NULL) { argc = (env)->GetArrayLength(env, args); argv = (char *) malloc(sizeof(char *) * argc);

  for(i=0;i<argc;i++)         {           jstring str =

(jstring)(*env)->GetObjectArrayElement(env, args, i); argv[i] = (char *)(*env)->GetStringUTFChars(env, str, NULL); } } int j = 0; j = main(argc, argv); }

Trying to use java runtime.exec() type CLI call is what i would call a hack that will be a big waste of your time.

By using the NDK and the normal packaging in an .apk, you are assuring a higher degree of reliability and integration between things like the processor architecture on the deploy device and the processor that ffmpeg was built for.

try reading roman10's intro

Then you might try relying on the breadcrumbs from lots of people who have built ffmpeg for android .. ie google "android-ffmpeg"

If you are rooted and you have compiled an executable then you can invoke that by getting a shell and using the adb CLI. Note that is not like using java as a wrapper for runtime.exec calls.

adb push ffmpeg /data/local/ffmpeg/ffmpeg

./ffmpeg -codecs

AFAIK You cannot use cd command. It is a bash directive, there is no executable cd. I guess ffmpeg is not working because of permissions. On adb shell do chmod 777 ffmpeg and try again

I might be little bit late

java.io.IOException: Error running exec(). Command: [ffmpeg] Working Directory: null Environment: null

It is clearly mentioned that ffmpeg file is not found . Before exexuting any command first check If File is present in the mentioned location.

boolean ifFileExists = new File(*path_of_ffmpeg_file*).exists();


       if(ifFileExists==false){
// code to write file in phone
    }
method(commandToExecute);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!