Reputation: 1
I have got FFmpeg
compiled (libffmpeg.so
) on Android. Now I have to build either an application like RockPlayer or use existing Android multimedia framework to invoke FFmpeg
along with video playing.
Do you have steps / procedures / code / example on integrating FFmpeg
on Android / StageFright?
Can you please guide me on how can I use this library for multimedia playback?
I already did rendering, mixing.
Upvotes: 0
Views: 1094
Reputation: 654
compile 'com.writingminds:FFmpegAndroid:0.3.2'
add this to gradle
Add this inside onCreate :
ffmpeg = FFmpeg.getInstance(this.getApplicationContext());
(Declare FFmpeg ffmpeg;
first)
Load library : loadFFMpegBinary();
Code to add audio to video using ffmpeg:
call function using execFFmpegBinaryShortest(null);
**
private void execFFmpegBinaryShortest(final String[] command) {
final File outputFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/videoaudiomerger/"+"Vid"+"output"+i1+".mp4");
String[] cmd = new String[]{"-i", selectedVideoPath,"-i",audiopath,"-map","1:a","-map","0:v","-codec","copy","-shortest",outputFile.getPath()};
try {
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
@Override
public void onFailure(String s) {
System.out.println("on failure----"+s);
}
@Override
public void onSuccess(String s) {
System.out.println("on success-----"+s);
}
@Override
public void onProgress(String s) {
//Log.d(TAG, "Started command : ffmpeg "+command);
System.out.println("Started---"+s);
}
@Override
public void onStart() {
//Log.d(TAG, "Started command : ffmpeg " + command);
System.out.println("Start----");
}
@Override
public void onFinish() {
System.out.println("Finish-----");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// do nothing for now
System.out.println("exceptio :::"+e.getMessage());
}
}
**
Upvotes: 1
Reputation: 2689
Download ffmpeg from here: http://bambuser.com/opensource. It contains scripts to build ffmpeg for android. Modify build.sh. Replace "com.bambuser.broadcaster" with your package name. You also need to set the ffmpeg flags to enable to codecs you're interested in. Run build.sh, and copy the build/ffmpeg directory into your apps jni/lib directory. Use fasaxc's makefile from the SO post. Create a native.c file in your jni directory and a java wrapper. To start with you can model it after hello-jni in NDK samples (/samples/hello-jni). Include headers in your native.c file like this: #include "libavcodec/avcodec.h". And call the functions you need: avcodec_register_all(), etc... Include the native libraries in your root activity by adding: static { System.loadLibraries(""); }
Upvotes: 0