2

I have the same doubt that here. I want to execute this command on Android:

ffmpeg -i input.mp4 -s 480x320 output.mp4

So I compiled all the librarys with the NDK following this tutorial, I only need to add this code (I suppose that in a .c file that I have created) but I don´t know how... I will appreciate any help and any example if it was possible!!

Community
  • 1
  • 1
Gonzalo Solera
  • 1,182
  • 12
  • 26

2 Answers2

1

You're probably looking for system or popen. There are plenty of existing questions on this topic.

Community
  • 1
  • 1
acj
  • 4,821
  • 4
  • 34
  • 49
  • 1
    Thanks for answering. I´m trying to execute this command on Android so I don´t think these links will help me. I have a C file code and I know I must to write the ffmpeg operations there but I don´t know how (I´m a bit noob and I think I have a lot of gaps...) Please, read the point "2" of this link (http://www.roman10.net/how-to-build-android-applications-based-on-ffmpeg-by-an-example/) and advise me what should I do... – Gonzalo Solera Sep 19 '13 at 18:12
  • When you're writing native C code for Android, you have access to the functions that I mentioned. If you're linking against the libffmpeg library, as suggested by the tutorial that you linked to, then you should be able to call functions in that library instead of executing ffmpeg as a shell command. In that case, I would suggest posting a separate (and reworded) question. Good luck! – acj Sep 19 '13 at 18:19
  • Okey... I think I'm beginning to understand it... Thanks!! – Gonzalo Solera Sep 19 '13 at 19:01
  • hello @GonzaloSolera I am stucked at the same point since last two days. I compiled all the libraries for NDK and FFmpeg using this tutorial [link](http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/) . I even tested some small code for JNI which runs fine. Now I have to run commands like yours ffmpeg -i input.mp4 -s 480x320 output.mp4 All i can figure out is that if i create a .c class and do something in it i can get some result. However i cannot figure out how to execute single line command which everybody is talking about. Can you suggest me what approach shall i take. Thank You – aNoviceGuy Nov 23 '13 at 00:45
  • Hi @aNoviceGuy, I know it's very confused, It took me so much time to find a solution. There are two ways to use FFmpeg on Android. The first is the way you're trying: compiling DINAMICALLY ffmpeg with the ndk. The problem is that if you use this way you can't use a command line, you need to need to use the JNI, etc. But the second way (that I'm using now because is very easy) is to compile STATICALLY FFmpeg. It means you will get only an executable file and you call it from your java files (not from a .c file). It´s very easy and I would recommend you to do that. I could link my ffmpeg file. – Gonzalo Solera Nov 23 '13 at 09:55
  • @GonzaloSolera Thank you so much. I spend so much time on this problem. This helps me a lot. So what i am understanding is that i do not need ndk anymore. I can download the executable file from here [link](http://www.ffmpeg.org/download.html), then put it in my raw folder and then from my java class using process builder or Runtime exec i can run my command. Am i right or still i have to write some wrapper to access raw folder and use this executable file ? Again Thank you so much for your help Gonzalo – aNoviceGuy Nov 25 '13 at 04:00
  • @aNoviceGuy Yes... It took me so much time and I was very confused...Yes, you need to put the ffmpeg executable into your raw folder, but this executable needs to be compiled for android (your link won´t work...) you can build a new executable on your own or download it from somewhere. If you want I can pass you my build that I compiled recently with the newest ffmpeg release so I suppose it will be useful to you. And what you are saying is correct, you need to use a process builder to use it putting your command as string. – Gonzalo Solera Nov 25 '13 at 15:03
  • The problem is that you will probably need to change the chmod permissions of the executable file. I think it´s very hard but (I don´t know how) I got it. I could pass you my compiled ffmpeg file and my code to "install" it and set the chmod. Let me know if you are interested in this. Hope it´s useful because all of that was very difficult for my!! – Gonzalo Solera Nov 25 '13 at 15:07
  • @GonzaloSolera That would be very helpful. I tried working on it, and it is always giving me permission denied error. It would be really helpful if you can show me the code to install it and set the chmod. I am pulling my hair on this. However this also raises another question in my mind - Do i need a rooted device to run these commands and give permission. I guess chmod is a shell command, so if i make it run using your code, will it only work on rooted devices that can grant shell permission ? – aNoviceGuy Nov 25 '13 at 18:01
  • When I was trying to avoid the permission problems, I read on all sites that the phone needs to be rooted because you need to use the superuser command to set the chmod but I got a way in which you don´t need a rooted phone and works perfectly. – Gonzalo Solera Nov 25 '13 at 18:27
  • ouhh.. I was trying to post the code over here but it´s too long... Could you open a new question and pass me the link?? – Gonzalo Solera Nov 25 '13 at 18:30
  • @GonzaloSolera Thank you so much. This is the link for the question i created [link](http://stackoverflow.com/questions/20201067/ffmpeg-executable-chmod-permission) . Also you can upload it on a github and post the link. Whatever you feel is best for you. Once again thank you for your help. – aNoviceGuy Nov 25 '13 at 19:04
  • Okey!! It´s answered!! – Gonzalo Solera Nov 25 '13 at 19:10
0

You are using this Command for FFmpeg4 library for better Video Quality and minimum Compression of Video in android. I have used in my project it's working successfully.

--> ffmpeg -i your input video path.mp4 -s 480x320 -acodec mp2 -strict -2 -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 your output video path.mp4