我正在使用ffmpeg-android来合并两个视频文件,但是合并时间太长了,我猜是因为使用了"-filter_complex"
但这是我在互联网上找到的唯一命令,可以请某人简化以下命令?我只想合并camera2
api捕获的两个视频文件,而无需进行任何修改。
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
}
}
答案 0 :(得分:1)
Idk会为您提供帮助,但是当我想用ffmpeg连接视频时,我使用了以下命令:
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
无论如何,总时长为20秒的级联视频需要大约20秒的处理时间。您可以看一下here,我是为串联多个视频而编写的,但是代码质量很糟糕,我不知道,您是否会明白那里的内容。 希望对您有帮助)
答案 1 :(得分:0)
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”};
使用的ffmpeg库:com.writingminds:FFmpegAndroid:0.3.2