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

Skip to content

Commit ecba1d2

Browse files
authored
Merge pull request #19056 from QuLogic/ffmpeg-file-raw
2 parents d53555b + 6e3864a commit ecba1d2

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

lib/matplotlib/animation.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -628,15 +628,28 @@ class FFMpegFileWriter(FFMpegBase, FileMovieWriter):
628628
Frames are written to temporary files on disk and then stitched
629629
together at the end.
630630
"""
631-
supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp',
632-
'pbm', 'raw', 'rgba']
631+
supported_formats = ['png', 'jpeg', 'tiff', 'raw', 'rgba']
633632

634633
def _args(self):
635634
# Returns the command line parameters for subprocess to use
636635
# ffmpeg to create a movie using a collection of temp images
637-
return [self.bin_path(), '-r', str(self.fps),
638-
'-i', self._base_temp_name(),
639-
'-vframes', str(self._frame_counter)] + self.output_args
636+
args = []
637+
# For raw frames, we need to explicitly tell ffmpeg the metadata.
638+
if self.frame_format in {'raw', 'rgba'}:
639+
args += [
640+
'-f', 'image2', '-vcodec', 'rawvideo',
641+
'-video_size', '%dx%d' % self.frame_size,
642+
'-pixel_format', 'rgba',
643+
'-framerate', str(self.fps),
644+
]
645+
args += ['-r', str(self.fps), '-i', self._base_temp_name(),
646+
'-vframes', str(self._frame_counter)]
647+
# Logging is quieted because subprocess.PIPE has limited buffer size.
648+
# If you have a lot of frames in your animation and set logging to
649+
# DEBUG, you will have a buffer overrun.
650+
if _log.getEffectiveLevel() > logging.DEBUG:
651+
args += ['-loglevel', 'error']
652+
return [self.bin_path(), *args, *self.output_args]
640653

641654

642655
# Base class of avconv information. AVConv has identical arguments to FFMpeg.
@@ -745,8 +758,7 @@ class ImageMagickFileWriter(ImageMagickBase, FileMovieWriter):
745758
together at the end.
746759
"""
747760

748-
supported_formats = ['png', 'jpeg', 'ppm', 'tiff', 'sgi', 'bmp',
749-
'pbm', 'raw', 'rgba']
761+
supported_formats = ['png', 'jpeg', 'tiff', 'raw', 'rgba']
750762

751763
def _args(self):
752764
# Force format: ImageMagick does not recognize 'raw'.

lib/matplotlib/tests/test_animation.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,31 @@ def isAvailable(cls):
141141
('html', 'movie.html'),
142142
('null', 'movie.null')
143143
]
144-
WRITER_OUTPUT += [
145-
(writer, Path(output)) for writer, output in WRITER_OUTPUT]
144+
145+
146+
def gen_writers():
147+
for writer, output in WRITER_OUTPUT:
148+
if not animation.writers.is_available(writer):
149+
mark = pytest.mark.skip(
150+
f"writer '{writer}' not available on this system")
151+
yield pytest.param(writer, None, output, marks=[mark])
152+
yield pytest.param(writer, None, Path(output), marks=[mark])
153+
continue
154+
155+
writer_class = animation.writers[writer]
156+
for frame_format in getattr(writer_class, 'supported_formats', [None]):
157+
yield writer, frame_format, output
158+
yield writer, frame_format, Path(output)
146159

147160

148161
# Smoke test for saving animations. In the future, we should probably
149162
# design more sophisticated tests which compare resulting frames a-la
150163
# matplotlib.testing.image_comparison
151-
@pytest.mark.parametrize('writer, output', WRITER_OUTPUT)
164+
@pytest.mark.parametrize('writer, frame_format, output', gen_writers())
152165
@pytest.mark.parametrize('anim', [dict(klass=dict)], indirect=['anim'])
153-
def test_save_animation_smoketest(tmpdir, writer, output, anim):
154-
if not animation.writers.is_available(writer):
155-
pytest.skip("writer '%s' not available on this system" % writer)
156-
166+
def test_save_animation_smoketest(tmpdir, writer, frame_format, output, anim):
167+
if frame_format is not None:
168+
plt.rcParams["animation.frame_format"] = frame_format
157169
anim = animation.FuncAnimation(**anim)
158170
dpi = None
159171
codec = None

0 commit comments

Comments
 (0)