Skip to content

Use rounding instead of truncation to calculate the frame size #8250

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

Closed
wants to merge 1 commit into from

Conversation

ngoldbaum
Copy link
Contributor

This fixes an issue I ran into where the frame sizes were supposed to be adjusted to integers by _adjust_frame_size, but because the frame_size property uses truncation, the vagaries of floating point math means that the frame size adjustment didn't work. Here's a snippet from my debugging session that illustrates the issue:

(Pdb) self.fig.get_size_inches()[1]*self.dpi
919.99999999999989

I think it's safe just to use rounding here instead of truncation? Maybe we need to add epsilon somewhere instead if this could cause issues.

Yay floating point math!

@@ -267,7 +267,7 @@ def __init__(self, fps=5, codec=None, bitrate=None, extra_args=None,
def frame_size(self):
'A tuple (width,height) in pixels of a movie frame.'
w, h = self.fig.get_size_inches()
return int(w * self.dpi), int(h * self.dpi)
return round(w * self.dpi), round(h * self.dpi)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use np.round? Otherwise, the behavior is Python version-dependent.

Copy link
Member

Choose a reason for hiding this comment

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

For clarity to Nathan, you mean np.round([w * self.dpi, h * self.dpi]), right?

Copy link
Member

Choose a reason for hiding this comment

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

(tuple of numpy scalars vs numpy array)

Copy link
Member

Choose a reason for hiding this comment

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

The result (according to the docstring) should still be a tuple.

@ngoldbaum
Copy link
Contributor Author

Apologies for the noise, this isn't actually right - I get this out the other end:

http://imgur.com/a/SWcPI

(which is among the weirdest results of a bug I've run into in a while).

Will try to dig in and figure out what the real fix is....

@ngoldbaum
Copy link
Contributor Author

I have an alternate fix for this that I will open another pull request for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants