26

I want to use FFmpeg with Android-NDK and I am very basic in this section, I need some help and I research about this topic before on the net, but got no satisfactory solution.

1 - How can I use FFmpeg through Windows OS. (I do not want to use Ubuntu, please do not suggest.)

2 - How can I inset FFmpeg commands via NDK?

Last notice : I using android-ndk-r7b and Cygwin.

Any suggestion would be appreciated.

iSun
  • 1,526
  • 6
  • 26
  • 53
  • iSUn did u solve this issue? do i have to compile ffmpeg to run it's commands on android? or can i run it w/o compiling it? can u please explain me a procedure? – Chaitanya Chandurkar Sep 30 '12 at 10:11
  • @ChaitanyaChandurkar Sure, You have to compile it first, put the compiled file into your mobile phone and change the permission to chmod 775 and then you can run commands with exec() method. – iSun Sep 30 '12 at 16:42
  • Hi @iSun.. Did you complete the process completly? Can you give a explanation how to use fmpeg in android using windows OS?? I am trying to compress the video using ffmpeg. But I can't find any proper documantations for developing using windows OS. Can you give me any sample?? – Vijay Jan 13 '16 at 07:07

2 Answers2

25

From your question it is hard to tell what exactly you want/need... so here some general information:

If you need further help please explain exactly what you want to achieve and what is not working...

UPDATE - as per comments:

To use ffmpeg via command line on Android you need to copy ffmpeg into your application's files directory and chmod 755 it using getRuntime.exec() then you can run ffmpeg with the following line for example:

Process p = Runtime.getRuntime().exec("/data/data/yourpackagename/files/ffmpeg -i infile.mp4 outfile.mp4")
Diego Rafael Souza
  • 4,599
  • 3
  • 18
  • 52
Yahia
  • 67,016
  • 7
  • 102
  • 131
  • @iSun When I asked you said you want to use commandline... now you are saying you want to use ffmpeg.so which is very different and complicated (needs JNI and other stuff!)... what exactly do you need ? – Yahia Mar 13 '12 at 10:26
  • @iSun I mean all relevant files to run the ffmpeg command... I can't answer what exactly to copy because this depends on how you compiled and linked ffmpeg (static versus dynamic, which codecs/options etc.). – Yahia Mar 13 '12 at 10:31
  • Yahia How can i set ffmpeg to chmod 755 on windows? – iSun Mar 14 '12 at 21:40
  • @iSun I don't understand... why on Windows ? you said you develop on Windows and want to execute ffmpeg on the android phone... – Yahia Mar 15 '12 at 05:16
  • Aha, I think you said I have to set ffmpeg folder to chmod 755 before moving to my phone. – iSun Mar 15 '12 at 15:48
  • Yahia !! How can i copy ffmpeg library (directory) to /data/data/packagename/files/ ??? in DDMS der is no option to copy entire directory – Chaitanya Chandurkar Sep 04 '12 at 12:15
  • youn mean ffmpeg directory should be copied to /data/data/packagename/files/ OR der is one single file which i should copy? – Chaitanya Chandurkar Sep 04 '12 at 12:20
  • @Yahia Your last solution using Runtime.getRuntime.exec is only for rooted devices?? Because I've tried your solution in non-routed devices and I've executed: /data/data/com.example.test/files/ffmpeg -i sdcard/DCIM/f.mp4 -vf \"transpose=1\" -r 24 -sameq sdcard/DCIM/f2.mp4" But the logcat says me: permision denied – beni Sep 13 '12 at 14:38
  • @Yahia What type of permissions I need to setup?? Do I need to include some permission in the manifest? I need to convert any video in my Android application and any terminal. – beni Sep 13 '12 at 14:48
  • @beni sorry, but I don't have access to a device currently so I can't check those details... – Yahia Sep 13 '12 at 14:50
  • @Yahia Thanks. But, Do you think it's possible to use this method to use the ffmpeg library without using your first solution, compile the ffmpeg library to obtain the .so I've searched information and I didn't find out nothing. So, I gonna to try to compile the ffmpeg library (Your first solution). – beni Sep 13 '12 at 14:56
  • @iSun Could you execute the ffmpeg library using the Runtime.getRuntime().exec() method? Because I've tried to use this method and the logcat returned me: permision denied. – beni Sep 14 '12 at 12:19
  • @iSun Yes, I put chmod 777 in the two folders, and I obtain the same output: permission denied. I copy the two code lines: Runtime.getRuntime().exec("chmod -R 777 /mnt/sdcard/DCIM"); Process p = Runtime.getRuntime().exec("/mnt/sdcard/DCIM/ffmpeg -i /mnt/sdcard/DCIM/f.mp4 -vf \"transpose=1\" -r 24 -sameq /mnt/sdcard/DCIM/f2.mp4"); p.waitFor(); Could you execute this in the end? – beni Sep 17 '12 at 07:12
  • @iSun I put the chmod in the exec() method, but when I check the permissions the contented folder and the file have only -rw, but I put the 777 parameter in the chmod method. So, the file don't have execute permission, I can't change this permission. – beni Sep 17 '12 at 07:57
  • @iSun No, a comment above said it's not needed to have a rooted phone. So, I've tried to execute the ffmpeg program but I couldn't – beni Oct 01 '12 at 08:51
  • @beni did u succeed running ffmpeg commands??? m stuck at permission problem. same thing. permission denied. – Chaitanya Chandurkar Oct 01 '12 at 15:40
  • @ChaitanyaChandurkar No, I've not succeed running ffmpeg commands. I've compiled the ffmpeg with NDK, cause I read only rooted devices can run the ffmpeg executable. – beni Oct 01 '12 at 15:48
  • so is there any other way to run ffmpeg commands in android on non-rooted devices?? – Chaitanya Chandurkar Oct 01 '12 at 15:57
  • @beni How can you change your android data permission when your phone not rooted ?! – iSun Oct 01 '12 at 16:21
  • 1
    @iSun This solution only is good if the device is rooted. So, you can't publish an app with this method cause you need to push the ffmpeg executable on the device in develop time. – beni Oct 02 '12 at 06:38
  • @iSun Yes, you've another way if you wanna publish an app, you can open ffmpeg.c file and then find the main function and change it to JNI interface, then you can invoke those JNI functions in your app but you couldn't use commands directly ! – iSun Oct 02 '12 at 07:47
  • @iSun, how could I use the ffmpeg commands in the ffmpeg.c file?? How could I invoke this command "ffmpeg -i sdcard/DCIM/in.mp4 -s 480x320 sdcard/output.mp4"?? Thanks!! – Gonzalo Solera Sep 22 '13 at 09:37
8

I made a tutorial on how to build ffmpeg and x264 for android: http://db.tt/TjMqIF3u

You can also download the zip file containing the files you need to make an application on android and also an executable of lastest ffmpeg to run on android.

EDIT: This is really old code and old compilation process. You can find a more up to date process on FFMPEG docs

Estevex
  • 772
  • 8
  • 17
  • HI. I have problems using it... can you please give me an example of using it ? a ffmpeg command thanks. – Paul Jun 05 '13 at 07:50
  • I'll try to be more explicit: I'm using the so and bin file and this command in Android app: `String[] ffmpegCommand = {"/data/data/com.mobvcasting.mjpegffmpeg/ffmpeg","-f", "image2", "-r", "1/5", "-i", Environment.getExternalStorageDirectory().getPath() + "/frames/frame_%d.jpg", "-c:v", "libx264", "-r", "30", Environment.getExternalStorageDirectory().getPath() + "/frames/video.mp4"};` – Paul Jun 05 '13 at 08:16
  • With this command I'm receiving `"Unknown input format: 'image2'"`. Removing `"-f", "image2"`, I'm receiving `"/mnt/sdcard/frames/frame_%d.jpg: Protocol not found"` and I'm stuck here. I'm using this Android code: https://github.com/vanevery/Android-MJPEG-Video-Capture-FFMPEG – Paul Jun 05 '13 at 08:16
  • I think I found the problem: you specified only `--enable-protocol=rtp \` - meaning that only rtp protocol can be used - this is what I understand from this, but I need to use `Output:` protocol :| . unfortunately I cannot compile ffmpeg since I'm under windows.. can I ask you a favor in compiling using `--enable-protocol=Output:` ? thanks a lot. – Paul Jun 05 '13 at 09:26
  • So, I was able to compile using `--enable-protocol=file \ ` and this resolved the issue related to `Protocol not found `, but now I'm having another issue: `/mnt/sdcard/frames/frame_%d.jpg: No such file or directory`. I have all permissions in Android application. Do you know what can be wrong now? Any help is more than welcome. Thanks – Paul Jun 05 '13 at 14:52
  • i have downloaded .so file that you have provided. now how can i execute FFmpeg command. ex. converting images to video – Butani Vijay Mar 20 '15 at 07:27
  • i am unable to open the link. can you please update the same. all though the question is old searching leads to this thread. so its better you update it. – Raghunandan Sep 15 '19 at 09:32
  • Please check https://trac.ffmpeg.org/wiki/CompilationGuide/Android for up to date documentation – Estevex Sep 16 '19 at 10:45