Python Matplotlib Basemap 动画使用 FFMpegwriter 在820帧后停止?

4

如果我运行以下代码,它只会在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,0,0),datetime(2012,6,4,0,0,0),fps=10,dpi=80)
print datetime.now() - start

为了解释代码的一些细节: 我想制作一个卫星数据的动画,这些数据是以小的3分钟文件形式提供的,并在旋转的地球上显示。这就是为什么我选择让以下示例代码中的循环以3分钟的步长遍历动画。我只是删除了读取和绘制卫星数据的部分,以使该代码可被任何人执行。
当我从程序中删除basemap并只绘制随机数据的散点图时,程序可以完整运行。
我不确定,但我认为这不是内存问题,因为程序运行时我的RAM仅被利用约20%。
感谢您帮助找到问题的根本原因。

你有收到任何错误吗?只使用基本地图运行是否正常? - tacaswell
很遗憾,没有错误信息。如果我删除ffmpegwriter,它就可以运行,如果这是你的意思。 - cpaulik
@cpaulik,我想告诉你,我在Windows 7、Python 2.7、Matplotlib 1.2.1和Basemap 1.0.6上运行了你的代码,它完美地运行了... - Saullo G. P. Castro
感谢您在Windows上进行测试。我现在已经从 https://launchpad.net/~jon-severinsson/+archive/ffmpeg 安装了ffmpeg,现在它也可以在Ubuntu上使用了。我之前不知道Ubuntu默认使用libav。 - cpaulik
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接