如何使用 ffmpeg 插入视频简介

如何使用 ffmpeg 插入视频简介

我想插入视频简介,我使用下面的过滤器生成带有水印的多种分辨率,但不知道如何添加简介。

{executable} -i {fileInput} -i {watermark} -filter_complex "overlay=x=(main_w-overlay_w-10):y=(10),split=4[wm1080][wm720][wm480][wm360];[wm1080]scale=-2:1080:flags=lanczos[v1080];[wm720]scale=-2:720:flags=lanczos[v720];[wm480]scale=-2:480:flags=lanczos[v480];[wm360]scale=-2:360:flags=lanczos[v360]" -map [v1080] -map [v720] -map [v480] -map [v360] -map 0:a -flags:v +global_header -c:v libx264 -preset:v fast -b:v:0 "800k" -b:v:1 "600k" -b:v:2 "400k" -b:v:3 "300k" -c:a aac -b:a 128k -f tee "[select=\\'v:0,a\\']'{outputPath}/1080.mp4'|[select=\\'v:1,a\\']'{outputPath}/720.mp4'|[select=\\'v:2,a\\']'{outputPath}/480.mp4'|[select=\\'v:3,a\\']'{outputPath}/360.mp4'

简介和视频的分辨率都不同

答案1

使用 scale + pad/crop + setsar + concat过滤器。您没有提供任何输入文件信息,因此我假设{fileInput}它是 1920x1080,SAR 为 1,并且{fileIntro}有音频。

{executable} -i {fileIntro} -i {fileInput} -i {watermark} -filter_complex "[0:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,setsar=1[introv];[introv][0:a][1:v][1:a]concat=n=2:v=1:a=1[vcat][acat];[vcat][2]overlay=x=(main_w-overlay_w-10):y=(10),split=4[wm1080][wm720][wm480][wm360];[wm1080]scale=-2:1080:flags=lanczos[v1080];[wm720]scale=-2:720:flags=lanczos[v720];[wm480]scale=-2:480:flags=lanczos[v480];[wm360]scale=-2:360:flags=lanczos[v360]" -map [v1080] -map [v720] -map [v480] -map [v360] -map [acat] -flags:v +global_header -c:v libx264 -preset:v fast -b:v:0 "800k" -b:v:1 "600k" -b:v:2 "400k" -b:v:3 "300k" -c:a aac -b:a 128k -f tee "[select=\\'v:0,a\\']'{outputPath}/1080.mp4'|[select=\\'v:1,a\\']'{outputPath}/720.mp4'|[select=\\'v:2,a\\']'{outputPath}/480.mp4'|[select=\\'v:3,a\\']'{outputPath}/360.mp4'

改编自使用 ffmpeg 调整视频大小以适应特定尺寸

如果{fileInput}没有音频,您有 2 个选择。添加另一个音频文件:

{executable} -i {fileIntro} -i {audioIntro} -i {fileInput} -i {watermark} -filter_complex "[0:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,setsar=1[introv];[introv][1:a][2:v][2:a]concat=n=2:v=1:a=1[vcat][acat];[vcat][3]overlay=x=(main_w-overlay_w-10):y=(10),split=4[wm1080][wm720][wm480][wm360];[wm1080]scale=-2:1080:flags=lanczos[v1080];[wm720]scale=-2:720:flags=lanczos[v720];[wm480]scale=-2:480:flags=lanczos[v480];[wm360]scale=-2:360:flags=lanczos[v360]" -map [v1080] -map [v720] -map [v480] -map [v360] -map [acat] -flags:v +global_header -c:v libx264 -preset:v fast -b:v:0 "800k" -b:v:1 "600k" -b:v:2 "400k" -b:v:3 "300k" -c:a aac -b:a 128k -f tee "[select=\\'v:0,a\\']'{outputPath}/1080.mp4'|[select=\\'v:1,a\\']'{outputPath}/720.mp4'|[select=\\'v:2,a\\']'{outputPath}/480.mp4'|[select=\\'v:3,a\\']'{outputPath}/360.mp4'

或者使用 anullsrc 过滤器添加静音/填充音频:

{executable} -i {fileIntro} -t 0.1 -f lavfi -i anullsrc -i {fileInput} -i {watermark} -filter_complex "[0:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,setsar=1[introv];[introv][1:a][2:v][2:a]concat=n=2:v=1:a=1[vcat][acat];[vcat][3]overlay=x=(main_w-overlay_w-10):y=(10),split=4[wm1080][wm720][wm480][wm360];[wm1080]scale=-2:1080:flags=lanczos[v1080];[wm720]scale=-2:720:flags=lanczos[v720];[wm480]scale=-2:480:flags=lanczos[v480];[wm360]scale=-2:360:flags=lanczos[v360]" -map [v1080] -map [v720] -map [v480] -map [v360] -map [acat] -flags:v +global_header -c:v libx264 -preset:v fast -b:v:0 "800k" -b:v:1 "600k" -b:v:2 "400k" -b:v:3 "300k" -c:a aac -b:a 128k -f tee "[select=\\'v:0,a\\']'{outputPath}/1080.mp4'|[select=\\'v:1,a\\']'{outputPath}/720.mp4'|[select=\\'v:2,a\\']'{outputPath}/480.mp4'|[select=\\'v:3,a\\']'{outputPath}/360.mp4'

保留-t 0.1anullsrc 的原样。这可确保音频不会无限期地播放。concat 过滤器将用静音填充剩余持续时间以匹配相应的视频。

相关内容