[安卓/flutter]给Media3.exoplayer编译扩展ffmpeg解码器

/ 1,670评论 / 11852阅读 / 2点赞

前言

引用文档

准备

配置NDK 、cmdtools、SDKManager

cd {你想放NDK的目录}
wget {官网复制Linux版的下载链接}
unzip {刚刚下载的zip文件}
cd {cmdline-tools目录}/bin
sudo ./sdkmanager --licenses --sdk_root={你的NDK的根目录}

编译ffmpge

NDK_PATH="$(pwd)"
cd {你想放Media3.decoder_ffmpeg的目录}
git clone https://github.com/androidx/media --depth 1
cd media
FFMPEG_MODULE_PATH="$(pwd)/libraries/decoder_ffmpeg/src/main"
Lunux执行:
HOST_PLATFORM="linux-x86_64"

MacOX执行:
HOST_PLATFORM="darwin-x86_64"
ANDROID_ABI=21
cd {你想放ffmpge源码的目录}
git clone git://source.ffmpeg.org/ffmpeg && \ cd ffmpeg && \ git checkout release/6.0 && \ FFMPEG_PATH="$(pwd)"
ENABLED_DECODERS=(vorbis opus flac alac pcm_mulaw pcm_alaw mp3 amrnb amrwb aac ac3 eac3 dca mlp truehd)
cd "${FFMPEG_MODULE_PATH}/jni"
ln -s "$FFMPEG_PATH" ffmpeg
./build_ffmpeg.sh \ "${FFMPEG_MODULE_PATH}" "${NDK_PATH}" "${HOST_PLATFORM}" "${ANDROID_ABI}" "${ENABLED_DECODERS[@]}"
cd {开头放Media3.decoder_ffmpeg的目录}
./gradlew lib-decoder-ffmpeg:assembleRelease

项目引入ffmpge的aar包


dependencies {
    implementation(fileTree('libs'))
}
import java.util.zip.ZipEntry
import java.util.zip.ZipFile

// 把aar拷贝进入主项目的方法 com.example.android_control换成你自己的插件包名
// * 只修改下面这一行的参数就可以了
copyAar2Host('com.example.android_control')

// 拷贝aar的方法
static aarFileCopy(String srcPath,String desPath) {
    System.out.println("copy aar from <<${srcPath}>> to <<${desPath}>>")
    try {
        FileInputStream fis = new FileInputStream(srcPath)
        FileOutputStream fos = new FileOutputStream(desPath)
        byte[] data = new byte[1024*8]
        int len = 0
        while ((len = fis.read(data))!=-1) {
            fos.write(data,0,len)
        }
        fis.close()
        fos.close()
    }catch(Exception e) {
        e.printStackTrace()
    }
}

void copyAar2Host(String pluginGroup) {
    Project currentProject = null
    Project appProject = null
    rootProject.allprojects.each {
        p->
            boolean  isApp = p.plugins.hasPlugin("com.android.application")
            println("<<${p.name}>> isHost ? ${isApp}")
            if (p.group == pluginGroup) {
                currentProject = p
                println("Plugin project name is $currentProject")
            }
            if(isApp) {
                appProject = p
                println("Host project name is <<${p.name}>>")
            }
    }
    Set<File> aarFiles = new HashSet<File>()
    if (appProject != null && currentProject != null) {
        File libs = new File("${currentProject.projectDir}","libs")
        if(libs.isDirectory()) {
            libs.listFiles().each {
                f->
                    if(f.name.endsWith(".aar")) {
                        println("The aar file name to be copied is <<${f.name}>>")
                        aarFiles.add(f)
                    }

            }
        }
        if (!aarFiles.isEmpty()) {
            File applibs = new File("${appProject.projectDir}${File.separator}libs")
            if(!applibs.isDirectory()) {
                applibs.mkdirs()
            }
            aarFiles.each {
                f->
                    File copyAar = new File("${appProject.projectDir}${File.separator}libs",f.name)
                    if(!copyAar.exists()) {
                        copyAar.createNewFile()
                        aarFileCopy(f.path,copyAar.path)
                    } else {

                    }
            }
            appProject.dependencies {
                implementation fileTree(dir:"${appProject.projectDir}${File.separator}libs",include:["*.jar","*.aar"])
            }
        }
    }
}

repositories{
    flatDir {
        dirs 'libs'
    }
}
apply plugin: 'com.android.library'
// 在这里插入下面这一行
apply from: './aar_tools.gradle'

// 然后找到dependencies块,
dependencies {
    // 这一行导入刚刚libs目录内的ffmpge的arr包

    compileOnly(fileTree("libs"))
    // 这里用于解决用android studio打开项目的android目录时里面的java/kotlin文件的import都是灰色的问题
    compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar")
    compileOnly("androidx.annotation:annotation:1.3.0")
}

在代码里引入ffmpeg


import androidx.media3.decoder.ffmpeg.FfmpegAudioRenderer;

class FfmpegRenderersFactory extends DefaultRenderersFactory {
    public FfmpegRenderersFactory(Context context) {
        super(context);
        setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
    }

    @Override
    protected void buildAudioRenderers(Context context, int extensionRendererMode, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, AudioSink audioSink, Handler eventHandler, AudioRendererEventListener eventListener, ArrayList<Renderer> out) {
        out.add(new FfmpegAudioRenderer(eventHandler, eventListener, audioSink));
        super.buildAudioRenderers(context, extensionRendererMode, mediaCodecSelector, enableDecoderFallback, audioSink, eventHandler, eventListener, out);
    }
}

ExoPlayer.Builder builder = new ExoPlayer.Builder(context);
// 添加ffmpeg

builder.setRenderersFactory(new FfmpegRenderersFactory(context));
ExoPlayer player = builder.build();
  1. Charlescoofs说道:

    https://clomidca.com/# prednisone 2.5 mg

  2. Billyziz说道:

    buy doxycycline 100mg online usa doxycycline azithromycinca can i buy doxycycline over the counter

  3. Carlosnatry说道:

    order zithromax without prescription: buy zithromax amoxicillinca – zithromax 500 mg lowest price pharmacy online

  4. Charlescoofs说道:

    https://azithromycinca.shop/# doxycycline 100mg online uk

  5. Clydewal说道:

    buy doxycycline online canada: azithromycinca.shop – where to buy doxycycline over the counter

  6. Charlescoofs说道:

    http://azithromycinca.com/# doxycycline medicine

  7. Carlosnatry说道:

    get generic clomid: clomid – can i get generic clomid pill

  8. Billyziz说道:

    amoxicillin 250 mg capsule cheapest amoxicillin buy amoxicillin online mexico

  9. Carlosnatry说道:

    buy 40 mg doxycycline: buy tetracycline antibiotics – doxycycline 100mg australia

  10. Charlescoofs说道:

    https://amoxicillinca.shop/# where can i buy zithromax uk

  11. Clydewal说道:

    prednisone over the counter cost: Deltasone – prednisone 1 tablet

  12. Carlosnatry说道:

    amoxicillin 500 coupon: amoxil best price – amoxicillin 500mg capsules antibiotic

  13. Billyziz说道:

    prednisone 20mg tab price clomidca.shop prednisone 2.5 mg price

  14. Charlescoofs说道:

    https://amoxicillinca.com/# generic zithromax online paypal

  15. Carlosnatry说道:

    where to get cheap clomid: Clomiphene – where buy generic clomid pill

  16. Charlescoofs说道:

    https://clomidca.shop/# prednisone 10 mg coupon

  17. Clydewal说道:

    amoxicillin 500mg cost: amoxil – purchase amoxicillin online without prescription

  18. Carlosnatry说道:

    can i order clomid without prescription: best price – buy clomid no prescription

  19. Billyziz说道:

    zithromax over the counter amoxicillinca buy zithromax online fast shipping

  20. Charlescoofs说道:

    https://doxycyclineca.com/# generic amoxicillin

  21. Carlosnatry说道:

    where can i get doxycycline over the counter: doxycycline best price – antibiotics doxycycline

  22. Clydewal说道:

    generic zithromax 500mg india: zithromax – zithromax canadian pharmacy

  23. Charlescoofs说道:

    https://azithromycinca.shop/# doxycycline 100mg without a prescription

  24. Carlosnatry说道:

    doxycycline 100 mg tablets: buy tetracycline antibiotics – doxycycline pharmacy uk

  25. Billyziz说道:

    where to get cheap clomid prices clomid Prednisonerxa buy clomid pills

  26. Charlescoofs说道:

    http://prednisonerxa.com/# cost clomid no prescription

  27. Clydewal说道:

    rexall pharmacy amoxicillin 500mg: buy cheapest antibiotics – amoxicillin 500mg pill

  28. Carlosnatry说道:

    amoxicillin capsules 250mg: amoxil – where can i buy amoxicillin over the counter

  29. Charlescoofs说道:

    https://amoxicillinca.shop/# order zithromax without prescription

  30. Billyziz说道:

    3000mg prednisone Deltasone prednisone sale

  31. Carlosnatry说道:

    buy zithromax without presc: buy zithromax online – zithromax for sale 500 mg

  32. Charlescoofs说道:

    https://prednisonerxa.shop/# can i purchase clomid

  33. Clydewal说道:

    buy doxycycline capsules: doxycycline – buy doxycycline in india

  34. Carlosnatry说道:

    buy prednisone online usa: prednisone clomidca – prednisone cream

  35. Charlescoofs说道:

    http://doxycyclineca.com/# cost of amoxicillin prescription

  36. Billyziz说道:

    how to get doxycycline prescription azithromycinca.com doxycycline 500mg price

  37. Carlosnatry说道:

    get cheap clomid price: prednisonerxa.com – order clomid price

  38. Clydewal说道:

    buy amoxicillin 500mg canada: buy cheapest antibiotics – amoxicillin for sale online

  39. Charlescoofs说道:

    http://clomidca.com/# prednisone for sale in canada

  40. Carlosnatry说道:

    doxycycline buy no prescription: doxycycline azithromycinca – doxycycline 100mg tablets no prescription

  41. Billyziz说道:

    generic for amoxicillin amoxil amoxicillin 250 mg capsule

  42. Charlescoofs说道:

    http://clomidca.com/# where to get prednisone

  43. Carlosnatry说道:

    average cost of generic zithromax: cheapest Azithromycin – buy zithromax online with mastercard

  44. Clydewal说道:

    prednisone 20mg capsule: Deltasone – prednisone 5 mg tablet without a prescription

  45. Charlescoofs说道:

    https://clomidca.shop/# no prescription online prednisone

  46. Carlosnatry说道:

    where to buy clomid without dr prescription: clomid Prednisonerxa – buying cheap clomid without dr prescription

  47. Billyziz说道:

    amoxicillin 500mg without prescription amoxicillin buy amoxicillin 500mg capsules uk

  48. Charlescoofs说道:

    https://doxycyclineca.com/# amoxicillin 500 coupon

  49. Clydewal说道:

    clomid generics: cheap fertility drug – cost cheap clomid without prescription

  50. Carlosnatry说道:

    pharmacy prices for doxycycline: here – doxycycline sale uk

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注