Skip to content

Commit

Permalink
提升转码效率
Browse files Browse the repository at this point in the history
  • Loading branch information
microshow committed Dec 15, 2018
1 parent c8d996b commit 20a88e1
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 42 deletions.
27 changes: 15 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
compileSdkVersion compileSdkValue
defaultConfig {
applicationId "com.superman.fastffmpegandroid"
minSdkVersion 15
targetSdkVersion 27
versionCode 2
versionName "1.0.1"
applicationId "io.microshow.rxffmpegdemo"
minSdkVersion minSdkValue
targetSdkVersion targetSdkValue
versionCode versionCodeValue
versionName versionNameValue
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationIdSuffix ".debug"
}

release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Expand All @@ -22,22 +29,18 @@ android {
jniLibs.srcDirs = ['libs']
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibValue}"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

//rxjava and rxandroid
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'

//动态权限
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'

implementation project(path: ':rxffmpeg')
}
Binary file removed app/libs/armeabi-v7a/libffmpeg-invoke.so
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.superman.fastffmpegandroid;
package io.microshow.rxffmpegdemo;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.superman.fastffmpegandroid">
package="io.microshow.rxffmpegdemo">

<!--网络连接-->
<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -9,7 +9,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".FFmpegApplication"
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.superman.fastffmpegandroid;
package io.microshow.rxffmpegdemo;

import android.app.Application;

import com.superman.ffmpeg.FFmpegInvoke;
import io.microshow.rxffmpeg.RxFFmpegInvoke;

/**
* Created by Super on 2018/12/7.
*/

public class FFmpegApplication extends Application {
public class App extends Application {

@Override
public void onCreate() {
super.onCreate();

//开启debug模式,正式环境设为false即可
FFmpegInvoke.getInstance().setDebug(true);
RxFFmpegInvoke.getInstance().setDebug(BuildConfig.DEBUG);

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.superman.fastffmpegandroid;
package io.microshow.rxffmpegdemo;

import android.Manifest;
import android.app.AlertDialog;
Expand All @@ -11,11 +11,12 @@
import android.widget.EditText;
import android.widget.Toast;

import com.superman.ffmpeg.FFmpegInvoke;
import com.tbruyelle.rxpermissions2.RxPermissions;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import io.microshow.rxffmpeg.RxFFmpegInvoke;
import io.reactivex.functions.Consumer;

public class MainActivity extends AppCompatActivity {
Expand Down Expand Up @@ -77,7 +78,7 @@ private void runFFmpegRxJava () {
final String text = editText.getText().toString();
String[] commands = text.split(" ");

FFmpegInvoke.getInstance().runCommandRxJava(commands).subscribe(new Subscriber<Integer>() {
RxFFmpegInvoke.getInstance().runCommandRxJava(commands).subscribe(new Subscriber<Integer>() {

@Override
public void onSubscribe(Subscription s) {
Expand Down Expand Up @@ -178,7 +179,7 @@ public void openProgressDialog() {

@Override
public void onClick(DialogInterface dialog, int which) {
FFmpegInvoke.getInstance().exit();
RxFFmpegInvoke.getInstance().exit();
}
});
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
Expand Down Expand Up @@ -206,4 +207,4 @@ public void onClick(DialogInterface dialogInterface, int i) {
builder.create().show();
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.superman.fastffmpegandroid;
package io.microshow.rxffmpegdemo;

/**
* Created by Super on 2018/12/8.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity">
tools:context="io.microshow.rxffmpegdemo.MainActivity">

<EditText
android:id="@+id/editText"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">FastFFmpegAndroid</string>
<string name="app_name">RxFFmpeg</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.superman.fastffmpegandroid;
package io.microshow.rxffmpegdemo;

import org.junit.Test;

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

apply from: "configs.gradle"
buildscript {

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'


// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
18 changes: 18 additions & 0 deletions configs.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ext {
/*---- 官方 Support 库、Build 工具版本、主配文件参数 ----*/
//最小SDK版本
minSdkValue = 16
//目标版本
targetSdkValue = 27
//编译 SDK 版本
compileSdkValue = 27
//构建工具
buildToolsValue = "27.0.3"
//支持包版本
supportLibValue = "27.1.1"
//应用 versionCode
versionCodeValue = 1
//应用 version 名称,更多设置里显示的
versionNameValue = "1.0.1"

}
1 change: 1 addition & 0 deletions rxffmpeg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
43 changes: 43 additions & 0 deletions rxffmpeg/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion compileSdkValue
defaultConfig {
minSdkVersion minSdkValue
targetSdkVersion targetSdkValue
versionCode versionCodeValue
versionName versionNameValue
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// externalNativeBuild {
// cmake {
// cppFlags "-std=c++11"
// }
// ndk {
// abiFilters "armeabi-v7a"
// }
// }
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// externalNativeBuild {
// cmake {
// path "CMakeLists.txt"
// }
// }
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}

dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
//rxjava and rxandroid
api 'io.reactivex.rxjava2:rxandroid:2.1.0'
api 'io.reactivex.rxjava2:rxjava:2.2.4'
}
File renamed without changes.
Binary file added rxffmpeg/libs/armeabi-v7a/libffmpeg-invoke.so
Binary file not shown.
25 changes: 25 additions & 0 deletions rxffmpeg/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\DevConfig\android\sdk\android-sdk-windows\android-sdk-windows/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
3 changes: 3 additions & 0 deletions rxffmpeg/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.microshow.rxffmpeg">
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.superman.ffmpeg;
package io.microshow.rxffmpeg;

import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
Expand All @@ -11,27 +11,27 @@
* Created by Super on 2018/6/14.
*/

public class FFmpegInvoke {
public class RxFFmpegInvoke {

public static final String TAG = FFmpegInvoke.class.getSimpleName();
public static final String TAG = RxFFmpegInvoke.class.getSimpleName();

static {
System.loadLibrary("ffmpeg-core");
System.loadLibrary("ffmpeg-invoke");
}

private static FFmpegInvoke instance;
private static RxFFmpegInvoke instance;

/**
* ffmpeg 回调监听
*/
private IFFmpegListener ffmpegListener;

public static FFmpegInvoke getInstance(){
public static RxFFmpegInvoke getInstance(){
if (instance == null) {
synchronized (FFmpegInvoke.class) {
synchronized (RxFFmpegInvoke.class) {
if (instance == null) {
instance = new FFmpegInvoke();
instance = new RxFFmpegInvoke();
}
}
}
Expand All @@ -45,7 +45,7 @@ public static FFmpegInvoke getInstance(){
*/
public void runCommandAsync(final String[] command, IFFmpegListener mffmpegListener){
setFFmpegListener (mffmpegListener);
synchronized (FFmpegInvoke.class){
synchronized (RxFFmpegInvoke.class){
// 不允许多线程访问
new Thread(new Runnable() {
@Override
Expand All @@ -65,7 +65,7 @@ public void run() {
public int runCommand(final String[] command, IFFmpegListener mffmpegListener){
setFFmpegListener (mffmpegListener);
int ret;
synchronized (FFmpegInvoke.class){
synchronized (RxFFmpegInvoke.class){
ret = runFFmpegCmd(command);
return ret;
}
Expand All @@ -81,7 +81,7 @@ public Flowable<Integer> runCommandRxJava(final String[] command){
return Flowable.create(new FlowableOnSubscribe<Integer>() {
@Override
public void subscribe(final FlowableEmitter<Integer> emitter) {
setFFmpegListener (new FFmpegInvoke.IFFmpegListener() {
setFFmpegListener (new RxFFmpegInvoke.IFFmpegListener() {
@Override
public void onFinish() {
emitter.onComplete();
Expand Down
2 changes: 2 additions & 0 deletions rxffmpeg/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<resources>
</resources>
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app'
include ':app', ':rxffmpeg'

0 comments on commit 20a88e1

Please sign in to comment.