FFMPEG linux android编译篇

环境搭建

  • 安装VMware Workstation Pro
  • 安装 ubuntu 虚拟机
  • 下载NDK r15 就可以了 也不要下最新 有坑
  • 下载之后解压 修改 sudo vim /etc/profile 在文件末尾加入如下内容

    export ANDROIID_NDK_15C=/home/zhangyan/SDK/android-ndk-r15c
    export ANDROID_NDK_16=/home/zhangyan/SDK/android-ndk-r16
    export ANDROID_NDK_14=/home/zhangyan/SDK/android-ndk-r14
    export PATH=$PATH:$ANDROID_NDK_15C
    
  • source /etc/profile

下载源码

修改配置文件

  • 修改configure 文件
  • 由于FFmpeg默认生成的库文件格式为libavcodec.so.xx.xx.x。其中的xx就是主副版本号,这种格式在Ubuntu下使用是没有问题的,但是在Android下开发使用,并不把其作为有效的库文件。所以需要修改其他生成的文件名的格式,通过修改configure文件要实现,打开configure,找到如下内容

    SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'  
    LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'  
    SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'  
    SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR)$(SLIBNAME)'
    

    修改为:

    SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'  
    LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'  
    SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'  
    SLIB_INSTALL_LINKS='$(SLIBNAME)' 
    

    vim configure 然后输入 /SLIBNAME_WITH_MAJOR 按 N 或者 shift +N 上下跳转查看搜索结果 找到了 按回车 然后按 i 切换至 insert 修改 ,改完之后 按ESC 输入:wq 回车 就保存退出了

    编译生成类库:第一次编译写个脚本去执行 vim andorid.sh

    #!/bin/bash
    make clean
    # 你的ndk路径,其他不用动!
    export NDK=/home/zhangyan/SDK/android-ndk-r15c
    export SYSROOT=$NDK/platforms/android-18/arch-arm/
    export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
    export CPU=arm
    #这是动态库输出路径
    export PREFIX=$(pwd)/android/$CPU
    export ADDI_CFLAGS="-marm"
    
    ./configure --target-os=linux \
        --prefix=$PREFIX --arch=arm \
        --disable-doc \
        --enable-shared \
        --disable-static \
        --disable-yasm \
        --disable-symver \
        --enable-gpl \
        --disable-ffmpeg \
        --disable-ffplay \
        --disable-ffprobe \
        --disable-ffserver \
        --disable-doc \
        --disable-symver \
        --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
        --enable-cross-compile \
        --sysroot=$SYSROOT \
        --extra-cflags="-Os -fpic $ADDI_CFLAGS" \                                    
        --extra-ldflags="$ADDI_LDFLAGS" \
        $ADDITIONAL_CONFIGURE_FLAG
    make clean
    make
    make install
    

    退出保存,然后赋予该文件执行权限 sudo chmod 777 android.sh
    执行脚本 /.andorid.sh 顺利的话 大概十分钟吧,就可以在该目录下看到/android/
    成功生成的目录结构:

    └── arm
        ├── include
        │   ├── libavcodec
        │   │   ├── avcodec.h
        │   │   ├── avdct.h
        │   │   ├── avfft.h
        │   │   ├── d3d11va.h
        │   │   ├── dirac.h
        │   │   ├── dv_profile.h
        │   │   ├── dxva2.h
        │   │   ├── jni.h
        │   │   ├── qsv.h
        │   │   ├── vaapi.h
        │   │   ├── vda.h
        │   │   ├── vdpau.h
        │   │   ├── version.h
        │   │   ├── videotoolbox.h
        │   │   ├── vorbis_parser.h
        │   │   └── xvmc.h
        │   ├── libavdevice
        │   │   ├── avdevice.h
        │   │   └── version.h
        │   ├── libavfilter
        │   │   ├── avfiltergraph.h
        │   │   ├── avfilter.h
        │   │   ├── buffersink.h
        │   │   ├── buffersrc.h
        │   │   └── version.h
        │   ├── libavformat
        │   │   ├── avformat.h
        │   │   ├── avio.h
        │   │   └── version.h
        │   ├── libavutil
        │   │   ├── adler32.h
        │   │   ├── aes_ctr.h
        │   │   ├── aes.h
        │   │   ├── attributes.h
        │   │   ├── audio_fifo.h
        │   │   ├── avassert.h
        │   │   ├── avconfig.h
        │   │   ├── avstring.h
        │   │   ├── avutil.h
        │   │   ├── base64.h
        │   │   ├── blowfish.h
        │   │   ├── bprint.h
        │   │   ├── bswap.h
        │   │   ├── buffer.h
        │   │   ├── camellia.h
        │   │   ├── cast5.h
        │   │   ├── channel_layout.h
        │   │   ├── common.h
        │   │   ├── cpu.h
        │   │   ├── crc.h
        │   │   ├── des.h
        │   │   ├── dict.h
        │   │   ├── display.h
        │   │   ├── downmix_info.h
        │   │   ├── error.h
        │   │   ├── eval.h
        │   │   ├── ffversion.h
        │   │   ├── fifo.h
        │   │   ├── file.h
        │   │   ├── frame.h
        │   │   ├── hash.h
        │   │   ├── hmac.h
        │   │   ├── hwcontext_cuda.h
        │   │   ├── hwcontext_dxva2.h
        │   │   ├── hwcontext.h
        │   │   ├── hwcontext_vaapi.h
        │   │   ├── hwcontext_vdpau.h
        │   │   ├── imgutils.h
        │   │   ├── intfloat.h
        │   │   ├── intreadwrite.h
        │   │   ├── lfg.h
        │   │   ├── log.h
        │   │   ├── lzo.h
        │   │   ├── macros.h
        │   │   ├── mastering_display_metadata.h
        │   │   ├── mathematics.h
        │   │   ├── md5.h
        │   │   ├── mem.h
        │   │   ├── motion_vector.h
        │   │   ├── murmur3.h
        │   │   ├── opt.h
        │   │   ├── parseutils.h
        │   │   ├── pixdesc.h
        │   │   ├── pixelutils.h
        │   │   ├── pixfmt.h
        │   │   ├── random_seed.h
        │   │   ├── rational.h
        │   │   ├── rc4.h
        │   │   ├── replaygain.h
        │   │   ├── ripemd.h
        │   │   ├── samplefmt.h
        │   │   ├── sha512.h
        │   │   ├── sha.h
        │   │   ├── stereo3d.h
        │   │   ├── tea.h
        │   │   ├── threadmessage.h
        │   │   ├── timecode.h
        │   │   ├── time.h
        │   │   ├── timestamp.h
        │   │   ├── tree.h
        │   │   ├── twofish.h
        │   │   ├── version.h
        │   │   └── xtea.h
        │   ├── libpostproc
        │   │   ├── postprocess.h
        │   │   └── version.h
        │   ├── libswresample
        │   │   ├── swresample.h
        │   │   └── version.h
        │   └── libswscale
        │       ├── swscale.h
        │       └── version.h
        └── lib
            ├── libavcodec-57.so
            ├── libavcodec.so -> libavcodec-57.so
            ├── libavdevice-57.so
            ├── libavdevice.so -> libavdevice-57.so
            ├── libavfilter-6.so
            ├── libavfilter.so -> libavfilter-6.so
            ├── libavformat-57.so
            ├── libavformat.so -> libavformat-57.so
            ├── libavutil-55.so
            ├── libavutil.so -> libavutil-55.so
            ├── libpostproc-54.so
            ├── libpostproc.so -> libpostproc-54.so
            ├── libswresample-2.so
            ├── libswresample.so -> libswresample-2.so
            ├── libswscale-4.so
            ├── libswscale.so -> libswscale-4.so
            └── pkgconfig
                ├── libavcodec.pc
                ├── libavdevice.pc
                ├── libavfilter.pc
                ├── libavformat.pc
                ├── libavutil.pc
                ├── libpostproc.pc
                ├── libswresample.pc
                └── libswscale.pc
    

    生成的目录包括每个ffmpeg子模块的头文件 和动态库 根据自己的需求集成

遇到的问题

找不到nerror,h 缺少什么头文件 诸如此类的 请降低你的NDK 版本 和FFMPEG版本 这就是前面的坑

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值