2

I want to use FFMPEG via COMMAND LINE in my android application.For this purpose:

  1. I have cross-compiled the ffmpeg lib and got the libffmpeg.so
  2. I have stored libffmpeg.so and the ffmpeg exectable in files directory of the my project.

This is the code i am using:

public class FFMPEGActivity extends Activity {

Process p;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        String[] cmd =new String[4];
    cmd[0]="/data/data/com.example.ffmpegnew/files/libffmpeg";
    cmd[1]="-i";
    cmd[2]="mnt/sdcard/music/baba.mp4";
    cmd[3]="mnt/sdcard/music/outfile.mp4";

    p = Runtime.getRuntime().exec(cmd,null, new File("/data/data/com.example.ffmpegnew/files"));

    }
    catch(Exception e)
    {
        System.out.println("exception"+e);
    }

}

}

This is the exception i am getting:

09-17 13:47:01.679: I/System.out(3752): exceptionjava.io.IOException: Error running exec(). Command: [/data/data/com.example.ffmpegnew/files/libffmpeg.so, -i, mnt/sdcard/music/baba.mp4, mnt/sdcard/music/outfile.mp4] Working Directory: /data/data/com.example.ffmpegnew/files Environment: null

Please tell me how to solve this problem.Thanks in advance.

user1662334
  • 659
  • 2
  • 9
  • 21

3 Answers3

1

I think this won't work, unless you somehow manage to compile ffmpeg executable, place it somewhere in the file system , then access it through your native layer. Normally, though, they use libffmpeg API in android such as in Dolphin Player

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
  • Sir i have ffmpeg executable file.Can't i place it in some app folder itself and then work with that like we work with ffmpeg in cmd prompt. – user1662334 Sep 18 '12 at 08:31
  • can you please help me with compiling ffmpeg? I am struggling to create a video by combining an audio and an image. Please help! – TharakaNirmana Jan 15 '13 at 06:57
1

Your code seems to try to run the library, not the ffmpeg executable. Note that even after fixing your cmd you will need extra tricks to load the libffmpeg.so, because Android loader does not load shared libs from ./

I would suggest to build a statically linked ffmpeg executable to save hassle.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
0

Place ffmpeg and all the files it accesses on the internal card (obtain through context.getDir("", 0). After you do this, you will be able to run ffmpeg through exec().

Some models, however, will refuse running this too.

Guy
  • 12,250
  • 6
  • 53
  • 70