Skip to content

Commit 59eca70

Browse files
committed
Support raw/rgba frame format in FFMpegFileWriter.
1 parent b2308fa commit 59eca70

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/matplotlib/animation.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,15 +627,23 @@ class FFMpegFileWriter(FFMpegBase, FileMovieWriter):
627627
def _args(self):
628628
# Returns the command line parameters for subprocess to use
629629
# ffmpeg to create a movie using a collection of temp images
630-
args = [self.bin_path(), '-r', str(self.fps),
631-
'-i', self._base_temp_name(),
632-
'-vframes', str(self._frame_counter)]
630+
args = []
631+
# For raw frames, we need to explicitly tell ffmpeg the metadata.
632+
if self.frame_format in {'raw', 'rgba'}:
633+
args += [
634+
'-f', 'image2', '-vcodec', 'rawvideo',
635+
'-video_size', '%dx%d' % self.frame_size,
636+
'-pixel_format', 'rgba',
637+
'-framerate', str(self.fps),
638+
]
639+
args += ['-r', str(self.fps), '-i', self._base_temp_name(),
640+
'-vframes', str(self._frame_counter)]
633641
# Logging is quieted because subprocess.PIPE has limited buffer size.
634642
# If you have a lot of frames in your animation and set logging to
635643
# DEBUG, you will have a buffer overrun.
636644
if _log.getEffectiveLevel() > logging.DEBUG:
637645
args += ['-loglevel', 'error']
638-
return [*args, *self.output_args]
646+
return [self.bin_path(), *args, *self.output_args]
639647

640648

641649
# Base class of avconv information. AVConv has identical arguments to FFMpeg.

0 commit comments

Comments
 (0)