编译Android版本的ffmpeg

Ffmpeg的下载链接

Ffmpeg官网可以直接下载最新的版本:https://ffmpeg.org/

如果要下载旧的版本,可进入该链接,往下拉即可看到各个版本:Download FFmpeg

编译Android版本的Ffmpeg

本文下载的是ffmpeg-3.2.16,同时考虑到Ffmpeg的源码中没有libx264,因此还需要下载libx264的源码,下载链接为:x264, the best H.264/AVC encoder - VideoLAN

编译libx264

环境:ubuntu16.04

编译脚本build_libx264.sh:

#!/bin/bash

export NDK=/home/penglin/data/others/ffmpeg/android-ndk-r9d
export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
export CC=$PREBUILT/bin/arm-linux-androideabi-gcc
export LD=$PREBUILT/bin/arm-linux-androideabi-ld
export AS=$PREBUILT/bin/arm-linux-androideabi-gcc
export AR=$PREBUILT/bin/arm-linux-androideabi-ar
export RANLIB=$PREBUILT/bin/arm-linux-androideabi-ranlib
export STRIP=$PREBUILT/bin/arm-linux-androideabi-strip
export PLATFORM=$NDK/platforms/android-8/arch-arm
export PREFIX=/home/penglin/data/others/ffmpeg/ffmpeg-3.2.16/x264-master/temp
export STRIP=$PREBUILT/bin/arm-linux-androideabi-strip

EXTRA_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__"
EXTRA_LDFLAGS="-nostdlib"

./configure --prefix=$PREFIX \
 --enable-static \
 --enable-pic \
 --enable-strip \
 --enable-share \
 --disable-asm \
 --disable-cli \
 --extra-cflags= "-march=armv7-a  -mfloat-abi=softfp -mfpu=neon" \
 --host=arm-linux \
 --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
 --extra-cflags="$EXTRA_CFLAGS" \
 --extra-ldflags="$EXTRA_LDFLAGS" \
 --sysroot=$PLATFORM \

make

make install

直接运行上面的build_libx264.sh脚本即可将libx264编译到PREFIX指定的目录中;

编译Ffmpeg

环境:ubuntu16.04

编译脚本build_ffmpeg.sh:

#!/bin/bash
export TMPDIR=/home/penglin/data/others/ffmpeg/ffmpeg-3.2.16/android/armv7-a/temp
NDK=/home/penglin/data/others/ffmpeg/android-ndk-r9d
SYSROOT=$NDK/platforms/android-16/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64

libx264_path=/home/penglin/data/others/ffmpeg/ffmpeg-3.2.16/x264-master/temp

CPU=arm
#PREFIX=/project/codec/jni
PREFIX=/home/penglin/data/others/ffmpeg/ffmpeg-3.2.16/android/armv7-a
#ADDI_CFLAGS="-marm"

# x264头文件
ADDI_CFLAGS="-marm -I/home/penglin/data/others/ffmpeg/ffmpeg-3.2.16/x264-master/temp/include"
# x264so库
ADDI_LDFLAGS="-L/home/penglin/data/others/ffmpeg/ffmpeg-3.2.16/x264-master/temp/lib"

export PKG_CONFIG_PATH=$libx264_path/lib/pkgconfig:$PKG_CONFIG_PATH
echo $PKG_CONFIG_PATH

function build_one
{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-symver \
--enable-small \
--enable-jni \
--enable-yasm \
--enable-libx264 \
--enable-mediacodec \
--enable-encoder=libx264 \
--enable-encoder=aac \
--enable-encoder=mpeg4 \
--enable-encoder=h264_omx \
--enable-encoder=h264_nvenc \
--enable-encoder=h264_qsv \
--enable-encoder=h264_vaapi \
--enable-encoder=h264_videotoolbox \
--enable-encoder=hap \
--enable-encoder=hevc_nvenc \
--enable-encoder=hevc_qsv \
--enable-encoder=hevc_vaapi \
--enable-encoder=libopenh264 \
--enable-encoder=libx264rgb \
--enable-encoder=libx265 \
--enable-encoder=nvenc_h264 \
--enable-encoder=nvenc_hevc \
--enable-encoder=h261 \
--enable-encoder=h263 \
--enable-hwaccel=h264_mediacodec \
--enable-decoder=h264_mediacodec \
--enable-hwaccels \
--enable-neon \
--enable-postproc \
--enable-nonfree \
--enable-gpl \
--enable-decoder=aac \
--enable-decoder=aac_latm \
--enable-decoder=mjpeg \
--enable-decoder=png \
--enable-decoder=mpeg4_mediacodec \
--enable-parser=aac \
--enable-parser=h264 \
--enable-parser=hevc \
--enable-parser=mpeg4video \
--enable-swscale \
--enable-swscale-alpha \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=android \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
--bindir="${libx264_path}/bin" \
--extra-libs=-ldl \
$ADDITIONAL_CONFIGURE_FLAG
}


build_one
make
make install

直接运行上面的build_ffmpeg.sh脚本即可将ffmpeg编译到PREFIX指定的目录中;

编译完成后,如下图所示

penglin@penglin-VirtualBox:~/data/others/ffmpeg/ffmpeg-3.2.16/android$ tree
.
└── armv7-a
    ├── include
    │   ├── libavcodec
    │   │   ├── avcodec.h
    │   │   ├── avdct.h
    │   │   ├── avfft.h
    │   │   ├── d3d11va.h
    │   │   ├── dirac.h
    │   │   ├── dv_profile.h
    │   │   ├── dxva2.h
    │   │   ├── jni.h
    │   │   ├── mediacodec.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_qsv.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.so
    │   ├── libavdevice.so
    │   ├── libavfilter.so
    │   ├── libavformat.so
    │   ├── libavutil.so
    │   ├── libpostproc.so
    │   ├── libswresample.so
    │   ├── libswscale.so
    │   └── pkgconfig
    │       ├── libavcodec.pc
    │       ├── libavdevice.pc
    │       ├── libavfilter.pc
    │       ├── libavformat.pc
    │       ├── libavutil.pc
    │       ├── libpostproc.pc
    │       ├── libswresample.pc
    │       └── libswscale.pc
    └── temp

13 directories, 123 files

拷贝上述对应的so、.h文件和.pc文件到Android工程对应的目录下即可。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值