arthenica / ffmpeg-kit

FFmpeg Kit for applications. Supports Android, Flutter, iOS, Linux, macOS, React Native and tvOS. Supersedes MobileFFmpeg, flutter_ffmpeg and react-native-ffmpeg.
https://arthenica.github.io/ffmpeg-kit
GNU Lesser General Public License v3.0
4.57k stars 611 forks source link

android.sh fails with NDK r26 or above #1076

Open srcejon opened 1 day ago

srcejon commented 1 day ago

android.sh fails with NDK r26 or above.

Error in build.log is:

/home/me/Android/Sdk/ndk/28.0.12674087/build/core/build-binary.mk:591: Android NDK: Module ffmpegkit depends on undefined modules: c++_shared    
/home/me/Android/Sdk/ndk/28.0.12674087/build/core/build-binary.mk:604: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies.

It seems to be caused by the following lines in android/jni/Android.mk:

ifeq ($(APP_STL), c++_shared)
    LOCAL_SHARED_LIBRARIES += c++_shared # otherwise NDK will not add the library for packaging
endif

If I comment that out, then it builds OK. (That may break builds with older NDKs - r25 seems ok without it)

Next problem is:

jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_mux_init.c:294:55: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
    { ENC_STATS_FRAME_NUM_IN,   "ni",       0, 0, 1         },

Presumably this can be fixed with:

+++ b/android/ffmpeg-kit-android-lib/src/main/cpp/fftools_ffmpeg_mux_init.c @@ -284,9 +284,9 @@ static int enc_stats_init(OutputStream ost, EncStats es, int pre, static const struct { enum EncStatsType type; const char *str;

Environment

juha-h commented 16 hours ago

My ffmpeg build works fine with latest NDK r27 and ffmpeg-kit development branch:

$ make ffmpeg
rm -rf /usr/src/libbaresip-android/ffmpeg-kit/prebuilt/android-arm64-28 && \
cd ffmpeg-kit && \
ANDROID_SDK_ROOT=/foo/bar \
ANDROID_NDK_ROOT=/opt/Android/ndk/27.2.12479018 \
./android.sh --api-level=28 --enable-gpl --no-archive \
    --disable-arm-v7a --disable-x86-64 --disable-arm-v7a-neon --disable-x86 \
    --enable-android-media-codec \
    --enable-x264 --enable-libaom --enable-libvpx \
    --enable-libpng --skip-ffmpeg-kit

Building ffmpeg-kit library for Android

Architectures: arm64-v8a
Libraries: android-zlib, android-media-codec, libvpx, x264, libaom

Downloading sources: ok

Building arm64-v8a platform on API level 28

x264: ok
libaom: ok
libpng: ok
cpu-features: ok
libvpx: ok

ffmpeg: ok

ffmpeg-kit: skipped

Makefile is available here: https://github.com/juha-h/libbaresip-android (video branch).

srcejon commented 16 hours ago

You probably don't see the second problem as you are using --skip-ffmpeg-kit

juha-h commented 16 hours ago

srcejon writes:

You probably don't see the second problem as you are using --skip-ffmpeg-kit

Correct, I skip it, since I only use the libs.

juha-h commented 16 hours ago

I enabled ffmpeg-kit and then the build failed:

[arm64-v8a] Compile        : ffmpegkit <= fftools_ffprobe.c
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:2868:31: error: unknown type name 'AVHDRVivid3SplineParams'
 2868 |                         const AVHDRVivid3SplineParams *three_spline =
      |                               ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:2869:41: error: no member named 'three_spline' in 'struct AVHDRVividColorToneMappingParams'
 2869 |                             &tm_params->three_spline[j];
      |                              ~~~~~~~~~  ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:3314:46: error: use of undeclared identifier 'AV_FRAME_FLAG_KEY'
 3314 |     print_int("key_frame", !!(frame->flags & AV_FRAME_FLAG_KEY));
      |                                              ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:3368:37: error: use of undeclared identifier 'AV_FRAME_FLAG_INTERLACED'
 3368 |                   !!(frame->flags & AV_FRAME_FLAG_INTERLACED));
      |                                     ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:3370:37: error: use of undeclared identifier 'AV_FRAME_FLAG_TOP_FIELD_FIRST'
 3370 |                   !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
      |                                     ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:3691:29: error: use of undeclared identifier 'AV_PROFILE_UNKNOWN'; did you mean 'AV_FIELD_UNKNOWN'?
 3691 |         if (par->profile != AV_PROFILE_UNKNOWN) {
      |                             ^~~~~~~~~~~~~~~~~~
      |                             AV_FIELD_UNKNOWN
jni/ffmpeg/../../../prebuilt/android-arm64-28/ffmpeg/lib/../include/libavcodec/codec_par.h:39:5: note: 'AV_FIELD_UNKNOWN' declared here
   39 |     AV_FIELD_UNKNOWN,
      |     ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:3886:27: error: no member named 'nb_coded_side_data' in 'struct AVCodecParameters'
 3886 |     if (stream->codecpar->nb_coded_side_data) {
      |         ~~~~~~~~~~~~~~~~  ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:3888:47: error: no member named 'nb_coded_side_data' in 'struct AVCodecParameters'
 3888 |         for (int i = 0; i < stream->codecpar->nb_coded_side_data; i++) {
      |                             ~~~~~~~~~~~~~~~~  ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/fftools_ffprobe.c:3890:52: error: no member named 'coded_side_data' in 'struct AVCodecParameters'
 3890 |                                 &stream->codecpar->coded_side_data[i],
      |                                  ~~~~~~~~~~~~~~~~  ^
9 errors generated.