ffmpeg需要用支持libx264的版本,如果需要,可以从这个网站下载编译支持libx264\x265的ffmpeg
https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-6.1-essentials_build.7z
#-*- coding:utf-8-*-
import os
if __name__ == "__main__":
# 1 输入想要合并序列,按顺序放
input_w = 2560
input_h = 1440
input_seqs = [
r"D:\input\\2_2k_420.yuv",
r"D:\input\\4_2k_420.yuv",
r"D:\input\\10_2K_420.yuv", ]
# 2 每个yuv转码成mp44
ffmpeg_trans_param = "ffmpeg -y -f rawvideo -video_size %sx%s -pixel_format yuv420p -i %s \
-c:v libx264 -q 10 %d_out.mp4"
if os.path.exists("concat_list.txt"):
os.remove("concat_list.txt")
f_concat = open("concat_list.txt","a")
for i in range(0,len(input_seqs)):
cur_cmd = ffmpeg_trans_param %( input_w, input_h, input_seqs[i], i)
os.system(cur_cmd)
write_info = "file %d_out.mp4\n" % ( i)
f_concat.write(write_info)
f_concat.close()
# 3 按顺序合并所有mp4文件
cur_cmd = "ffmpeg -y -hide_banner -f concat -i concat_list.txt -c:v copy concat_total.mp4"
os.system(cur_cmd)