ffmpeg合并多个视频文件
某某视频,通过工具把一个视频被切割成12个视频都下载下来。想要合并12个视频文件到一个视频文件,试过各种,达芬奇、QQ影音、PR,要么视频模糊了,要么文件巨大,受不了了。只好找到视频编辑鼻祖(不接受反抗,事实如此)。
Mark:本文不解释ffmpeg安装和环境设置问题。
方法一: 直接合并
a.编辑 2.txt
###### 仅包含12行,不包含#号。
file '01.mp4'
file '02.mp4'
file '03.mp4'
file '04.mp4'
file '05.mp4'
file '06.mp4'
file '07.mp4'
file '08.mp4'
file '09.mp4'
file '10.mp4'
file '11.mp4'
file '12.mp4'
#####
b.直接无损合并
ffmpeg.exe -f concat -safe 0 -i 2.txt -c copy -y o1.mp4
-f concat是指合并
-safe 为了避免权限报错
-c copy 一定要指定,不然会重新封装,数据文件就会变大。
好处:不会变大,且加了 -c copy很快完成合并。
方法二:转成ts 再转回mp4
根据各位大佬的描述,貌似转回ts,再重新压制是比较科学的做法,但是我这个场景可能比较简单。
a. 先把12个mp4转换为ts文件
编辑 1.bat
####### 1.bat 不包含#####
ffmpeg -i 01.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 01.ts
ffmpeg -i 02.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 02.ts
ffmpeg -i 03.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 03.ts
ffmpeg -i 04.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 04.ts
ffmpeg -i 05.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 05.ts
ffmpeg -i 06.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 06.ts
ffmpeg -i 07.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 07.ts
ffmpeg -i 08.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 08.ts
ffmpeg -i 09.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 09.ts
ffmpeg -i 10.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 10.ts
ffmpeg -i 11.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 11.ts
ffmpeg -i 12.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 12.ts
#######到这里结束,#号不要复制
不要直接复制12个命令到cmd运行,会跑漏掉。
在cmd里面 执行1.bat
b.整合12个ts文件到一个mp4
编辑 1.txt
########
file '01.ts'
file '02.ts'
file '03.ts'
file '04.ts'
file '05.ts'
file '06.ts'
file '07.ts'
file '08.ts'
file '09.ts'
file '10.ts'
file '11.ts'
file '12.ts'
########
执行整合
ffmpeg -f concat -i 1.txt -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4
3. 删除所有ts文件
rm *.ts
第二个方法,挺费时间,给大家备用吧。可能对于不同的文件格式确实需要转回ts再处理。