Mac 下編譯FFmpeg4.3.1

需要使用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/sysroot TOOLCHAIN=NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin
darwin-x86_64

armv7a-linux-androideabi21-clang 路徑不對(duì)

4.權(quán)限問題:


image.png

解決:系統(tǒng)偏好設(shè)置->安全性與隱私->通用->最底下 勾選允許

最后編輯結(jié)果在ffmpeg根目錄下android目錄下:
/Users/springtom/Documents/ffmpeg/ffmpeg4.3.1/ffmpeg-4.3.1/android/armeabi-v7a/lib

image.png

ffmpge導(dǎo)入android studio

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末祝辣,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子切油,更是在濱河造成了極大的恐慌蝙斜,老刑警劉巖,帶你破解...
    沈念sama閱讀 207,113評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件澎胡,死亡現(xiàn)場(chǎng)離奇詭異孕荠,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)攻谁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,644評(píng)論 2 381
  • 文/潘曉璐 我一進(jìn)店門稚伍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人戚宦,你說(shuō)我怎么就攤上這事个曙。” “怎么了受楼?”我有些...
    開封第一講書人閱讀 153,340評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵垦搬,是天一觀的道長(zhǎng)呼寸。 經(jīng)常有香客問我,道長(zhǎng)猴贰,這世上最難降的妖魔是什么对雪? 我笑而不...
    開封第一講書人閱讀 55,449評(píng)論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮糟趾,結(jié)果婚禮上慌植,老公的妹妹穿的比我還像新娘。我一直安慰自己义郑,他們只是感情好蝶柿,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,445評(píng)論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著非驮,像睡著了一般交汤。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上劫笙,一...
    開封第一講書人閱讀 49,166評(píng)論 1 284
  • 那天芙扎,我揣著相機(jī)與錄音,去河邊找鬼填大。 笑死戒洼,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的允华。 我是一名探鬼主播圈浇,決...
    沈念sama閱讀 38,442評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼靴寂!你這毒婦竟也來(lái)了磷蜀?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,105評(píng)論 0 261
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤百炬,失蹤者是張志新(化名)和其女友劉穎褐隆,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體剖踊,經(jīng)...
    沈念sama閱讀 43,601評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡庶弃,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,066評(píng)論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了德澈。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片虫埂。...
    茶點(diǎn)故事閱讀 38,161評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖圃验,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情缝呕,我是刑警寧澤澳窑,帶...
    沈念sama閱讀 33,792評(píng)論 4 323
  • 正文 年R本政府宣布斧散,位于F島的核電站,受9級(jí)特大地震影響摊聋,放射性物質(zhì)發(fā)生泄漏鸡捐。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,351評(píng)論 3 307
  • 文/蒙蒙 一麻裁、第九天 我趴在偏房一處隱蔽的房頂上張望箍镜。 院中可真熱鬧,春花似錦煎源、人聲如沸色迂。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,352評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)歇僧。三九已至,卻和暖如春锋拖,著一層夾襖步出監(jiān)牢的瞬間诈悍,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,584評(píng)論 1 261
  • 我被黑心中介騙來(lái)泰國(guó)打工兽埃, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留放妈,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,618評(píng)論 2 355
  • 正文 我出身青樓堪侯,卻偏偏與公主長(zhǎng)得像催蝗,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子鄙陡,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,916評(píng)論 2 344

推薦閱讀更多精彩內(nèi)容