<p>在修补了ffmpeg(请参阅Joe Kington对我的问题的评论)之后,我能够将png的管道设置为ffmpeg,如下所示:</p>
<pre><code>import subprocess
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
outf = 'test.avi'
rate = 1
cmdstring = ('local/bin/ffmpeg',
'-r', '%d' % rate,
'-f','image2pipe',
'-vcodec', 'png',
'-i', 'pipe:', outf
)
p = subprocess.Popen(cmdstring, stdin=subprocess.PIPE)
plt.figure()
frames = 10
for i in range(frames):
plt.imshow(np.random.randn(100,100))
plt.savefig(p.stdin, format='png')
</code></pre>
<p>如果没有<a href="http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090601/887e0be1/attachment.patch">patch</a>,它将无法工作,后者只需简单地修改两个文件并添加<code>libavcodec/png_parser.c</code>。我不得不手动将修补程序应用到<code>libavcodec/Makefile</code>。最后,我从<code>Makefile</code>中删除了'-number',以获取要构建的手册页。有了编译选项</p>
<pre><code>FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
built on Nov 30 2010 20:42:02 with gcc 4.2.1 (Apple Inc. build 5664)
configuration: --prefix=/Users/paul/local_test --enable-gpl --enable-postproc --enable-swscale --enable-libxvid --enable-libx264 --enable-nonfree --mandir=/Users/paul/local_test/share/man --enable-shared --enable-pthreads --disable-indevs --cc=/usr/bin/gcc-4.2 --arch=x86_64 --extra-cflags=-I/opt/local/include --extra-ldflags=-L/opt/local/lib
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0.11. 0 / 0.11. 0
libpostproc 51. 2. 0 / 51. 2. 0
</code></pre>