问题描述
我需要将多个视频文件(包含音频)合并到一个视频中.我注意到xfade最近已经发布并使用过,但是我遇到了音频同步问题.
I need to merge multiple video files (with included audio) into a single video. I've noticed xfade has been recently released and used it but I am running into an audio sync issue.
所有视频的音频和视频格式/分辨率/成名率和比特率均相同.
All videos are in the same format / resolution / fame and bitrate / etc both for video and audio.
这是我用来合并5个具有0.5淡入淡出过渡的不同时长的视频的方法:
Here is what I am using to merge 5 videos of various durations with 0.5 crossfade transitions:
ffmpeg \
-i v0.mp4 \
-i v1.mp4 \
-i v2.mp4 \
-i v3.mp4 \
-i v4.mp4 \
-filter_complex \
"[0][1]xfade=transition=fade:duration=0.5:offset=3.5[V01]; \
[V01][2]xfade=transition=fade:duration=0.5:offset=32.75[V02]; \
[V02][3]xfade=transition=fade:duration=0.5:offset=67.75[V03]; \
[V03][4]xfade=transition=fade:duration=0.5:offset=98.75[video]; \
[0:a][1:a]acrossfade=d=0.5:c1=tri:c2=tri[A01]; \
[A01][2:a]acrossfade=d=0.5:c1=tri:c2=tri[A02]; \
[A02][3:a]acrossfade=d=0.5:c1=tri:c2=tri[A03]; \
[A03][4:a]acrossfade=d=0.5:c1=tri:c2=tri[audio]" \
-vsync 0 -map "[video]" -map "[audio]" out.mp4
上面的代码生成带音频的视频.第一部分和第二部分与音频对齐,但是从第二个过渡开始,声音未对齐.
The code above generates a video with audio. The first and second segment is aligned with audio but starting with the second transition the sound is misaligned.
推荐答案
您的偏移量不正确.试试:
Your offsets are incorrect. Try:
ffmpeg -i v0.mp4 -i v1.mp4 -i v2.mp4 -i v3.mp4 -i v4.mp4 -filter_complex \
"[0][1]xfade=transition=fade:duration=0.5:offset=3.5[V01]; \
[V01][2]xfade=transition=fade:duration=0.5:offset=12.1[V02]; \
[V02][3]xfade=transition=fade:duration=0.5:offset=15.1[V03]; \
[V03][4]xfade=transition=fade:duration=0.5:offset=22.59,format=yuv420p[video]; \
[0:a][1:a]acrossfade=d=0.5:c1=tri:c2=tri[A01]; \
[A01][2:a]acrossfade=d=0.5:c1=tri:c2=tri[A02]; \
[A02][3:a]acrossfade=d=0.5:c1=tri:c2=tri[A03]; \
[A03][4:a]acrossfade=d=0.5:c1=tri:c2=tri[audio]" \
-map "[video]" -map "[audio]" -movflags +faststart out.mp4
如何获取xfade offset
值:
How to get xfade offset
values:
v0.mp4 | 4.00 | + | 0 | - | 0.5 | 3.5 |
v1.mp4 | 9.19 | + | 3.5 | - | 0.5 | 12.1 |
v2.mp4 | 3.41 | + | 12.1 | - | 0.5 | 15.1 |
v3.mp4 | 7.99 | + | 15.1 | - | 0.5 | 22.59 |
v0.mp4 | 4.00 | + | 0 | - | 0.5 | 3.5 |
v1.mp4 | 9.19 | + | 3.5 | - | 0.5 | 12.1 |
v2.mp4 | 3.41 | + | 12.1 | - | 0.5 | 15.1 |
v3.mp4 | 7.99 | + | 15.1 | - | 0.5 | 22.59 |
- 请参见 xfade 和 acrossfade 过滤器文档以获取更多信息.
- 您可以使用
ffprobe
获取输入持续时间. - See xfade and acrossfade filter documentation for more info.
- You can get input durations with
ffprobe
.
这篇关于使用ffmpeg和xfade过滤器合并多个视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!