Skip to content
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

Instantiate AudioSegment in from_file, instead of using _from_safe_wav #490

Merged
merged 3 commits into from Feb 28, 2021

Conversation

Harrison88
Copy link
Contributor

Hello,
I previously made a pull request (#453) which failed under Python 2.7. After thinking about it some more, I also realized that using a bytearray changed things in a pretty major way by making AudioSegments mutable. So I went back to the drawing board. The graphs in #453 still apply, so I won't repeat them here, but here are some new ones from the Fil memory profiler.
Prior to the change (pydub at master):

fil-profile-master

And after the change:
fil-profile-change

This is the memory usage of opening a 57MB MP3 file using from_file and changing the sample rate to 16000.

The only change to pydub is replacing the call to _from_safe_wav with an instantiation of the class directly. Since _from_safe_wav just reads the BytesIO object and instantiates the class using the bytes, this should be exactly the same as before in every way, except with fewer copies of the data getting made.

Thank you for your time!

@Harrison88 Harrison88 mentioned this pull request Jun 11, 2020
@Harrison88
Copy link
Contributor Author

Hi @jiaaro, I hope all is well. Is there any way this can get merged? It's a relatively small change, but the benefits are large for those of us it impacts.

@jiaaro jiaaro merged commit 8b9bd24 into jiaaro:master Feb 28, 2021
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.

None yet

3 participants