python使用MoviePy 视频合并报错:OSError: MoviePy error: failed to read the first frame of video file xxx的解决方法

已解决:OSError: MoviePy error: failed to read the first frame of video file \\视频\ts\78.ts. That might mean that the file is corrupted. That may also mean that you are using a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is deprecated. Please update to a recent version from the website.

报错信息翻译:OSError: MoviePy error:无法读取视频文件的第一帧 xxx.mp4.这可能意味着文件已损坏。这也可能意味着您使用的是已弃用的 FFMPEG 版本。例如,在 Ubuntu/Debian 上,存储库中的版本已被弃用。请从网站更新到最新版本。

因为在做视频合并的时候老是报这个错误,又要重新运行脚本,很烦,为了解决该问题尝试了很多方法,最后在GitHub上找到了类似情况话题,找到了解决方法:在moviepy库下找到.../moviepy/video/io/ffmpeg_reader.py该文件,找到close()函数,把最后两行注释掉,成功解决。如下:
 # if hasattr(self, 'lastread'):
        #     del self.lastread

def close(self):
    if self.proc:
            self.proc.terminate()
            self.proc.stdout.close()
            self.proc.stderr.close()
            self.proc.wait()
            self.proc = None
        # if hasattr(self, 'lastread'):
        #     del self.lastread

来源GitHub:该回答显示时间在2020年2月,在社区里讨论最多的是关于MoviePy包内部逻辑的问题,我是用pip命令下载的MoviePy库 版本号为1.0.3。

附上GitHub话题地址:https://github.com/Zulko/moviepy/issues/1078

在该板块下寻找到了更好的解决办法,最后找到了.../moviepy/video/io/ffmpeg_reader.py的迭代版本,替换原来的ffmpeg_reader.py后运行,也成功解决了该问题。

附上迭代版本源地址:https://github.com/tburrows13/moviepy/blob/617ee91f8aa05e12127a1f18e7260bc0b8a4f2e2/moviepy/video/io/ffmpeg_reader.py

以上是此问题报错原因的解决方法,欢迎评论区留言讨论是否能解决,如果有用欢迎点赞收藏文章谢谢支持!!!

公众号:笔记分享社

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值