我已经在Android上编译了FFmpeg (libffmpeg.so)。现在我必须构建一个应用程序,如RockPlayer或使用现有的Android多媒体框架来调用FFmpeg。
你有在Android / StageFright上集成FFmpeg的步骤/过程/代码/示例吗?
你能指导我如何使用这个库来播放多媒体吗?
我有一个需求,我已经有音频和视频传输流,我需要将其馈送到FFmpeg并将其解码/渲染。我怎么能在Android上做到这一点,因为IOMX api是基于OMX的,不能在这里插件FFmpeg ?
我也找不到FFmpeg api的文档,需要用于回放。
受到Android上其他FFmpeg实现(主要是guadianproject)的启发,我找到了一个解决方案(也有Lame支持)。
(lame和FFmpeg: https://github.com/intervigilium/liblame和http://bambuser.com/opensource)
调用FFmpeg:
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
FfmpegController ffmpeg = null;
try {
ffmpeg = new FfmpegController(context);
} catch (IOException ioe) {
Log.e(DEBUG_TAG, "Error loading ffmpeg. " + ioe.getMessage());
}
ShellDummy shell = new ShellDummy();
String mp3BitRate = "192";
try {
ffmpeg.extractAudio(in, out, audio, mp3BitRate, shell);
} catch (IOException e) {
Log.e(DEBUG_TAG, "IOException running ffmpeg" + e.getMessage());
} catch (InterruptedException e) {
Log.e(DEBUG_TAG, "InterruptedException running ffmpeg" + e.getMessage());
}
Looper.loop();
}
}).start();
并处理控制台输出:
private class ShellDummy implements ShellCallback {
@Override
public void shellOut(String shellLine) {
if (someCondition) {
doSomething(shellLine);
}
Utils.logger("d", shellLine, DEBUG_TAG);
}
@Override
public void processComplete(int exitValue) {
if (exitValue == 0) {
// Audio job OK, do your stuff:
// i.e.
// write id3 tags,
// calls the media scanner,
// etc.
}
}
@Override
public void processNotStartedCheck(boolean started) {
if (!started) {
// Audio job error, as above.
}
}
}
以下是我在让ffmpeg在Android上工作时所经历的步骤:
Build static libraries of ffmpeg for Android. This was achieved by building olvaffe's ffmpeg android port (libffmpeg) using the Android Build System. Simply place the sources under /external and make away. You'll need to extract bionic(libc) and zlib(libz) from the Android build as well, as ffmpeg libraries depend on them.
Create a dynamic library wrapping ffmpeg functionality using the Android NDK. There's a lot of documentation out there on how to work with the NDK. Basically you'll need to write some C/C++ code to export the functionality you need out of ffmpeg into a library java can interact with through JNI. The NDK allows you to easily link against the static libraries you've generated in step 1, just add a line similar to this to Android.mk: LOCAL_STATIC_LIBRARIES := libavcodec libavformat libavutil libc libz
Use the ffmpeg-wrapping dynamic library from your java sources. There's enough documentation on JNI out there, you should be fine.
关于使用ffmpeg进行回放,有很多例子(ffmpeg二进制本身就是一个很好的例子),这里是一个基本教程。最好的文档可以在标题中找到。
祝你好运。
受到Android上其他FFmpeg实现(主要是guadianproject)的启发,我找到了一个解决方案(也有Lame支持)。
(lame和FFmpeg: https://github.com/intervigilium/liblame和http://bambuser.com/opensource)
调用FFmpeg:
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
FfmpegController ffmpeg = null;
try {
ffmpeg = new FfmpegController(context);
} catch (IOException ioe) {
Log.e(DEBUG_TAG, "Error loading ffmpeg. " + ioe.getMessage());
}
ShellDummy shell = new ShellDummy();
String mp3BitRate = "192";
try {
ffmpeg.extractAudio(in, out, audio, mp3BitRate, shell);
} catch (IOException e) {
Log.e(DEBUG_TAG, "IOException running ffmpeg" + e.getMessage());
} catch (InterruptedException e) {
Log.e(DEBUG_TAG, "InterruptedException running ffmpeg" + e.getMessage());
}
Looper.loop();
}
}).start();
并处理控制台输出:
private class ShellDummy implements ShellCallback {
@Override
public void shellOut(String shellLine) {
if (someCondition) {
doSomething(shellLine);
}
Utils.logger("d", shellLine, DEBUG_TAG);
}
@Override
public void processComplete(int exitValue) {
if (exitValue == 0) {
// Audio job OK, do your stuff:
// i.e.
// write id3 tags,
// calls the media scanner,
// etc.
}
}
@Override
public void processNotStartedCheck(boolean started) {
if (!started) {
// Audio job error, as above.
}
}
}