Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b836275

Browse files
committed
Merge pull request #989 from tonysyu/animation-subprocess-bug
Fix a bug with too much output from ffmpeg stalling the pipe.
2 parents 1ee7e7b + 467fa90 commit b836275

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/matplotlib/animation.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# * Movies
1818
# * Can blit be enabled for movies?
1919
# * Need to consider event sources to allow clicking through multiple figures
20+
import sys
2021
import itertools
2122
import contextlib
2223
import subprocess
@@ -175,10 +176,14 @@ def _run(self):
175176
# movie file. *args* returns the sequence of command line arguments
176177
# from a few configuration options.
177178
command = self._args()
179+
if verbose.ge('debug'):
180+
output = sys.stdout
181+
else:
182+
output = subprocess.PIPE
178183
verbose.report('MovieWriter.run: running command: %s'%' '.join(command))
179184
self._proc = subprocess.Popen(command, shell=False,
180-
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
181-
stdin=subprocess.PIPE)
185+
stdout=output, stderr=output,
186+
stdin=subprocess.PIPE)
182187

183188
def finish(self):
184189
'Finish any processing for writing the movie.'
@@ -356,10 +361,15 @@ def output_args(self):
356361
class FFMpegWriter(MovieWriter, FFMpegBase):
357362
def _args(self):
358363
# Returns the command line parameters for subprocess to use
359-
# ffmpeg to create a movie using a pipe
360-
return [self.bin_path(), '-f', 'rawvideo', '-vcodec', 'rawvideo',
361-
'-s', '%dx%d' % self.frame_size, '-pix_fmt', self.frame_format,
362-
'-r', str(self.fps), '-i', 'pipe:'] + self.output_args
364+
# ffmpeg to create a movie using a pipe.
365+
args = [self.bin_path(), '-f', 'rawvideo', '-vcodec', 'rawvideo',
366+
'-s', '%dx%d' % self.frame_size, '-pix_fmt', self.frame_format,
367+
'-r', str(self.fps)]
368+
# Logging is quieted because subprocess.PIPE has limited buffer size.
369+
if not verbose.ge('debug'):
370+
args += ['-loglevel', 'quiet']
371+
args += ['-i', 'pipe:'] + self.output_args
372+
return args
363373

364374

365375
#Combine FFMpeg options with temp file-based writing

0 commit comments

Comments
 (0)