Skip to content

Commit

Permalink
Merge pull request #989 from tonysyu/animation-subprocess-bug
Browse files Browse the repository at this point in the history
Fix a bug with too much output from ffmpeg stalling the pipe.
  • Loading branch information
dopplershift committed Jul 20, 2012
2 parents 1ee7e7b + 467fa90 commit b836275
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/matplotlib/animation.py
Expand Up @@ -17,6 +17,7 @@
# * Movies
# * Can blit be enabled for movies?
# * Need to consider event sources to allow clicking through multiple figures
import sys
import itertools
import contextlib
import subprocess
Expand Down Expand Up @@ -175,10 +176,14 @@ def _run(self):
# movie file. *args* returns the sequence of command line arguments
# from a few configuration options.
command = self._args()
if verbose.ge('debug'):
output = sys.stdout
else:
output = subprocess.PIPE
verbose.report('MovieWriter.run: running command: %s'%' '.join(command))
self._proc = subprocess.Popen(command, shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
stdout=output, stderr=output,
stdin=subprocess.PIPE)

def finish(self):
'Finish any processing for writing the movie.'
Expand Down Expand Up @@ -356,10 +361,15 @@ def output_args(self):
class FFMpegWriter(MovieWriter, FFMpegBase):
def _args(self):
# Returns the command line parameters for subprocess to use
# ffmpeg to create a movie using a pipe
return [self.bin_path(), '-f', 'rawvideo', '-vcodec', 'rawvideo',
'-s', '%dx%d' % self.frame_size, '-pix_fmt', self.frame_format,
'-r', str(self.fps), '-i', 'pipe:'] + self.output_args
# ffmpeg to create a movie using a pipe.
args = [self.bin_path(), '-f', 'rawvideo', '-vcodec', 'rawvideo',
'-s', '%dx%d' % self.frame_size, '-pix_fmt', self.frame_format,
'-r', str(self.fps)]
# Logging is quieted because subprocess.PIPE has limited buffer size.
if not verbose.ge('debug'):
args += ['-loglevel', 'quiet']
args += ['-i', 'pipe:'] + self.output_args
return args


#Combine FFMpeg options with temp file-based writing
Expand Down

0 comments on commit b836275

Please sign in to comment.