Environment:
Operating System: Ubuntu 10.04
Ffmpeg source code version: ffmpeg-0.6.1
Android ndk version: android-ndk-r5b-linux-x86
Purpose:
It is used to understand the compiling scenario and process of ffmpeg source code.
Preparations:
Unzip the android-ndk-r5b and place it in the/home/mfcai directory
Create an FFMPEG folder under the/home/mfcai/android-ndk-r5b/samples/directory, create a new jni folder under the FFMPEG directory, and then place the ffmpeg-0.6 source code inside jni, the final ffmpeg source code path is:
/Home/mfcai/android-ndk-r5b/samples/FFMPEG/jni/ffmpeg-0.6
1. Set NDK Environment Variables
Configure the NDK environment and add the/home/ndk directory to the path environment variable:
$ Sudo gedit ~ /. Bashrc
Add the following two lines at the bottom of the file:
NDK_ROOT =/home/mfcai/android-ndk-r5b
Export NDK_ROOT
Ii. Configure compilation Parameters
Create a config. sh under the ffmpeg-0.6 source folder
Config. sh is a script. Another configure script is called when the script is executed,
Configure mainly generates the corresponding compilation configuration based on the Compilation options, that is, the content of the customized compilation options.
1) create a config. sh
#! /Bin/bash
PREBUILT = ${NDK_ROOT}/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86
PLATFORM =$ {NDK_ROOT}/platforms/android-8/arch-arm
./Configure -- target-OS = linux \
-- Arch = arm \
Enable-version3 \
-- Enable-gpl \
-- Enable-nonfree \
-- Disable-stripping \
-- Disable-ffmpeg \
-- Disable-ffplay \
-- Disable-ffserver \
-- Disable-ffprobe \
-- Disable-encoders \
-- Disable-muxers \
-- Disable-devices \
-- Disable-protocols \
-- Enable-protocol = file \
-- Enable-avfilter \
-- Disable-network \
-- Disable-mpegaudio-hp \
-- Disable-avdevice \
-- Enable-cross-compile \
-- Cc = $ PREBUILT/bin/arm-eabi-gcc \
-- Cross-prefix = $ PREBUILT/bin/arm-eabi -\
-- Nm = $ PREBUILT/bin/arm-eabi-nm \
-- Extra-cflags = "-fPIC-DANDROID "\
-- Disable-asm \
-- Enable-neon \
Enable-armv5te \
-- Extra-ldflags = "-Wl,-T, $ PREBUILT/arm-eabi/lib/ldscripts/armelf. x-Wl,-rpath-link = $ PLATFORM/usr/lib-L $ PLATFORM/usr/lib-nostdlib $ PREBUILT/lib/gcc/arm-eabi/4.4.0/crtbegin. o $ PREBUILT/lib/gcc/arm-eabi/4.4.0/crtend. o-lc-lm-ldl"
2) execute the config. sh script file
$ Chmod + x config. sh
$./Config. sh
If the configuration is correct, the last two lines are shown as follows:
License: nonfree and unredistributable
Creating config. mak and config. h...
3) EDIT config. h file
Edit the config. h file in the/root/ffmpeg/jni/ffmpeg-0.6.1 directory,
Change # define restrict to # define restrict
Set
# Define HAVE_LLRINT 0
# Define HAVE_LLRINTF 0
# Define HAVE_LRINT 0
# Define HAVE_LRINTF 0
# Define HAVE_ROUND 0
# Define HAVE_ROUNDF 0
# Define HAVE_TRUNCF 0
To:
# Define HAVE_LLRINT 1
# Define HAVE_LLRINTF 1
# Define HAVE_LRINT 1
# Define HAVE_LRINTF 1
# Define HAVE_ROUND 1
# Define HAVE_ROUNDF 1
# Define HAVE_TRUNCF 1
3. Prepare to compile ffmpeg1. Edit Makefile files for each module in the ffmpegffmpeg-0.6.1
Delete the following two Makefile files in libavutil, libavcodec, libavformat, libavfilter, libpostproct, and libswscale respectively:
Include $ (SUBDIR) ../subdir. mak
Include $ (SUBDIR) ../config. mak
2. Create a New av. mk file under the ffmpegffmpeg-0.6.1 root directory
# 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
# 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-Wno-sign-compare-Wno-switch-Wno-pointer-sign
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 ))
3. Create an Android. mk File
Create the Android. mk file in the jni directory.
Create an Android. mk file in the ffmpegffmpeg-0.6.1
Create the same file in the libavformat, libavcodec, libavfilter, libavutil, libpostproc, and libswscale directories.
1) Create an Android. mk file in the jni folder.
Include $ (all-subdir-makefiles)
2) create an Android. mk file under ffmpeg
LOCAL_PATH: = $ (call my-dir)
Include $ (CLEAR_VARS)
LOCAL_WHOLE_STATIC_LIBRARIES: = libavformat libavcodec libavutil libpostproc libswscale libavfilter
LOCAL_MODULE: = ffmpeg
Include $ (BUILD_SHARED_LIBRARY)
Include $ (call all-makefiles-under, $ (LOCAL_PATH ))
3) create Android. mk in ffmpeg/libavformat
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"-d1_6mr_interface = ipv6mr_ifindex
LOCAL_LDLIBS: =-lz
LOCAL_SHARED_LIBRARIES: = libavutil libavcodec
LOCAL_MODULE: = $ (FFNAME)
Include $ (BUILD_SHARED_LIBRARY)
4) Create Android. mk in ffmpeg/libavcodec
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_LDLIBS: =-lz
LOCAL_SHARED_LIBRARIES: = libavutil
LOCAL_MODULE: = $ (FFNAME)
Include $ (BUILD_SHARED_LIBRARY)
5) Create Android. mk in ffmpeg/libavfilter
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_SHARED_LIBRARIES: = libavutil libswscale libavcodec
LOCAL_MODULE: = $ (FFNAME)
Include $ (BUILD_SHARED_LIBRARY)
6) Create Android. mk under ffmpeg/libavutil
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_MODULE: = $ (FFNAME)
Include $ (BUILD_SHARED_LIBRARY)
7) Create Android. mk in ffmpeg/libpostproc
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_SHARED_LIBRARIES: = libavutil
LOCAL_MODULE: = $ (FFNAME)
Include $ (BUILD_SHARED_LIBRARY)
8) Android. mk file under ffmpeg/libswscale
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_SHARED_LIBRARIES: = libavutil
LOCAL_MODULE: = $ (FFNAME)
Include $ (BUILD_SHARED_LIBRARY)
Iv. Compilation
Run ndk-build in the jni directory
If the compilation is successful, libavcodec. so, libavfilter. so, libavformat. so, libavutil. so, libffmpeg. so, libpostproc. so, and libswscale. so are generated.
V. Problems
1. For the same configuration, the compilation in cygwin won't work for two days. Therefore, we recommend that you compile the SDK in linux.
2. libffmpeg. so is only 1 k in size.
How to modify android. mk in ffmpeg
The libffmpeg. so found is only a dozen KB,
Method 1: Modify android. mk in ffmpeg:
LOCAL_STATIC_LIBRARIES: = libavcodec libavformat libavutil libavfilter libpostproc libswscale
Changed:
LOCAL_WHOLE_STATIC_LIBRARIES: = libavcodec libavformat libavutil libavfilter libpostproc libswscale
Method 2: specify the use of arm-eabi-4.4.0 to compile:
Because the android-ndk-r5 is compiled with a arm-linux-androideabi-4.4.3 by default, instead of a arm-eabi-4.4.0.
But the cmd-build-shared-library function defined in the setup. mk file in the android-ndk-r5/toolchains/arm-linux-androideabi-4.4.3 directory
Static library files are not linked together to generate dynamic library files. So the solution is to add the NDK_TOOLCHAIN parameter when running ndk-build, specifying the use of arm-eabi-4.4.0 for compilation.
The complete command is as follows:
Ndk-build NDK_TOOLCHAIN = arm-eabi-4.4.0 NDK_PLATFORM = android-8
No.
I hope the experts can give me some tips.
Need to compile the ffmpeg-0.61 file, the file is too large to upload, please
Http://download.csdn.net/detail/mfcai_blog/5968953,download
You are welcome to repost this article. For more information, see the source and author.
Source: http://blog.sina.com.cn/staratsky
Author: meteor
This article is from the "Meteor blog" blog, please be sure to keep this source http://staratsky.blog.51cto.com/2513234/1275699