diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 96cc43e..fb7f4a8 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,22 +1,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 616c4e3..338ecbd 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,8 +1,10 @@
+
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 7d1db63..62e9be7 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,8 +2,8 @@
-
-
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
index 7f68460..e497da9 100644
--- a/.idea/runConfigurations.xml
+++ b/.idea/runConfigurations.xml
@@ -3,6 +3,7 @@
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..6ac7d2f 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,5 +2,6 @@
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 44ba752..94082f3 100644
--- a/README.md
+++ b/README.md
@@ -2,26 +2,10 @@
## Description ##
-x264 jni for android
+x264 encoder to being using through jni in Android.
## Using ##
-* Make sure you have the jcenter repository included in the `build.gradle` file in the root of your project:
-
-```
-repositories {
- jcenter()
-}
-```
-
-* Include the following in your module's `build.gradle` file:
-
-```
-compile 'com.github.bakaoh:x264-android:X.X.X'
-```
-
-for the version X.X.X, see the project on [Bintray](https://bintray.com/bakaoh/maven/x264-android).
-
* Create `X264Encoder` and `X264Params`
```
@@ -59,26 +43,32 @@ if (encodedFrame.err == 0) {
## Build instructions ##
-* Set the following environment variable:
+* Download the [Android NDK][]:
+
+[Android NDK]: https://developer.android.com/tools/sdk/ndk/index.html
+* Set the following environment variables:
```
-X264_ANDROID_ROOT=""
+ANDROID_NDK_ROOT=""
+ANDROID_NDK_PLATFORM=""
+ANDROID_NDK_HOST=""
```
-* Download the [Android NDK][] and set its location in an environment variable:
-
-[Android NDK]: https://developer.android.com/tools/sdk/ndk/index.html
-
+** Example:
```
-NDK_PATH=""
+ANDROID_NDK_ROOT=/home/forlayo/android-ndk-r21e
+ANDROID_NDK_PLATFORM=android-21
+ANDROID_NDK_HOST=linux-x86_64
```
* Fetch and build libx264.
```
-cd "${X264_ANDROID_ROOT}/x264/src/main/cpp" && \
+cd "/x264-android/src/main/cpp" && \
git clone http://git.videolan.org/git/x264.git libx264 && \
+git checkout ae03d92b52bb7581df2e75d571989cb1ecd19cbd && \
./build_x264.sh
```
+You can use other commit of libx264, but its tested on provided one; which is the most actual at the momment of writting this.
* Open project in Android Studio to build the JNI native libraries.
diff --git a/build.gradle b/build.gradle
index f1af524..c011065 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,19 +1,19 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
buildscript {
repositories {
+ google()
jcenter()
+ maven { url "https://jitpack.io" }
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.2.2'
- classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
- classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
+ classpath 'com.android.tools.build:gradle:4.2.1'
}
}
allprojects {
repositories {
+ google()
jcenter()
+ maven { url "https://jitpack.io" }
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 04e285f..4d9ca16 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/x264-android/bintrayv1.gradle b/x264-android/bintrayv1.gradle
deleted file mode 100644
index 001fc2b..0000000
--- a/x264-android/bintrayv1.gradle
+++ /dev/null
@@ -1,59 +0,0 @@
-apply plugin: 'com.jfrog.bintray'
-
-version = libraryVersion
-
-if (project.hasProperty("android")) { // Android libraries
- task sourcesJar(type: Jar) {
- classifier = 'sources'
- from android.sourceSets.main.java.srcDirs
- }
-
- task javadoc(type: Javadoc) {
- source = android.sourceSets.main.java.srcDirs
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- }
-} else { // Java libraries
- task sourcesJar(type: Jar, dependsOn: classes) {
- classifier = 'sources'
- from sourceSets.main.allSource
- }
-}
-
-task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
-}
-
-artifacts {
- archives javadocJar
- archives sourcesJar
-}
-
-// Bintray
-Properties properties = new Properties()
-properties.load(project.rootProject.file('local.properties').newDataInputStream())
-
-bintray {
- user = properties.getProperty("bintray.user")
- key = properties.getProperty("bintray.apikey")
-
- configurations = ['archives']
- pkg {
- repo = bintrayRepo
- name = bintrayName
- desc = libraryDescription
- websiteUrl = siteUrl
- vcsUrl = gitUrl
- licenses = allLicenses
- publish = true
- publicDownloadNumbers = true
- version {
- desc = libraryDescription
- gpg {
- sign = true //Determines whether to GPG sign the files. The default is false
- passphrase = properties.getProperty("bintray.gpg.password")
- //Optional. The passphrase for GPG signing'
- }
- }
- }
-}
diff --git a/x264-android/build.gradle b/x264-android/build.gradle
index 4742382..7de5d54 100644
--- a/x264-android/build.gradle
+++ b/x264-android/build.gradle
@@ -1,32 +1,7 @@
apply plugin: 'com.android.library'
-ext {
- bintrayRepo = 'maven'
- bintrayName = 'x264-android'
-
- publishedGroupId = 'com.github.bakaoh'
- libraryName = 'X264Android'
- artifact = 'x264-android'
-
- libraryDescription = 'Simple x264 encoder jni for android'
-
- siteUrl = 'https://github.com/bakaoh/X264Android'
- gitUrl = 'https://github.com/bakaoh/X264Android.git'
-
- libraryVersion = '1.0.0'
-
- developerId = 'bakaoh'
- developerName = 'Tata Tata'
- developerEmail = 'tatattai@gmail.com'
-
- licenseName = 'The Apache Software License, Version 2.0'
- licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- allLicenses = ["Apache-2.0"]
-}
-
android {
- compileSdkVersion 25
- buildToolsVersion "25.0.2"
+ compileSdkVersion 30
defaultConfig {
minSdkVersion 15
@@ -40,7 +15,7 @@ android {
}
}
ndk {
- abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
+ abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
@@ -49,7 +24,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild {
ndkBuild {
- arguments "LOCAL_LDFLAGS:=-Wl,-s"
+ arguments "LOCAL_LDFLAGS:=-Wl,-s "
}
}
}
@@ -62,8 +37,5 @@ android {
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
-}
-
-apply from: 'installv1.gradle'
-apply from: 'bintrayv1.gradle'
\ No newline at end of file
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+}
\ No newline at end of file
diff --git a/x264-android/installv1.gradle b/x264-android/installv1.gradle
deleted file mode 100644
index 0396115..0000000
--- a/x264-android/installv1.gradle
+++ /dev/null
@@ -1,42 +0,0 @@
-apply plugin: 'com.github.dcendents.android-maven'
-
-group = publishedGroupId // Maven Group ID for the artifact
-
-install {
- repositories.mavenInstaller {
- // This generates POM.xml with proper parameters
- pom {
- project {
- packaging 'aar'
- groupId publishedGroupId
- artifactId artifact
-
- // Add your description here
- name libraryName
- description libraryDescription
- url siteUrl
-
- // Set your license
- licenses {
- license {
- name licenseName
- url licenseUrl
- }
- }
- developers {
- developer {
- id developerId
- name developerName
- email developerEmail
- }
- }
- scm {
- connection gitUrl
- developerConnection gitUrl
- url siteUrl
-
- }
- }
- }
- }
-}
diff --git a/x264-android/src/main/cpp/Application.mk b/x264-android/src/main/cpp/Application.mk
index 6f5ebbf..3697dac 100644
--- a/x264-android/src/main/cpp/Application.mk
+++ b/x264-android/src/main/cpp/Application.mk
@@ -1,4 +1,4 @@
-APP_STL := gnustl_static
-APP_ABI := x86 armeabi-v7a arm64-v8a
-APP_PLATFORM := android-9
+APP_STL := c++_shared
+APP_ABI := x86 x86_64 armeabi-v7a arm64-v8a
+APP_PLATFORM := android-21
APP_OPTIM := release
diff --git a/x264-android/src/main/cpp/build_x264.sh b/x264-android/src/main/cpp/build_x264.sh
index 5fefbcf..c91abc8 100755
--- a/x264-android/src/main/cpp/build_x264.sh
+++ b/x264-android/src/main/cpp/build_x264.sh
@@ -1,45 +1,72 @@
#!/bin/bash
-set -e
+if [ -z $ANDROID_NDK_ROOT ]; then
+ ANDROID_NDK_ROOT=/home/forlayo/android-ndk-r21e
+ echo ANDROID_NDK_ROOT not defined.
+ echo Setting it up to ${ANDROID_NDK_ROOT}
+fi
+
+if [ -z $ANDROID_NDK_PLATFORM ]; then
+ ANDROID_NDK_PLATFORM=android-21
+ echo ANDROID_NDK_PLATFORM not defined.
+ echo Setting it up to ${ANDROID_NDK_PLATFORM}
-ARM_PLATFORM=$NDK_PATH/platforms/android-9/arch-arm/
-ARM_PREBUILT=$NDK_PATH/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
-AARCH64_PLATFORM=$NDK_PATH/platforms/android-21/arch-arm64/
-AARCH64_PREBUILT=$NDK_PATH/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
-X86_PLATFORM=$NDK_PATH/platforms/android-9/arch-x86/
-X86_PREBUILT=$NDK_PATH/toolchains/x86-4.9/prebuilt/linux-x86_64
+fi
+
+if [ -z $ANDROID_NDK_HOST ]; then
+ ANDROID_NDK_HOST=linux-x86_64
+ echo ANDROID_NDK_HOST not defined.
+ echo Setting it up to ${ANDROID_NDK_HOST}
+fi
+
+TOOLCHAIN=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${ANDROID_NDK_HOST}
+ANDROID_VERSION=`echo "${ANDROID_NDK_PLATFORM}"|cut -d - -f 2`
function build_one
{
if [ $ARCH == "arm" ]
then
- SYSROOT=$ARM_PLATFORM
- PREBUILT=$ARM_PREBUILT
- CROSS_PREFIX=$PREBUILT/bin/arm-linux-androideabi-
+ COMPILER=armv7a-linux-androideabi
+ COMPILER_PREFIX=arm-linux-androideabi-
HOST=arm-linux
+ export CC=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang # c compiler path
+ export CXX=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang++ # c++ compiler path
+
elif [ $ARCH == "aarch64" ]
then
- SYSROOT=$AARCH64_PLATFORM
- PREBUILT=$AARCH64_PREBUILT
- CROSS_PREFIX=$PREBUILT/bin/aarch64-linux-android-
+ COMPILER=aarch64-linux-android
+ COMPILER_PREFIX=aarch64-linux-android-
HOST=aarch64-linux
-else
- SYSROOT=$X86_PLATFORM
- PREBUILT=$X86_PREBUILT
- CROSS_PREFIX=$PREBUILT/bin/i686-linux-android-
+ export CC=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang # c compiler path
+ export CXX=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang++ # c++ compiler path
+elif [ $ARCH == "x86_64" ]
+then
+ COMPILER=x86_64-linux-android
+ COMPILER_PREFIX=x86_64-linux-android-
+ HOST=x86_64-linux
+ export CC=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang # c compiler path
+ export CXX=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang++ # c++ compiler path
+elif [ $ARCH == "x86" ]
+then
+ COMPILER=i686-linux-android
+ COMPILER_PREFIX=i686-linux-android-
HOST=i686-linux
+ export CC=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang # c compiler path
+ export CXX=${TOOLCHAIN}/bin/${COMPILER}${ANDROID_VERSION}-clang++ # c++ compiler path
fi
pushd libx264
./configure --prefix=$PREFIX \
--host=$HOST \
- --sysroot=$SYSROOT \
- --cross-prefix=$CROSS_PREFIX \
+ --sysroot=${TOOLCHAIN}/sysroot \
+ --cross-prefix=${TOOLCHAIN}/bin/${COMPILER_PREFIX} \
--extra-cflags="$OPTIMIZE_CFLAGS" \
--extra-ldflags="-nostdlib" \
--enable-pic \
--enable-static \
--enable-strip \
+ --disable-asm \
+ --disable-opencl \
--disable-cli \
--disable-win32thread \
--disable-avs \
@@ -68,9 +95,15 @@ OPTIMIZE_CFLAGS="-march=armv8-a"
PREFIX=`pwd`/prebuilt/arm64-v8a
build_one
-#x86
-CPU=i686
-ARCH=i686
+#x86_64
+ARCH=x86_64
+OPTIMIZE_CFLAGS=
+PREFIX=`pwd`/prebuilt/x86_64
+build_one
+
+#x86_64
+ARCH=x86
OPTIMIZE_CFLAGS=
PREFIX=`pwd`/prebuilt/x86
build_one
+
diff --git a/x264-android/src/main/cpp/libx264_jni.cpp b/x264-android/src/main/cpp/libx264_jni.cpp
index a661e13..b5c513e 100644
--- a/x264-android/src/main/cpp/libx264_jni.cpp
+++ b/x264-android/src/main/cpp/libx264_jni.cpp
@@ -8,7 +8,7 @@
#define X264A_OK 0
#define X264A_ERR_APPLY_PROFILE -2
#define X264A_ERR_OPEN_ENCODER -3
-#define X264A_ERR_NOT_SUPPORT_CPS -4
+#define X264A_ERR_NOT_SUPPORT_CSP -4
#define X264A_ERR_ENCODE_FRAME -5
#define X264A_PACKAGE "com/github/bakaoh/x264/"
@@ -142,7 +142,7 @@ JNIEXPORT jobject encodeFrame(JNIEnv *env, jobject thiz, jbyteArray frame, jint
ctx->input_picture.img.i_stride[2] = ctx->params.i_width / 2;
break;
default:
- return env->NewObject(rsCls, rsInit, X264A_ERR_NOT_SUPPORT_CPS, NULL, 0, false);
+ return env->NewObject(rsCls, rsInit, X264A_ERR_NOT_SUPPORT_CSP, NULL, 0, false);
}
int len = x264_encoder_encode(ctx->encoder, &nal, &nnal, &ctx->input_picture, &out_pic);
@@ -162,9 +162,9 @@ JNIEXPORT jstring getVersion(JNIEnv *env, jobject thiz) {
}
static JNINativeMethod methods[] = {
- {"initEncoder", "(L"X264A_PACKAGE"X264Params;)L"X264A_PACKAGE"X264InitResult;", (void *) initEncoder},
+ {"initEncoder", "(L" X264A_PACKAGE "X264Params;)L" X264A_PACKAGE "X264InitResult;", (void *) initEncoder},
{"releaseEncoder", "()V", (void *) releaseEncoder},
- {"encodeFrame", "([BIJ)L"X264A_PACKAGE"X264EncodeResult;", (void *) encodeFrame},
+ {"encodeFrame", "([BIJ)L" X264A_PACKAGE "X264EncodeResult;", (void *) encodeFrame},
{"getVersion", "()Ljava/lang/String;", (void *) getVersion},
};
diff --git a/x264-android/src/main/java/com/github/bakaoh/x264/X264Params.java b/x264-android/src/main/java/com/github/bakaoh/x264/X264Params.java
index 94f8935..cd2f06b 100644
--- a/x264-android/src/main/java/com/github/bakaoh/x264/X264Params.java
+++ b/x264-android/src/main/java/com/github/bakaoh/x264/X264Params.java
@@ -6,10 +6,10 @@
public class X264Params {
- public static final int CSP_I420 = 0x0001; // yuv 4:2:0 planar
- public static final int CSP_YV12 = 0x0002; // yvu 4:2:0 planar
- public static final int CSP_NV12 = 0x0003; // yuv 4:2:0, with one y plane and one packed u+v
- public static final int CSP_NV21 = 0x0004; // yuv 4:2:0, with one y plane and one packed v+u
+ public static final int CSP_I420 = 0x0002; // yuv 4:2:0 planar
+ public static final int CSP_YV12 = 0x0003; // yvu 4:2:0 planar
+ public static final int CSP_NV12 = 0x0004; // yuv 4:2:0, with one y plane and one packed u+v
+ public static final int CSP_NV21 = 0x0005; // yuv 4:2:0, with one y plane and one packed v+u
public int width = 1280;
public int height = 720;
public int bitrate = 500;