在ubuntu环境下编译 ffmpeg for android
参考:Cross Compiling FFmpeg 4.0 for Android
怕链接打不开,先记录一下主要步骤:
环境:ubuntu 1604版本;
Step 1: Downloading the prerequisites:
- Android-ndk-r15c — 因为从r16版本编译ffmpeg就会出现问题,因此我们选用r16以前的版本,: https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip
- 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$ lsbuild meta ndk-depends ndk-stack platforms python-packages shader-tools source.properties sysrootCHANGELOG.md ndk-build ndk-gdb ndk-which prebuilt README.md simpleperf sources toolchainsgs@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$ lsandroid cxx-stl ffmpeg-4.0 ffmpeg-4.0.tar.bz2 ffmpeg-4.2 ffmpeg-4.2.tar.gz third_partygs@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/bashNDK=/path/to/ndkSYSROOT=$NDK/platforms/android-19/arch-arm/TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64function 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_FLAGmake clean allmake -j3make install}CPU=armPREFIX=$(pwd)/android/$CPUADDI_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编译教程)
更多相关文章
- 一款常用的 Squid 日志分析工具
- GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
- RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
- Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
- Android各版本名称
- Android使用apktool进行反编译出现了resource spec: 0x01010543
- Android(安卓)Studio的几个Error与解决方案:“NDK not configure
- android 反编译apk文件
- Android(安卓)Studio调试技巧(基于Android(安卓)Studio 3.1.2版本