问题描述
当我使用 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
。文件说:
所以你可以尝试
FFwriter = animation.FFMpegWriter(fps = 30,codec =libx264)
/ pre>
video_ani.save('basic_animation1.mp4',writer = FFwriter)
使用
编解码器
参数指定编解码器,而不是一些额外的参数。
从您可能需要测试某些内容的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:
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秒视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!