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

Skip to content

Cleanup Animation frame_formats. #19044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2020
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 29, 2020

  • Warn if the requested frame format is unsupported and fallback occurs.
  • FFMpegFileWriter does not support 'raw' or 'rgba' (AFAICT there's no
    way to forward the relevant frame size/bitdepth info).
  • ImageMagickFileWriter supports 'rgba' but requires explicit frame_size
    and depth to do so (they are the same as for ImageMagickWriter, and
    passing them doesn't negatively impact other formats), but it does not
    support 'raw' (per https://imagemagick.org/script/formats.php).

Test script:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()

x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))

def animate(i):
    line.set_ydata(np.sin(x + i / 50))  # update the data.
    return line,

ani = animation.FuncAnimation(
    fig, animate, interval=50, blit=True, save_count=20)

plt.rcParams["animation.frame_format"] = "rgba"  # or "raw"
writer = animation.FFMpegFileWriter()  # or animation.ImageMagickFileWriter()
ani.save("/tmp/movie.mp4", writer=writer)

(Also move import of PIL up, as it's a standard dependency now.)

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@QuLogic
Copy link
Member

QuLogic commented Dec 1, 2020

FFMpegFileWriter does not support 'raw' or 'rgba' (AFAICT there's no
way to forward the relevant frame size/bitdepth info).

I'm not sure about the class in Matplotlib, but at least ffmpeg can accept rgba frames (specifying size, etc. via command-line info) https://ffmpeg.org/ffmpeg-formats.html#rawvideo

@anntzer
Copy link
Contributor Author

anntzer commented Dec 1, 2020

I specifically meant the Matplotlib class, when used for reconstituting a movie from on-disk image (rgba) files. If you (or someone else) knows the right invocation to make the example given above work, then that's even better :)

@QuLogic
Copy link
Member

QuLogic commented Dec 1, 2020

Yes, I linked to the wrong format, but it should be possible. I just need to test out the other frame formats to be sure I didn't break it.

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert the raw/rgba removal bits, and then I can add tests into #19056.

@anntzer
Copy link
Contributor Author

anntzer commented Dec 2, 2020

Actually, looks like the check for FileMovieWriter when setting the frame format to rgba is still needed for HTMLWriter, which does not support that format...

@QuLogic
Copy link
Member

QuLogic commented Dec 3, 2020

Isn't that overwritten in FileMovieWriter.__init__ anyway? Ah, I see you want to avoid that new warning. How about re-ordering supported_formats to put rgba first, and then use frame_format = supported_formats[0] in the init?

@anntzer
Copy link
Contributor Author

anntzer commented Dec 3, 2020

Ah yes, that's a good idea.

@QuLogic
Copy link
Member

QuLogic commented Dec 4, 2020

Unfortunately, seems to have broken docs.

- Warn if the requested frame format is unsupported and fallback occurs.
- ImageMagickFileWriter supports 'rgba' but requires explicit frame_size
  and depth to do so (they are the same as for ImageMagickWriter, and
  passing them doesn't negatively impact other formats); it does not
  support 'raw' (per https://imagemagick.org/script/formats.php) but we
  can just override it as 'rgba'.

Test script:
```python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()

x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))

def animate(i):
    line.set_ydata(np.sin(x + i / 50))  # update the data.
    return line,

ani = animation.FuncAnimation(
    fig, animate, interval=50, blit=True, save_count=20)

plt.rcParams["animation.frame_format"] = "rgba"  # or "raw"
writer = animation.FFMpegFileWriter()  # or animation.ImageMagickFileWriter()
ani.save("/tmp/movie.mp4", writer=writer)
```

(Also move import of PIL up, as it's a standard dependency now.)
@anntzer
Copy link
Contributor Author

anntzer commented Dec 4, 2020

hopefully fixed now...

@QuLogic QuLogic requested a review from dopplershift December 8, 2020 05:36
@timhoffm timhoffm added this to the v3.4.0 milestone Dec 12, 2020
@timhoffm timhoffm merged commit 7a5458b into matplotlib:master Dec 12, 2020
@anntzer anntzer deleted the animframefmts branch December 12, 2020 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants