From 66b14f189413309fa468882f72f420d52c8f1026 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sat, 7 Jul 2012 11:34:12 -0400 Subject: [PATCH 1/2] Fix subprocess bug when saving animations. Ffmpeg prints a lot of info to stderr. For longer animations, this logging fills up the (very-small) buffer for subprocess.PIPE and subprocess just hangs (no error). Suppress logging in ffmpeg to prevent this issue. --- lib/matplotlib/animation.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 5f01b1cf8369..14d9a521785c 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -356,10 +356,12 @@ 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 + # ffmpeg to create a movie using a pipe. + # Logging is quieted because subprocess.PIPE has limited buffer size. 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 + '-s', '%dx%d' % self.frame_size, '-pix_fmt', self.frame_format, + '-r', str(self.fps), '-loglevel', 'quiet', + '-i', 'pipe:'] + self.output_args #Combine FFMpeg options with temp file-based writing From 467fa90cdb8e364182deb361d5b293c1990f0560 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Sat, 7 Jul 2012 14:45:58 -0400 Subject: [PATCH 2/2] Add print-out of ffmpeg output when debugging. --- lib/matplotlib/animation.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 14d9a521785c..5eb49529629f 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -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 @@ -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.' @@ -357,11 +362,14 @@ class FFMpegWriter(MovieWriter, FFMpegBase): def _args(self): # Returns the command line parameters for subprocess to use # ffmpeg to create a movie using a pipe. - # Logging is quieted because subprocess.PIPE has limited buffer size. - return [self.bin_path(), '-f', 'rawvideo', '-vcodec', 'rawvideo', + args = [self.bin_path(), '-f', 'rawvideo', '-vcodec', 'rawvideo', '-s', '%dx%d' % self.frame_size, '-pix_fmt', self.frame_format, - '-r', str(self.fps), '-loglevel', 'quiet', - '-i', 'pipe:'] + self.output_args + '-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