3

I am able to compile and add ffmpeg to jni folder in my project created Android.mk file now I want to use ffmpeg to create a video file from the images I have stored in my static arraylist

I have searched alot but couldn't find any tutorial any help is really appreciated.

Aashish Bhatnagar
  • 2,781
  • 2
  • 21
  • 36
  • In this link http://stackoverflow.com/questions/4248316/video-generation-using-ffmpeg the poster says he's able to do so on emulator. You may want to check this. Never did that myself – Alexander Kulyakhtin May 01 '12 at 08:21
  • it's for the iPhone how can I implement it in android – Aashish Bhatnagar May 01 '12 at 08:26
  • okay I have added the whole ffmpeg-android folder to jni folder added the Android.mk file that you provided now I need to create a C file and add this function to it?? – Aashish Bhatnagar May 01 '12 at 08:34
  • I think first you can create something like hello-jni example from ndk to make sure your function gets called. Then you add your ffmpeg code to it, first maybe just av_register_all() to make sure it works. Then you can add that iphone-based code from that link only you have to figure out how to do that for android. I mean, these are only FFMPEG API calls nothing iphone or android-specific. The only tutorial I know is http://dranger.com/ffmpeg/ – Alexander Kulyakhtin May 01 '12 at 08:37
  • First of all cross compile ffmpeg for android and create shared object file (.so) from ffmpeg source. – N.Droid May 01 '12 at 09:13
  • Alex so shall I add another line to Android.mk for my own c file?? – Aashish Bhatnagar May 01 '12 at 11:34
  • @Aashish Hi you could able to use ffmpeg fr your project? Can you please suggest some tutorials/links for building ffmpeg for android.Any help is really appreciated.Thanks – Abhishek V Oct 22 '13 at 12:59

1 Answers1

6

I was in a similar need and accomplished the same. There are two ways in which you can do this. I would like to share the simpler one first.

  • Create a temporary folder inside the Android.

  • Copy your images in the new folder

  • First, rename your pictures to follow a numerical sequence. For example, img1.jpg, img2.jpg, img3.jpg,... Then you may run:

  • Run this program programmetcally ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg

To run this programmatically,

Use the following code:

void convertImg_to_vid()
{
    Process chperm;
    try {
        chperm=Runtime.getRuntime().exec("su");
          DataOutputStream os = 
              new DataOutputStream(chperm.getOutputStream());

              os.writeBytes("ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg\n");
              os.flush();

              chperm.waitFor();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Get started with this. I will help you.. All the best

Use the tutorial : http://ffmpeg.org/faq.html Specially gothrough 3.2 section inside the tutorial.

To be able to run the above commands, you should have ffmpeg command in bin directory. The ffmpeg binary should be cross compiled for Android platform...

mk..
  • 15,357
  • 13
  • 60
  • 96
  • so can I use ffmpeg command directly what should I do in JNI folder and Android.mk file I have placed the ffmpeg-android folder as it it in JNI folder i build that from bambuser library – Aashish Bhatnagar May 02 '12 at 10:46
  • 1
    yes like other commands(ls, cd etc..) you can use ffmpeg also by copying the executable inside the bin library. But there are some problems when you want to deploy it in final product. I will help you with that aswell. But initially get started and see if you are able to do this or not.. – mk.. May 02 '12 at 10:50
  • 1
    where would I find "ffmpeg" command and how shuld I place it in the bin folder please guide me thru I am total stranger to ndk and ffmpeg – Aashish Bhatnagar May 02 '12 at 10:50
  • please google out for ffmpeg code and cross compile it for Android using NDK or any other cross compiler. Once the compilation is finished, result of it would be few libraries and an eeexecutable. The executable copy it in /system/bin using adb and libraries copy in /system/lib.. Once you do that, you can copy the executable from app. Please do some research on building final executable for ffmpeg. It is straight forward. and you will get it from internet.. I exactly dont rememner the source from where did i get the code. Bambuser also i attempted to compile but dont remember which one i used. – mk.. May 02 '12 at 10:56
  • You might want to refer to my post http://stackoverflow.com/questions/4725773/ffmpeg-on-android/9885907#9885907 – mk.. May 02 '12 at 10:57
  • thanks alot for you help just one last thing I compiled ffmpeg on ubuntu and I am using the resulting directory in windows so what is the executable file like I mean it's syntax and by libraries I hope you mean libavcodec ,etc.. files right ?? – Aashish Bhatnagar May 02 '12 at 11:06
  • I saw you post asking for help on bulding ffmpeg. The make file there will not build the executable. And yes the libraries are libavcodec, etc... there are other places which illustrate you the build of ffmpeg. Those places you need to use... I dont have my code in hand.. I will check it and let you more details tomorrow. But befire that search google frm your end... you will have something like BUILD_EXECUTABLE inside the makefile.. – mk.. May 02 '12 at 11:11
  • it did create two executable files but /system/bin is read only file system so I am unable to add it there – Aashish Bhatnagar May 02 '12 at 12:06
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10787/discussion-between-happy2help-and-aashish) – mk.. May 02 '12 at 12:11
  • Hey.. How can i copy ffmpeg binaries to system/bin from adb?? from adb m not able to ding my ffmpeg binaries !! please help me out !! – Chaitanya Chandurkar Aug 27 '12 at 13:48
  • @Sandy I've tried to use ffmpeg library with an Android project. But when I've executed the code, the output was: permission denied. Does the device need to be rooted to execute the code? The app should be able to run on most of the devices. Do I need to compile the ffmpeg library, like bambuser code, to execute the code using the Runtime class? Where should I place the compiled library? Do I need to create the Android.mk and Application.mk? If the devices must be rooted I need to compile the library with NDK, which library I should use? – beni Sep 18 '12 at 10:19
  • Hi, i read your answer and I am also doing in this way, but I have images in a folder say '/mnt/sdcard/Pic/image%d.jpg' but this gives me an error that no such file or directory found. But if i give '/mnt/sdcard/Pic/image1.jpg' then it works. but how to work with multiple images.?? – Jagdeep Singh Jun 27 '13 at 05:22
  • Hi Jagdeep. It should work properly. You mmight have done a mistake in naming files some where.Cross check once. As i pointed out please check the FFMPEG faq link. http://ffmpeg.org/faq.html#How-do-I-encode-single-pictures-into-movies_003f – mk.. Jun 28 '13 at 09:08
  • Can anyone example me how to put the commands? or how commands workks? ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg what is -f? image2? – Ahmad Arslan Apr 10 '14 at 10:48