需要使用NDK來(lái)編譯FFmpeg,需要下載NDK和FFmpeg
我使用的NDK版本:android-ndk-r21
FFmpeg版本 FFemeg4.3.1
FFmpeg下載鏈接:
http://ffmpeg.org/releases/ffmpeg-4.3.1.tar.xz
NDK下載鏈接:
https://dl.google.com/android/repository/android-ndk-r21-darwin-x86_64.dmg
下載后解壓ffmpeg和ndk(略)
配置NDK環(huán)境變量:
進(jìn)入終端
pico 命令打開bash_profile
關(guān)于環(huán)境變量
pico ./.bash_profile
springtomdeMacBook-Pro:~ springtom$ pico ./.bash_profile
#Setting PATH for Python 2.7
#The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
#Setting PATH for Python 3.6
#The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
#export JAVA_HOME = "/Users/springtom/Library/Java/JavaVirtualMachines/jdk-11.0$
#export RED5_HOME = "/Users/springtom/Documents/red5/red5-server"
export ANDROID_HOME=/Users/springtom/Library/Android/sdk
export NDKROOT=/Users/springtom/Documents/android-ndk-r21
#export PATH = ”${PATH}:${ANDROID_HOME}/platform-tools“
#export PATH = ${PATH}:${ANDROID_HOME}/tools
export PATH=$PATH:$NDKROOT
#export PATH = ${PATH}:${NDKROOT}/toolchains
#export PATH = ${PATH}:${ANDROID_HOME}/build-tools
export PATH=/Users/springtom/Library/Android/sdk:$PATH
export PATH=/Users/springtom/Library/Android/sdk/build-tools:$PATH
export PATH=/Users/springtom/Library/Android/sdk/platform-tools:$PATH
export PATH=/Users/springtom/Library/Android/sdk/tools:$PATH
export PATH=/Users/springtom/Documents/android-ndk-r21:$PATH
export PATH=/Users/springtom/Documents/android-ndk-r21/toolchains:$PATH
control+x保持
選擇y(yes)
然后按enter結(jié)束編輯
輸入 source ~/.bash_profile使改動(dòng)立即有效潘酗。
springtomdeMacBook-Pro:~ springtom$ source ~/.bash_profile
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
': not a valid identifier
': not a valid identifier
: command not found
springtomdeMacBook-Pro:~ springtom$
ndk-build -verison 檢查環(huán)境變量是否生效
: command not found
springtomdeMacBook-Pro:~ springtom$ ndk-build -version
GNU Make 4.2.1
Built for x86_64-apple-darwin
Copyright (C) 1988-2016 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.
springtomdeMacBook-Pro:~ springtom$
如果不生效去查找環(huán)境變量是否配置正確
在ffmpeg根目錄下編寫build_android.sh
#!/bin/bash
NDK=/Users/springtom/Documents/android-ndk-r21
ADDI_LDFLAGS="-fPIE -pie"
ADDI_CFLAGS="-fPIE -pie -march=armv7-a -mfloat-abi=softfp -mfpu=neon"
CPU=armeabi-v7a
ARCH=armeabi-v7a
HOST=arm-linux
SYSROOT=$NDK/toolchains/llvm/prebuilt/darwin-x86_64/sysroot
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin
PREFIX=$(pwd)/android/$CPU
#x264=$(pwd)/x264/android/$CPU
#export PATH=$x264/bin:$PATH
#export PATH=$x264/include:$PATH
#export PATH=$x264/lib:$PATH
#export PKG_CONFIG_PATH=$x264/lib/pkgconfig:$PKG_CONFIG_PATH
configure()
{
./configure \
--prefix=$PREFIX \
--toolchain=clang-usan \
--enable-cross-compile \
--target-os=android \
--arch=$ARCH \
--sysroot=$SYSROOT \
--cc=$TOOLCHAIN/armv7a-linux-androideabi21-clang \
--cxx=$TOOLCHAIN/armv7a-linux-androideabi21-clang++ \
--strip=$TOOLCHAIN/arm-linux-androideabi-strip \
--extra-cflags="$ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
--disable-encoders \
--disable-decoders \
--disable-avdevice \
--disable-static \
--disable-doc \
--disable-ffplay \
--disable-network \
--disable-doc \
--disable-symver \
--disable-ffprobe \
--enable-neon \
--enable-shared \
#--enable-libx264 \
--enable-gpl \
--enable-pic \
--enable-jni \
--enable-pthreads \
--enable-mediacodec \
--enable-encoder=aac \
--enable-encoder=gif \
--enable-encoder=libopenjpeg \
--enable-encoder=libmp3lame \
--enable-encoder=libwavpack \
#--enable-encoder=libx264 \
--enable-encoder=mpeg4 \
--enable-encoder=pcm_s16le \
--enable-encoder=png \
--enable-encoder=mjpeg \
--enable-encoder=srt \
--enable-encoder=subrip \
--enable-encoder=yuv4 \
--enable-encoder=text \
--enable-decoder=aac \
--enable-decoder=aac_latm \
--enable-decoder=libopenjpeg \
--enable-decoder=mp3 \
--enable-decoder=mpeg4_mediacodec \
--enable-decoder=pcm_s16le \
--enable-decoder=flac \
--enable-decoder=flv \
--enable-decoder=gif \
--enable-decoder=png \
--enable-decoder=srt \
--enable-decoder=xsub \
--enable-decoder=yuv4 \
--enable-decoder=vp8_mediacodec \
#--enable-decoder=h264_mediacodec \
--enable-decoder=hevc_mediacodec \
--enable-bsf=aac_adtstoasc \
#--enable-bsf=h264_mp4toannexb \
--enable-bsf=hevc_mp4toannexb \
--enable-bsf=mpeg4_unpack_bframes
}
build_android()
{
configure
make clean
make -j4
make install
}
build_android
進(jìn)入root權(quán)限
springtomdeMacBook-Pro:~ springtom$ su
Password:
問題:Sorry!
解決:
在 Linux 下检访,執(zhí)行 su 命令后輸入密碼即可切換到 root 用戶執(zhí)行各類操作
但是 Mac 下囊卜,這樣行不通茅诱,只會(huì)返回你一句 Sorry!
解決方法很簡(jiǎn)單畦戒,首先打開終端
依次輸入命令:
sudo su
提示輸入密碼籍嘹,輸入當(dāng)前用戶登錄密碼后回車
左邊變成了 sh-x.x(我這兒是 sh-3.2闪盔,可能不一樣)
接著輸入
passwd root
提示 Changing password for root.
New password: 輸入新密碼
Retype new password: 再次輸入新密碼
回車后完成 root 用戶的密碼修改
接下來(lái)再試試 su 命令,輸入剛剛設(shè)置的密碼后噩峦,成功……
修改權(quán)限:
sh-3.2# cd ffmpeg-4.3.1/
sh-3.2# chmod 777 build_android.sh
執(zhí)行腳本:
sh-3.2# ./build_android.sh
問題:
1锭沟、Yasm版本過低
nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.
原因:
原因是ffmpeg使用了yasm編譯指令,需要機(jī)器安裝yasm插件识补。
解決:
解決方法非常簡(jiǎn)單族淮,命令行輸入:
brew install yasm
前提是本機(jī)已經(jīng)安裝了brew插件,如果沒有安裝參考命令:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2凭涂、權(quán)限問題
install: /usr/local/share/ffmpeg/libvpx-1080p.ffpreset: Permission denied
make: *** [install-data] Error 71
解決:
需要進(jìn)入root權(quán)限
3.問題
prefix=/Users/springtom/Documents/ffmpeg/ffmpeg4.3.1/ffmpeg-4.3.1/android/armeabi-v7a: No such file or directory
./build_android.sh: line 115: --cc=/Users/springtom/Documents/android-ndk-r21/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi21-clang: No such file or directory
Enabled outdevs:
License: LGPL version 2.1 or later
config.h is unchanged
config.asm is unchanged
libavutil/avconfig.h is unchanged
libavfilter/filter_list.c is unchanged
libavcodec/codec_list.c is unchanged
libavcodec/parser_list.c is unchanged
libavcodec/bsf_list.c is unchanged
libavformat/demuxer_list.c is unchanged
libavformat/muxer_list.c is unchanged
libavdevice/indev_list.c is unchanged
libavdevice/outdev_list.c is unchanged
libavformat/protocol_list.c is unchanged
ffbuild/config.sh is unchanged
./build_android.sh: line 94: --prefix=/Users/springtom/Documents/ffmpeg/ffmpeg4.3.1/ffmpeg-4.3.1/android/armeabi-v7a: No such file or directory
./build_android.sh: line 96: --enable-shared: command not found
./build_android.sh: line 99: --enable-jni: command not found
./build_android.sh: line 101: --disable-doc: command not found
./build_android.sh: line 103: --disable-programs: command not found
./build_android.sh: line 105: --disable-symver: command not found
./build_android.sh: line 107: --disable-x86asm: command not found
./build_android.sh: line 109: --target-os=linux: command not found
./build_android.sh: line 111: --arch=arm: command not found
./build_android.sh: line 113: --cpu=armv7-a: command not found
./build_android.sh: line 115: --cc=/Users/springtom/Documents/android-ndk-r21/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi21-clang: No such file or directory
./build_android.sh: line 117: --cxx=/Users/springtom/Documents/android-ndk-r21/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi21-clang++: No such file or directory
./build_android.sh: line 119: --enable-cross-compile: command not found
./build_android.sh: line 121: --sysroot=/Users/springtom/Documents/android-ndk-r21/toolchains/llvm/prebuilt/darwin-x86_64/sysroot: No such file or directory
./build_android.sh: line 123: --extra-cflags=-Os -fpic -march=armv7-a: command not found
./build_android.sh: line 125: --extra-ldflags=: command not found
./build_android.sh: line 127: --disable-asm: command not found
原因:NDK工具鏈路徑不對(duì):
SYSROOT=NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin
darwin-x86_64
armv7a-linux-androideabi21-clang 路徑不對(duì)
4.權(quán)限問題:
解決:系統(tǒng)偏好設(shè)置->安全性與隱私->通用->最底下 勾選允許
最后編輯結(jié)果在ffmpeg根目錄下android目錄下:
/Users/springtom/Documents/ffmpeg/ffmpeg4.3.1/ffmpeg-4.3.1/android/armeabi-v7a/lib
ffmpge導(dǎo)入android studio