将各种音频和视频源混合到单个视频中 [英] Mixing various audio and video sources into a single video
问题描述
我已经阅读了 FFmpeg-将一个视频叠加到另一个视频上?/a>,(以及许多关于 setpts
的类似问题,标记为 [ffmpeg]
>),并且下面的代码可以正常工作,但是我敢肯定我们可以简化它,并提供更优雅的解决方案.
I've already read FFmpeg - Overlay one video onto another video?, How to overlay 2 videos at different time over another video in single ffmpeg command?, FFmpeg - Multiple videos with 4 areas and different play times (and many similar questions tagged [ffmpeg]
about setpts
), and the following code is working, but I'm sure we can simplify it, and have a more elegant solution.
我想混合使用不同起点的多种来源(图像和声音):
I'd like to mix multiple sources (image and sound) , with different starting points:
t (seconds) 0 1 2 3 4 5 6 7 8 9 10 11 12 13
test.png [-------------------------------]
a.mp3 [-------]
without_sound.mp4 [-------------------] (overlay at x,y=200,200)
b.mp3 [---]
with_sound.mp4 [---------------------------------------] (overlay at x,y=100,100)
这有效:
ffmpeg -i test.png
-t 2 -i a.mp3
-t 5 -i without_sound.mp4
-t 1 -i b.mp3
-t 10 -i with_sound.mp4
-filter_complex "
[0]setpts=PTS-STARTPTS[s0];
[1]adelay=2000^|2000[s1];
[2]setpts=PTS-STARTPTS+7/TB[s2];
[3]adelay=5000^|5000[s3];
[4]setpts=PTS-STARTPTS+3/TB[s4];
[4:a]adelay=3000^|3000[t4];
[s1][s3][t4]amix=inputs=3[outa];
[s0][s4]overlay=100:100[o2];
[o2][s2]overlay=200:200[outv]
" -map [outa] -map [outv]
out.mp4 -y
但是:
-
我们必须同时使用
setpts
和adelay
是正常的吗?我尝试了没有adelay
的情况,但声音没有移位.换句话说,有没有一种方法可以简化:
is it normal that we have to use both
setpts
andadelay
? I have tried withoutadelay
and then the sound is not shifted. Said differently, is there a way to simplify:
[4]setpts=PTS-STARTPTS+3/TB[s4];
[4:a]adelay=3000^|3000[t4];
?
是否可以仅使用 setpts
和 asetpts
来做到这一点?当我将 adelay = 5000 | 5000
替换为 asetpts = PTS-STARTPTS + 5/TB
时,对于另外一个,它没有给出预期的时移(见下文)
is there a way to do it with setpts
and asetpts
only? When I replaced adelay=5000|5000
with asetpts=PTS-STARTPTS+5/TB
and also for the other one, it didn't give the expected time-shifting (see below)
在类似的问题/答案中,我经常看到 overlay = ...:enable ='between(t,...,...)'
,这里似乎不是需要,为什么?
in similar questions/answers I often see overlay=...:enable='between(t,...,...)'
, here it seems it is not needed, why?
更一般而言,您如何简化这种混合多个音频和视频"? ffmpeg
代码?
More generally, how would you simplify this "mix multiple audio and video" ffmpeg
code?
有关第二个要点的更多详细信息:如果我们将 adelay
替换为 asetpts
,
More details about the second bullet point: if we replace adelay
by asetpts
,
-filter_complex "
[0]setpts=PTS-STARTPTS[s0];
[1]asetpts=PTS-STARTPTS+2/TB[s1];
[2]setpts=PTS-STARTPTS+7/TB[s2];
[3]asetpts=PTS-STARTPTS+5/TB[s3];
[4]setpts=PTS-STARTPTS+3/TB[s4];
[4:a]asetpts=PTS-STARTPTS+3/TB[t4];
[s1][s3][t4]amix=inputs=3[outa];
[s0][s4]overlay=100:100[o2];
[o2][s2]overlay=200:200[outv]
它不起作用:[3]应该从0'05开始,而[4:a]应该从0'03"开始但它们都比[1]在同一时间开始,即从0'02开始.
it doesn't work: [3] should begin at 0'05", and [4:a] at 0'03" but they all begin at the same time than [1], i.e. at 0'02".
amix
似乎只考虑了第一个
It seems that amix
only takes the first asetpts
in consideration, and discards the others; is it true?
推荐答案
我们必须同时使用setpts和adelay吗?
is it normal that we have to use both setpts and adelay?
是的,前者用于视频流;后者,用于音频.asetpts不适合与amix一起使用,因为后者会忽略开始时间偏移.adelay会从0填充到所需的偏移量.
Yes, the former is for video streams; the latter, for audio. asetpts is not suitable for use with amix since the latter ignores starting time offsets. adelay fills in with silence from 0 to the desired offset.
我经常看到overlay = ...:enable ='between(t,...,...)',这里似乎不需要,为什么?
I often see overlay=...:enable='between(t,...,...)', here it seems it is not needed, why?
重叠式广告会根据时间戳同步其主要视频帧和重叠式视频帧.如果在两个输入均具有同步帧时希望禁用覆盖,则需要 enable
.
Overlay syncs its main and overlay video frames by timestamps. enable
is needed if one wishes to disable overlay when synced frames are available for both inputs.
这篇关于将各种音频和视频源混合到单个视频中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!