【问题标题】:Python Matplotlib Basemap animation with FFMpegwriter stops after 820 Frames?带有FFMpegwriter的Python Matplotlib底图动画在820帧后停止?
【发布时间】:2013-07-27 01:31:45
【问题描述】:

如果我运行以下代码,它会在 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 分钟的步长逐步完成动画。我刚刚删除了对卫星数据的读取和绘图,以使任何人都可以执行代码。

当我从程序中删除底图并绘制随机数据的散点图时,程序一直运行。

我不确定,但我认为这不是内存问题,因为我的 RAM 仅使用了大约 10 分钟。程序运行时 20%。

感谢您提供任何帮助以了解详情。

【问题讨论】:

  • 您有任何错误吗? just 底图可以正常运行吗?
  • 遗憾的是没有错误消息。是的,如果我删除 ffmpegwriter 如果这就是你的意思,它就会运行
  • @cpaulik 只是让你知道,我在 Windows 7、python 2.7、matplotlib 1.2.1 和 Basemap 1.0.6 中运行了你的代码,它运行良好......
  • 感谢您在 Windows 上进行测试。我现在已经从launchpad.net/~jon-severinsson/+archive/ffmpeg 安装了 ffmpeg,现在它也可以在 ubuntu 上运行。我不知道 ubuntu 默认使用 libav。

标签: python matplotlib ffmpeg matplotlib-basemap


【解决方案1】:

在我从https://launchpad.net/~jon-severinsson/+archive/ffmpeg 安装 FFMPEG 版本 0.10.7 后,它可以工作了。

看来这可能是 ubuntu 默认使用的 libav 的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-16
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 2013-05-19
    相关资源
    最近更新 更多