Using FFmpeg with Android-NDK
Solution 1
From your question it is hard to tell what exactly you want/need... so here some general information:
- Using FFmpeg with Android
- Good starting point for FFmpeg on Android based on ndkr5
- Another good starting point for building FFmpeg for Android
- Helpful information to build FFmpeg for android see here, here and here
- Make sure that you use Windows paths instead of
/cydrive...
when doing ffmpeg/android/cygwin/windows dev
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")
Solution 2
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
Related videos on Youtube
iSun
Updated on September 17, 2020Comments
-
iSun almost 4 years
I want to use
FFmpeg
withAndroid-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 viaNDK
?Last notice : I using
android-ndk-r7b
andCygwin
.Any suggestion would be appreciated.
-
Chaitanya Chandurkar almost 12 yearsiSUn 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?
-
iSun almost 12 years@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.
-
Vijay over 8 yearsHi @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??
-
-
Yahia over 12 years@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 over 12 years@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.).
-
iSun over 12 yearsYahia How can i set ffmpeg to chmod 755 on windows?
-
Yahia over 12 years@iSun I don't understand... why on Windows ? you said you develop on Windows and want to execute ffmpeg on the android phone...
-
iSun over 12 yearsAha, I think you said I have to set ffmpeg folder to chmod 755 before moving to my phone.
-
Chaitanya Chandurkar almost 12 yearsYahia !! How can i copy ffmpeg library (directory) to /data/data/packagename/files/ ??? in DDMS der is no option to copy entire directory
-
Chaitanya Chandurkar almost 12 yearsyoun mean ffmpeg directory should be copied to /data/data/packagename/files/ OR der is one single file which i should copy?
-
beni almost 12 years@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 almost 12 years@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.
-
Yahia almost 12 years@beni sorry, but I don't have access to a device currently so I can't check those details...
-
beni almost 12 years@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 almost 12 years@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 almost 12 years@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 almost 12 years@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 almost 12 years@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
-
Chaitanya Chandurkar almost 12 years@beni did u succeed running ffmpeg commands??? m stuck at permission problem. same thing. permission denied.
-
beni almost 12 years@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.
-
Chaitanya Chandurkar almost 12 yearsso is there any other way to run ffmpeg commands in android on non-rooted devices??
-
iSun almost 12 years@beni How can you change your android data permission when your phone not rooted ?!
-
beni almost 12 years@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.
-
iSun almost 12 years@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 !
-
Paul about 11 yearsHI. I have problems using it... can you please give me an example of using it ? a ffmpeg command thanks.
-
Paul about 11 yearsI'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 about 11 yearsWith 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: github.com/vanevery/Android-MJPEG-Video-Capture-FFMPEG -
Paul about 11 yearsI 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 about 11 yearsSo, I was able to compile using
--enable-protocol=file \
and this resolved the issue related toProtocol 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 -
Gonzalo Solera almost 11 years@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!!
-
Butani Vijay over 9 yearsi have downloaded .so file that you have provided. now how can i execute FFmpeg command. ex. converting images to video
-
Raghunandan almost 5 yearsi 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.
-
Estevex almost 5 yearsPlease check trac.ffmpeg.org/wiki/CompilationGuide/Android for up to date documentation