I used this project https://github.com/guardianproject/android-ffmpeg-java
It has already been compiled for the version of the FFMPEG library for Android and this file will be located in the res / raw folder (you can update this file if you need a newer version). You need to add this project as a library for yours. And after 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 the FfmpegController object. Please note if you have any questions or if that is what you want.
EDIT: Hope you put together this github code as a library for your project. There is a class FfmpegController.java in the src folder. This is the shell for using the ffmpeg exe command line file. If you want, for example, to execute a command like this,
ffmpeg -i source.wav -b:a 128k output.mp3
you need to add the function to the FfmpegController.java class. Something like that:
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;
Now in your project, initialize the FfmpegController object and run your function.
Karol Żygłowicz
source share