diff --git a/app/build.gradle b/app/build.gradle index 9b22ab7..60d147d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,5 +32,6 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' implementation project(path: ':library') +// implementation 'com.github.xch168:ffmpeg-invoker:0.0.1' } diff --git a/build_ffmpeg.sh b/build_ffmpeg.sh index 2599616..bb289b0 100755 --- a/build_ffmpeg.sh +++ b/build_ffmpeg.sh @@ -21,25 +21,25 @@ HOST_PLATFORM="darwin-x86_64" TOOLCHAIN_PREFIX="${NDK_PATH}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin" ENABLED_ENCODERS=(h264 png) -ENABLED_DECODERS=(h264 png) +ENABLED_DECODERS=(h264 mpeg4 png) ENABLED_MUXERS=(h264 mp4 3gp webm matroska avi image2) ENABLED_DEMUXERS=(webm matroska concat) ENABLED_PROTOCOLS=(file) +ENABLED_FILTERS=(scale) COMMON_OPTIONS=" --target-os=android - --disable-static - --enable-shared + --enable-static + --disable-shared --disable-doc + --disable-everything --disable-programs + --disable-protocols + --disable-parsers --disable-avdevice --disable-postproc --disable-symver - --enable-swscale - --enable-avformat - --enable-avfilter - --enable-avresample - --enable-swresample + --disable-debug " for encoder in "${ENABLED_ENCODERS[@]}" @@ -62,9 +62,13 @@ for protocol in "${ENABLED_PROTOCOLS[@]}" do COMMON_OPTIONS="${COMMON_OPTIONS} --enable-protocol=${protocol}" done +for filter in "${ENABLED_FILTERS[@]}" +do + COMMON_OPTIONS="${COMMON_OPTIONS} --enable-filter=${filter}" +done -cd "${FFMPEG_EXT_PATH}" -(git -C ffmpeg pull || git clone git://source.ffmpeg.org/ffmpeg ffmpeg) +cd "${FFMPEG_PATH}" +# (git -C ffmpeg pull || git clone git://source.ffmpeg.org/ffmpeg ffmpeg) cd ffmpeg git checkout release/4.2 @@ -73,15 +77,37 @@ git checkout release/4.2 --prefix=android-libs/armeabi-v7a \ --arch=arm \ --cpu=armv7-a \ - --cross-prefix="${TOOLCHAIN_PREFIX}/armv7a-linux-androideabi16-" \ + --cross-prefix="${TOOLCHAIN_PREFIX}/arm-linux-androideabi-" \ --nm="${TOOLCHAIN_PREFIX}/arm-linux-androideabi-nm" \ - --strip="${TOOLCHAIN_PREFIX}/arm-linux-androideabi-strip" \ + --cc="${TOOLCHAIN_PREFIX}/armv7a-linux-androideabi16-clang" \ + --ar="${TOOLCHAIN_PREFIX}/arm-linux-androideabi-ar" \ --extra-cflags="-march=armv7-a -mfloat-abi=softfp" \ --extra-ldflags="-Wl,--fix-cortex-a8" \ --extra-ldexeflags=-pie \ ${COMMON_OPTIONS} make -j4 make install + +SYSROOT="${NDK_PATH}/platforms/android-16/arch-arm" +PREFIX="$(pwd)/android-libs/armeabi-v7a" + +# 打包 +${TOOLCHAIN_PREFIX}/arm-linux-androideabi-ld \ + -rpath-link=$SYSROOT/usr/lib \ + -L$SYSROOT/usr/lib \ + -L$PREFIX/lib \ + -soname libffmpeg.so -shared -nostdlib -Bsymbolic --whole-archive --no-undefined -o \ + $PREFIX/libffmpeg.so \ + libavcodec/libavcodec.a \ + libavfilter/libavfilter.a \ + libavformat/libavformat.a \ + libavutil/libavutil.a \ + libswresample/libswresample.a \ + libswscale/libswscale.a \ + -lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker \ + ${NDK_PATH}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/lib/gcc/arm-linux-androideabi/4.9.x/libgcc_real.a \ + +${TOOLCHAIN_PREFIX}/arm-linux-androideabi-strip $PREFIX/libffmpeg.so make clean # arm64-v8a @@ -89,13 +115,35 @@ make clean --prefix=android-libs/arm64-v8a \ --arch=aarch64 \ --cpu=armv8-a \ - --cross-prefix="${TOOLCHAIN_PREFIX}/aarch64-linux-android21-" \ + --cross-prefix="${TOOLCHAIN_PREFIX}/aarch64-linux-android-" \ --nm="${TOOLCHAIN_PREFIX}/aarch64-linux-android-nm" \ - --strip="${TOOLCHAIN_PREFIX}/aarch64-linux-android-strip" \ + --cc="${TOOLCHAIN_PREFIX}/aarch64-linux-android21-clang" \ + --ar="${TOOLCHAIN_PREFIX}/aarch64-linux-android-ar" \ --extra-ldexeflags=-pie \ ${COMMON_OPTIONS} -make -j4 +make -j8 make install + +SYSROOT="${NDK_PATH}/platforms/android-21/arch-arm64" +PREFIX="$(pwd)/android-libs/arm64-v8a" + + # 打包 +${TOOLCHAIN_PREFIX}/aarch64-linux-android-ld \ + -rpath-link=$SYSROOT/usr/lib \ + -L$SYSROOT/usr/lib \ + -L$PREFIX/lib \ + -soname libffmpeg.so -shared -nostdlib -Bsymbolic --whole-archive --no-undefined -o \ + $PREFIX/libffmpeg.so \ + libavcodec/libavcodec.a \ + libavfilter/libavfilter.a \ + libavformat/libavformat.a \ + libavutil/libavutil.a \ + libswresample/libswresample.a \ + libswscale/libswscale.a \ + -lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker \ + ${NDK_PATH}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/lib/gcc/aarch64-linux-android/4.9.x/libgcc_real.a \ + +${TOOLCHAIN_PREFIX}/aarch64-linux-android-strip $PREFIX/libffmpeg.so make clean # x86 @@ -103,12 +151,33 @@ make clean --prefix=android-libs/x86 \ --arch=x86 \ --cpu=i686 \ - --cross-prefix="${TOOLCHAIN_PREFIX}/i686-linux-android16-" \ + --cross-prefix="${TOOLCHAIN_PREFIX}/i686-linux-android-" \ --nm="${TOOLCHAIN_PREFIX}/i686-linux-android-nm" \ - --strip="${TOOLCHAIN_PREFIX}/i686-linux-android-strip" \ + --cc="${TOOLCHAIN_PREFIX}/i686-linux-android16-clang" \ + --ar="${TOOLCHAIN_PREFIX}/i686-linux-android-ar" \ --extra-ldexeflags=-pie \ --disable-asm \ ${COMMON_OPTIONS} make -j4 make install + +SYSROOT="${NDK_PATH}/platforms/android-16/arch-x86" +PREFIX="$(pwd)/android-libs/x86" + +${TOOLCHAIN_PREFIX}/i686-linux-android-ld \ + -rpath-link=$SYSROOT/usr/lib \ + -L$SYSROOT/usr/lib \ + -L$PREFIX/lib \ + -soname libffmpeg.so -shared -nostdlib -Bsymbolic --whole-archive --no-undefined -o \ + $PREFIX/libffmpeg.so \ + libavcodec/libavcodec.a \ + libavfilter/libavfilter.a \ + libavformat/libavformat.a \ + libavutil/libavutil.a \ + libswresample/libswresample.a \ + libswscale/libswscale.a \ + -lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker \ + ${NDK_PATH}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/lib/gcc/i686-linux-android/4.9.x/libgcc_real.a \ + +${TOOLCHAIN_PREFIX}/i686-linux-android-strip $PREFIX/libffmpeg.so make clean diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index bdecf96..e7e7481 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -24,81 +24,22 @@ add_library( ffmpeg-invoker # 库名称 SHARED # 库类型 ${SRC}) # 编译进库的源码) -# 添加libavcodec.so库 -add_library( avcodec +# 添加libffmpeg.so库 +add_library( ffmpeg SHARED IMPORTED ) -# 指定libavcodec.so库的位置 -set_target_properties( avcodec +# 指定libffmpeg.so库的位置 +set_target_properties( ffmpeg PROPERTIES IMPORTED_LOCATION - ${distribution_DIR}/libavcodec.so ) + ${distribution_DIR}/libffmpeg.so ) -# libavfilter.so库 -add_library( avfilter - SHARED - IMPORTED ) -# libavfilter.so库的位置 -set_target_properties( avfilter - PROPERTIES IMPORTED_LOCATION - ${distribution_DIR}/libavfilter.so ) - -# 添加libavformat.so库 -add_library( avformat - SHARED - IMPORTED ) -# 指定libavformat.so库的位置 -set_target_properties( avformat - PROPERTIES IMPORTED_LOCATION - ${distribution_DIR}/libavformat.so ) - -# 添加libavresample.so库 -add_library( avresample - SHARED - IMPORTED ) -# 指定libavresample.so库的位置 -set_target_properties( avresample - PROPERTIES IMPORTED_LOCATION - ${distribution_DIR}/libavresample.so ) - -# libavutil.so库 -add_library( avutil - SHARED - IMPORTED ) -# 指定libavutil.so库的位置 -set_target_properties( avutil - PROPERTIES IMPORTED_LOCATION - ${distribution_DIR}/libavutil.so ) - -# libswresample.so库 -add_library( swresample - SHARED - IMPORTED ) -# 指定libswresample.so库的位置 -set_target_properties( swresample - PROPERTIES IMPORTED_LOCATION - ${distribution_DIR}/libswresample.so ) - -# libswscale.so库 -add_library( swscale - SHARED - IMPORTED ) -# 指定libswscale.so库的位置 -set_target_properties( swscale - PROPERTIES IMPORTED_LOCATION - ${distribution_DIR}/libswscale.so ) find_library( log-lib log ) target_link_libraries( ffmpeg-invoker - avcodec - avfilter - avformat - avresample - swresample - swscale - avutil + ffmpeg -landroid # native_window -ljnigraphics # bitmap -lOpenSLES # openSLES diff --git a/library/libs/arm64-v8a/libavcodec.so b/library/libs/arm64-v8a/libavcodec.so deleted file mode 100755 index 96c5706..0000000 Binary files a/library/libs/arm64-v8a/libavcodec.so and /dev/null differ diff --git a/library/libs/arm64-v8a/libavfilter.so b/library/libs/arm64-v8a/libavfilter.so deleted file mode 100755 index f4b8ae4..0000000 Binary files a/library/libs/arm64-v8a/libavfilter.so and /dev/null differ diff --git a/library/libs/arm64-v8a/libavformat.so b/library/libs/arm64-v8a/libavformat.so deleted file mode 100755 index 3fe585e..0000000 Binary files a/library/libs/arm64-v8a/libavformat.so and /dev/null differ diff --git a/library/libs/arm64-v8a/libavresample.so b/library/libs/arm64-v8a/libavresample.so deleted file mode 100755 index 6e764a2..0000000 Binary files a/library/libs/arm64-v8a/libavresample.so and /dev/null differ diff --git a/library/libs/arm64-v8a/libavutil.so b/library/libs/arm64-v8a/libavutil.so deleted file mode 100755 index bf8b1a0..0000000 Binary files a/library/libs/arm64-v8a/libavutil.so and /dev/null differ diff --git a/library/libs/arm64-v8a/libffmpeg.so b/library/libs/arm64-v8a/libffmpeg.so new file mode 100755 index 0000000..8c4add2 Binary files /dev/null and b/library/libs/arm64-v8a/libffmpeg.so differ diff --git a/library/libs/arm64-v8a/libswresample.so b/library/libs/arm64-v8a/libswresample.so deleted file mode 100755 index eebf1c4..0000000 Binary files a/library/libs/arm64-v8a/libswresample.so and /dev/null differ diff --git a/library/libs/arm64-v8a/libswscale.so b/library/libs/arm64-v8a/libswscale.so deleted file mode 100755 index f1609d0..0000000 Binary files a/library/libs/arm64-v8a/libswscale.so and /dev/null differ diff --git a/library/libs/armeabi-v7a/libavcodec.so b/library/libs/armeabi-v7a/libavcodec.so deleted file mode 100755 index d6b9bfd..0000000 Binary files a/library/libs/armeabi-v7a/libavcodec.so and /dev/null differ diff --git a/library/libs/armeabi-v7a/libavfilter.so b/library/libs/armeabi-v7a/libavfilter.so deleted file mode 100755 index e3acf1c..0000000 Binary files a/library/libs/armeabi-v7a/libavfilter.so and /dev/null differ diff --git a/library/libs/armeabi-v7a/libavformat.so b/library/libs/armeabi-v7a/libavformat.so deleted file mode 100755 index e725906..0000000 Binary files a/library/libs/armeabi-v7a/libavformat.so and /dev/null differ diff --git a/library/libs/armeabi-v7a/libavresample.so b/library/libs/armeabi-v7a/libavresample.so deleted file mode 100755 index 7eecc28..0000000 Binary files a/library/libs/armeabi-v7a/libavresample.so and /dev/null differ diff --git a/library/libs/armeabi-v7a/libavutil.so b/library/libs/armeabi-v7a/libavutil.so deleted file mode 100755 index 3b970e2..0000000 Binary files a/library/libs/armeabi-v7a/libavutil.so and /dev/null differ diff --git a/library/libs/armeabi-v7a/libffmpeg.so b/library/libs/armeabi-v7a/libffmpeg.so new file mode 100755 index 0000000..2674c23 Binary files /dev/null and b/library/libs/armeabi-v7a/libffmpeg.so differ diff --git a/library/libs/armeabi-v7a/libswresample.so b/library/libs/armeabi-v7a/libswresample.so deleted file mode 100755 index 1560c0c..0000000 Binary files a/library/libs/armeabi-v7a/libswresample.so and /dev/null differ diff --git a/library/libs/armeabi-v7a/libswscale.so b/library/libs/armeabi-v7a/libswscale.so deleted file mode 100755 index b8adf60..0000000 Binary files a/library/libs/armeabi-v7a/libswscale.so and /dev/null differ diff --git a/library/libs/x86/libavcodec.so b/library/libs/x86/libavcodec.so deleted file mode 100755 index 492cda4..0000000 Binary files a/library/libs/x86/libavcodec.so and /dev/null differ diff --git a/library/libs/x86/libavfilter.so b/library/libs/x86/libavfilter.so deleted file mode 100755 index fd8983c..0000000 Binary files a/library/libs/x86/libavfilter.so and /dev/null differ diff --git a/library/libs/x86/libavformat.so b/library/libs/x86/libavformat.so deleted file mode 100755 index 5657b70..0000000 Binary files a/library/libs/x86/libavformat.so and /dev/null differ diff --git a/library/libs/x86/libavresample.so b/library/libs/x86/libavresample.so deleted file mode 100755 index b8a41b1..0000000 Binary files a/library/libs/x86/libavresample.so and /dev/null differ diff --git a/library/libs/x86/libavutil.so b/library/libs/x86/libavutil.so deleted file mode 100755 index 43b4cda..0000000 Binary files a/library/libs/x86/libavutil.so and /dev/null differ diff --git a/library/libs/x86/libffmpeg.so b/library/libs/x86/libffmpeg.so new file mode 100755 index 0000000..20a2d2d Binary files /dev/null and b/library/libs/x86/libffmpeg.so differ diff --git a/library/libs/x86/libswresample.so b/library/libs/x86/libswresample.so deleted file mode 100755 index 55399e9..0000000 Binary files a/library/libs/x86/libswresample.so and /dev/null differ diff --git a/library/libs/x86/libswscale.so b/library/libs/x86/libswscale.so deleted file mode 100755 index 0d4b6e9..0000000 Binary files a/library/libs/x86/libswscale.so and /dev/null differ diff --git a/library/src/main/cpp/ffmpeg/cmdutils.c b/library/src/main/cpp/ffmpeg/cmdutils.c index 147a55b..2b9df33 100644 --- a/library/src/main/cpp/ffmpeg/cmdutils.c +++ b/library/src/main/cpp/ffmpeg/cmdutils.c @@ -556,7 +556,7 @@ int opt_default(void *optctx, const char *opt, const char *arg) const char *p; const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(); #if CONFIG_AVRESAMPLE - const AVClass *rc = avresample_get_class(); +// const AVClass *rc = avresample_get_class(); #endif #if CONFIG_SWSCALE const AVClass *sc = sws_get_class(); @@ -628,11 +628,11 @@ int opt_default(void *optctx, const char *opt, const char *arg) } #endif #if CONFIG_AVRESAMPLE - if ((o=opt_find(&rc, opt, NULL, 0, - AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { - av_dict_set(&resample_opts, opt, arg, FLAGS); - consumed = 1; - } +// if ((o=opt_find(&rc, opt, NULL, 0, +// AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { +// av_dict_set(&resample_opts, opt, arg, FLAGS); +// consumed = 1; +// } #endif if (consumed) @@ -1137,7 +1137,7 @@ static void print_all_libs_info(int flags, int level) PRINT_LIB_INFO(avformat, AVFORMAT, flags, level); PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level); PRINT_LIB_INFO(avfilter, AVFILTER, flags, level); - PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level); +// PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level); PRINT_LIB_INFO(swscale, SWSCALE, flags, level); PRINT_LIB_INFO(swresample, SWRESAMPLE, flags, level); PRINT_LIB_INFO(postproc, POSTPROC, flags, level); diff --git a/library/src/main/cpp/include/libavutil/parseutils.h b/library/src/main/cpp/include/libavutil/parseutils.h index ad29631..e66d24b 100644 --- a/library/src/main/cpp/include/libavutil/parseutils.h +++ b/library/src/main/cpp/include/libavutil/parseutils.h @@ -19,7 +19,7 @@ #ifndef AVUTIL_PARSEUTILS_H #define AVUTIL_PARSEUTILS_H -#include "time.h" +#include #include "rational.h"