Saving matplotlib.animation outputs a 0 second vid

2019-09-20 07:35发布

I am fairly new to matplotlib and animations, the animation I have works when using pyplot.show but when attempting to use the animation.save function, the only thing outputted is a 0 second video with the initial frame of the animation.

This is my code:

plt.rcParams['animation.ffmpeg_path'] = r'C:\FFMPEG\bin\ffmpeg.exe'
FFwriter = animation.FFMpegWriter()     
video_ani.save('basic_animation1.mp4', writer = FFwriter, fps=30, extra_args=['-vcodec', 'libx264'])

Any help would be appreciated, thanks

1条回答
Anthone
2楼-- · 2019-09-20 07:36

I think you need to supply the arguments to the FFMpegWriter class, not to animate.save. The documenation says:

fps, codec, bitrate, extra_args, metadata are used to construct a MovieWriter instance and can only be passed if writer is a string.

So you could try

FFwriter = animation.FFMpegWriter(fps=30, codec="libx264")     
video_ani.save('basic_animation1.mp4', writer = FFwriter )

where the codec is specified using the codec argument instead of some extra argument.

Appart from that you'd probably need to test certain things:

  • Can you save the animation as animated gif?
    • If yes, then you have a problem creating the mp4,
    • if no, you may have a problem with the animation itself.
  • What does using another codec specification do? I always used codec="h264", maybe that matters.
查看更多
登录 后发表回答