次のようなプロットを動画として出力するコードを動かすと
python
1import matplotlib 2matplotlib.use('Agg') 3import random 4import matplotlib.animation as animation 5import matplotlib.pyplot as plt 6 7 8def run(): 9 10 def update(k, ax): 11 ax.clear() 12 X=[1,2,3,4] 13 Y=[random.random() for i in range(len(X))] 14 ax.plot(X,Y) 15 fig,ax=plt.subplots(1,1) 16 ani = animation.FuncAnimation(fig, update, fargs=[ax,], interval=50, frames=10) 17 ani.save("hogehoge.mp4", writer="ffmpeg") 18 19 20run() 21
下記のエラーが出ます。
Traceback (most recent call last): File "main.py", line 20, in <module> run() File "main.py", line 17, in run ani.save("hogehoge.mp4", writer="ffmpeg") File "/home/usr/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 1200, in save writer.grab_frame(**savefig_kwargs) File "/home/usr/anaconda3/lib/python3.6/contextlib.py", line 99, in __exit__ self.gen.throw(type, value, traceback) File "/home/usr/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 241, in saving self.finish() File "/home/usr/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 367, in finish self.cleanup() File "/home/usr/anaconda3/lib/python3.6/site-packages/matplotlib/animation.py", line 405, in cleanup out, err = self._proc.communicate() File "/home/usr/anaconda3/lib/python3.6/subprocess.py", line 843, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "/home/usr/anaconda3/lib/python3.6/subprocess.py", line 1505, in _communicate selector.register(self.stdout, selectors.EVENT_READ) File "/home/usr/anaconda3/lib/python3.6/selectors.py", line 351, in register key = super().register(fileobj, events, data) File "/home/usr/anaconda3/lib/python3.6/selectors.py", line 237, in register key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data) File "/home/usr/anaconda3/lib/python3.6/selectors.py", line 224, in _fileobj_lookup return _fileobj_to_fd(fileobj) File "/home/usr/anaconda3/lib/python3.6/selectors.py", line 39, in _fileobj_to_fd "{!r}".format(fileobj)) from None ValueError: Invalid file object: <_io.BufferedReader name=6>
環境は次の通りです。
原因のわかる方ご教示ください
環境は次の通りです。
$ python Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib >>> matplotlib.__version__ '2.2.2'
ffmpeg ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 7.2.0 (crosstool-NG fa8859cb) configuration: --prefix=/home/usr/anaconda3 --cc=/tmp/build/80754af9/ffmpeg_1526323631431/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc --disable-doc --enable-shared --enable-static --enable-zlib --enable-pic --enable-gpl --enable-version3 --disable-nonfree --enable-hardcoded-tables --enable-avresample --enable-libfreetype --disable-openssl --disable-gnutls --enable-libvpx --enable-pthreads --enable-libopus --enable-postproc --disable-libx264 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 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 libpostproc 55. 1.100 / 55. 1.100 Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... Use -h to get full help or, even better, run 'man ffmpeg'