Skip to content

Instantly share code, notes, and snippets.

@vxhviet
Last active January 11, 2019 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vxhviet/0a4e48f903bf9b99a7bd7fbb61a206eb to your computer and use it in GitHub Desktop.
Save vxhviet/0a4e48f903bf9b99a7bd7fbb61a206eb to your computer and use it in GitHub Desktop.
How to use FFmpeg built by VPlayer in Android Studio?

Source: GitHub

Question: How to use FFmpeg built by VPlayer (version 0.3.2 at the time I write this Gist) in Android Studio?

Answer This will take the FFmpeg built from here and use it as a library for our project in Android Stuio in Window 10.

  1. Download NDK from here, uncompress it to anywhere you want (C:\Users\Viet\AppData\Local\Android\ndk\android-ndk-r11c in my case).
  2. Copy the whole VPlayer_lib folder build from here into the root of your project.
  3. In Android studio, click on app -> F4 -> SDK Location -> Android NDK location.
  4. Edit/create gradle.properties file in the root folder of your project with android.useDeprecatedNdk=true.
  5. Edit your project's settings.gradle and add these two lines at the bottom
include ':VPlayer_library'
project(':VPlayer_library').projectDir = new File(settingsDir, 'VPlayer_lib/VPlayer_library')
  1. Edit your application's build.gradle file to add the dependency by adding this:
dependencies {
 ...
 compile project(':VPlayer_library')
 ...
}
  1. After synchronizing your project, follow the below instructions to resolve the errors related to this project in Android Studio.
  2. Get the dependencies: tropicssl, ffmpeg (headers only) and libyuv (DO ONE of the following):
  • Unzip and extract the dependencies to VPlayer_lib folder (this should add folders to VPlayer_library/jni/)
  • OR Run the script /{root}/VPlayer_lib/VPlayer_library/jni/setup.sh.

Your folder structure should look like this under /jni

jni/
|- android-ndk-profiler-3.1/
|- application/
|- ffmpeg/
|- ffmpeg-build/
|- libyuv/
|- tropicssl/
|- Android.mk
|- Android-tropicssl.mk
|- Application.mk
|- setup.sh
  1. [Optional] Edit the Application.mk to change architectures.
  2. [Optional] Edit the Android.mk:
  • FEATURE_NEON: if you comment this, you need to remove NativeTester code in VPlayerController.java@LINE292. (leave this)
  • SUBTITLES: remove if you do not want subtitle support; if you download the binaries or built one without subtitles you must comment this out. (temporrary leave this as our FFmpeg come with subtitle, need to update it to a version without subtitles).
  • MODULE_ENCRYPT: remove if you do not want encryption for networking. (comment out)
  • LIBRARY_PROFILER: remove if you do not want the profiler. (leave this, I dont even know what this is).
  1. If you get a Are you sure your NDK_MODULE_PATH variable is properly defined ? error, add the following to Android.mk:
...
$(call import-add-path,C:\Users\Viet\AppData\Local\Android\ndk\android-ndk-r11c\sources\android)
$(call import-module,cpufeatures)

of course this will need to be your path to the NDK, TRIPLE CHECK it don't be lazy.

  1. If the build fail because gradle heap size too small try uncomment this line in the project's gradle.properties:

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

  1. Another possible error you may encouter is UnsatisfiedLinkError, libffmpeg-neon.so: has text relocations. Temporary solution is to change the targetSDK of your app to anything smaller than 23.
@surent15
Copy link

I hv done all the steps u explained but i face this problem can u help me? Android NDK: ERROR:jni/Android.mk:ffmpeg-prebuilt: LOCAL_SRC_FILES points to a missing file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment