Android Development Note: Compiling ijkplayer to support more video formats

Posted by meomike2000 on Thu, 23 May 2019 02:55:43 +0200

Preface

ijkplayer is good. Thank you for the big man in Station B. ijkplayer is developed based on FFmpeg and adapts to Android/iOS platform. FFmpeg is a god-like project in the development world. Full-format audio and video coding and decoding support is provided on the whole platform. Like the previous "killing programmers to sacrifice the heavens" storm, a wide audience of QQ audio and video are FFmpeg beneficiaries, because they do not follow the GUN LGPL agreement, but also members of the FFmpeg project humiliation pillar.

But ijkplayer does not support playing avi by default. Ha-ha, the line is wrong. It's avi. Today, I'll share my compilation of ijkplayer to support avi, mpeg/mpg and more format videos.

Prerequisite

The production environment is MacOS or Linux system, the author is MacOS, Android 6.0, here take Mac as an example to record the process of compiling ijkplayer for Android. build ijkplayer for Android.

Compilation preparation

  1. Install homebrew: ruby-e "$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Install git: brew install git
  3. Install yasm: brew install yasm

Download the ijkplayer project:
git clone https://github.com/Bilibili/ijkplayer.git

Replace support format compilation scripts:

cd ijkplayer/config
rm module.sh # This is a soft link, pointing to module-lite.sh by default.
ln -s module-default.sh module.sh

Set compilation environment variables:
Execute the following commands at the terminal (point to your own path specifically)

export ANDROID_NDK=/Users/michaelx/Library/Android/sdk/ndk-bundle
export ANDROID_SDK=/Users/michaelx/Library/Android/sdk

The official recommendation is that NDK version is r10e, the author is r13.1, MacOS 10.12.6, and the actual test is compiled.

Start compilation

cd enters the project root directory

bash init-android.sh
cd android/contrib
# Execute the following two commands
./compile-ffmpeg.sh clean
# If the default shell is not bash, the following commands are recommended
bash compile-ffmpeg.sh clean

./compile-ffmpeg.sh all
# If the default shell is not bash, the following commands are recommended
bash compile-ffmpeg.sh all

The following similar prompts during execution are negligible:

WARNING: aarch64-linux-android-pkg-config not found, library detection may fail.

--------------------
[*] compile ffmpeg
--------------------
libavfilter/avfiltergraph.c: In function 'avfilter_graph_free':
libavfilter/avfiltergraph.c:132:5: warning: 'resample_lavr_opts' is deprecated (declared at libavfilter/avfilter.h:847) [-Wdeprecated-declarations]
     av_freep(&(*graph)->resample_lavr_opts);
     ^

When the following prompt appears, FFmpeg is compiled:

--------------------
[*] Finished
--------------------
# to continue to build ijkplayer, run script below,
sh compile-ijk.sh

Then we can compile ijkplayer and get so dynamic library file. Follow the instructions:

bash compile-ijk.sh
# or
sh compile-ijk.sh

The following prompt indicates that ijkplayer has compiled:

[armeabi-v7a] Compile++ thumb: ijksoundtouch <= BPMDetect.cpp
[armeabi-v7a] Compile++ thumb: ijksoundtouch <= PeakFinder.cpp
[armeabi-v7a] Compile++ thumb: ijksoundtouch <= SoundTouch.cpp
[armeabi-v7a] Compile++ thumb: ijksoundtouch <= mmx_optimized.cpp
[armeabi-v7a] Compile++ thumb: ijksoundtouch <= ijksoundtouch_wrap.cpp
[armeabi-v7a] Install        : libijkffmpeg.so => libs/armeabi-v7a/libijkffmpeg.so
[armeabi-v7a] StaticLibrary  : libcpufeatures.a
[armeabi-v7a] StaticLibrary  : libijkj4a.a
[armeabi-v7a] StaticLibrary  : libandroid-ndk-profiler.a
[armeabi-v7a] StaticLibrary  : libijksoundtouch.a
[armeabi-v7a] StaticLibrary  : libyuv_static.a
[armeabi-v7a] SharedLibrary  : libijksdl.so
[armeabi-v7a] SharedLibrary  : libijkplayer.so
[armeabi-v7a] Install        : libijksdl.so => libs/armeabi-v7a/libijksdl.so
[armeabi-v7a] Install        : libijkplayer.so => libs/armeabi-v7a/libijkplayer.so
/Users/michealx/Documents/ijkplayer/android

If you enter ijkplayer/android/ijkplayer/armeabi-v7a/you can get the ijkplayer so, how can the ijkplayer so be used in the project? Then look.

Using the compiled ijkplayer so Library

The default usage of ijkplayer is as follows:

compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.3'
compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.3'

The second dependency does not have any code, but is actually a so library. Since you want to use your compiled so, the second dependency can be removed.

compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.3'
// compile 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.3'

Put the three so files compiled by yourself into the main/jniLibs/armeabi-v7a/of the project. The playback code doesn't need to be changed. Now ijkplayer can play avi, mpeg/mpg and more format videos.

As for ijkplayer's more ways of playing, the author is also exploring, if the follow-up is free, the author will update one after another.

Portal

Android so library compiled based on ijkplayer 0.8.3 (supports more formats than default dependencies):
github:compiled_ijkplayer4android (Continuous updates will follow according to ijkplayer version)

Thank

Bilibili/ijkplayer

Topics: Android git Linux brew