Can I save a matplotlib animation to webm format?

2019-08-17 14:32发布

问题:

I am using this example code as a test case: https://matplotlib.org/examples/animation/moviewriter.html

In this code, they use FFMPEG to write the matplotlib animation to an .mp4 video file. Is it possible to write to a .webm format?

But I am not sure how to go about doing this.

回答1:

Make sure you have ffmpeg compiled with libvpx (run ffmpeg with no arguments and see if there's a --enable-libvpx in the output).

FFMpegWriter = manimation.writers['ffmpeg']
writer = FFMpegWriter(fps=15, codec='libvpx-vp9') # or libvpx-vp8

[...]

with writer.saving(fig, "writer_test.webm", 100):
    [...]