The cloud server has been set up based on the article “Cloud Server Ubuntu Basic Configuration”, which uses Ubuntu to compile FFmpeg.

Set up the NDK environment

1. Create the NDK directory and upload the Linux NDK.

The NDK version used here is R10E.

2. Grant DRWX permission to all files in the NDK folder to make them executable.

Chmod 777-r NDK After permission is granted to the NDK directory, the. Bin file becomes green (executable).

3. Decompress the. Bin file

Go to the NDK directory and run the./android-ndk-r10e-linux-x86_64.bin file.

The figure above shows that the execution is complete.

4. Configure environment variables

Run the vim ~/. Bashrc command to enter the environment configuration file and add

export NDKROOT=/usr/ndk/android-ndk-r10e
export PATH=$NDKROOT:$PATH
Copy the code

Update environment variables

Use the source ~/.bashrc command to update environment variables

At this point, the NDK environment is set up.

Compile FFmpeg

Go to the official website to download ffmpge.zip.

FFmpeg version 2.6.9 is used here.

1. Upload files

Upload the FFmpeg zip package to Ubuntu using XFTP.

2. Decompress FFmpeg

Run the unzip ffmpeg-2.6.9.zip command to decompress the file

Xftp Displays decompressed files

3. Write shell script files

Build_android. Sh file:

#! /bin/bash
make clean
export NDK=/usr/ndk/android-ndk-r10e
export SYSROOT=$NDK/platforms/android-9/arch-arm/
export TOOLCHAIN=$NDK/ toolchains/arm - Linux - androideabi - 4.8 / prebuilt/Linux - x86_64export CPU=arm
export PREFIX=$(pwd)/android/$CPU
export ADDI_CFLAGS="-marm"

./configure --target-os=linux \
--prefix=$PREFIX --arch=arm \
--disable-doc \
--enable-shared \
--disable-static \
--disable-yasm \
--disable-symver \
--enable-gpl \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
Copy the code

Note:

1) Line wrap should have \, be careful not to have extra Spaces, otherwise the compilation will fail

2) All script files are converted to UTF-8 format without BOM. Transcoding can be done via note pad++, or the file can be created by Linux and edited by Windows.

3) Try not to use too new version of NDK, generally use Android-9, otherwise the new version will appear incompatible problems.

4) Place the prepared shell script in the decompressed FFmPEG-2.6.9 folder.

Export NDK=/usr/ndk/android-ndk-r10e; Configure the CPU architecture type: export CPU= ARM, PREFIX is used to specify the output path of the dynamic library, and disable some unnecessary libraries (to reduce the size of the output dynamic library). Enable-shared: a shared library is generated.

Build_android. sh grant permission.

Build_android. sh does not have execution permission.

Run the chmod 777 build_android.sh command to grant build_android.sh execution permission.

5. Run the build_android file

Run the./build_android.sh command

Command not found No make command. Make: sudo apt-get install make

6. Install dos2UNIX

Sudo apt-get install tofrodos

The file is created under the window. Use the dos2UNIX build_android.sh command to convert the file.

Bad interpreter: No such file or directory cause: The file is not converted to Linux encoding format.

There are two ways to convert Linux encoding formats:

1. Create a file called "touch build_android.sh" under Linux, copy the script to this file from Linux to desktop, and upload it to Linux. 2, use dos2UNIX build_android.sh to convert to Linux encoding formatCopy the code

7. Run build_android again

Compile:

The diagram above shows the dynamic library generated after compilation.

The resulting dynamic libraries are.56,.5 libraries, which are hard for Android to load, so we need to modify the configure file.

Modifying the configure file

Change the naming rules for the output dynamic library:

# change before
#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)'

# modified
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='? (RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'
Copy the code

Recompile to generate a dynamic library: