使用FFMpegwriter的Python Matplotlib底图动画在820帧之后停止?
发布时间:2020-12-20 13:36:06 所属栏目:Python 来源:网络整理
导读:如果我运行以下代码,它会在820帧之后停止.我在Ubuntu 12.04 VM和 Linux Mint 15上测试了这个.不幸的是没有错误消息.该程序在打印后暂停,2012-06-02T16:54:00 import os,sysimport matplotlib.pyplot as pltfrom mpl_toolkits.basemap import Basemapimport
如果我运行以下代码,它会在820帧之后停止.我在Ubuntu 12.04 VM和
Linux Mint 15上测试了这个.不幸的是没有错误消息.该程序在打印后暂停,2012-06-02T16:54:00
import os,sys import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap import matplotlib.animation as animation from datetime import datetime,timedelta def animation_test(start,end,fps=10,save_path='/home/username/animation_test/', save_name="test.mp4",dpi=80): step = timedelta(minutes = 3) current = start dates =[] frame = 0 while current <=end: dates.append(current) current += step fig = plt.figure(figsize=(16,9),facecolor='k',edgecolor='k') ax = fig.add_subplot(111) metadata = dict(title='Movie Test',artist='Matplotlib',comment='Movie support!') writer = animation.FFMpegWriter(fps=fps,metadata=metadata,bitrate=20000) direction = -0.5 lat_current = 0 lon_current = 0 with writer.saving(fig,os.path.join(save_path,save_name),dpi): for current in dates: ax.cla() if direction > 0 and lat_current > 40 or direction < 0 and lat_current < -40: direction = - direction lat_current = lat_current + direction lon_current = lon_current - 0.75 if lon_current < -180 : lon_current += 360 basem = Basemap(projection='ortho',lat_0=lat_current,lon_0=lon_current,resolution='l',ax=ax) basem.drawcoastlines() #plt.show() plt.savefig(os.path.join(save_path,'frame%d.png'%frame),dpi=dpi,facecolor='w',edgecolor='k') writer.grab_frame() frame += 1 print current.isoformat() start = datetime.now() animation_test(datetime(2012,6,1,0),datetime(2012,4,dpi=80) print datetime.now() - start 稍微解释一下代码: 当我从程序中删除底图并只绘制了随机数据的散点图时,程序一直在运行. 我不确定,但我不认为这是一个内存问题,因为我的RAM仅使用约.程序运行时为20%. 感谢您帮助我们深入了解这一点. 解决方法
从
https://launchpad.net/~jon-severinsson/+archive/ffmpeg安装FFMPEG版本0.10.7后,它可以工作.
所以看起来这可能是libav的一个问题,默认情况下ubuntu使用它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |