1

I am using matplotlib and ffmpeg to do some animations. I usually code on a remote server because the code runs faster; we are having some issues making animations on the remote server. Here is an example of code that works perfectly on my local mac but does not work remotely.

import matplotlib as mpl
mpl.use('agg')
import matplotlib as mpl 
from matplotlib import animation
import pylab

def init():
    pylab.plot(pylab.arange(10), [0]*10)

def redraw(frame):
    pylab.plot(pylab.arange(10), pylab.arange(10) * frame)

fig = pylab.figure()
ani = animation.FuncAnimation(fig, redraw, frames=10, interval=1000, init_func=init)
ani.save('animation.mp4')

I get the animation I want on my local machine (macOS Sierra). When I run it on the remote host (Debian GNU/Linux 8 (jessie)), I get the following error message after 5 frames

Traceback (most recent call last):
  File "animation.py", line 14, in <module>
    ani.save('animation.mp4')
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/animation.py", line 1200, in save
    writer.grab_frame(**savefig_kwargs)
  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/animation.py", line 241, in saving
    self.finish()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/animation.py", line 367, in finish
    self.cleanup()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/animation.py", line 405, in cleanup
    out, err = self._proc.communicate()
  File "/usr/local/lib/python2.7/dist-packages/subprocess32.py", line 724, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/local/lib/python2.7/dist-packages/subprocess32.py", line 1535, in _communicate
    orig_timeout)
  File "/usr/local/lib/python2.7/dist-packages/subprocess32.py", line 1591, in _communicate_with_poll
    register_and_append(self.stdout, select_POLLIN_POLLPRI)
  File "/usr/local/lib/python2.7/dist-packages/subprocess32.py", line 1570, in register_and_append
    poller.register(file_obj.fileno(), eventmask)
ValueError: I/O operation on closed file

My local machine uses matplotlib version 2.0.0; the remote machine uses matplotlib version 2.2.2

On my local machine I have ffmpeg version 3.2.4

$ ffmpeg -version
ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.4 --enable-shared - 
-enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables 
--enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
libavutil      55. 34.101 / 55. 34.101
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.101 / 57. 56.101
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libavresample   3.  1.  0 /  3.  1.  0
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100 

On the remote host i have ffmpeg version 4.0.1

ffmpeg -version
ffmpeg version 4.0.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10+deb8u1)
configuration: --prefix=/usr/local
libavutil      56. 14.100 / 56. 14.100
libavcodec     58. 18.100 / 58. 18.100
libavformat    58. 12.100 / 58. 12.100
libavdevice    58.  3.100 / 58.  3.100
libavfilter     7. 16.100 /  7. 16.100
libswscale      5.  1.100 /  5.  1.100
libswresample   3.  1.100 /  3.  1.100

If I recall correctly I installed ffmpeg locally through homebrew; I have the anaconda distribution of python. On the remote machine we have the default version of python that comes with Jessie; I'm not sure how the sysadmin installed ffmpeg.

I am by no means an expert on ffmpeg, but I have generally never had issues with making animations in matplotlib on my local machine and I would really like to be able to make videos more quickly on the remote machine. Any help would be appreciated!

Edit On the remote machine, the animation works if I use avconv as the writer instead of ffmpeg. I installed avconv locally...which led me to get the same ffmpeg issues locally (probably due to updating shared dependencies). However, I uninstalled ffmpeg and reinstalled it with x264 codec enables Animations in ipython (jupyter) notebook - ValueError: I/O operation on closed file

arjunc12
  • 181
  • 1
  • 2
  • 9
  • I can't reproduce the problem on any of my remote machines so I don't think the code executed being remote is an issue (matplotlib 2.2.2, ffmpeg 3.4.2). It's not something silly such as that you are running out of disk space? – Paul Brodersen Jun 29 '18 at 11:36
  • We keep all our largest files on a separate data drive, and I am having no trouble saving large pdfs (i.e. a scatterplot with 40000 points), so I don't think disk space is an issue – arjunc12 Jun 30 '18 at 02:18
  • I suggest you update matplotlib and ffmpeg (although I don't think the latter is the issue, as it seems to me from the error message that you don't get that far). – Paul Brodersen Jul 02 '18 at 09:36

0 Answers0