原因是字体路径问题。使用font_path=font_path.replace('\\', '/')将路径中的\转为/就好了。
f = open(txt_file, 'r', encoding='utf-8')
text = f.read()
f.close()
print(text)
fontsize=int(layer_config["字幕字体大小"].strip()) if layer_config["字幕字体大小"].strip().isnumeric() else int(CONFIG["默认字幕字体大小"])
font=os.path.join(os.getcwd(),CONFIG['字体路径'])+"\\"+layer_config['字幕字体']
if not os.path.exists(font):font = FONTS_DEFAULT_ZIMU
font=font.replace('\\', '/')
color_str = layer_config["字幕字体颜色"].strip() if len(layer_config["字幕字体颜色"].strip()) > 1 else '(255, 0, 0, 255)'
font_color = tuple(int(i) for i in color_str.replace('(', "").replace(")", "").replace(",", ",").split(','))
color_str = layer_config["字幕字体颜色"].strip() if len(layer_config["字幕字体颜色"].strip()) > 1 else '(255, 0, 0, 255)'
#bg_color = tuple(int(i) for i in color_str.replace('(', "").replace(")", "").replace(",", ",").split(','))
clip_layer=mp.TextClip(text,fontsize = fontsize,font = font,color = 'red').set_position(('center','bottom')).set_duration(video_duration)