问题遇到的现象和发生背景
想给视频添加字幕,跑网上的例子, 跑不通
问题相关代码,请勿粘贴截图
if not(isfile(src_video) and src_video.endswith('.mp4') and
isfile(sentences) and sentences.endswith('.txt')):
print('请正确使用本程序, 视频文件支持mp4 字幕支持 txt')
else:
video = VideoFileClip(src_video)
w, h = video.w, video.h
txts = []
with open(sentences, encoding='utf8') as fp:
for line in fp:
ss , start , span = line.split(':')
start , span = map(float, (start, span))
txt = (TextClip(ss, fontsize=40,
font='Arial', size=(w-20, 40),
align='center', color='black').set_position((10, h-150)).set_duration(span).set_start(start))
txts.append(txt)
video = CompositeVideoClip([video, *txts])
fn, ext = splitext(src_video)
video.write_videofile('test.mp4')
运行结果及报错内容
builtins.ValueError: Could not find a backend to open C:\Users\ADMINI~1\AppData\Local\Temp\tmp1vq27p1y.png`` with iomode
ri`.
Based on the extension, the following plugins might add capable backends:
pyav: pip install imageio[pyav]
opencv: pip install imageio[opencv]
我的解答思路和尝试过的方法
发现一定会生成临时文件, 图片 和视频文件。 当我把临时生成的png 和 视频 文件换成本地的之后, 还是会出错。
我想要达到的结果
跑通, 视频可以正常添加字幕。