您的位置:首页 > 移动开发 > Android开发

Mac下面编译Android FFmpeg3.2.4

2017-07-26 20:10 387 查看
需要搞直播,打算使用ffmpeg进行推流,于是在Mac下进行了编译FFMmpeg。

1、下载ffmpeg源码,我下载的是ffmpeg-3.2.4

2、配置好build_android.sh编译安卓脚本,脚本如下,

cd /Users/xxxx/Documents/DevTool/ffmpeg-3.2.4
NDK=/Users/xxxx/Documents/DevTool/AndroidSDK/android-sdk-macosx/ndk-bundle
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
function build_one{
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one


我这里选择的CPU的架构是arm,有其他需要可自行添加;

3、为脚本赋予可执行权限;

chmod -R 775 build_android.sh


4、执行脚本,经过一番编译等待之后,我这边编译了几遍大约在十五分钟编译完成;



5、打开AS,我的测试版本是AS 2.3版本,所以使用的是CMakelist.txt来进行编译的,把刚才编译好的源码复制到项目的libs下面;



6、编译CMakelist.txt文件,完整的如下;

//For more information about using CMake with Android Studio, read the
//documentation: https://d.android.com/studio/projects/add-native-code.html //Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log )

set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../libs)

add_library( avutil-55
SHARED
IMPORTED )
set_target_properties( avutil-55
PROPERTIES IMPORTED_LOCATION
../../../../libs/arm/libavutil-55.so )

add_library( swresample-2
SHARED
IMPORTED )
set_target_properties( swresample-2
PROPERTIES IMPORTED_LOCATION
../../../../libs/arm/libswresample-2.so )

add_library( avcodec-57
SHARED
IMPORTED )
set_target_properties( avcodec-57
PROPERTIES IMPORTED_LOCATION
../../../../libs/arm/libavcodec-57.so )

add_library( avfilter-6
SHARED
IMPORTED)
set_target_properties( avfilter-6
PROPERTIES IMPORTED_LOCATION
../../../../libs/arm/libavfilter-6.so )

add_library( swscale-4
SHARED
IMPORTED)
set_target_properties( swscale-4
PROPERTIES IMPORTED_LOCATION
../../../../libs/arm/libswscale-4.so )

add_library( avformat-57
SHARED
IMPORTED)
set_target_properties( avformat-57
PROPERTIES IMPORTED_LOCATION
../../../../libs/arm/libavformat-57.so )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

add_library( native-lib
SHARED
src/main/cpp/native-lib.cpp )

include_directories(libs/include)

//target_include_directories(native-lib PRIVATE libs/include)

target_link_libraries(native-lib
${avutil-55}
${swresample-2}
${avcodec-57}
${avfilter-6}
${swscale-4}
${avformat-57}
${log-lib} )


7、编译运行,成功,明天就可以开撸直播了,哈哈,附上下载链接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ffmpeg