美文网首页
解决 matplotlib.animation 动画无法保存为视

解决 matplotlib.animation 动画无法保存为视

作者: 寂风如雪 | 来源:发表于2019-12-29 13:43 被阅读0次

参考:https://github.com/python-pillow/Pillow/issues/3850

Pillow 暂时无法保存为 .mp4,可以选用 ffmpeg 代替,下载地址 https://www.ffmpeg.org/download.html
之后参考

plt.rcParams['animation.ffmpeg_path'] ='C:\\Sushanti\\ffmpeg\\bin\\ffmpeg.exe'
FFwriter=animation.FFMpegWriter(fps=10, extra_args=['-vcodec', 'libx264'])
anim.save('plswork.mp4', writer=FFwriter)

即可保存动画为 .mp4 格式。

有时候保存的视频长度不对,考虑是考虑是 save_count 的问题,比较方便的做法是把 frames 设成 iterable,这样视频保存的长度总是和实际长度相等。

相关文章

网友评论

      本文标题:解决 matplotlib.animation 动画无法保存为视

      本文链接:https://www.haomeiwen.com/subject/etuyoctx.html