├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── Android-FFmpegExecutor.iml ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── library.iml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── crust87 │ │ └── ffmpegexecutor │ │ ├── FFmpegExecutor.java │ │ └── FileMover.java │ └── res │ └── values │ └── strings.xml ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── sample.iml └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── ffmpeg │ ├── java │ └── com │ │ └── crust87 │ │ └── ffmpegexecutorsample │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Android-FFmpegExecutor -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /Android-FFmpegExecutor.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-FFmpegExecutor 2 | simple ffmpeg command executor for android
3 | 4 | ffmpeg binary in this project comes from
5 | https://github.com/WritingMinds/ffmpeg-android-java 6 | 7 | Check permission before running test code!!!! 8 | 9 | ## Update 10 | ### 1.3.0 11 | Update library 12 | 13 | ### 1.1.4 14 | add method executeCommandAsync 15 | 16 | ### 1.1.3 17 | check if ffmpeg file has already copied 18 | 19 | ### 1.1.0 20 | add constructor with InputStream 21 | 22 | ### 1.0.1 23 | ffmpeg binary has moved to app
24 | ffmpeg binary must be copied into internal storage 25 | 26 | ## Example 27 | 28 | add build.gradle
29 | ``` groovy 30 | compile 'com.crust87:ffmpeg-executor:1.3.0' 31 | ``` 32 | 33 | ```java 34 | try { 35 | InputStream ffmpegFileStream = getApplicationContext().getAssets().open("ffmpeg"); 36 | mExecutor = new FFmpegExecutor(getApplicationContext(), ffmpegFileStream); 37 | } catch (IOException e) { 38 | // TODO something 39 | } catch (InterruptedException e) { 40 | // TODO something 41 | } 42 | ``` 43 | 44 | if you want to know ffmpeg log while process running, set this listener 45 | ```java 46 | mExecutor.setFFmepgExecutorListener(new FFmpegExecutor.FFmepgExecutorListener() { 47 | 48 | @Override 49 | public void onReadProcessLine(String line) { 50 | // TODO Something to on read process line 51 | } 52 | 53 | @Override 54 | public void onFinishProcess() { 55 | // TODO Something to finish job 56 | } 57 | 58 | @Override 59 | public void onError(Exception e) { 60 | // TODO Something for error from library 61 | } 62 | }); 63 | ``` 64 | 65 | you must call init() before put command
66 | put some commands 67 | ```java 68 | mExecutor.init(); 69 | 70 | mExecutor.putCommand("-y") 71 | .putCommand("-i") 72 | .putCommand(originalPath) 73 | .putCommand("-vcodec") 74 | .putCommand("libx264") 75 | .putCommand("-profile:v") 76 | .putCommand("baseline") 77 | .putCommand("-level") 78 | .putCommand("3.1") 79 | .putCommand("-b:v") 80 | .putCommand("1000k") 81 | .putCommand("-vf") 82 | .putCommand(filter) 83 | .putCommand("-c:a") 84 | .putCommand("copy") 85 | .putCommand(Environment.getExternalStorageDirectory().getAbsolutePath() + "/result.mp4"); 86 | ``` 87 | 88 | and execute command 89 | ```java 90 | mExecutor.executeCommandAsync(); 91 | ``` 92 | 93 | ## Summary 94 | ### Public Constructors 95 | | | 96 | |:---| 97 | | FFmpegExecutor(Context context, InputStream ffmpegInputStream) | 98 | 99 | ### Public Methods 100 | | | | 101 | |:---|:---| 102 | | void | init()
Reset FFmpeg command | 103 | | FFmpegExecuter | putCommand(String command)
Add ffmpeg command, It can be Method chaining | 104 | | void | executeCommand()
Execute FFmpeg with added command, this method throws IOException | 105 | | void | executeCommandAsync()
Execute asynchronously FFmpeg with added command | 106 | | void | destroy()
Destroy FFmpeg process, not tested | 107 | | void | setFFmepgExecutorListener(FFmepgExecutorListener l)
Add listener lesten read line from FFmpeg process | 108 | 109 | ### Interface FFmepgExecutorListener 110 | | | | 111 | |:---|:---| 112 | | void | onReadProcessLine()
| 113 | | void | onFinishProcess()
| 114 | | void | onError(FFmepgExecutorListener l)
| 115 | 116 | ## License 117 | Copyright 2015 Mabi 118 | 119 | Licensed under the Apache License, Version 2.0 (the "License");
120 | you may not use this work except in compliance with the License.
121 | You may obtain a copy of the License at 122 | 123 | http://www.apache.org/licenses/LICENSE-2.0 124 | 125 | Unless required by applicable law or agreed to in writing, software
126 | distributed under the License is distributed on an "AS IS" BASIS,
127 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128 | See the License for the specific language governing permissions and
129 | limitations under the License. 130 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | classpath 'com.novoda:bintray-release:0.3.0' 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | } 20 | 21 | tasks.withType(Javadoc) { 22 | options.addStringOption('Xdoclint:none', '-quiet') 23 | options.addStringOption('encoding', 'UTF-8') 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crust87/Android-FFmpegExecutor/67ce3bce5480ff831a24becdd4473720b2b3077a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.novoda.bintray-release' 3 | 4 | publish { 5 | userOrg = 'mabi87' 6 | groupId = 'com.crust87' 7 | artifactId = 'ffmpeg-executor' 8 | publishVersion = '1.3.0' 9 | desc = 'FFmpeg binary executor for Android' 10 | website = 'https://github.com/crust87/Android-FFmpegExecutor' 11 | issueTracker = "${website}/issues" 12 | repository = "${website}.git" 13 | } 14 | 15 | android { 16 | compileSdkVersion 23 17 | buildToolsVersion '23.0.2' 18 | 19 | defaultConfig { 20 | minSdkVersion 14 21 | targetSdkVersion 23 22 | versionCode 7 23 | versionName '1.3.0' 24 | } 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | compile fileTree(include: ['*.jar'], dir: 'libs') 35 | compile 'com.android.support:appcompat-v7:23.1.1' 36 | } 37 | -------------------------------------------------------------------------------- /library/library.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/mabibak/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /library/src/main/java/com/crust87/ffmpegexecutor/FFmpegExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Android-FFmpegExecutor 3 | * https://github.com/crust87/Android-FFmpegExecutor 4 | * 5 | * Mabi 6 | * crust87@gmail.com 7 | * last modify 2016-09-21 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | package com.crust87.ffmpegexecutor; 23 | 24 | import android.content.Context; 25 | import android.os.AsyncTask; 26 | import android.os.Handler; 27 | import android.util.Log; 28 | 29 | import java.io.BufferedReader; 30 | import java.io.File; 31 | import java.io.IOException; 32 | import java.io.InputStream; 33 | import java.io.InputStreamReader; 34 | import java.util.ArrayList; 35 | 36 | public class FFmpegExecutor { 37 | 38 | /* 39 | Constants 40 | */ 41 | public static final String TAG = "FFmpegExecutor"; 42 | 43 | /* 44 | State Enum 45 | */ 46 | public enum ExecutorState { 47 | idle, // Executor do nothing 48 | running, // Process working 49 | error // has Error on Process 50 | } 51 | 52 | /* 53 | Event Listener 54 | */ 55 | public interface FFmepgExecutorListener { 56 | void onReadProcessLine(String line); // on read process line 57 | void onFinishProcess(); // on finish process 58 | void onError(Exception e); // on executor has error 59 | } 60 | 61 | /* 62 | Components 63 | */ 64 | private Context mContext; 65 | private Handler mHandler; 66 | private ArrayList mCommands; 67 | private ArrayList mCommendQueue; 68 | private FFmepgExecutorListener mFFmepgExecutorListener; 69 | 70 | /* 71 | Attributes 72 | */ 73 | private String mFFmpegPath; 74 | private ExecutorState mExecutorState; 75 | 76 | /* 77 | Working Components 78 | */ 79 | private Process mCurrentProcess; 80 | 81 | /** 82 | * Constructor 83 | * Copy ffmpeg to internal storage and change file permission 84 | * 85 | * @param context the context of application 86 | * @param ffmpegInputStream the InputStream of ffmpeg binary 87 | * @throws IOException Exception for copy binary to internal storage 88 | * @throws InterruptedException Exception for change permission ffmpeg directory 89 | */ 90 | public FFmpegExecutor(Context context, InputStream ffmpegInputStream) throws IOException, InterruptedException { 91 | mContext = context; 92 | mCommands = new ArrayList<>(); 93 | mCommendQueue = new ArrayList<>(); 94 | 95 | File ffmpegDirPath = new File(mContext.getFilesDir().getAbsolutePath() + "/ffmpeg"); 96 | if (!ffmpegDirPath.exists()) { 97 | ffmpegDirPath.mkdir(); 98 | } 99 | 100 | mHandler = new Handler(); 101 | mFFmpegPath = ffmpegDirPath.getAbsolutePath() + "/ffmpeg"; 102 | mExecutorState = ExecutorState.idle; 103 | 104 | File ffmpeg = new File(mFFmpegPath); 105 | if (!ffmpeg.exists()) { 106 | FileMover fileMover = new FileMover(ffmpegInputStream, ffmpeg); 107 | fileMover.moveIt(); 108 | } 109 | 110 | String[] args = {"/system/bin/chmod", "755", mFFmpegPath}; 111 | Process process = new ProcessBuilder(args).start(); 112 | process.waitFor(); 113 | process.destroy(); 114 | } 115 | 116 | /** 117 | * Initialization 118 | *

119 | * clear Command and Process Queue 120 | */ 121 | public void init() { 122 | mExecutorState = ExecutorState.idle; 123 | 124 | mCommands.clear(); 125 | mCommands.add(mFFmpegPath); 126 | 127 | mCommendQueue.clear(); 128 | } 129 | 130 | /** 131 | * @param command the string command for FFmpeg 132 | * @return this 133 | */ 134 | public FFmpegExecutor putCommand(String command) { 135 | mCommands.add(command); 136 | 137 | return this; 138 | } 139 | 140 | /** 141 | * add FFmpeg commands to Queue 142 | * 143 | * @return this 144 | */ 145 | private FFmpegExecutor addQueue() { 146 | mCommendQueue.add(new ProcessBuilder(mCommands)); 147 | 148 | return this; 149 | } 150 | 151 | /** 152 | * clear FFmpeg command line Queue 153 | * 154 | * @return this 155 | */ 156 | private void clearQueue() { 157 | mCommendQueue.clear(); 158 | } 159 | 160 | /** 161 | * execute FFmpeg commends with process queue 162 | * 163 | * @throws IOException 164 | */ 165 | public void executeProcessQueue() throws IOException { 166 | mExecutorState = ExecutorState.running; 167 | 168 | for (ProcessBuilder builder : mCommendQueue) { 169 | executeProcess(builder); 170 | } 171 | 172 | mCommendQueue.clear(); 173 | 174 | mExecutorState = ExecutorState.idle; 175 | } 176 | 177 | /** 178 | * execute FFmpeg commends with process queue Async 179 | */ 180 | public void executeProcessQueueAsync() { 181 | new AsyncTask() { 182 | @Override 183 | protected void onPreExecute() { 184 | mExecutorState = ExecutorState.running; 185 | } 186 | 187 | @Override 188 | protected Void doInBackground(Void... params) { 189 | try { 190 | for (ProcessBuilder builder : mCommendQueue) { 191 | executeProcess(builder); 192 | } 193 | 194 | mCommendQueue.clear(); 195 | } catch (final IOException e) { 196 | mExecutorState = ExecutorState.error; 197 | 198 | mHandler.post(new Runnable() { 199 | @Override 200 | public void run() { 201 | if (mFFmepgExecutorListener != null) { 202 | mFFmepgExecutorListener.onError(e); 203 | } 204 | } 205 | }); 206 | } 207 | 208 | return null; 209 | } 210 | 211 | @Override 212 | protected void onPostExecute(Void aVoid) { 213 | mExecutorState = ExecutorState.idle; 214 | 215 | if (mFFmepgExecutorListener != null) { 216 | mFFmepgExecutorListener.onFinishProcess(); 217 | } 218 | } 219 | 220 | }.execute(); 221 | } 222 | 223 | /** 224 | * execute ffmpeg command line process 225 | * 226 | * @throws IOException if Process can not start 227 | */ 228 | public void executeCommand() throws IOException { 229 | mExecutorState = ExecutorState.running; 230 | executeProcess(new ProcessBuilder(mCommands)); 231 | mExecutorState = ExecutorState.idle; 232 | } 233 | 234 | /** 235 | * execute ffmpeg command line process Async 236 | */ 237 | public void executeCommandAsync() { 238 | new AsyncTask() { 239 | @Override 240 | protected void onPreExecute() { 241 | mExecutorState = ExecutorState.running; 242 | } 243 | 244 | @Override 245 | protected Void doInBackground(Void... params) { 246 | try { 247 | executeProcess(new ProcessBuilder(mCommands)); 248 | } catch (final IOException e) { 249 | mExecutorState = ExecutorState.error; 250 | 251 | mHandler.post(new Runnable() { 252 | @Override 253 | public void run() { 254 | if (mFFmepgExecutorListener != null) { 255 | mFFmepgExecutorListener.onError(e); 256 | } 257 | } 258 | }); 259 | } 260 | 261 | return null; 262 | } 263 | 264 | @Override 265 | protected void onPostExecute(Void aVoid) { 266 | mExecutorState = ExecutorState.idle; 267 | 268 | if (mFFmepgExecutorListener != null) { 269 | mFFmepgExecutorListener.onFinishProcess(); 270 | } 271 | } 272 | 273 | }.execute(); 274 | } 275 | 276 | /** 277 | * Execute FFmpeg commend line process with ProcessBuilder 278 | * 279 | * @param builder ProcessBuilder of FFmpeg commend line 280 | * @throws IOException 281 | */ 282 | private void executeProcess(ProcessBuilder builder) throws IOException { 283 | mCurrentProcess = builder.redirectErrorStream(true).start(); 284 | 285 | BufferedReader reader = new BufferedReader(new InputStreamReader(mCurrentProcess.getInputStream())); 286 | String line; 287 | while ((line = reader.readLine()) != null) { 288 | if (mFFmepgExecutorListener != null) { 289 | mFFmepgExecutorListener.onReadProcessLine(line); 290 | } else { 291 | Log.v(TAG, line); 292 | } 293 | } 294 | 295 | destroy(); 296 | } 297 | 298 | /* 299 | * I'm not sure it's work 300 | */ 301 | public void destroy() { 302 | if (mCurrentProcess != null) { 303 | mCurrentProcess.destroy(); 304 | mCurrentProcess = null; 305 | } 306 | } 307 | 308 | /** 309 | * @param l listener 310 | */ 311 | public void setFFmepgExecutorListener(FFmepgExecutorListener l) { 312 | mFFmepgExecutorListener = l; 313 | } 314 | 315 | /** 316 | * 317 | * @return State of FFmpeg executor state 318 | */ 319 | public ExecutorState getExecutorState() { 320 | return mExecutorState; 321 | } 322 | 323 | /** 324 | * get System architecture 325 | * 326 | * @return System architecture 327 | */ 328 | public static String getArchitecture() { 329 | return System.getProperty("os.arch"); 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /library/src/main/java/com/crust87/ffmpegexecutor/FileMover.java: -------------------------------------------------------------------------------- 1 | package com.crust87.ffmpegexecutor; 2 | 3 | import java.io.BufferedOutputStream; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | 10 | /** 11 | * Created by mabi on 2015. 12. 18.. 12 | */ 13 | public class FileMover { 14 | private InputStream mInputStream; 15 | private File mDestination; 16 | 17 | public FileMover(InputStream inputStream, File destination) { 18 | mInputStream = inputStream; 19 | mDestination = destination; 20 | } 21 | 22 | public void moveIt() throws IOException { 23 | OutputStream destinationOut = new BufferedOutputStream(new FileOutputStream(mDestination)); 24 | 25 | int numRead; 26 | byte[] buf = new byte[1024]; 27 | while ((numRead = mInputStream.read(buf) ) >= 0) { 28 | destinationOut.write(buf, 0, numRead); 29 | } 30 | 31 | destinationOut.flush(); 32 | destinationOut.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FFmpegExecutor 3 | 4 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion '23.0.2' 6 | 7 | defaultConfig { 8 | applicationId "com.crust87.ffmpegexecutor" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 7 12 | versionName '1.3.0' 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | lintOptions { 21 | abortOnError false 22 | } 23 | } 24 | 25 | dependencies { 26 | compile fileTree(include: ['*.jar'], dir: 'libs') 27 | compile 'com.crust87:ffmpeg-executor:1.3.0' 28 | compile 'com.crust87:video-crop-view:1.0.1' 29 | compile 'com.android.support:appcompat-v7:23.1.1' 30 | } 31 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/mabibak/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample/src/main/assets/ffmpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crust87/Android-FFmpegExecutor/67ce3bce5480ff831a24becdd4473720b2b3077a/sample/src/main/assets/ffmpeg -------------------------------------------------------------------------------- /sample/src/main/java/com/crust87/ffmpegexecutorsample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Android-FFmpegExecutor 3 | * https://github.com/crust87/Android-FFmpegExecutor 4 | * 5 | * Mabi 6 | * crust87@gmail.com 7 | * last modify 2016-09-21 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); 10 | * you may not use this file except in compliance with the License. 11 | * You may obtain a copy of the License at 12 | * 13 | * http://www.apache.org/licenses/LICENSE-2.0 14 | * 15 | * Unless required by applicable law or agreed to in writing, software 16 | * distributed under the License is distributed on an "AS IS" BASIS, 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | * See the License for the specific language governing permissions and 19 | * limitations under the License. 20 | */ 21 | 22 | package com.crust87.ffmpegexecutorsample; 23 | 24 | import android.app.ProgressDialog; 25 | import android.content.Intent; 26 | import android.database.Cursor; 27 | import android.media.MediaPlayer; 28 | import android.net.Uri; 29 | import android.os.Bundle; 30 | import android.os.Environment; 31 | import android.os.Handler; 32 | import android.os.Message; 33 | import android.provider.MediaStore; 34 | import android.support.v4.util.Pair; 35 | import android.support.v7.app.AppCompatActivity; 36 | import android.util.Log; 37 | import android.view.View; 38 | import android.widget.Toast; 39 | 40 | import com.crust87.ffmpegexecutor.FFmpegExecutor; 41 | import com.crust87.ffmpegexecutor.FileMover; 42 | import com.crust87.videocropview.VideoCropView; 43 | 44 | import java.io.File; 45 | import java.io.FileInputStream; 46 | import java.io.FileNotFoundException; 47 | import java.io.IOException; 48 | import java.io.InputStream; 49 | 50 | 51 | public class MainActivity extends AppCompatActivity { 52 | 53 | // Layout Components 54 | private VideoCropView mVideoCropView; 55 | private ProgressDialog mProgressDialog; 56 | 57 | // Component 58 | private FFmpegExecutor mExecutor; 59 | 60 | // Attributes 61 | private String originalPath; 62 | @Override 63 | protected void onCreate(Bundle savedInstanceState) { 64 | super.onCreate(savedInstanceState); 65 | 66 | try { 67 | InputStream ffmpegFileStream = getApplicationContext().getAssets().open("ffmpeg"); 68 | mExecutor = new FFmpegExecutor(getApplicationContext(), ffmpegFileStream); 69 | } catch (Exception e) { 70 | Toast.makeText(getApplicationContext(), "Fail FFmpeg Setting", Toast.LENGTH_LONG).show(); 71 | finish(); 72 | } 73 | 74 | loadGUI(); 75 | bindEvent(); 76 | } 77 | 78 | private void loadGUI() { 79 | setContentView(R.layout.activity_main); 80 | 81 | mVideoCropView = (VideoCropView) findViewById(R.id.cropVideoView); 82 | } 83 | 84 | private void bindEvent() { 85 | mVideoCropView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 86 | 87 | @Override 88 | public void onPrepared(MediaPlayer mp) { 89 | mVideoCropView.start(); 90 | } 91 | }); 92 | 93 | mExecutor.setFFmepgExecutorListener(new FFmpegExecutor.FFmepgExecutorListener() { 94 | 95 | @Override 96 | public void onReadProcessLine(String line) { 97 | Log.d("TEST", line); 98 | 99 | Message message = Message.obtain(); 100 | 101 | message.obj = line; 102 | message.setTarget(mMessageHandler); 103 | message.sendToTarget(); 104 | } 105 | 106 | @Override 107 | public void onFinishProcess() { 108 | Toast.makeText(getApplicationContext(), "Finish FFmpeg Process", Toast.LENGTH_LONG).show(); 109 | 110 | if (mProgressDialog != null) { 111 | mProgressDialog.dismiss(); 112 | mProgressDialog = null; 113 | } 114 | } 115 | 116 | @Override 117 | public void onError(Exception e) { 118 | 119 | } 120 | }); 121 | } 122 | 123 | private Handler mMessageHandler = new Handler(new Handler.Callback() { 124 | @Override 125 | public boolean handleMessage(Message msg) { 126 | String message = (String) msg.obj; 127 | 128 | if(mProgressDialog != null) { 129 | mProgressDialog.setMessage(message); 130 | } 131 | 132 | return true; 133 | } 134 | }); 135 | 136 | @Override 137 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 138 | if (requestCode == 1000 && resultCode == RESULT_OK) { 139 | setOriginalVideo(data.getData()); 140 | } 141 | } 142 | 143 | public void onButtonLoadClick(View v) { 144 | Intent lIntent = new Intent(Intent.ACTION_PICK); 145 | lIntent.setType("video/*"); 146 | lIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 147 | startActivityForResult(lIntent, 1000); 148 | } 149 | 150 | public void onButtonCropClick(View v) { 151 | if(originalPath == null) { 152 | return; 153 | } 154 | 155 | mVideoCropView.pause(); 156 | 157 | float scale; 158 | int viewWidth; 159 | int viewHeight; 160 | int width; 161 | int height; 162 | int positionX; 163 | int positionY; 164 | int videoWidth; 165 | int videoHeight; 166 | int rotate; 167 | 168 | mExecutor.init(); 169 | mProgressDialog = ProgressDialog.show(MainActivity.this, null, "execute....", true); 170 | 171 | scale = mVideoCropView.getScale(); 172 | viewWidth = mVideoCropView.getWidth(); 173 | viewHeight = mVideoCropView.getHeight(); 174 | width = (int)(viewWidth * scale); 175 | height = (int)(viewHeight * scale); 176 | positionX = (int) mVideoCropView.getRealPositionX(); 177 | positionY = (int) mVideoCropView.getRealPositionY(); 178 | videoWidth = mVideoCropView.getVideoWidth(); 179 | videoHeight = mVideoCropView.getVideoHeight(); 180 | rotate = mVideoCropView.getRotate(); 181 | 182 | String filter = ""; 183 | 184 | if(rotate == 0) { 185 | filter = "crop="+width+":"+height+":"+positionX+":"+positionY+", scale=640:640, setsar=1:1"; 186 | } else if(rotate == 90) { 187 | filter = "crop="+height+":"+width+":"+positionY+":"+positionX +", scale=640:640, setsar=1:1"; 188 | } else if(rotate == 180) { 189 | filter = "crop="+width+":"+height+":"+(videoWidth - positionX - width)+":"+positionY+ ", scale=640:640, setsar=1:1"; 190 | } else if(rotate == 270) { 191 | filter = "crop="+height+":"+width+":"+(videoHeight - positionY - height)+":"+positionX + ", scale=640:640, setsar=1:1"; 192 | } else { 193 | filter = "crop="+width+":"+height+":"+positionX+":"+positionY+", scale=640:640, setsar=1:1"; 194 | } 195 | 196 | mExecutor.putCommand("-y") 197 | .putCommand("-i") 198 | .putCommand(originalPath) 199 | .putCommand("-vcodec") 200 | .putCommand("libx264") 201 | .putCommand("-profile:v") 202 | .putCommand("baseline") 203 | .putCommand("-level") 204 | .putCommand("3.1") 205 | .putCommand("-b:v") 206 | .putCommand("1000k") 207 | .putCommand("-vf") 208 | .putCommand(filter) 209 | .putCommand("-c:a") 210 | .putCommand("copy") 211 | .putCommand(Environment.getExternalStorageDirectory().getAbsolutePath() + "/result.mp4") 212 | .executeCommandAsync(); 213 | } 214 | 215 | // Initialization original video 216 | private void setOriginalVideo(Uri uri) { 217 | originalPath = getRealPathFromURI(uri); 218 | 219 | mVideoCropView.setVideoURI(uri); 220 | mVideoCropView.seekTo(1); 221 | } 222 | 223 | public String getRealPathFromURI(Uri contentUri) { 224 | Cursor cursor = null; 225 | try { 226 | String[] proj = { MediaStore.Images.Media.DATA }; 227 | cursor = getApplicationContext().getContentResolver().query(contentUri, proj, null, null, null); 228 | int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 229 | cursor.moveToFirst(); 230 | return cursor.getString(column_index); 231 | } finally { 232 | if (cursor != null) { 233 | cursor.close(); 234 | } 235 | } 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 14 | 15 | 20 | 21 |