banner
jzman

jzman

Coding、思考、自觉。
github

How to compile ijkplayer on Ubuntu

PS: No matter what you do, practice is the most important. The experience accumulated through personal practice cannot be compared to casually reading a technical article.

Recently, video playback may be required in the project, and later it may also need to support the playback of videos using the rtsp protocol. After weighing the options, I decided to compile Bilibili's open-source ijkplayer. ijkplayer is a lightweight cross-platform player based on ffmpeg that can be used on Android and iOS, and can support more formats through compilation. It can be said that ijkplayer supports any format supported by ffmpeg.

I initially used Cygwin for compilation, but there were always errors when generating the so file. Of course, there were many pitfalls in between, so I decided to use the Ubuntu environment to compile ijkplayer. There were basically no problems during compilation in the Ubuntu environment. The compilation process is as follows:

  1. Preparation
  2. Configure environment variables
  3. Install necessary components
  4. Formal compilation
  5. Run ijkplayer

Preparation#

Install VMware virtual machine and Ubuntu system. After installing VMware, create a virtual machine and choose the typical installation mode, as shown in the figure below:

image

Then click Next and select the downloaded system image, as shown in the figure below:

image

After selecting correctly, the image information will be displayed. For example, I chose Ubuntu 64-bit 18.04. Then continue to the next step, as shown in the figure below:

image

Fill in the username, password, and other information, and click Next, as shown in the figure below:

image

Fill in the virtual machine name and the location where the virtual machine will be installed, and click Next:

image

Set the size of the virtual machine disk. To ensure that the disk performance is not reduced, select to store the disk as a single file, and then click Next, as shown in the figure below:

image

The Ubuntu virtual machine is now created. Click Finish and wait for the Ubuntu installation to complete. Enter the set password to enter the Ubuntu system, as shown in the figure below:

image

In addition, you also need to download the Linux version of Android SDK and NDK. Here, I chose android-sdk_r24.4.1-linux.tgz and android-ndk-r10e-linux-x86_64.zip. After downloading, you can use the following commands to unzip the files:

unzip xxx.zip
tar -xvf xxx.tgz

Remember not to put the NDK directory in the shared directory of the virtual machine. To ensure smooth compilation, the NDK directory should be placed in the system directory of Ubuntu, which is the directory under /home/username.

Configure environment variables#

In /home/username/ under Ubuntu, press Ctrl+h to view the .bashrc file and configure the SDK and NDK environment variables, as shown below:

NDK=/home/jzman/android/android-ndk-r10e
export NDK
ADB=/home/jzman/android/android-sdk-linux/platform-tools
export ADB
# ANDROID_NDK and ANDROID_SDK paths
ANDROID_NDK=/home/jzman/android/android-ndk-r10e
export ANDROID_NDK
ANDROID_SDK=/home/jzman/android/android-sdk-linux
export ANDROID_SDK 
# Add to PATH
PATH=${PATH}:${NDK}:${ADB}:${ANDROID_NDK}:${ANDROID_SDK}

After configuring, save and close .bashrc, open Terminal, and enter ndk-build -v to check if the ndk is configured successfully. If the following log is displayed, the configuration is successful:

jzman@ubuntu:~$ ndk-build -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

Install necessary components#

Enter the following commands one by one to update and install git, yasm, and make:

sudo apt-get update
sudo apt install git
sudo apt install yasm
sudo apt install make

Use git --version and make -v to check if git and make tools are installed successfully. If successful, the corresponding version numbers will be displayed, as shown below:

jzman@ubuntu:~$ git --version
git version 2.17.1
jzman@ubuntu:~$ make -v
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
jzman@ubuntu:~$ 

Formal compilation#

// Clone the ijkplayer source code
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer
cd ijkplayer
git checkout -B latest k0.8.8
// Use the lighter module-lite.sh
cd ijkplayer/config
rm module.sh
ln -s module-lite module.sh
// Download the ffmpeg source code
cd ijkplayer
./init-android
// Compile ffmpeg
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
// Compile ijkplayer and generate so files
cd ijkplayer/android
./compile-ijk.sh all

If you want to support https, execute the following command during compilation:

cd ijkplayer
./init-android-openssl.sh (support https)
cd ijkplayer/android/contrib
./compile-openssl.sh clean
./compile-openssl.sh all

After successful compilation, the corresponding Android project will be generated under ijkplayer/android, as shown in the figure below:

image

Check whether the corresponding so files are generated in each abi library, such as ijkplayer/android/ijkplayer/ijkplayer-arm64/src/main/libs. Taking arm64 as an example, the figure below shows the generated so files:

image

Run ijkplayer#

Open the generated Android project with Android Studio and run it. The screenshot is as follows:

image

The compilation of ijkPlayer is complete. If you have any questions, please leave a comment.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.