I'm trying to use pydub to convert uploaded mp3s to a certain bitrate, using this code:
from pydub import AudioSegment
def process_mp3(mp3, id):
print(mp3) # media/track1-original
audio = AudioSegment.from_mp3(mp3)
bitrates = [128, 192, 256, 320]
for bitrate in bitrates:
audio.export(settings.MEDIA_ROOT + '/' + 'track' + id + '-' + bitrate, format="mp3", bitrate=bitrate + 'k')
def save_file(file, name):
with open(default_storage.path(settings.MEDIA_ROOT + '/' + name), 'wb+') as destination:
for chunk in file.chunks():
destination.write(chunk)
return name
I'm getting this error:
FileNotFoundError: [WinError 2] Systemet finner ikke angitt fil
And the code that calls process_mp3
is (Note: track_obj is a Django model object and the ID is from a database):
from mutagen.mp3 import MP3
....
mp3 = save_file(mp3, 'track' + str(track_obj.id) + '-' + 'original')
mp3_info = MP3('media/' + mp3); # This works
process_mp3('media/' + mp3, str(track_obj.id)) # This does not
Apparently, mutagen can read the file just fine, but pydub cannot. What gives?