| # From Eclipse create a new Android project. |
| 1. Create new "Android Application Project" |
| 2. Fill Application Name with "Test WebM JNI". Project Name will be "TestWebMJNI". Package Name will be "com.example.testwebmjni". |
| 3. [optional] You can change the Minimum required SDK to what your application needs. |
| 4. Click Next button on the Configure Project screen. |
| 5. Click Next on the Icon screen. |
| 6. Click Next on the Create Activity screen. |
| 7. Click Finish on the Blank Activity screen. |
| |
| # Add the JNI code. |
| 8. Create <project>/jni folder. |
| |
| # Get JNI bindings |
| 9. git clone https://chromium.googlesource.com/webm/bindings |
| |
| # Get libvpx |
| 10. git clone https://chromium.googlesource.com/webm/libvpx |
| |
| 11. cd bindings/JNI |
| |
| # Get libwebm |
| 12. git clone https://chromium.googlesource.com/webm/libwebm |
| |
| # Get libogg |
| 13. Download ogg code from https://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.xz |
| 14. extract to bindings/JNI |
| |
| # We need to run configure to generate config_types.h. |
| 15. cd libogg-1.3.0 && ./configure && cd .. |
| |
| # Get libvorbis |
| 16. Download vorbis code from https://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.xz |
| 17. extract to bindings/JNI |
| |
| # Get libyuv |
| 18. git clone https://chromium.googlesource.com/libyuv/libyuv |
| |
| 19. cd ../.. |
| |
| 20. Create <project>/jni/Application.mk with the data below: |
| APP_ABI := armeabi-v7a |
| APP_OPTIM := release |
| APP_STL := gnustl_static |
| APP_CPPFLAGS := -frtti |
| |
| 21. Create <project>/jni/Android.mk with the data below: |
| WORKING_DIR := $(call my-dir) |
| BINDINGS_DIR := $(WORKING_DIR)/bindings/JNI |
| include $(BINDINGS_DIR)/Android.mk |
| |
| # Configure libvpx for Android |
| 22. ./libvpx/configure --target=armv7-android-gcc --disable-examples \ |
| --enable-external-build --sdk-path=<full path to NDK>/android-ndk/ |
| |
| # Build the JNI code. |
| 23. ndk-build |
| |
| # Copy the java code. |
| 24. cp -R bindings/JNI/com/google ../src/com/ |
| |
| # Adding code to test the bindings. |
| 25. Change MainActivity.java onCreate to: |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| int[] major = new int[2]; |
| int[] minor = new int[2]; |
| int[] build = new int[2]; |
| int[] revision = new int[2]; |
| MkvMuxer.getVersion(major, minor, build, revision); |
| String outStr = "libwebm:" + Integer.toString(major[0]) + "." + |
| Integer.toString(minor[0]) + "." + Integer.toString(build[0]) + "." + |
| Integer.toString(revision[0]); |
| TextView tv = new TextView(this); |
| tv.setText(outStr); |
| setContentView(tv); |
| } |
| |
| 26. Run the app. You should see libwebm version output. |
| |
| # Test encoding audio and video |
| 27. Copy raw I420 y4m file and a Raw PCM Wav file to ExternalStorage on the device. |
| |
| 28. Add "<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />" to AndroidManifest.xml. |
| |
| # Copy example code. |
| 29. cp bindings/JNI/examples/EncodeY4mWavExample.java ../src/com/example/testwebmjni/ |
| 30. Add "package com.example.testwebmjni;" to the top of EncodeY4mWavExample.java. |
| |
| 31. Change MainActivity.java onCreate to: |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| String storageDir = Environment.getExternalStorageDirectory().getAbsolutePath(); |
| String inputVideo = storageDir + "/<Y4M file>"; |
| String inputAudio = storageDir + "/<WAV file>"; |
| String outputWebM = storageDir + "/testjni.webm"; |
| StringBuilder error = new StringBuilder(); |
| String outStr = "\nencodeY4mWavExample(): "; |
| if (EncodeY4mWavExample.encodeY4mWavExample(inputVideo, inputAudio, outputWebM, 200, error)) { |
| outStr += " Success!"; |
| } else { |
| outStr += " Error: " + error.toString(); |
| } |
| TextView tv = new TextView(this); |
| tv.setText(outStr); |
| setContentView(tv); |
| } |
| |
| 32. Run the app. You should see output of "Success!". |
| 33. Playback "testjni.webm" on the device. |