Android – FFmpeg android execute

androidexecuteffmpeg

On windows I could cut a video with below code with ffmpeg.exe

Can't use ffmpeg in android.
I used gradle to grab ffmpeg in my app.

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.github.hiteshsondhi88.libffmpeg:FFmpegAndroid:0.2.5'
}

I have these lines in my method

VideoIn = getInternalDirectoryPath() + "/Download/Ab.mp4";
VideoOut = getInternalDirectoryPath() + "/Download/Ab1.mp4";

try {
ffmpeg.execute("ffmpeg -i " + VideoIn + " -ss 00:00:03 -c:v libx264 -crf 17 -t 00:00:5 " + VideoOut + " -y",null);
}
catch (FFmpegCommandAlreadyRunningException e) { 
e.printStackTrace();
}

Shows this error: Error running exec(). Command: [/data/data/com.videoeditor.myname.myapp/files/ffmpeg, ffmpeg, -i, /storage/emulated/0/Download/Ab.mp4, -ss, 00:00:03, -c:v, libx264, -crf, 17, -t, 00:00:5, /storage/emulated/0/Download/Ab1.mp4, -y] Working Directory: null Environment: null

What's wrong with this method? Thanks for your help

Best Answer

Ok I found the answer: There is no need for "ffmpeg" in cmd with this method of using ffmpeg

Simple video cut example:

 /**
 * Returns the path to internal storage ex:- /storage/emulated/0
 *
 * @return
 */
private String getInternalDirectoryPath() {
    return Environment.getExternalStorageDirectory().getAbsolutePath();
}

VideoIn = getInternalDirectoryPath() + "/Download/Ab.mp4";
VideoOut = getInternalDirectoryPath() + "/Download/Ab1.mp4";

private void CutVideo(){
try {
     ffmpeg.execute("-i "+VideoIn+" -ss 00:01:00 -to 00:02:00 -c copy "+VideoOut ,
new ExecuteBinaryResponseHandler() {

                @Override
                public void onStart() {
                //for logcat
                    Log.w(null,"Cut started");
                }

                @Override
                public void onProgress(String message) {
                //for logcat
                    Log.w(null,message.toString());
                }

                @Override
                public void onFailure(String message) {

                    Log.w(null,message.toString());
                }

                @Override
                public void onSuccess(String message) {

                    Log.w(null,message.toString());
                }

                @Override
                public void onFinish() {

                    Log.w(null,"Cutting video finished");
                }
            });
        } catch (FFmpegCommandAlreadyRunningException e) {
            // Handle if FFmpeg is already running
            e.printStackTrace();
            Log.w(null,e.toString());
        }
}