保存matplotlib.animation输出0秒视频 [英] Saving matplotlib.animation outputs a 0 second video

查看:907
本文介绍了保存matplotlib.animation输出0秒视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 pyplot.show 而尝试使用 animation.save时,我对于matplotlib和动画是相当新鲜的。 功能,唯一输出的是0秒的视频,动画的初始帧。



这是我的代码:

  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'])

任何帮助不胜感激,谢谢

解决方案>

我想你需要向FFMpegWriter类提供参数,而不是 animate.save 。文件说:


fps,编解码器,比特率,extra_args,元数据用于构建MovieWriter实例,只有在writer是一个字符串。


所以你可以尝试

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

使用编解码器参数指定编解码器,而不是一些额外的参数。



从您可能需要测试某些内容的Appart:




  • 可以将动画保存为动画GIF吗?


    • 如果是,则创建mp4时,您有问题,

    • 如果否,您可能有问题动画本身。


  • 使用其他编解码器规范做什么?我总是使用 codec =h264,也许这很重要。


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

解决方案

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.

这篇关于保存matplotlib.animation输出0秒视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆