1. 在x264的源码目录下创建b1.sh,内容如下:

点击(此处)折叠或打开

  1. export NDK=/opt/google/android/android-ndk-r8e
  2. export VERSION=4.4.3
  3. export PREBUILT=$NDK/toolchains/arm-linux-androideabi-$VERSION/prebuilt
  4. export PLATFORM=$NDK/platforms/android-8/arch-arm
  5. ./configure --enable-static \
  6. --enable-shared \
  7. --enable-pic \
  8. --disable-asm \
  9. --disable-cli \
  10. --host=arm-linux \
  11. --cross-prefix=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi- \
  12. --sysroot=$PLATFORM
2. 在ffmepg的父目录下创建b1.sh,内容如下:并创建目录elib,并 把上面生成的lib264.a 拷贝到该目录下

点击(此处)折叠或打开

  1. #!/bin/bash
  2. export VERSION=4.4.3
  3. export NDK=/opt/google/android/android-ndk-r8e
  4. export PREBUILT=$NDK/toolchains/arm-linux-androideabi-$VERSION/prebuilt/linux-x86_64
  5. export PLATFORM=$NDK/platforms/android-9/arch-arm
  6. export FFMPEG_ROOT=/home/test/code/ffmpeg-1.1.5 
  7. export X264_ROOT=/home/test/code/x264_and #上面的x264的源码目录
  8. export ELIB="$FFMPEG_ROOT/elib"
  9. function build_one
  10. {
  11. $FFMPEG_ROOT/configure --target-os=linux \
  12. --enable-cross-compile \
  13. --enable-runtime-cpudetect \
  14. --disable-asm \
  15. --arch=arm \
  16. --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
  17. --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
  18. --disable-stripping \
  19. --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
  20. --sysroot=$PLATFORM \
  21. --enable-nonfree \
  22. --enable-version3 \
  23. --disable-everything \
  24. --enable-gpl \
  25. --disable-doc \
  26. --enable-avresample \
  27. --enable-demuxer=rtsp \
  28. --enable-muxer=rtsp \
  29. --disable-ffplay \
  30. --disable-ffserver \
  31. --enable-ffmpeg \
  32. --disable-ffprobe \
  33. --enable-libx264 \
  34. --enable-encoder=libx264 \
  35. --enable-decoder=h264 \
  36. --enable-protocol=rtp \
  37. --enable-hwaccels \
  38. --enable-zlib \
  39. --disable-devices \
  40. --disable-avdevice \
  41. --extra-cflags="-I$X264_ROOT -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \
  42. --extra-ldflags="-L$ELIB"
  43. make -j4
  44. }
  45. build_one
  46. $PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
  47. $PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L$ELIB -soname libffmpeg.so -shared -nostdlib -z noexecstack -Bsymbolic --whole-archive --no-undefined -o libffmpeg.so libavcodec/libavcodec.a libavfilter/libavfilter.a libavresample/libavresample.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog -lx264 --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/$VERSION/libgcc.a
到此为止so文件已经编译完毕:
下面编译jni的so文件;

点击(此处)折叠或打开

  1. LOCAL_PATH := $(call my-dir)

  2. include $(CLEAR_VARS)
  3. MY_PATH := /home/wanjm/code/binary #上面的so文件的目录
  4. LOCAL_MODULE := ffmpeg
  5. LOCAL_SRC_FILES := $(MY_PATH)/libffmpeg.so #仅支持一个文件;
  6. include $(PREBUILT_SHARED_LIBRARY)


  7. include $(CLEAR_VARS)
  8. LOCAL_MODULE := myffmp
  9. LOCAL_SRC_FILES := VideoEncoder.c #jni的c文件;
  10. LOCAL_C_INCLUDES := /home/wanjm/code/ffmpeg-1.2.4 
  11. LOCAL_LDLIBS := -llog -lm -lc -ldl -lz -lstdc++
  12. LOCAL_STATIC_LIBRARIES := libffmpeg #引用5处生成的so文件;
  13. include $(BUILD_SHARED_LIBRARY)
上面so方式弄出来的,还是两个文件,在实际的java中,要限价在libffmpeg.so,然后在加载myffmp; 反序后会报告少依赖包, 但是按照该顺序还是加载失败;

然后按照下面的写法,可以生成单个so文件,且可以调试;

点击(此处)折叠或打开

  1. LOCAL_PATH := $(call my-dir)
  2. MY_PATH :=/home/wanjm/code/binary/elib

  3. include $(CLEAR_VARS)
  4. #MY_PATH := /home/wanjm/code/binary
  5. #LOCAL_MODULE := ffmpeg
  6. #LOCAL_SRC_FILES := $(MY_PATH)/libffmpeg.so
  7. #include $(PREBUILT_SHARED_LIBRARY)

  8. include $(CLEAR_VARS)
  9. LOCAL_MODULE := avcodec
  10. LOCAL_SRC_FILES := $(MY_PATH)/libavcodec.a
  11. include $(PREBUILT_STATIC_LIBRARY)

  12. include $(CLEAR_VARS)
  13. LOCAL_MODULE := avformat
  14. LOCAL_SRC_FILES := $(MY_PATH)/libavformat.a
  15. include $(PREBUILT_STATIC_LIBRARY)

  16. include $(CLEAR_VARS)
  17. LOCAL_MODULE := avutil
  18. LOCAL_SRC_FILES := $(MY_PATH)/libavutil.a
  19. include $(PREBUILT_STATIC_LIBRARY)

  20. include $(CLEAR_VARS)
  21. LOCAL_MODULE := x264
  22. LOCAL_SRC_FILES := $(MY_PATH)/libx264.a
  23. include $(PREBUILT_STATIC_LIBRARY)

  24. include $(CLEAR_VARS)
  25. LOCAL_MODULE := swscale
  26. LOCAL_SRC_FILES := $(MY_PATH)/libswscale.a
  27. include $(PREBUILT_STATIC_LIBRARY)


  28. include $(CLEAR_VARS)
  29. LOCAL_MODULE := myffmp
  30. LOCAL_SRC_FILES := VideoEncoder.c
  31. LOCAL_C_INCLUDES := /home/wanjm/code/ffmpeg-1.2.4
  32. LOCAL_LDLIBS := -llog -lm -lc -ldl -lz -lstdc++
  33. LOCAL_STATIC_LIBRARIES := libavformat libavutil libavcodec libswscale libavutil libx264
  34. include $(BUILD_SHARED_LIBRARY)




makefile 脚本: 注意-lgcc 应该放在最后,否则找到__aeabi_idiv等方法;

点击(此处)折叠或打开

  1. VERSION=4.8
  2. NDK_ROOT=/opt/google/android-ndk-r9b
  3. TOOLCHAINS_ROOT=$(NDK_ROOT)/toolchains/arm-linux-androideabi-$(VERSION)/prebuilt/linux-x86_64
  4. TOOLCHAINS_PREFIX=$(TOOLCHAINS_ROOT)/bin/arm-linux-androideabi
  5. TOOLCHAINS_INCLUDE=$(TOOLCHAINS_ROOT)/lib/gcc/arm-linux-androideabi/$(VERSION)/include-fixed
  6. SYSROOT=$(NDK_ROOT)/platforms/android-9/arch-arm
  7. PLATFORM_INCLUDE=$(SYSROOT)/usr/include
  8. PLATFORM_LIB=$(SYSROOT)/usr/lib
  9. FLAGS= -fpic -DANDROID
  10. #如果没有-lc,实际运行时会找不到gettimeofday;
  11. LDFLAGS=-shared -L$(PLATFORM_LIB) --no-undefined -lc -llog -lm -lc -ldl -lz #-nostdlib -ldl -lm -Bdynamic -lc -lstdc++
  12. #FLAGS="-I$(TOOLCHAINS_INCLUDE) -I$(PLATFORM_INCLUDE) " #-L$(PLATFORM_LIB) -nostdlib -lgcc -Bdynamic -lc"
  13. CC=$(TOOLCHAINS_PREFIX)-gcc --sysroot=$(SYSROOT)
  14. LD=$(TOOLCHAINS_PREFIX)-ld
  15. libtime.so: main.o
  16. $(LD) $(LDFLAGS) main.o -o libtime.so -L/home/wanjm/code/binary/elib -lavformat -lavutil -lavcodec -lswscale -lavutil -lx264 -L$(TOOLCHAINS_ROOT)/lib/gcc/arm-linux-androideabi/$(VERSION) -lgcc
  17. cp libtime.so ../libs/armeabi
  18. main.o: VideoEncoder.c
  19. $(CC) -c VideoEncoder.c -o main.o -I/home/wanjm/code/ffmpeg-1.2.4
  20. clean:
  21. rm -rf libtime.so
  22. rm main.o

一步到位的ffmpeg+x264 for android 的编译;
1. 建立目录android,其下放置解压的ffmpeg和x264源码目录;建立install 目录,和make目录;
2. 在make中创建build.sh; 注意此处用的是相对目录,所以只能在make目录下运行;

点击(此处)折叠或打开

  1. #!/bin/bash
  2. export VERSION=4.6
  3. export NDK=/opt/google/android-ndk-r9b
  4. export PREBUILT=$NDK/toolchains/arm-linux-androideabi-$VERSION/prebuilt/linux-x86_64
  5. export PLATFORM=$NDK/platforms/android-9/arch-arm
  6. export FFMPEG_ROOT=../ffmpeg-1.2.4
  7. export X264_ROOT=../x264 #上面的x264的源码目录
  8. export PREFIX=../install
  9. export ELIB="$PREFIX/lib"
  10. export FAAC_ROOT=../faac-1.28
  11. function build_x264
  12. {
  13. cd $X264_ROOT
  14. pwd
  15. ./configure --enable-static \
  16. --prefix=$PREFIX \
  17. --enable-shared \
  18. --enable-pic \
  19. --disable-asm \
  20. --disable-cli \
  21. --host=arm-linux \
  22. --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
  23. --sysroot=$PLATFORM
  24. make
  25. cp libx264.a $ELIB
  26. cd -
  27. }
  28. function build_faac
  29. {
  30. cd $FAAC_ROOT
  31. pwd
  32. CFLAGS="-fpic -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID -Wa,--noexecstack -MMD -MP "
  33. #FLAGS="--host=arm-androideabi-linux --enable-static --disable-shared --prefix=$HOME --enable-armv5e "
  34. CROSS_COMPILE=$PREBUILT/bin/arm-linux-androideabi-
  35. export CPPFLAGS="$CFLAGS"
  36. export CFLAGS="$CFLAGS"
  37. export CXXFLAGS="$CFLAGS"
  38. export CXX="${CROSS_COMPILE}g++ --sysroot=${PLATFORM}"
  39. export LDFLAGS="$LDFLAGS"
  40. export CC="${CROSS_COMPILE}gcc --sysroot=${PLATFORM}"
  41. export NM="${CROSS_COMPILE}nm"
  42. export STRIP="${CROSS_COMPILE}strip"
  43. export RANLIB="${CROSS_COMPILE}ranlib"
  44. export AR="${CROSS_COMPILE}ar"
  45. ./configure --program-prefix=$PREFIX \
  46. --host=arm-linux
  47. make
  48. cp ./libfaac/.libs/libfaac.a $ELIB
  49. cd -
  50. }
  51. function build_one
  52. {
  53. $FFMPEG_ROOT/configure --target-os=linux \
  54. --prefix=$PREFIX \
  55. --enable-cross-compile \
  56. --enable-runtime-cpudetect \
  57. --disable-asm \
  58. --arch=arm \
  59. --cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
  60. --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
  61. --disable-stripping \
  62. --nm=$PREBUILT/bin/arm-linux-androideabi-nm \
  63. --sysroot=$PLATFORM \
  64. --enable-nonfree \
  65. --enable-version3 \
  66. --enable-gpl \
  67. --disable-doc \
  68. --enable-avresample \
  69. --enable-demuxer=rtsp \
  70. --enable-muxer=rtsp \
  71. --disable-ffplay \
  72. --disable-ffserver \
  73. --enable-ffmpeg \
  74. --disable-ffprobe \
  75. --enable-libx264 \
  76. --enable-libfaac --enable-nonfree \
  77. --enable-encoder=libx264 \
  78. --enable-decoder=h264 \
  79. --enable-protocol=rtp \
  80. --enable-encoder=libfaac \
  81. --enable-decoder=aac \
  82. --enable-hwaccels \
  83. --enable-zlib \
  84. --disable-devices \
  85. --disable-avdevice \
  86. --extra-cflags="-I$X264_ROOT -I$FAAC_ROOT/include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \
  87. --extra-ldflags="-L$ELIB"
  88. make -j4
  89. make install
  90. }
  91. mkdir -p $ELIB
  92. build_faac
  93. build_x264
  94. build_one

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐