below is my method to add image in a video, I am passing image path as a parameter
Here I am first initializing my ffmpeg and then by executing the command in background thread I am converting the video for having the Image at position defined at xposition and ypposition
private void doReplaceTheFrame(String image) {
String[] complexCommand;
int frameCount = (int) (timeInsec * 30);
int startTimeFrame = frameCount - 5;
File f = new File("/storage/emulated/0");
String rootPath = f.getPath();
complexCommand =
new String[]{"-y", "-i", VideoPath1, "-i", image, "-filter_complex",
"[0:v][1:v]overlay=" + xPosition + ":" + yPosition + 10 +
":enable='between" + "(t," + 0 + "," + endTimeOfVideo + ")"
+ "'[out]", "-map", "[out]", rootPath + "/outputFrame.mp4"};
FFmpeg ffmpeg = FFmpeg.getInstance(this);
try {
//Load the binary
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onFailure() {
}
@Override
public void onStart() {
}
@Override
public void onSuccess() {
}
@Override
public void onFinish() {
}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
Toast.makeText(getApplicationContext(), "Not Supported by Device",
Toast.LENGTH_LONG).show();
}
try {
final String finalRootPath = rootPath;
ffmpeg.execute(complexCommand, new FFmpegExecuteResponseHandler() {
@Override
public void onSuccess(String message) {
Log.d("Success", message);
Toast.makeText(getApplicationContext(), "Successful" + finalRootPath
.toString(),
Toast.LENGTH_LONG).show();
Uri path = Uri.parse(finalRootPath + "/outputFrame.mp4");
playVideo(path.toString());
}
@Override
public void onStart() {
Log.d("Start", "merge started");
}
@Override
public void onProgress(String message) {
Log.d("progress", message);
pd.show();
}
@Override
public void onFailure(String message) {
Log.d("failure", message);
pd.dismiss();
}
@Override
public void onFinish() {
Log.d("finish", "merge finish");
pd.dismiss();
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
e.printStackTrace();
}
}