I am processing video in android using FFMPEG android java library to change play back of speed. for 6 sec video to make it play back slow by 0.5 setpts , its taking more than 1 min. Here is my code
public class TestFFMpegActivity {
private static String cmd,
private static FFmpeg ffmpeg;
private static Context mContext;
public static String getInternalDirectoryPath() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
public static void initiateFFmpeg(Context context, String path) {
mContext = context;
ffmpeg = FFmpeg.getInstance(context);
VideoIn = getInternalDirectoryPath() + "/Download/input.mp4";
VideoOut = getInternalDirectoryPath() + "/Download/output.mp4";
cmd = "-i "+VideoIn+" -vf setpts=2*PTS -strict -2 "+VideoOut;
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onFailure() {
}
@Override
public void onSuccess() {
}
@Override
public void onFinish() {
processVideo();
}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
}
}
private static void processVideo(){
try {
ffmpeg.execute(cmd ,
new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
//for logcat
Log.w(null,"processing started");
}
@Override
public void onProgress(String message) {
//for logcat
Log.w(null, "onProgress");
}
@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() {
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
Toast.makeText(mContext, "Video processing failed due to exception", Toast.LENGTH_LONG).show();
// Handle if FFmpeg is already running
e.printStackTrace();
Log.w(null, e.toString());
}
}
}
This is the gradle build path for using above library
compile 'com.github.hiteshsondhi88.libffmpeg:FFmpegAndroid:0.2.5'
For changing playback command add in it parameter "-ultrafast". Now cmd will be like
cmd= "-i " + VideoIn+ " -vf setpts=2*PTS -c:v libx264 -c:a aac -strict experimental -vcodec libx264 -preset ultrafast -b:a 128k " + VideoOut;
this parameter has magical effect on processing. The video processing time decreases from 1 min 6 sec to 13 secs with same environment.