mac ffmpeg 合成多个视频

61 阅读1分钟

复制一个视频100遍

mycount=1;while (( $mycount < 100 ));do cp 1.flv $mycount.flv;((mycount=$mycount+1)); done;

合成视频

touch a.py
vim a.py
import os
from natsort import natsorted

# 存储当前文件夹下的所有mp4文件路径
L = []
for root, dirs, files in os.walk('.'):
    files = natsorted(files)
    for file in files:
        # 只处理mp4文件
        if os.path.splitext(file)[1] == '.flv':
            file_path = os.path.join(root, file)
            L.append(file_path)

# 生成bash文件
with open('concat_flv.sh', 'w') as f:
    f.write("#! /bin/bash\n\n")
    for l in L:
        f.write(f"ffmpeg -i {l} -vcodec copy -acodec copy -vbsf h264_mp4toannexb {l.replace('.flv', '.ts')}\n")

    f.write(f'\nffmpeg -i "concat:{"|".join([i.replace(".flv", ".ts") for i in L])}" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4\n')
    f.write('rm *.ts')

chmod 755 concat_flv.sh
./concat_flv.sh