Problem with ani.save

Hi,

running the "AnimatedImage.py" I get the appended error message.

What's wrong?

Cheers
Elmar

In [5]: run AnimatedImage.py
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (23, 0))

···

---------------------------------------------------------------------------
OSError Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
     173 else:
     174 filename = fname
--> 175 __builtin__.execfile(filename, *where)

/home/elmar/PyScripts/examples_mpl/AnimatedImage.py in <module>()
      27 repeat_delay=1000)
      28
---> 29 ani.save('dynamic_images.mp4')
      30
      31

/usr/local/lib/python2.7/dist-packages/matplotlib/animation.pyc in save(self, filename, fps, codec, clear_temp, frame_prefix)
     125 self._fig.savefig(fname)
     126
--> 127 self._make_movie(filename, fps, codec, frame_prefix)
     128
     129 #Delete temporary files

/usr/local/lib/python2.7/dist-packages/matplotlib/animation.pyc in _make_movie(self, fname, fps, codec, frame_prefix, cmd_gen)
     162 verbose.report('Animation._make_movie running command: %s'%' '.join(command))
     163 proc = Popen(command, shell=False,
--> 164 stdout=PIPE, stderr=PIPE)
     165 proc.wait()
     166

/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
     677 p2cread, p2cwrite,
     678 c2pread, c2pwrite,
--> 679 errread, errwrite)
     680
     681 if mswindows:

/usr/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
    1237 if fd is not None:
    1238 os.close(fd)
-> 1239 raise child_exception
    1240
    1241

It seems that the Animation.save method assume that ffmpeg is installed,
as there is no cmd_gen keyword argument for this method.

As a quick and dirty fix, you may change the imposed commandline
constructor overloading the ffmpeg_cmd method

        ani.ffmpeg_cmd = ani.mencoder_cmd

or, if you prefer using gstreamer, something like that (not tested)
        def gst_cmd(fname, fps, codec, frame_prefix):
            cmd = 'gst-launch multifilesrc location="{prefix}%%04d.png" index={i0} num-buffers={nb} '\
            'caps="image/png,framerate=\(fraction\){fps}/1" ! pngdec ! ffmpegcolorspace ! '\
            '{codec_f} ! filesink location={fname} '
           nb_frames = len([tmp for tmp in os.listdir('./') if tmp.endswith('.png') and tmp.startswith(frame_prefix)])
           return cmd.format(prefix=frame_prefix, i0=0, nb=nb_frames, fps=fps, codec_f=codec+'mux', fname=fname)
        
        ani.ffmpeg_cmd = gst_cmd

···

--
Fabrice Silva

yeap, thanks a lot.

after installing ffmpeg everything is working smoothly.

···

On 29.12.2011 12:12, Fabrice Silva wrote:

It seems that the Animation.save method assume that ffmpeg is installed,
as there is no cmd_gen keyword argument for this method.

As a quick and dirty fix, you may change the imposed commandline
constructor overloading the ffmpeg_cmd method

         ani.ffmpeg_cmd = ani.mencoder_cmd

or, if you prefer using gstreamer, something like that (not tested)
         def gst_cmd(fname, fps, codec, frame_prefix):
             cmd = 'gst-launch multifilesrc location="{prefix}%%04d.png" index={i0} num-buffers={nb} '\
             'caps="image/png,framerate=\(fraction\){fps}/1" ! pngdec ! ffmpegcolorspace ! '\
             '{codec_f} ! filesink location={fname} '
            nb_frames = len([tmp for tmp in os.listdir('./') if tmp.endswith('.png') and tmp.startswith(frame_prefix)])
            return cmd.format(prefix=frame_prefix, i0=0, nb=nb_frames, fps=fps, codec_f=codec+'mux', fname=fname)

         ani.ffmpeg_cmd = gst_cmd