我已经在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.
        }
    }
}

其他回答

奇怪的是,这个项目没有被提及:Appunite的AndroidFFmpeg

它有相当详细的步骤说明复制/粘贴到命令行,为像我这样的懒人))

以下是我在让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 NDK配置和构建X264和FFMPEG。主要缺少的是一个像样的JNI接口,可以通过Java访问它,但这是比较容易的部分(相对而言)。当我腾出时间使JNI接口适合我自己使用时,我将把它推进去。

与olvaffe的构建系统相比,它的优势在于不需要Android。Mk文件来构建库,它只使用常规的makefiles和工具链。这使得当你从FFMPEG或X264中做出新的改变时,它不太可能停止工作。

https://github.com/halfninja/android-ffmpeg-x264

受到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.
        }
    }
}

经过大量的研究,现在这是我发现的最新的Android编译库:

https://github.com/bravobit/FFmpeg-Android

目前使用的是FFmpeg版本n4.0-39-gda39990 包括FFmpeg和FFProbe 包含用于启动命令的Java接口 FFprobe或FFmpeg可以从APK中删除,检查维基https://github.com/bravobit/FFmpeg-Android/wiki