Location>code7788 >text

FFmpeg development notes (fifty-nine) Linux compiler ijkplayer Android platform so library

Popularity:354 ℃/2024-10-23 13:29:14
ijkplayer is a mobile domestic player developed by B station, it is based on FFmpeg3.4 version, compatible with Android and iOS two mobile operating systems at the same time. ijkplayer's source code is hosted at /bilibili/ijkplayer, as of September 15, 2024, ijkplayer got 32,400 stars, and 0.81 million branches, and this is still ijkplayer stopped updating 6 years after the data, you can imagine that year's ijkplayer is how hot.

However, because ijkplayer has not been updated for many years, it can only be compiled and run on older platforms according to the way of package guide, for example, the Android platform supported by ijkplayer is limited to API 9~23, and the iOS platform supported by iOS is limited to iOS 7.0~10. In order to make ijkplayer work properly on newer development environments, you need to cross-compile ijkplayer's so files on Linux before you can import and call the so libraries in your app project. Here is how to compile ijkplayer's so library on Linux.

I. Preparing the Linux compilation environment

First install the compilation tool by executing the following command on your Linux system.

yum install git make yasm

Then execute the following command to temporarily resize the tmp partition to ensure that the system has enough temporary space to avoid failing to decompress large files.

mount -o remount,size=2G /tmp

Second, install Android's SDK and NDK

Execute the following commands in order to download and install the SDK for Android, be careful not to use too high a version of the SDK, because ijkplayer does not adapt to high versions of the SDK.

mkdir -p /usr/local/src_ijkplayer
cd /usr/local/src_ijkplayer
curl -O /android/repository/
unzip 
mkdir sdk
mv tools sdk/cmd_tools
cd sdk/cmd_tools/bin
./sdkmanager "build-tools;28.0.3" "platforms;android-28"

Execute the following commands in order to download and install Android NDK, pay attention not to use too high version of the NDK, because ijkplayer is not adapted to a high version of the NDK, the official recommendation is to use the r10e version of the NDK can be.

cd /usr/local/src_ijkplayer
curl -O /android/repository/android-ndk-r10e-linux-x86_64.zip
unzip android-ndk-r10e-linux-x86_64.zip

Execute the following environment variable setting commands to set the environment variable ANDROID_SDK for the SDK and ANDROID_NDK for the NDK, respectively.

export ANDROID_SDK=/usr/local/src_ijkplayer/sdk
export ANDROID_NDK=/usr/local/src_ijkplayer/android-ndk-r10e

Three, download and compile ijkplayer

First execute the following command to download the ijkplayer source package.

cd /usr/local/src_ijkplayer
git clone /Bilibili/

Execute the following command again to check and initialize ijkplayer's Android compilation environment.

cd ijkplayer
./
./

Then execute the following commands to compile the openssl and ffmpeg libraries needed by ijkplayer and the ijkplayer so library respectively. The reason why we add "arm64" to the end of the three scripts is to compile only the so files that are adapted to the arm64 directive.

cd android/contrib
./ arm64
./ arm64
cd ../
./ arm64

If everything goes well, you can see the three compiled so libraries in the ijkplayer/android/ijkplayer/ijkplayer-arm64/src/main/libs/arm64-v8a directory: , , , . Copy the entire libs directory containing the three so files to the libs directory of the app project to complete the ijkplayer so library import.

For more details on FFmpeg development seeFFmpeg Development in Action: From Zero Basics to Short Video OnlineA book.