After I installed FFMPEG version 0.10.7 from https://launchpad.net/~jon-severinsson/+archive/ffmpeg it works.
So it seems that this might be an issue with libav which is used by ubuntu by default.
質問
If I run the following code it just stops after 820 Frames. I tested this on both a Ubuntu 12.04 VM and on Linux Mint 15. Unfortunately there is no error message. The program just hangs after printing 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
To explain the code a little bit: I want to make an animation of satellite data which comes in small 3 minute files and show it on a rotating globe. This is why I chose to make the loop in the following example code step through the animation in 3 minute steps. I just removed the reading and plotting of the satellite data in order to make the code executable by anyone.
When I removed basemap from the program and just plotted a scatterplot of random data the program ran all the way through.
I'm not sure but I don't think that it is a memory issue since my RAM is only utilized approx. 20% while the program is running.
Thanks for any help in getting to the bottom of this.
解決
After I installed FFMPEG version 0.10.7 from https://launchpad.net/~jon-severinsson/+archive/ffmpeg it works.
So it seems that this might be an issue with libav which is used by ubuntu by default.