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

/ 1,667评论 / 11823阅读 / 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. JeffreyBuing说道:

    http://northern-doctors.org/# mexico pharmacy

  2. WilliamGlapy说道:

    mexico drug stores pharmacies: mexican online pharmacies prescription drugs – buying prescription drugs in mexico online

  3. JeffreyBuing说道:

    https://northern-doctors.org/# buying from online mexican pharmacy

  4. JeffreyBuing说道:

    http://northern-doctors.org/# buying prescription drugs in mexico online

  5. RichardBlelt说道:

    mexican border pharmacies shipping to usa mexican northern doctors mexican online pharmacies prescription drugs

  6. WilliamGlapy说道:

    mexican border pharmacies shipping to usa: mexican northern doctors – mexico drug stores pharmacies

  7. RichardBlelt说道:

    mexico drug stores pharmacies mexican pharmacy mexican pharmaceuticals online

  8. WilliamGlapy说道:

    mexican mail order pharmacies: northern doctors – п»їbest mexican online pharmacies

  9. JeffreyBuing说道:

    https://northern-doctors.org/# п»їbest mexican online pharmacies

  10. Robertver说道:

    https://azithromycinca.com/# buy online doxycycline
    buy generic doxycycline 40mg

  11. Carlosnatry说道:

    prednisone buy online nz: clomidca.shop – prednisone 1 mg daily

  12. Clydewal说道:

    amoxicillin script: amoxil online – generic amoxicillin 500mg

  13. Carlosnatry说道:

    how to buy cheap clomid price: cheap fertility drug – cost clomid pills

  14. Charlescoofs说道:

    https://amoxicillinca.shop/# zithromax online paypal

  15. Carlosnatry说道:

    80 mg prednisone daily: clomidca.com – prednisone 20 mg tablet price

  16. Charlescoofs说道:

    https://amoxicillinca.shop/# zithromax capsules

  17. Clydewal说道:

    buying generic clomid tablets: cheap fertility drug – clomid without prescription

  18. Carlosnatry说道:

    prednisone 4mg tab: prednisone clomidca – no prescription online prednisone

  19. Charlescoofs说道:

    http://azithromycinca.com/# doxycycline 50 medicine

  20. Charlescoofs说道:

    https://amoxicillinca.shop/# buy generic zithromax no prescription

  21. Clydewal说道:

    amoxicillin generic: cheapest amoxicillin – amoxicillin 30 capsules price

  22. Carlosnatry说道:

    amoxicillin for sale: buy cheapest antibiotics – amoxicillin 500mg capsules uk

  23. Charlescoofs说道:

    https://doxycyclineca.com/# where to buy amoxicillin 500mg

  24. Carlosnatry说道:

    doxycycline 50 mg cap: here – doxycycline no script

  25. Clydewal说道:

    how to buy clomid online: best price – where buy generic clomid price

  26. Charlescoofs说道:

    https://azithromycinca.com/# buy doxycycline without prescription uk

  27. Carlosnatry说道:

    3000mg prednisone: Deltasone – non prescription prednisone 20mg

  28. Charlescoofs说道:

    https://doxycyclineca.com/# amoxicillin generic

  29. Carlosnatry说道:

    where to buy generic clomid without a prescription: prednisonerxa.shop – buy clomid tablets

  30. Clydewal说道:

    amoxicillin 500mg pill: amoxil doxycyclineca – buy amoxicillin online without prescription

  31. Charlescoofs说道:

    https://doxycyclineca.shop/# where to get amoxicillin over the counter

  32. Carlosnatry说道:

    can i purchase clomid without insurance: clomid Prednisonerxa – where buy generic clomid no prescription

  33. Charlescoofs说道:

    http://amoxicillinca.com/# buy generic zithromax no prescription

  34. Carlosnatry说道:

    buy amoxicillin canada: amoxil doxycyclineca – amoxicillin without rx

  35. Clydewal说道:

    can you buy cheap clomid without dr prescription: cheap fertility drug – can i order generic clomid without a prescription

  36. Charlescoofs说道:

    http://azithromycinca.com/# doxycycline coupon

  37. Carlosnatry说道:

    doxycycline minocycline: doxycycline azithromycinca – doxycycline 40 mg price

  38. Charlescoofs说道:

    https://azithromycinca.shop/# doxycycline online pharmacy

  39. Clydewal说道:

    doxycycline 100mg lowest price: azithromycinca – doxycycline 100mg cap price

  40. Carlosnatry说道:

    doxycycline 20 mg capsules: azithromycinca.com – buy generic doxycycline 40mg

  41. Charlescoofs说道:

    http://clomidca.com/# prednisone 10mg tabs

  42. Carlosnatry说道:

    doxycycline 100mg price in india: here – doxycycline hyc

  43. Clydewal说道:

    buy cheap generic zithromax: cheapest Azithromycin – zithromax 1000 mg pills

  44. Charlescoofs说道:

    http://prednisonerxa.com/# can i get generic clomid without dr prescription

  45. Carlosnatry说道:

    buy clomid: Clomiphene – where to get generic clomid without prescription

  46. Charlescoofs说道:

    https://azithromycinca.shop/# pharmacy prices for doxycycline

  47. Carlosnatry说道:

    amoxicillin 500 mg without prescription: amoxil doxycyclineca – how much is amoxicillin

  48. Clydewal说道:

    order zithromax over the counter: buy zithromax amoxicillinca – zithromax 1000 mg online

  49. Charlescoofs说道:

    http://azithromycinca.com/# buy generic doxycycline

  50. Carlosnatry说道:

    zithromax capsules 250mg: Azithromycin best price – where can i buy zithromax uk

发表回复

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