1. Get the code:
git clone https://github.com/Bilibili/ijkplayer.git ijkplayer-android
cd ijkplayer-android
git checkout -B latest k0.8.8
2. Before Build:
# install homebrew, git, yasm
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
brew install yasm
# add these lines to your ~/.bash_profile or ~/.profile
# export ANDROID_SDK=<your sdk path>
# export ANDROID_NDK=<your ndk path>
# on Cygwin (unmaintained)
# install git, make, yasm
3. get dependent on open source library
./init-android.sh
Get FFmpeg different armabi library,
Get libyuv and libtouchsound lib library:
Introduction of several open source libraries:
1. jni4android is a jni generation tool, it can provide java classes, automatically generating a corresponding jni layer * .c files * .h header files.
2. SoundTouch is an open source audio library, mainly in the following functions:
Variable speed constant tone ( the TSM , Time Scale Modification ), changing audio playback speed (fast or slow) without affecting audio tone (Pitch) .
Tone does not shift Pitch Shifting, , change the audio tone while maintaining constant the speed of audio playback
Tone transmission, while varying the audio tones and speed
3. libyuv is Google open source to achieve a variety of YUV to RGB conversion, rotation, scaling between libraries. It is cross-platform, available in Windows , Linux , Mac , Android and other operating systems, x86 , x64 , ARM compiled to run on the architecture to support SSE , AVX , NEON and other SIMD instructions to accelerate.
4. Compile Android FFmpeg library:
cd android/contrib
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh all
FFmpeg Git repository:
Different armabi corresponding ffmpeg library:
FFmpeg build script:
Compile libavfiter and other object files:
5. Compile ijk :
cd ..
./compile-ijk.sh all
By NDK compiled ijkplayer directory JNI folder
Package generated ijkffmpeg like SO .
Compile ijkplayer
6. Import AS (3.2):
File-> Open, click Select android-> ijkplayer
AS Configuration attention to the problem:
1. Gradle version switch. Manually download gradle version as gradle-4.6-all.zip into gradle next file.
2. Jcenter download timeout issues, replace aliyun .
Two . Ijk code analysis:
IjkPlayer In addition to providing ijkPlayer API , but also provides Android native MediaPlayer and google his ExoPlayer API . ijkPlayer in VideoView by Player factory pattern Create
IjkDemo overall architecture:
Demo unused sdl drawn, Android use may refer to:
https://github.com/wanliyang1990/SDL2ForAndroid
ijkplayer playback timing diagram:
./android/ijkplayer_jni.c
IjkMediaPlayer_native_setup
ijkplayer_android.c
ijkmp_android_create
ffpipeline_android.c
ffpipeline_create_from_android
Player basic block diagram:
ffplay.c main code calling procedure as shown below:
1. The data read
stream_open mainly to do the following things :
Create a stored video / audio data before decoding videoq / audioq
Create a stored video / audio decoded data pictq / sampq
Create a data read thread read_thread
Creating video rendering thread video_refresh_thread
2. The audio and video decoding:
Video decoding mode selection
If you configure ffp-> mediacodec , will give priority to try to open the hardware ×××, if you do not support hardware decoding, Soft Solutions is switched.
Video_thread/audio_thread。
3. audio and video rendering
Initialization Player , build vout Object: ijksdl -> S4a
mp->ffplayer->vout = SDL_VoutAndroid_CreateForAndroidSurface();
Calls SDL_VoutDisplayYUVOverlay
draw
SDL_VoutDisplayYUVOverlay(ffp->vout, vp->bmp);