在ubuntu环境下编译 ffmpeg for android

参考:Cross Compiling FFmpeg 4.0 for Android

怕链接打不开,先记录一下主要步骤:

环境:ubuntu 1604版本;

Step 1: Downloading the prerequisites:

  1. Android-ndk-r15c — 因为从r16版本编译ffmpeg就会出现问题,因此我们选用r16以前的版本,: https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip
  2. FFmpeg 4.0 — 文档中用的是4.0版本,而最新的版本是4.2版本,我用同样的方法试了4.2版本编译不成功,暂时就用4.0版本吧, https://ffmpeg.org/releases/ffmpeg-4.0.tar.bz2

Step 2: Configuring FFmpeg:

For the rest of the post, I assume that path to your NDK is /path/to/ndkand path to your ffmpeg as /path/to/ffmpeg . Now, move your ffmpeg to the sources folder in NDK. Your new ffmpeg path should look like this, /path/to/ndk/sources/ffmpeg-4.0

我的目录文件如下:

gs@tk:~/04_ffmpeg/android-ndk-r15c$ 
gs@tk:~/04_ffmpeg/android-ndk-r15c$ ls
build         meta       ndk-depends  ndk-stack  platforms  python-packages  shader-tools  source.properties  sysroot
CHANGELOG.md  ndk-build  ndk-gdb      ndk-which  prebuilt   README.md        simpleperf    sources            toolchains
gs@tk:~/04_ffmpeg/android-ndk-r15c$ 
gs@tk:~/04_ffmpeg/android-ndk-r15c$ cd sources/
gs@tk:~/04_ffmpeg/android-ndk-r15c/sources$ 
gs@tk:~/04_ffmpeg/android-ndk-r15c/sources$ ls
android  cxx-stl  ffmpeg-4.0  ffmpeg-4.0.tar.bz2  ffmpeg-4.2  ffmpeg-4.2.tar.gz  third_party
gs@tk:~/04_ffmpeg/android-ndk-r15c/sources$ 
gs@tk:~/04_ffmpeg/android-ndk-r15c/sources$ 

Before we actually configure ffmpeg, FFmpeg is configured by default to have version codes (Ex: libavcodec-10.so) but android can’t recognize such files, so all you need to do is to replace the lines in /path/to/ffmpeg/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)'

with

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

 

Now in ffmpeg folder, create a new Build Script and name it as ffmpeg_android.sh (“Just a random name”). Copy paste the below commands into the file

#!/bin/bash
NDK=/path/to/ndk
SYSROOT=$NDK/platforms/android-19/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-symver \
--enable-protocol=concat \
--enable-protocol=file \
--enable-muxer=mp4 \
--enable-demuxer=mpegts \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean all
make -j3
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one

Please remember to replace /path/to/ndk to the NDK Path in your local machine.

Step 3: Running the script file:

Before you run the script file above, make sure that required permissions are given to the file, run the command

chmod a+x ffmpeg_android.sh

Now run the script file as a super user.

sudo ./ffmpeg_android.sh

Have a tea, let your machine do the work for the next 20 minutes.

After some minutes (Depending on your machine’s architecture), you will find this path /path/to/ffmpeg/android/arm

There you can see some folders like “Include”, “lib”..etc .

 

编译

在这基础上实现一个最小demo。

参考:https://github.com/saitestop/FFmpegPlayer-Android

将上面的代码导入到工程,然后将编译好的lib文件和include文件替换,然后运行正常。

 

---------

或者参考:编译FFmpeg4.1.3并移植到Android app中使用(最详细的FFmpeg-Android编译教程)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值