Recent projects need to parse Apple's HLS streaming protocol, and FFmpeg has added support for HLS protocols since the 0.11.1 "happiness" version. There are many articles on the internet about ffmpeg compiling and porting, but most of them are descriptions of the old versions. The new version of the source code has made changes to many places, including some variable names, constant names, function names, function parameters, structure, etc., so in the old version of the JNI interface, you need to make corresponding changes. This compilation porting work really took me a lot of time, now summed up, I hope to give you some help. Note that this article is not necessarily correct, everyone in the compilation process, will inevitably encounter a variety of errors, can be proposed to discuss together.
Compilation environment: Ubuntu 12.04, Android NDK R8
First, download the source code, new project
: http://ffmpeg.org/download.html, download the latest ffmpeg-0.11.1 compression pack.
Under the $ndk_home/samples/directory (mine is/root/develop/android-ndk-r8/samples/ Create a FFMPEG-0.11 directory, in which a new JNI directory, and then the FFmpeg source decompression in the JNI, the source folder renamed to Libffmpeg, so the final source of the path is:
/root/develop/android-ndk-r8/samples/ffmpeg-0.11/jni/libffmpeg
Second, configure the source code
1. Create a config_common.sh script
Create a config_common.sh in the JNI directory with the following content:
Shellscript Code
- #!/bin/bash
- Ffconfig_common= '
- --enable-version3
- --disable-gpl
- --disable-nonfree
- --disable-debug
- --disable-ffmpeg
- --disable-ffplay
- --disable-ffserver
- --disable-ffprobe
- --disable-encoders
- --disable-muxers
- --disable-devices
- --disable-protocols
- --enable-protocol=file
- --disable-swscale
- --disable-avfilter
- --enable-network
- --disable-avdevice
- --enable-parsers
- --disable-decoders
- --disable-demuxers
- --enable-demuxer=matroska
- --disable-demuxer=rm
- --disable-demuxer=avi
- --disable-demuxer=flv
- --disable-demuxer=mov
- --enable-demuxer=mp3
- --enable-demuxer=mpegps
- --enable-demuxer=mpegvideo
- --enable-demuxer=asf
- --enable-decoder=aac
- --enable-decoder=ac3
- --enable-decoder=dca
- --enable-decoder=flv
- --disable-decoder=h263
- --disable-decoder=h264
- --enable-decoder=svq3
- --enable-decoder=amrnb
- --enable-decoder=nellymoser
- --enable-decoder=pcm_alaw
- --enable-decoder=pcm_dvd
- --enable-decoder=pcm_mulaw
- --enable-decoder=pcm_s16be
- --enable-decoder=pcm_s16le
- --enable-decoder=pcm_s16le_planar
- --enable-decoder=pcm_s24be
- --enable-decoder=pcm_s24daud
- --enable-decoder=pcm_s24le
- --enable-decoder=pcm_s32be
- --enable-decoder=pcm_s32le
- --enable-decoder=pcm_s8
- --enable-decoder=pcm_u16be
- --enable-decoder=pcm_u16le
- --enable-decoder=pcm_u24be
- --enable-decoder=pcm_u24le
- --enable-decoder=pcm_u32be
- --enable-decoder=pcm_u32le
- --enable-decoder=atrac3
- --enable-decoder=pcm_u8
- --enable-decoder=sipr
- --enable-decoder=mjpeg
- --enable-decoder=mp1
- --enable-decoder=mp2
- --enable-decoder=mp3
- --enable-decoder=tscc
- --enable-decoder=mpeg1video
- --enable-decoder=mpeg2video
- --enable-decoder=mpeg4
- --enable-decoder=ra_144
- --enable-decoder=ra_288
- --enable-decoder=cook
- --enable-decoder=rv10
- --enable-decoder=rv20
- --enable-decoder=rv30
- --enable-decoder=rv40
- --enable-decoder=wmav1
- --enable-decoder=wmav2
- --enable-decoder=wmapro
- --disable-decoder=wmv1
- --disable-decoder=wmv2
- --disable-decoder=wmv3
- --enable-decoder=vc1
- --enable-decoder=msmpeg4v1
- --enable-decoder=msmpeg4v2
- --enable-decoder=msmpeg4v3
- ‘
You can configure the above parameters yourself as needed.
2. Create a config.sh script
Create a config.sh in the JNI directory with the following content:
Shellscript Code
- #!/bin/bash
- SOURCE config_common.sh/* Execute the above config_common.sh script here */
- CD libffmpeg/* Enter the LIBFFMPEG directory */
- prebuilt=/root/develop/android-ndk-r8/toolchains/arm-linux-androideabi-4.4. 3/prebuilt/linux-x86
- platform=/root/develop/android-ndk-r8/platforms/android-14/arch-arm
- ./configure--target-os=linux \
- --arch=arm \
- --enable-shared \
- --enable-cross-compile \
- --cc= $PREBUILT/BIN/ARM-LINUX-ANDROIDEABI-GCC \
- --cross-prefix= $PREBUILT/bin/arm-linux-androideabi-\
- --strip= $PREBUILT/bin/arm-linux-androideabi-strip \
- --extra-cflags="-fpic-dandroid" \
- --extra-ldflags="-wl,-t, $PREBUILT/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x-wl,-rpath-link=$ Platform/usr/lib-l$platform/usr/lib-nostdlib $PREBUILT/LIB/GCC/ARM-LINUX-ANDROIDEABI/4.4.3/CRTBEGIN.O $PREBUILT/ Lib/gcc/arm-linux-androideabi/4.4.3/crtend.o-lc-lm-ldl "\
- $FFCONFIG _common
- Cd.. /* Return to JNI directory */
- Ndk-build Clean
3. Execute the config.sh script
Then open the terminal and execute the following command:
$chmod +x config.sh/* Give config.sh Execute permission */
$./config.sh
If configured correctly, the last two lines shown are:
LICENSE:LGPL version 3 or later
Creating Config.mak and Config.h ...
If Warning:/root/develop/android-ndk-8/.............../arm-linux-androideabi-pkg-config not found appears, the library Detection may fail. can be ignored.
4. Modify Config.h
Enter the jni/libffmpeg/directory and find this sentence in the newly generated config.h:
#define Restrict Restrict
Because the Android GCC does not recognize the Restrict keyword, it is rewritten as:
#define Restrict
If you need to be networked, you also need to set the following definition in Config.h to 1:
#define Config_network 1
#define CONFIG_HTTP_PROTOCOL 1
#define CONFIG_HTTPPROXY_PROTOCOL 1
#define CONFIG_HTTPS_PROTOCOL 1
#define CONFIG_TCP_PROTOCOL 1
#define CONFIG_UDP_PROTOCOL 1
#define HAVE_STRUCT_SOCKADDR_STORAGE 1
#define HAVE_STRUCT_ADDRINFO 1
#define HAVE_SOCKLEN_T 1
#define Have_inet_aton 0
Accordingly, the Config.mak also needs to be modified to:
Config_network=yes
Config_http_protocol=yes
Config_httpproxy_protocol=yes
Config_https_protocol=yes
Config_tcp_protocol=yes
Config_udp_protocol=yes
Have_struct_sockaddr_storage=yes
Have_struct_addrinfo=yes
Have_socklen_t=yes
! Have_inet_aton=yes
5. Modify the Libm.h file
All of the static functions in the/libavutil/libm.h are commented out.
6. Modify the Makefile file
Modify the Libpostproc file in the Libavcodec, Libavfilter, Libavformat, Libavutil, Libswscale, and makefile directories and comment out the following sentence:
Include $ (subdir): /config.mak
7. Create a new AV.MK script
Under/jni/libffmpeg, create a script file av.mk with the following content:
# Local_path is one of Libavutil, Libavcodec, Libavformat, or Libswscale
#include $ (Local_path)/.. /config-$ (target_arch). Mak
Include $ (local_path)/. /config.mak
OBJS: =
Objs-yes: =
Mmx-objs-yes: =
Include $ (local_path)/makefile
Ifdef addition_inc
Include $ (addition_inc)
endif
# Collect objects
objs-$ (HAVE_MMX) + = $ (mmx-objs-yes)
OBJS + = $ (objs-yes)
Ffname: = lib$ (NAME)
Fflibs: = $ (foreach,name,$ (fflibs), lib$ (NAME))
Ffcflags =-dhave_av_config_h $ (CFLAGS)
Ffcflags + =-dtarget_config=\ "config-$ (target_arch). H\"
All_s_files: = $ (wildcard $ (local_path)/$ (target_arch)/*. S
All_s_files: = $ (Addprefix $ (target_arch)/, $ (Notdir $ (all_s_files)))
Ifneq ($ (all_s_files),)
ALL_S_OBJS: = $ (patsubst%). s,%.o,$ (All_s_files))
C_OBJS: = $ (Filter-out $ (ALL_S_OBJS), $ (OBJS))
S_OBJS: = $ (Filter $ (ALL_S_OBJS), $ (OBJS))
Else
C_OBJS: = $ (OBJS)
S_OBJS: =
endif
C_files: = $ (Patsubst%.o,%.c,$ (C_OBJS))
S_files: = $ (Patsubst%.o,%. s,$ (S_OBJS))
Fffiles: = $ (sort $ (s_files)) $ (sort $ (c_files))
8. Create a new ANDROID.MK script
Create a new android.mk in the JNI directory with the following content:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Local_src_files: = ExportJNI.cpp ExportPlayer.cpp packetqueue.cpp/* where ExportJNI.cpp is the JNI interface I wrote */
Local_static_libraries: = Libavformat libavcodec libswscale libavutil libpostproc ffmpeg libsubtitle/* Note the order of LIBRARIES */
Local_module: = export/* final Generation libexport.so*/
Local_arm_mode: = ARM
Local_cflags: =-d__stdc_constant_macros-i$ (Local_path)/libffmpeg/-i$ (Local_path)/libsubtitle/
Local_ldlibs: =-llog
Include $ (build_shared_library)
Include $ (call all-makefiles-under,$ (Local_path))
Create a new android.mk under the Jni/libffmpeg directory:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Local_src_files: = SETTINGS.C MyLog.cpp/* If you do not need auxiliary functions such as print output, this line can be deleted */
Local_module: = FFmpeg
Local_arm_mode: = ARM
Include $ (build_static_library)
Include $ (call all-makefiles-under,$ (Local_path))
Create a new android.mk under the Jni/libffmpeg/libavformat directory:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Include $ (local_path)/. /av.mk
Local_src_files: = $ (fffiles)
Local_c_includes: =\
$ (Local_path) \
$ (Local_path)/..
Local_cflags + = $ (ffcflags)
Local_cflags + =-include "String.h"-dipv6mr_interface=ipv6mr_ifindex
Local_ldlibs: =-lz
Local_static_libraries: = $ (fflibs)
Local_module: = $ (Ffname)
Local_arm_mode: = ARM
Include $ (build_static_library)
Create a new android.mk under the Jni/libffmpeg/libavcodec directory:
Local_path: = $ (call My-dir)
Include $ (clear_vars)
Addition_inc: = $ (Local_path)/arm/makefile
Include $ (local_path)/. /av.mk
Addition_inc: =
Local_src_files: = $ (fffiles)
Local_c_includes: =\
$ (Local_path) \
$ (Local_path)/..
Local_cflags + = $ (ffcflags)
Ifeq ($ (Target_arch_abi), Armeabi)
Local_cflags + =-duse_int
endif
Local_ldlibs: =-lz
Local_static_libraries: = $ (fflibs)
Local_module: = $ (Ffname)
Local_arm_mode: = ARM
Include $ (build_static_library)
Create new android.mk in the Libavfilter, Libavutil, Libpostproc, and Libswscale directories:
Local_path:= $ (call My-dir)
Include $ (clear_vars)
include$ (Local_path)/. /av.mk
Local_src_files:= $ (fffiles)
local_c_includes:= \
$ (Local_path) \
$ (Local_path)/..
local_cflags+= $ (ffcflags)
Local_static_libraries:= $ (fflibs)
Local_module:= $ (ffname)
include$ (Build_static_library)
9. Create a new APPLICATION.MK script
Create a application.mk in the JNI directory with the following content:
App_stl: = stlport_static
App_abi: = Armeabi
Iii. NDK Compilation
Execute the Ndk-build under ffmpeg-0.11/:
$/ffmpeg-0.11# Ndk-build
The compilation process takes about 10 minutes, and finally generates LIBAVCODEC.A, LIBAVFORMAT.A, LIBAVUTIL.A, libffmpeg.a, ffmpeg-0.11/obj/local/armeabi/directory, Libswscale.a and LIBPOSTPROC.A, and libexport.so, generate libexport.so in the ffmpeg-0.11/libs/armeabi/directory.
Reprint: http://superonion.iteye.com/blog/1609777
FFmpeg Transplant Android