ffmpeg - android Platform Source Coding (latest version 4.1)

Keywords: Linux Android codec github

ffmpeg - the latest version of source code compilation for android platform 4.1

1. Introduction of ffmpeg:

FFmpeg is an open source computer program that can be used to record, convert digital audio and video, and convert them into streams. Use LGPL or GPL license. It provides a complete solution for recording, converting and streaming audio and video. It includes a very advanced audio/video codec library, libav codec. In order to ensure high portability and quality of codec, many codes in libav codec are developed from scratch.
FFmpeg is developed on Linux platform, but it can also be compiled and run in other operating system environments, including Windows, Mac OS X and so on. The project was initiated by Fabrice Bellard and maintained by Michael Niedermayer from 2004 to 2015. Many FFmpeg developers come from the MPlayer project, and currently FFmpeg is also placed on the server of the MPlayer project group. The name of the project comes from the MPEG video coding standard. The previous "FF" stands for "Fast Forward".
Multimedia video processing tool FFmpeg has very powerful functions, including video capture, video format conversion, video capture, video watermarking and so on.
The above introduction is taken from Baidu.

2. Source code download:

Official website: https://ffmpeg.org/
github: https://github.com/FFmpeg/FFmpeg

3. Environmental allocation:

This mainly refers to the NDK configuration, compiling the android platform requires NDK support, the steps are as follows:

  1. vim ~/.bashrc
  2. At the end of the document, add:
export NDKROOT=/home/ceshi/ceshi/android-ndk-r17cexport PATH=$NDKROOT:$PATH
  1. source ~/.bashrc

IV. Configuration file modification:

Open the configuration file in the FFmpeg directory and find the following lines:

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)'

Replace 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)'

Purpose: To modify the generated. so file name to enable android project identification

V. Scripting:

Create a new script file android_build.sh and add the following:

  #!/bin/bash
  # Clear the last compilation
  make clean
  #Your own NDK path.
  export NDK = / home / ceshi / ceshi / android - ndk - r17c
  # Set up the version of your android platform compiler using android 21 here
  export SYSROOT = $NDK / platforms / android - 21 / arch - arm /
  #Toollchain for compilation
  export TOOLCHAIN = $NDK / toolchains / arm - linux - androideabi - 4.9 / prebuilt / linux - x86_64
  export CPU = arm
  # This is the path to the output.
  export PREFIX = $(pwd) / android / $CPU
  export ADDI_CFLAGS = "-marm"
  . / configure --target - os = linux \
  --prefix = $PREFIX --arch = arm \
  --disable - doc \
  --enable - shared \
  --disable - static \
  --disable - x86asm \
  --disable - symver \
  --enable - gpl \
  --disable - ffmpeg \
  --disable - ffplay \
  --disable - ffprobe \
  --disable - doc \
  --disable - symver \
  --cross - prefix = $TOOLCHAIN / bin / arm - linux - androideabi - \
  --enable - cross - compile \
  --sysroot = $SYSROOT \
  --extra - cflags = "-I$NDK/sysroot/usr/include/arm-linux-androideabi -Os -fpic $ADDI_CFLAGS -isysroot $NDK/sysroot" \
  --extra - ldflags = "$ADDI_LDFLAGS" \
  $ADDITIONAL_CONFIGURE_FLAG
  # make clean
  make
  make install

6. Compiling:

Add executable permissions for the script in the previous step and execute.

7. Trampled pits

error 1:

/home/cece/cece/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /home/cece/cece/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/.../bin/.../lib/bfd-plugins/.../lib64/libc++.so.1)
https://www.jianshu.com/p/feab970fd74c

Solution:
Do not affect compilation, do not easily upgrade. Upgrade may lead to system paralysis, I upgraded once, and sure enough the system hangs...
If you need to upgrade, you can refer to: https://blog.csdn.net/qq_39295044/article/details/86685789

error 2:

_64/lib/gcc/arm-linux-androideabi/4.9.x/include/stdint.h:9:26: fatal error: stdint.h: No such file or directory

Solution:
You need to add "-isysroot $NDK/sysroot" in extra-cflags
Header files for the compilation are also separated.
You need to specify "-I$NDK/sysroot/usr/include/arm-linux-androideabi" according to the target platform, and change "arm-linux-androideabi" to the platform you need.

error 3:

 libavcodec / aaccoder.c : In function 'search_for_ms' :
  libavcodec / aaccoder.c : 803 : 25 : error : expected identifier or '(' before numeric constant
  int B0 = 0, B1 = 0;
      ^
  libavcodec / aaccoder.c:865 : 28 : error : lvalue required as left operand of assignment
  B0 += b1 + b2;
  ^
  libavcodec / aaccoder.c:866 : 25 : error : 'B1' undeclared(first use in this function)
  B1 += b3 + b4;
  ^

Solution:
The latest version naming conflicts, modify the libavcodec/aaccoder.c file B0 to b0.

error 4:

 libavcodec / hevc_mvs.c : In function 'derive_spatial_merge_candidates' :
  libavcodec / hevc_mvs.c : 208 : 15 : error : 'y0000000' undeclared(first use in this function)
  ((y ## v) >> s->ps.sps->log2_min_pu_size))
    ^

Solution:
Ibid., change the variable name to avoid conflict.

error 5:

 libavcodec / opus_pvq.c : In function 'quant_band_template' :
  libavcodec / opus_pvq.c : 498 : 9 : error : expected identifier or '(' before numeric constant
  int B0 = blocks;

Solution:
Ibid., change the variable name to avoid conflict.

VIII. Supplementary

Different NDK versions require different compilation errors. I use android - ndk - r17c here, which needs attention.

Reference link:
https://blog.csdn.net/qq_34902522/article/details/87879145
https://www.jianshu.com/p/feab970fd74c

Posted by IanM on Sun, 28 Jul 2019 22:28:26 -0700