質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

2886閲覧

ani.save("hogehoge.mp4", writer="ffmpeg")とすると、ValueError: Invalid file object

ruei

総合スコア284

Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2018/11/06 03:11

編集2022/01/12 10:55

次のようなプロットを動画として出力するコードを動かすと

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'

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tiitoi

2018/11/06 04:12 編集

一部ではなく、現状を再現できる動くコードを貼れますか?
ruei

2018/11/06 07:04

修正しました。すみません。
tiitoi

2018/11/06 07:09

そのままコピペして動きましたよ。依存ライブラリの ffmpeg はインストールされてますか?
ruei

2018/11/06 07:11

インストールされています。ffmpegをつかってgifをmp4に変換したことがあります。バージョンを追記しました。
tiitoi

2018/11/06 07:15

一応質問欄のコードが動いた環境を貼っておきます。ffmpeg version 3.2.4/matplotlib 2.2.3/Python 3.5.4/Ubuntu 16.04
guest

回答1

0

開発でも「トレースバックがわけわからないからなんとかした方が良い」と話題が上がって、現在改善中のようです。

Traceback from animation.MovieWriter.saving method is confusing because it provides no useful information · Issue #8760 · matplotlib/matplotlib · GitHub

debugのヒントにもなるような情報が載っていると思うので(有益なログを取る方法とか)、参考にどうぞ。

投稿2018/11/06 07:06

hayataka2049

総合スコア30933

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問