Butani Vijay Butani Vijay - 5 months ago 213
Android Question

Using FFmpeg without NDK in android

I go though many site and search regarding "FFMPEG" implementation for android project.

Most solution founded are using NDK.

but i want to use FFmpeg without using NDK as i found in This Link

Answer

I have used this project https://github.com/guardianproject/android-ffmpeg-java

It has already compiled for android version of FFMPEG library and this file will be in res/raw folder (you can update this file if you need newer version). You need to add this project as a library to your's. And after thst you can write your own function in java for example like this:

public Clip convert (Clip mediaIn, String outPath, ShellCallback sc) throws Exception
{
    ArrayList<String> cmd = new ArrayList<String>();

    cmd.add(mFfmpegBin);
    cmd.add("-y");
    cmd.add("-i");
    cmd.add(new File(mediaIn.path).getCanonicalPath());

    if (mediaIn.startTime != null)
    {
        cmd.add("-ss");
        cmd.add(mediaIn.startTime);
    }
    if (mediaIn.duration != -1)
    {
        cmd.add("-t");
        cmd.add(String.format(Locale.US,"%f",mediaIn.duration));

    }
    Clip mediaOut = new Clip();
    File fileOut = new File(outPath);
    mediaOut.path = fileOut.getCanonicalPath();
    cmd.add(mediaOut.path);
    execFFMPEG(cmd, sc);
    return mediaOut;
}

and execute it using FfmpegController Object. Please notice me if you have any questions or if this is what you want.

EDIT: I hope you connect this github code as a library for your project. There is FfmpegController.java class in src folder. It's a wrapper for using command line ffmpeg exe file. If you want for example execute command like this one

ffmpeg -i source.wav -b:a 128k output.mp3

you need to add function to FfmpegController.java class. Something like this:

    public Clip convert(Clip mediaIn, String outPath, ShellCallback sc) throws Exception
    {
    ArrayList<String> cmd = new ArrayList<String>();

    Clip mediaOut = new Clip();

    String mediaPath = mediaIn.path;

    cmd = new ArrayList<String>();

    cmd.add(mFfmpegBin);
    cmd.add("-i");
    cmd.add(mediaPath);

    cmd.add("-b:a");
    cmd.add("128k");

    mediaOut.path = outPath;

    cmd.add(mediaOut.path);

    execFFMPEG(cmd, sc);

    return mediaOut; // this is not importatnt because file will be put in outPath
    }

Now in your project initialize FfmpegController object and run your function.