2

I want to use ffmpeg via command line arguments in android application.For this purpose:

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

This is the code i am using:

public class MainActivity 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

1 Answers1

1

I guess you are trying to run an .so file with this Linux command:

/data/data/com.example.ffmpegnew/files/libffmpeg.so -i mnt/sdcard/music/baba.mp4 mnt/sdcard/music/outfile.mp4

Did you actually mean running ffmpeg executable file (see man ffmpeg)?

ffmpeg -i mnt/sdcard/music/baba.mp4 mnt/sdcard/music/outfile.mp4

I think the first step might be making your command, then your code snippet run on regular Linux, then moving it to Android.

PS. In any event, the leading "/" is missing from "mnt/..."; should be "/mnt/..."

PPS. And other discussions might be helpful 1

Community
  • 1
  • 1
full.stack.ex
  • 1,747
  • 2
  • 11
  • 13
  • yes sir, i want to run ffmpeg executable file like we run it on cmd in windows. – user1662334 Sep 17 '12 at 09:19
  • I think sir,there must be some way of running the ffmpeg using command line in android – user1662334 Sep 17 '12 at 09:20
  • Please check the link in the answer above: some people have apparently had some success with that: http://stackoverflow.com/questions/4725773/ffmpeg-on-android?rq=1 – full.stack.ex Sep 17 '12 at 09:32
  • This is not helpful in my case sir. – user1662334 Sep 17 '12 at 10:00
  • Anyway, I think to go further down that path, you will need to: 1) build the (static?) executable; 2) at least fix the leading "/". Then run your code, having the leading "lib" removed from your first parameter. Oh, and, BTW, make sure the binaries (executable, lib) are really deployed to that directory. – full.stack.ex Sep 17 '12 at 11:31
  • Thanks sir for your efforts.But still i am getting the same problem. – user1662334 Sep 17 '12 at 12:45
  • You still can approach it step by step. Try calling ls, /bin/sh -c "ls >full-path-to-your-file-on-sd-card", building your hello world executable and calling it as above, etc. That will help you find out where things get wrong. – full.stack.ex Sep 17 '12 at 13:43