How can I use Runtime.getRuntime.exec with the ffmpeg library in Android?

I'm trying to set the correct rotation in my recorded video, because on some devices the setOrientationHint method does not work, because some video players can ignore the compost matrix in the video during playback, Android Documentation .

So, I decided to use the ffmpeg library. I am developing a test for an application. In Ubuntu, I download this library and run configure and make to get the ffmpeg executable, I copy this executable to the DCIM folder on the SD card, the same for the video that I recorded for my camcorder recording application. So, in the DCIM folder, I have the ffmpeg executable and video.

I created a test project and in the onCreate method, I included:

try { Process p= Runtime.getRuntime().exec("chmod 777 /mnt/sdcard/beni/ffmpeg"); p.waitFor(); p = Runtime.getRuntime().exec("/mnt/sdcard/beni/ffmpeg -i /mnt/sdcard/beni/f.mp4 -vf \"transpose=1\" -r 24 -sameq /mnt/sdcard/beni/f2.mp4"); p.waitFor(); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } 

but I have the following warning:

 09-13 13:14:03.547: W/System.err(7782): java.io.IOException: Error running exec(). Command: [/mnt/sdcard/beni/ffmpeg, -i, /mnt/sdcard/beni/f.mp4, -vf, "transpose=1", -r, 24, -sameq, /mnt/sdcard/beni/f2.mp4] Working Directory: null Environment: null 09-13 13:14:03.547: W/System.err(7782): at java.lang.ProcessManager.exec(ProcessManager.java:224) 09-13 13:14:03.547: W/System.err(7782): at java.lang.Runtime.exec(Runtime.java:189) 09-13 13:14:03.547: W/System.err(7782): at java.lang.Runtime.exec(Runtime.java:275) 09-13 13:14:03.547: W/System.err(7782): at java.lang.Runtime.exec(Runtime.java:210) 09-13 13:14:03.547: W/System.err(7782): at com.example.prueba.MainActivity.onCreate(MainActivity.java:22) 09-13 13:14:03.547: W/System.err(7782): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 09-13 13:14:03.547: W/System.err(7782): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623) 09-13 13:14:03.547: W/System.err(7782): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675) 09-13 13:14:03.547: W/System.err(7782): at android.app.ActivityThread.access$1500(ActivityThread.java:121) 09-13 13:14:03.547: W/System.err(7782): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943) 09-13 13:14:03.547: W/System.err(7782): at android.os.Handler.dispatchMessage(Handler.java:99) 09-13 13:14:03.547: W/System.err(7782): at android.os.Looper.loop(Looper.java:138) 09-13 13:14:03.547: W/System.err(7782): at android.app.ActivityThread.main(ActivityThread.java:3701) 09-13 13:14:03.547: W/System.err(7782): at java.lang.reflect.Method.invokeNative(Native Method) 09-13 13:14:03.547: W/System.err(7782): at java.lang.reflect.Method.invoke(Method.java:507) 09-13 13:14:03.547: W/System.err(7782): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) 09-13 13:14:03.547: W/System.err(7782): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 09-13 13:14:03.547: W/System.err(7782): at dalvik.system.NativeStart.main(Native Method) 09-13 13:14:03.547: W/System.err(7782): Caused by: java.io.IOException: Permission denied 09-13 13:14:03.547: W/System.err(7782): at java.lang.ProcessManager.exec(Native Method) 09-13 13:14:03.547: W/System.err(7782): at java.lang.ProcessManager.exec(ProcessManager.java:222) 09-13 13:14:03.547: W/System.err(7782): ... 17 more 

Is this code correct? Or I did something wrong.

+4
source share

Source: https://habr.com/ru/post/1433989/


All Articles