ndk编译ffmpeg

2018/05/17 15:47
阅读数 8

#!/bin/bash

NDK=/opt/android-ndk-r9d

SYSROOT=$NDK/platforms/android-9/arch-arm/

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64


function build_go_go_go
{
echo "go go go"
}
function build_ffmpeg
{
echo "start ./configure"
sed -i 's#require_pkg_config speex speex/speex.h#require speex speex/speex.h#g' ./configure
./configure \
    --prefix=$PREFIX    \
    --disable-shared    \
    --enable-static    \
    --enable-runtime-cpudetect \
    --disable-doc \
    --enable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-ffserver \
    --disable-symver \
    --enable-gpl \
    --enable-nonfree \
    --enable-libfaac \
    --enable-libx264 \
    --enable-cross-compile \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --target-os=linux \
    --arch=arm \
    --cc=$CC \
    --nm=$NM \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic -DANDROID  -I$(pwd)/../x264-build/arm/include/" \
    --extra-ldflags="-L$(pwd)/../x264-build/arm/lib/" \
    --extra-libs="-lgcc -ldl" \
    #--enable-libspeex \
    #--enable-encoder=libx264 \
    #--enable-libx264 \
    #--extra-cflags="-Os -fpic -DANDROID $ADDI_CFLAGS -I../x264-build/arm/include -I../faac/include -I../speex/include" \
    #--extra-ldflags="$ADDI_LDFLAGS -L../x264-build/arm/lib -L../faac/obj/local/armeabi -L../speex/obj/local/armeabi" \

    $ADDITIONAL_CONFIGURE_FLAG \
    || exit 1
make clean || exit 1
sed -i 's/HAVE_CBRT 0/HAVE_CBRT 1/g' ./config.h
sed -i 's/HAVE_TRUNC 0/HAVE_TRUNC 1/g' ./config.h
sed -i 's/HAVE_ROUND 0/HAVE_ROUND 1/g' ./config.h
sed -i 's/HAVE_LRINTF 0/HAVE_LRINTF 1/g' ./config.h
sed -i 's/HAVE_LRINT 0/HAVE_LRINT 1/g' ./config.h
sed -i 's/HAVE_RINT 0/HAVE_RINT 1/g' ./config.h
sed -i 's/HAVE_ISINF 0/HAVE_ISINF 1/g' ./config.h
sed -i 's/HAVE_ISNAN 0/HAVE_ISNAN 1/g' ./config.h
make -j4 || exit 1
make install || exit 1
}
function build_mcy
{
    ./configure --target-os=linux \
        --prefix=$PREFIX \
        --enable-cross-compile \
        --extra-libs="-lgcc" \
        --arch=arm \
        --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
        --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
        --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
        --sysroot=$PLATFORM \
        --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS " \
        --disable-shared \
        --enable-static \
        --extra-ldflags="-Wl, -L../x264-build/arm/lib -nostdlib -lc -lm -ldl -llog" \
        --disable-everything \
        --enable-demuxer=mov \
        --enable-demuxer=h264 \
        --disable-ffplay \
        --enable-protocol=file \
        --enable-avformat \
        --enable-avcodec \
        --enable-decoder=rawvideo \
        --enable-decoder=mjpeg \
        --enable-decoder=h263 \
        --enable-decoder=mpeg4 \
        --enable-decoder=h264 \
        --enable-parser=h264 \
        --disable-network \
        --enable-zlib \
        --enable-avfilter \
        --disable-avdevice \
        $ADDITIONAL_CONFIGURE_FLAG

    make clean
    #make  -j4 install
    #$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
    #$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -soname libffmpeg.so -shared -nostdlib  -z noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavfilter/libavfilter.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.6/libgcc.a
}

function build_one
{
  echo "$TOOLCHAIN/bin/$EABIARCH-gcc -Wl,-rpath-link=$SYSROOT/usr/lib -L$SYSROOT/usr/lib -L$PREFIX/lib -shared -Wl,-soname,$SONAME -nostdlib -Wl,-Bsymbolic -o $OUT_LIBRARY -Wl,--whole-archive -lavcodec -lavfilter -lavformat -lavutil -lswresample -lswscale -Wl,--no-whole-archive --sysroot=$SYSROOT -Wl,--as-needed -lc -lm -lz -ldl -llog $TOOLCHAIN/lib/gcc/$EABIARCH/4.6/libgcc.a"
  $TOOLCHAIN/bin/$EABIARCH-gcc -Wl,-rpath-link=$SYSROOT/usr/lib -L$SYSROOT/usr/lib -L$PREFIX/lib -L../x264-build/arm/lib -L../faac/obj/local/armeabi -L../speex/obj/local/armeabi -shared -Wl,-soname,$SONAME -nostdlib -Wl,-Bsymbolic -o $OUT_LIBRARY -Wl,--whole-archive -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswresample -lswscale -lpostproc -lx264 -lfaac -lspeex -Wl,--no-whole-archive --sysroot=$SYSROOT -Wl,--as-needed -lc -lm -lz -ldl -llog $TOOLCHAIN/lib/gcc/$EABIARCH/4.6/libgcc.a || exit 1
  cp -f $OUT_LIBRARY $OUT_LIBRARY.sym
  $TOOLCHAIN/bin/$EABIARCH-strip $OUT_LIBRARY
 
  echo "$TOOLCHAIN/bin/$EABIARCH-g++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=$SYSROOT -Wl,-rpath-link=$SYSROOT/usr/lib -Wl,-rpath-link=. cmdutils.o ffmpeg_filter.o ffmpeg.o ffmpeg_opt.o -lgcc -no-canonical-prefixes  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  -L$SYSROOT/usr/lib -L$PREFIX/lib -Wl,--whole-archive -lavcodec -lavfilter -lavformat -lavutil -lswresample -lswscale -Wl,--no-whole-archive -Wl,--as-needed -llog -lc -lm -lz -ldl -o ffmpeg"
  $TOOLCHAIN/bin/$EABIARCH-g++ -Wl,--gc-sections -Wl,-z,nocopyreloc --sysroot=$SYSROOT -Wl,-rpath-link=$SYSROOT/usr/lib -Wl,-rpath-link=. cmdutils.o ffmpeg_filter.o ffmpeg.o ffmpeg_opt.o -lgcc -no-canonical-prefixes  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  -L$SYSROOT/usr/lib -L$PREFIX/lib -L../x264-build/arm/lib -L../faac/obj/local/armeabi -L../speex/obj/local/armeabi -Wl,--whole-archive -lavcodec -lavdevice -lavfilter -lavformat -lavutil -lswresample -lswscale -lpostproc -lx264 -lfaac -lspeex -Wl,--no-whole-archive -Wl,--as-needed -llog -lc -lm -lz -ldl -shared -o libffmpeg2.so || exit 1
  $TOOLCHAIN/bin/$EABIARCH-strip ffmpeg
}

CPU=arm
PREFIX=$(pwd)/../ffmpeg-build/$CPU
ADDI_CFLAGS="-marm -I$PREFIX/include"
ADDI_LDFLAGS="-Wl,-rpath-link=$SYSROOT/usr/lib -L$SYSROOT/usr/lib -nostdlib -lc -lm -ldl -llog -L$PREFIX/lib"
EABIARCH=arm-linux-androideabi
SONAME=libffmpeg.so
OUT_LIBRARY=$PREFIX/$SONAME
CC=$TOOLCHAIN/bin/$EABIARCH-gcc
NM=$TOOLCHAIN/bin/$EABIARCH-nm

build_go_go_go
build_ffmpeg
#build_one
#build_mcy
#make install || exit 1

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部