好的,感谢一位用户,我有以下 FFMPEG 命令将 4 个视频连接在一起。现在,如果我将此命令与 4 个都有音频的视频文件一起使用,一切正常!但是,如果 1 个或多个视频没有声音,我会收到“不匹配流”错误。
有人可以发现这里有什么问题吗?
视频输入 1 - 无音频,因此添加 anullsrc
视频 2 - 有音频
视频 3 - 无音频
视频 4 - 有音频
ffmpeg -i noSound1.mp4 -i story1.mp4 -i noSound2.mp4 -i story2.mp4 -t 0.1 -f lavfi -i anullsrc=channel_layout=stereo -filter_complex
"[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v0];
[1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v1];
[2:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v2];
[3:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v3];
[0:a]aformat=sample_rates=48000:channel_layouts=stereo[a0];
[1:a]aformat=sample_rates=48000:channel_layouts=stereo[a1];
[2:a]aformat=sample_rates=48000:channel_layouts=stereo[a2];
[3:a]aformat=sample_rates=48000:channel_layouts=stereo[a3];
[v0][a0][v1][a1][v2][a2][v3][a3]concat=n=4:v=1:a=1[v][a]"
-map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart testOutput.mp4
这是错误:Stream specifier ':a' in filtergraph description [0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v0]; [1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v1]; [2:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v2]; [3:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v3]; [0:a]aformat=sample_rates=48000:channel_layouts=stereo[a0]; [1:a]aformat=sample_rates=48000:channel_layouts=stereo[a1]; [2:a]aformat=sample_rates=48000:channel_layouts=stereo[a2]; [3:a]aformat=sample_rates=48000:channel_layouts=stereo[a3]; [v0][a0][v1][a1][v2][a2][v3][a3]concat=n=4:v=1:a=1[v][a] matches no streams.
现在是一个稍微分开的问题。如果我有 N 个输入视频,但我不知道它们是否有声音,有没有一种方法可以让我在没有大量命令行的情况下执行上述操作?非常感谢!
最佳答案
Can someone spot whats wrong here please?
在您的命令中,您尝试从
noSound1.mp4
提供音频。 ( [0:a]
) 和 noSound2.mp4
( [2:a]
) 格式化,但这些输入没有音频。所有输入必须要么有音频,要么没有音频:你不能混合它们。这就是 anullsrc(静音音频发生器)的用途。它将为没有音频的输入制作虚拟/静音/填充音频。对于没有音频的输入,您需要将 anullsrc(在您的示例中为
[4]
或 [4:a]
)提供给 concat:ffmpeg -i noSound1.mp4 -i story1.mp4 -i noSound2.mp4 -i story2.mp4 -t 0.1 -f lavfi -i anullsrc=channel_layout=stereo -filter_complex
"[0:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v0];
[1:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v1];
[2:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v2];
[3:v]scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30,format=yuv420p[v3];
[1:a]aformat=sample_rates=48000:channel_layouts=stereo[a1];
[3:a]aformat=sample_rates=48000:channel_layouts=stereo[a3];
[v0][4][v1][a1][v2][4][v3][a3]concat=n=4:v=1:a=1[v][a]"
-map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart testOutput.mp4
了解[0:a]
语法见 FFMPEG mux video and audio (from another video) - mapping issue和 FFmpeg Wiki: Map .Now a slightly separate question. If I have N input videos where i do not know if they have sound or not, is there a way I can have a loop that does the above without having massive amounts of command lines?
不,但您可以使用
ffprobe
确定输入是否有音频,这应该有助于编写解决方案的脚本。见 Using ffprobe
to check audio-only files .
关于bash - FFMPEG - 尝试连接多个带和不带音频的文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63300881/