如何使用长度超过 2 分钟的 ffmpeg 并排合并视频



我想合并两个长度为 4 分钟的 mp2 视频,我正在使用 FFMPEG 命令合并视频,这需要太多的处理时间,还有其他方法或命令可以加快速度吗 我也使用-preset ultrafast但它不起作用。

在这里我正在使用这个命令

ffmpegcommand = new String[]{"-y", "-i", recordedvideo, "-i", file.toString(),
"-filter_complex",
"[0:v:0]pad=iw*2:ih[bg];" +
"[bg][1:v:0]overlay=w;" +
"[1:a]volume=0.9[A];[0:a]aecho=1:0.1:" + Constant.DELAY + ":" + Constant.DECAY + "[B];[B]volume=70[C];[C][A]amix=inputs=2[a]",
"-map", "[a]",
"-c:v", "libx264", "-shortest", "-preset",
"ultrafast", path + time + ".mp4"};

我写这段代码是因为偶尔我想快速连接多个视频,而不必担心每个大小和格式。

具有相同和不同编解码器/格式/大小/纵横比的文件串联。

(确保每个视频都有音频!(如有必要,添加静音音频(

# set video size of the output
targetWidth=1024
targetHeight=576
#this scaler preserves the aspect ratio of the input video and adds padding if needed.
#a video with a size of 720x576 will be upscaled to 1350x1080 to preserve the aspect ratio and padded left and right to achieve 1920x1080.
smartScale="scale=iw*min($targetWidth/iw,$targetHeight/ih):ih*min($targetWidth/iw,$targetHeight/ih), pad=$targetWidth:$targetHeight:($targetWidth-iw*min($targetWidth/iw,$targetHeight/ih))/2:($targetHeight-ih*min($targetWidth/iw,$targetHeight/ih))/2:color=black, setdar=ratio=16/9, setfield=tff"
# inputs are scaled to the same size and given a label
# then they are concatenated
ffmpeg 
-i "01 video 1280x720.mov" 
-i "02 video 720x576.mkv" 
-i "03 video 1920x1080.mp4" 
-filter_complex "
[0:v]${smartScale}[scaled_v0]; 
[1:v]${smartScale}[scaled_v1]; 
[2:v]${smartScale}[scaled_v2]; 
[scaled_v0][0:a][scaled_v1][1:a][scaled_v2][2:a]
concat=n=3:v=1:a=1[v][a]" 
-map "[v]" -map "[a]" -c:v libx264 -crf 23 -c:a aac concatenated.mkv

我已经测试了多次,效果很好。

你的命令的输出是什么?

您是否有与 ffmpeg 相关的错误消息?

最新更新