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

MemoryError on Raspberry PI 4 #479

Open
MaxSox64 opened this issue May 15, 2020 · 2 comments
Open

MemoryError on Raspberry PI 4 #479

MaxSox64 opened this issue May 15, 2020 · 2 comments

Comments

@MaxSox64
Copy link

I'm using pydub on a RPi 4 model B with 4GB RAM, running Raspbian Buster Lite.
Reading a flac or ape file larger than 200-220MB raises a MemoryError exception, always at the same line of code.

Steps to reproduce

`import sys
import os
from pydub import AudioSegment

print ('Reading audio file:', sys.argv[1])
full_wav = AudioSegment.from_file(sys.argv[1], os.path.splitext(sys.argv[1])[1][1:])
print ("Done!")`

Expected behavior

'Done!' should be printed

Actual behavior

pi@raspberrypi:~/flask_app $ python3 testpydub.py "/mnt/musiclib/Bach, J.S/L'Arte della fuga/Bach, J. S. - L'arte della Fuga BWV 1080 - Glenn Gould/CDImage.ape" ape.mp3 Reading audio file: /mnt/musiclib/Bach, J.S/L'Arte della fuga/Bach, J. S. - L'arte della Fuga BWV 1080 - Glenn Gould/CDImage.ape Traceback (most recent call last): File "testpydub.py", line 6, in <module> full_wav = AudioSegment.from_file(sys.argv[1], os.path.splitext(sys.argv[1])[1][1:]) File "/home/pi/.local/lib/python3.7/site-packages/pydub/audio_segment.py", line 729, in from_file obj = cls._from_safe_wav(BytesIO(p_out)) File "/home/pi/.local/lib/python3.7/site-packages/pydub/audio_segment.py", line 761, in _from_safe_wav obj = cls(data=file) File "/home/pi/.local/lib/python3.7/site-packages/pydub/audio_segment.py", line 222, in __init__ wav_data = read_wav_audio(data) File "/home/pi/.local/lib/python3.7/site-packages/pydub/audio_segment.py", line 132, in read_wav_audio data[pos:pos + data_hdr.size]) MemoryError

Your System configuration

  • Python version: 3.7
  • Pydub version: 0.24.0
  • ffmpeg or avlib?: ffmpeg
  • ffmpeg/avlib version:
    ffmpeg version N-97723-gfc99a24782 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 8 (Raspbian 8.3.0-6+rpi1)
@mhurliman
Copy link

I'm getting this error as well on the Raspberry Pi Zero W, which only has 512 MB RAM. I'm trying to load/decompress ~5 MB mp3 files, which decompress to ~50-60 MB.

This callstack duplicates the raw audio data several times. This spikes the Python instance's memory usage, maxes out the 512 MB, hits swap memory causing the program to slow to a crawl, then finally hits the MemoryError.

If some of these memory copies could be eliminated we'd be all gucci.

@Harrison88
Copy link
Contributor

I've got a pull request open (#490) that eliminates some of those copies, reducing memory usage by about half.

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

No branches or pull requests

3 participants