FFmpeg has three concatenation methods

https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg?page=1\&tab=scoredesc#tab-top

FFmpeg has three concatenation methods:

  1. concat video filter
    Use this method if your inputs do not have the same parameters (width, height, etc), or are not the same formats/codecs, or if you want to perform any filtering.

Note that this method performs a re-encode of all inputs. If you want to avoid the re-encode, you could re-encode just the inputs that don't match so they share the same codec and other parameters, then use the concat demuxer to avoid re-encoding everything.

ffmpeg -i opening.mkv -i episode.mkv -i ending.mkv

-filter_complex "0:v 0:a 1:v 1:a 2:v 2:a

concat=n=3:v=1:a=1 v a"

-map "v" -map "a" output.mkv

  1. concat demuxer

Use this method when you want to avoid a re-encode and your format does not support file-level concatenation (most files used by general users do not support file-level concatenation).

$ cat mylist.txt

file '/path/to/file1'

file '/path/to/file2'

file '/path/to/file3'

$ ffmpeg -f concat -i mylist.txt -c copy output.mp4

For Windows:

(echo file 'first file.mp4' & echo file 'second file.mp4' )>list.txt

ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4

or

(for %i in (*.mp4) do @echo file '%i') > list.txt

ffmpeg -safe 0 -f concat -i list.txt -c copy output.mp4

  1. concat protocol
    Use this method with formats that support file-level concatenation (MPEG-1, MPEG-2 PS, DV). Do not use with MP4.

ffmpeg -i "concat:input1|input2" -codec copy output.mkv

This method does not work for many formats, including MP4, due to the nature of these formats and the simplistic physical concatenation performed by this method. It's the equivalent of just raw joining the files.

If in doubt about which method to use, try the concat demuxer.

Also see

FFmpeg FAQ: How can I join video files?

FFmpeg Wiki: How to concatenate (join, merge) media files

https://superuser.com/questions/1619992/audio-out-of-sync-when-using-ffmpeg-adelay-and-amix

you need to delay all the audio channels with the same value using adelay=milliseconds:all=true, and use -async 1 at the end of your command so ffmpeg will just corrects the start of the audio stream instead of stretching/squeezing.

so in your case :

bash 复制代码
ffmpeg 
-i input1.webm 
-i input2.webm
-i input3.webm
-i input4.webm
-i input5.webm
-filter_complex "
[0]adelay=1720:all=true[a0];
[1]adelay=48920:all=true[a1];
[2]adelay=76220:all=true[a2];
[3]adelay=3360980:all=true[a3];
[4]adelay=3689600:all=true[a4];
[a0][a1][a2][a3][a4]amix=inputs=5 [out]
"
-map "[out]"
out.webm -async 1 -y

as the documentations says :

-async samples_per_second

Audio sync method. "Stretches/squeezes" the audio stream to match the timestamps, the parameter is the maximum samples per second by which the audio is changed. -async 1 is a special case where only the start of the audio stream is corrected without any later correction.

Share

Improve this answer

Follow

相关推荐
专注仿真1 小时前
仿真智能体训练:强化学习多目标奖励算法与实战
python·算法·强化学习·afsim智能体
维爱智VR认知学能1 小时前
VR客户端异常诊断包白名单脱敏与受控字段构建实现
python·单元测试·软件工程·数据安全·日志脱敏
isfox2 小时前
Python 装饰器:别被 @ 符号吓到,它就是个"包装盒"
python
Sakura_j_h_2 小时前
用 uv 搭一个命令行待办工具:pyproject、argparse 与全局安装
python·uv·cli·argparse·pyproject
Wellijohn2 小时前
取 Top-K 别乱用 nlargest:我把 20 万条数据从 k=5 测到 k=199000,发现了三个反直觉的坑
python·算法·性能优化
DanCheng-studio3 小时前
毕设 yolov11血液细胞计数识别系统(源码+论文)
python·毕业设计·毕设
阿enna3 小时前
从误检和漏检出发改进YOLO26n:建立错误样本库
人工智能·python·深度学习·yolo·目标检测·机器学习·cnn
青少儿编程课堂4 小时前
蓝桥杯真题解析:手链配色计数与波利亚定理(全国青少年信息素养大赛与电子学会软件编程考级)
c++·python·算法·bfs·信息学竞赛
曲径海盗4 小时前
【Python 学习第 66 天】字典基础
python·学习笔记·编程入门
Haooog4 小时前
三段视频拼完少了 1 秒?实测 FFmpeg Skill 的淡化与硬切
ffmpeg·自动化·agent·视频剪辑·agent skills