ffmpeg concat两个带有可选音频的来源 [英] ffmpeg concat two sources with optional audio

查看:69
本文介绍了ffmpeg concat两个带有可选音频的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用ffmpeg将两个视频文件合并在一起.我已经找到了以下命令:

I want to concat two video files together by using ffmpeg. I already found this command:

ffmpeg -i INPUT1 -i INPUT2 -filter_complex \"[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]\" -map \"[v]\" -map \"[a]\" OUTPUT

问题在于,INPUT2始终不具有音频,因此ffm​​peg抛出无效的输入流.我对ffmpeg非常缺乏经验,我对文档也不了解.是否有可能在一个命令中就可以很好地理解的可能方法?

The Problem is, that INPUT2 not alway has Audio, so ffmpeg throws an invalid Input Stream. I'm very inexperienced with ffmpeg and I'm not getting smart out of the documentation. Is there a possible way that is decently understandable, possibly in one command?

总结:我想合并两个包含音频的视频文件,但是第二个文件可能有也可能没有音频层.

Summed up: I want to concat two Video Files including Audio, but the second file may or may not has an audio layer.

推荐答案

必须匹配流计数&输入

要串联的所有段必须具有相同数量和类型的流.因此,如果 input1.mp4 具有音频,而 input2.mp4 没有音频,则您需要从 input1.mp4 中忽略音频或添加 input2.mp4 的音频.一种方法是使用 anullsrc 过滤器添加无声音频,如下所示:

Must match stream count & type

All segments to be concatenated must have the same number and type of streams. So if input1.mp4 has audio, and input2.mp4 does not, then you need to either omit the audio from input1.mp4 or add audio for input2.mp4. One method is to add silent audio with the anullsrc filter as shown in:

没有选项可以自动添加丢失的音频,因此您必须使用 ffprobe 检查输入以告诉您输入是否有音频:

There is no option to automatically add missing audio, so you have to check the inputs with ffprobe to tell you if the inputs have audio or not:

然后您可以使用首选的脚本/编码语言中的结果来执行适当的命令.

You can then use the results in your preferred scripting/coding language to execute the appropriate command.

这篇关于ffmpeg concat两个带有可选音频的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆