原文:
使用moviepy用:
clip1 = VideoFileClip(‘F:\video\3.mp4’)加载视频时报错,如下:
Traceback (most recent call last):
File “<pyshell#3>”, line 1, in
clip1 = VideoFileClip(‘F:\video\3.mp4’)
File “C:\Program Files\Python37\lib\site-packages\moviepy\video\io\VideoFileClip.py”, line 91, in init
fps_source=fps_source)
File “C:\Program Files\Python37\lib\site-packages\moviepy\video\io\ffmpeg_reader.py”, line 36, in init
fps_source)
File “C:\Program Files\Python37\lib\site-packages\moviepy\video\io\ffmpeg_reader.py”, line 259, in ffmpeg_parse_infos
infos = error.decode(‘utf8’)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb9 in position 1721: invalid start byte
这种情况只在少数视频文件处理时报错,应该是解码问题,打开moviepy\video\io\ffmpeg_reader.py文件,将该行代码:
infos = error.decode(‘utf8’)
改为:infos = error.decode(‘ANSI’)
重启解释器后再执行问题顺利解决。
见解:
可以打开 ffmpeg_reader.py 文件将代码改为:
try:
infos = error.decode('utf8')
except:
infos = error.decode('ANSI')