Reputation: 543
I am using ffmpeg-android to concat two video files,bur it takes too long to concat and I guess it because of using "-filter_complex"
but that was the only command I found on internet,can please someone simplify the below command? I just want to concat two video files captured by camera2
api without any modifications.
String command[] = new String[]{
"-y",
"-i", firstPath,
"-i", secondPath,
"-strict",
"experimental",
"-filter_complex",
"[0:v]scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih)," +
"pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v0];[1:v] scale=iw*min(1920/iw\\,1080/ih):ih*min(1920/iw\\,1080/ih)," +
"pad=1920:1080:(1920-iw*min(1920/iw\\,1080/ih))/2:(1080-ih*min(1920/iw\\,1080/ih))/2,setsar=1:1[v1];[v0][0:a][v1][1:a] concat=n=2:v=1:a=1",
"-ab", "48000", "-ac", "2", "-ar", "22050", "-s", "1920x1080", "-vcodec", "libx264", "-crf", "27", "-q", "4", "-preset", "ultrafast", getVideoFilePath(getActivity())};
commandFFMPEG(command);
private void commandFFMPEG(String command[]) {
FFmpeg ffmpeg = FFmpeg.getInstance(getActivity());
try {
ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
startTime = System.currentTimeMillis();
}
@Override
public void onProgress(String message) {
}
@Override
public void onFailure(String message) {
}
@Override
public void onSuccess(String message) {
long endTime = System.currentTimeMillis();
long result = endTime - startTime;
Toast.makeText(getActivity(), "Videos are merged", Toast.LENGTH_SHORT).show();
}
@Override
public void onFinish() {
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
}
}
Upvotes: 2
Views: 2278
Reputation: 225
String cmd[] = new String[]{ "-y","-i", "vid.mp4", "i", "vid2.mp4", "-preset", "ultrafast", "-filter_complex", "[0:v] [0:a] [1:v] [1:a] concat=n=2:v=1:a=1 [v] [a]","-map","[v]","-map","[a]","/output.mp4"};
Used ffmpeg lib : com.writingminds:FFmpegAndroid:0.3.2
Upvotes: 0
Reputation: 832
Idk will it help you, but when I wanted to concat videos with ffmpeg, I used this command:
StringBuilder builder = new StringBuilder();
builder.append("-f ");
builder.append("concat ");
builder.append("-safe 0 ");
builder.append("-i ");
final String tempFile = getTextFile().getAbsolutePath();//it is text file with video files paths
builder.append(tempFile);
builder.append(" ");
builder.append("-c ");
builder.append("copy ");
builder.append(saveFile);// saveFile - it is your output file
Anyway, concatenation videos with total duration 20 sec took ~20 sec for processing. You can take a look here, I wrote it for concatenation several videos, but code quality is terrible, I don't know, will you understand something there. Hope it will help you)
Upvotes: 1