Android:Ubuntu编译ffmpeg动态库步骤

NDK版本:android-ndk-r14b
ffmpeg版本:4.2.4 / 4.4
Ubuntu版本:15.5

1、下载 android-ndk-r14b :https://developer.android.google.cn/ndk/downloads/
2、下载ffmpeg4.4:http://ffmpeg.org/download.html#releases
3、分别解压android-ndk-r14b、ffmpeg4.4
4、在ffmpeg4.4里面创建build_ffmpeg.sh
5、编译32位libffmpeg.so:将下面编译脚本复制拷贝到build_ffmpeg.sh

!/bin/bash

NDK=/home/linrendi/Desktop/Compile/android-ndk-r14b
PLATFORM=NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
PREFIX=/home/linrendi/Desktop/ffmpeg32
CPU=armv7-a
function build_one
{
./configure
--prefix=TOOLCHAIN/bin/arm-linux-androideabi-
--arch=arm
--cpu=PLATFORM
--extra-cflags="-ITOOLCHAIN/bin/arm-linux-androideabi-gcc
--nm=TOOLCHAIN/bin/arm-linux-androideabi-nm \ --disable-shared --enable-static \ --enable-small --disable-debug \ --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-symver \ --enable-neon --enable-pthreads \ --disable-devices --disable-encoders \ --enable-hwaccels --enable-jni --enable-mediacodec \ --enable-encoder=aac \ --enable-decoder=h264_mediacodec \ --enable-hwaccel=h264_mediacodec \ --enable-encoder=mjpeg \ --enable-encoder=ljpeg --enable-encoder=jpeg2000 --enable-encoder=jpegls \ --enable-muxer=mp4 --enable-muxer=mjpeg \ --enable-runtime-cpudetect \ make clean make -j4 make installTOOLCHAIN/bin/arm-linux-androideabi-ld
-rpath-link=PLATFORM/usr/lib
-LPREFIX/libffmpeg.so
libavcodec/libavcodec.a
libavfilter/libavfilter.a
libswresample/libswresample.a
libavformat/libavformat.a
libavutil/libavutil.a
libswscale/libswscale.a
libavdevice/libavdevice.a
-lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker
$TOOLCHAIN/lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a
}

build_one
6、编译64位libffmpeg.so:将下面编译脚本复制拷贝到build_ffmpeg.sh

!/bin/bash

NDK=/home/linrendi/Desktop/Compile/android-ndk-r14b
PLATFORM=NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
PREFIX=/home/linrendi/Desktop/ffmpeg64
CPU=armv8-a
function build_one
{
./configure
--prefix=TOOLCHAIN/bin/aarch64-linux-android-
--arch=arm64
--cpu=PLATFORM
--extra-cflags="-ITOOLCHAIN/bin/aarch64-linux-android-gcc
--nm=TOOLCHAIN/bin/aarch64-linux-android-nm \ --disable-shared --enable-static \ --enable-small --disable-debug \ --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-symver \ --enable-neon --enable-pthreads \ --disable-devices --disable-encoders \ --enable-hwaccels --enable-jni --enable-mediacodec \ --enable-encoder=aac \ --enable-decoder=h264_mediacodec \ --enable-hwaccel=h264_mediacodec \ --enable-encoder=mjpeg \ --enable-encoder=ljpeg --enable-encoder=jpeg2000 --enable-encoder=jpegls \ --enable-muxer=mp4 --enable-muxer=mjpeg \ --enable-runtime-cpudetect \ make clean make -j4 make installTOOLCHAIN/bin/aarch64-linux-android-ld
-rpath-link=PLATFORM/usr/lib
-LPREFIX/libffmpeg.so
libavcodec/libavcodec.a
libavfilter/libavfilter.a
libswresample/libswresample.a
libavformat/libavformat.a
libavutil/libavutil.a
libswscale/libswscale.a
libavdevice/libavdevice.a
-lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker
$TOOLCHAIN/lib/gcc/aarch64-linux-android/4.9.x/libgcc.a
}

build_one
7、因为我这边是用gcc编译器,所以要修改configure文件里面的编译器
将cc_default="clang"改为cc_default="gcc"
8、命令行依次输入命令 ./configure 、./build_ffmpeg.sh,开始编译
9、编译到libavformat/udp.c这个文件会出错,解决办法如下:
屏蔽289行到312行代码
/* for (i = 0; i < nb_sources; i++) {
struct ip_mreq_source mreqs;
if (sources[i].ss_family != AF_INET) {
av_log(h, AV_LOG_ERROR, "Source/block address %d is of incorrect protocol family\n", i + 1);
return AVERROR(EINVAL);
}

      mreqs.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
      if (local_addr)
          mreqs.imr_interface = ((struct sockaddr_in *)local_addr)->sin_addr;
      else
          mreqs.imr_interface.s_addr = INADDR_ANY;
      mreqs.imr_sourceaddr.s_addr = ((struct sockaddr_in *)&sources[i])->sin_addr.s_addr;

      if (setsockopt(sockfd, IPPROTO_IP,
                     include ? IP_ADD_SOURCE_MEMBERSHIP : IP_BLOCK_SOURCE,
                     (const void *)&mreqs, sizeof(mreqs)) < 0) {
          if (include)
              ff_log_net_error(h, AV_LOG_ERROR, "setsockopt(IP_ADD_SOURCE_MEMBERSHIP)");
          else
              ff_log_net_error(h, AV_LOG_ERROR, "setsockopt(IP_BLOCK_SOURCE)");
          return ff_neterrno();
      }
  }*/

10、重新 ./configure 、./build_ffmpeg.sh,大概10分钟编译成功

你可能感兴趣的:(Android:Ubuntu编译ffmpeg动态库步骤)