I want to use ffmpeg using command line.I have saved ffmpeg.so in files directory in the project.But i am getting exception while doing so.This is the code:
public class MainActivity extends Activity {
Process p;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Process p = Runtime.getRuntime().exec("/data/data/com.example.ffmpegnew/files/ffmpeg",null, new File("/data/data/com.example.ffmpegnew/files"));
}
catch(Exception e)
{
System.out.println("exception"+e);
}
}
}
This is the exception:
09-16 16:21:24.992: I/System.out(2103): exceptionjava.io.IOException: Error running exec(). Commands: [/data/data/com.example.ffmpegnew/files/ffmpeg] Working Directory: /data/data/com.example.ffmpegnew/files Environment: null
Please tell me what kind of mistake i am doing.Thanks.
The exception mentions the 'environment' is null...
maybe instead of 'exec', try using processbuilder as in the below sample of server-side code running ffmpeg wrapped in a shellscript(pars_submit)... note builder.environment
IMO - android-ffmpeg is going to be more reliable using a full JNI interface and wrapper for the call to ffmpeg.main(). Look at all the git projects... search on 'android-ffmpeg' and look how they invoke ffmpeg. CLI is not used.
pars_submit
So firstly, you cannot directly execute a
shared object
file. You need to build a ffmpeg executable that can be run using/system/bin
Kindly take this as reference FFmpeg on Android
After you are able to get it compiled, you can but the executable in your assets folder of the APK and extract it to
/data/data/<your package>/
(ensure a chmod 755 too!)Once that's done, you can run the executable by using building a command line string and passing it to
ProcessBuilder
instead of using the Runtime.exec()