1

Currently I have a process that creates a series of pictures and I then save them into a folder.

Is there a way that I can create a movie from them, say in 1 second, or 2 second intervals?

For example, I found this example from the matplotlib website:

from __future__ import print_function

import os
import matplotlib.pyplot as plt
import numpy as np

files = []
fig, ax = plt.subplots(figsize=(5, 5))
for i in range(50):  # 50 frames
    plt.cla()
    plt.imshow(np.random.rand(5, 5), interpolation='nearest')
    fname = '_tmp%03d.png' % i
    print('Saving frame', fname)
    plt.savefig(fname)
    files.append(fname)

print('Making movie animation.mpg - this make take a while')
os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o animation.mpg")
#os.system("convert _tmp*.png animation.mng")

# cleanup
for fname in files:
    os.remove(fname)

When I look at the folder that the notebook is in, I see the images being created. However, I don't see an animation.mpg being created anywhere.

What am I doing wrong?

Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60
  • [This](http://stackoverflow.com/questions/753190/programmatically-generate-video-or-animated-gif-in-python) is relevant. – Eli Sadoff Nov 05 '16 at 23:48
  • if you use `matplotlib` then it has `FuncAnimation` to create animation and `matplotlib` can save it as `mp4` – furas Nov 06 '16 at 00:09
  • `ImageMagic` can save many images into animated gif. (so you don't need Python) http://www.imagemagick.org/Usage/anim_basics/ – furas Nov 06 '16 at 00:11
  • [Here](http://matplotlib.org/examples/pylab_examples/movie_demo.html) is an example that generates `.png` files and creates an animation from them. – p-robot Nov 06 '16 at 00:17
  • Thank you. I looked into the matplotlib and tried the example. It creates the images just fine but it does not create mpg. – Trexion Kameha Nov 06 '16 at 06:02

0 Answers0