0

I came here to ask the experts. I'm working on an Android app that needs to capture camera preview frames from the NDK, for that I want to use OpenCV's VideoCapture (I properly integrated OpenCV with the NDK). The problem is that OpenCV's VideoCapture wont work on Android NDK since it has no backend, (Unable to read videos and start camera preview, VideoCapture.open(...) returns always false). So here I decided to use FFMPEG as the backend for capturing videos with OpenCV. I searched the web and found many tutorials that explain how to integrate FFMPEG with Android NDK, and I followed every one of them. The problem is that all what I've tried so far brought me to the same place, in which I get stuck with an error that completely blocks the entire process.

More Details:

I followed this tutorial for compiling FFMPEG for Android.

In order to build FFMPEG (before the part of linking it with Android NDK), I have to run a shell script that compiles the libraries to be linked with the project. When i just run the script i get this error:

[1268:0414/153141.454:ERROR:gpu_init.cc(454)] Passthrough is not supported, GL is disabled, ANGLE is

I searched the web about it and found many suggestions, most of them like this one suggest to enable WebGL. I checked it and made sure WebGL is enabled across all web browsers. But the error persists.

Screenshot:

enter image description here

build_script.sh:

#!/bin/bash
if [ -z "$ANDROID_NDK" ]; then
  echo "Please set ANDROID_NDK to the Android NDK folder"
  exit 1
fi

#Change to your local machine's architecture
HOST_OS_ARCH=windows-x86_64

function configure_ffmpeg {

  ABI=$1
  PLATFORM_VERSION=$2
  TOOLCHAIN_PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/${HOST_OS_ARCH}/bin
  local STRIP_COMMAND

  # Determine the architecture specific options to use
  case ${ABI} in
  armeabi-v7a)
    TOOLCHAIN_PREFIX=armv7a-linux-androideabi
    STRIP_COMMAND=arm-linux-androideabi-strip
    ARCH=armv7-a
    ;;
  arm64-v8a)
    TOOLCHAIN_PREFIX=aarch64-linux-android
    ARCH=aarch64
    ;;
  x86)
    TOOLCHAIN_PREFIX=i686-linux-android
    ARCH=x86
    EXTRA_CONFIG="--disable-asm"
    ;;
  x86_64)
    TOOLCHAIN_PREFIX=x86_64-linux-android
    ARCH=x86_64
    EXTRA_CONFIG="--disable-asm"
    ;;
  esac

  if [ -z ${STRIP_COMMAND} ]; then
    STRIP_COMMAND=${TOOLCHAIN_PREFIX}-strip
  fi

  echo "Configuring FFmpeg build for ${ABI}"
  echo "Toolchain path ${TOOLCHAIN_PATH}"
  echo "Command prefix ${TOOLCHAIN_PREFIX}"
  echo "Strip command ${STRIP_COMMAND}"

  ./configure \
  --prefix=build/${ABI} \ # The path where the resulting libraries and headers will be installed after `make install` is run. The resulting directory structure is "build/{armeabi-v7a,arm64-v8a,x86,x86_64}/{include, lib}".
  --target-os=android \ # Target operating system name.
  --arch=${ARCH} \ # Target CPU architecture e.g. armv7-a.
  --enable-cross-compile \ # We are compiling for a different target architecture than the host.
  --cc=${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}${PLATFORM_VERSION}-clang \ # Path to the C compiler. In our case we're using clang. 
  --strip=${TOOLCHAIN_PATH}/${STRIP_COMMAND} \ # Path to the strip binary for our target architecture.
  --enable-small \ # Optimize for size instead of speed.
  --disable-programs \ # Do not build command line programs. We don't need them as our app will be interacting with the FFmpeg API. 
  --disable-doc \ # Do not build documentation.
  --enable-shared \ # Build shared libraries. We'll keep the FFmpeg .so files separate from our main shared library.
  --disable-static \ # Do not build static libraries.
  ${EXTRA_CONFIG} \
  --disable-everything \ # Disable all modules. To keep the library size to a minimum we will explicitly specify the modules to be built below.
  --enable-decoder=mp3 \ # Enable the MP3 decoder. For a list of supported decoders type ./configure --help.
  --enable-demuxer=mp3 # Enable the MP3 demuxer. For a list of supported demuxers type ./configure --help.

  return $?
}

function build_ffmpeg {

  configure_ffmpeg $1 $2

  if [ $? -eq 0 ]
  then
          make clean
          make -j12
          make install
  else
          echo "FFmpeg configuration failed, please check the error log."
  fi
}

build_ffmpeg armeabi-v7a 16
build_ffmpeg arm64-v8a 21
build_ffmpeg x86 16
build_ffmpeg x86_64 21

I searched the entire web for a solution, but found that no one is talking about this error in the context of integrating FFMPEG with android, so I've no idea how to solve this problem. Am I missing something or what?

Versions:

Android studio 4.0.0
OpenCV 4.0.1
Windows 10 (x86_64)
Cloned the latest FFMPEG source code by running command git clone git://source.ffmpeg.org/ffmpeg.git under D:\Develop.

Thanks for reading this question so far, helpful ideas will be warmly welcomed.

Daniel Rotnemer
  • 107
  • 3
  • 12
  • 1
    Have you looked into [`ffmpeg-android-maker` project](https://github.com/Javernaut/ffmpeg-android-maker)? I found it linked from FFmpeg Wiki and is still active. The repo owner also has a few Medium posts relating to it. (The issue appears to be related to including necessarily hardware components, but that's beyond anything I know much of.) – kesh Apr 14 '22 at 15:15
  • @kesh Nice explanation, but the error is still there. – Daniel Rotnemer Apr 16 '22 at 22:29

0 Answers0