2013/12/17

Ubuntu12.04で動くグラフを作る

環境の構築
$sudo apt-get install imagemagick
$sudo apt-get install ffmpeg
pythonで動画を描きます。そして、jpgファイルで残します。
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import pylab
import math
import time

pylab.ion()

x = pylab.arange(0, 2*math.pi, 0.01)
line, = pylab.plot(x, pylab.cos(x))
for i in pylab.arange(1,200):
    line.set_ydata(pylab.cos(x+i/10.0))
    pylab.draw()
    pylab.savefig('test_{0:0>3}'.format(i))
jpgファイルを動画に変換します。
$convert -delay 10 test_*.png cos.mpg
以下のようなエラーがでました。
convert: delegate failed `"ffmpeg" -v -1 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 300 -i "%M%%d.jpg" "%u.%m" 2> "%Z"'  @ error/delegate.c/InvokeDelegate/1058.
以下のファイルの83行目を修正します。 /etc/ImageMagick/delegates.xml -pass 1/2の部分を削除しました。 すると、今度は無事に以下が実行できます。
$convert -delay 10 test_*.png cos.mpg
できたグラフの動画は以下のようになりました。

0 件のコメント:

コメントを投稿