nicfit / eyeD3

eyeD3 is a Python module and command line program for processing ID3 tags. Information about mp3 files (i.e bit rate, sample frequency, play time, etc.) is also provided. The formats supported are ID3v1 (1.0/1.1) and ID3v2 (2.3/2.4).
http://eyed3.nicfit.net/
GNU General Public License v3.0
547 stars 59 forks source link

Python API - Removing image from .mp3 file but the file size still remains the same #457

Closed kevinkt1 closed 1 year ago

kevinkt1 commented 4 years ago

I am removing an added image from an MP3 file. But the file size of the MP3 file after removing the image remains unchanged. I am checking the file size via Windows Explorer. Here's how I'm adding and removing the image:

audioFile = eyed3.load(mp3FilePath)

# Add image to file
audioFile.tag.images.set(3, open(mp3FilePath, 'rb').read(), 'image/png')
audioFile.tag.save()

# Note that the file size increases, and also...
print(list(audioFile.tag.images)) # ... outputs a non-empty list

# Remove image from file
audioImageDescriptions = [audioImage.description for audioImage in audioFile.tag.images]
for description in audioImageDescriptions:
  audioFile.tag.images.remove(description)

# Save the changes
audioFile.tag.save()

print(list(audioFile.tag.images)) # outputs an empty list

While the ImageFrame objects may be removed from the list, the file size of the modified MP3 file still remains the same after removing.

Am I doing something wrong? Or is this a legitimate issue? I also observed that this unit test does not appear to check for the file size before and after, so I am led to believe this may be a legitimate issue...

nicfit commented 4 years ago

Does eyeD3 --verbose show an APIC frame. If not, te image frame is removed. Tags can have padding though, I suspect the zero byte padding may be why the file size remains unchanged.

kevinkt1 commented 4 years ago

Does eyeD3 --verbose show an APIC frame. If not, te image frame is removed. Tags can have padding though, I suspect the zero byte padding may be why the file size remains unchanged.

Not sure, but I changed my Python script to run the Linux package eyeD3 instead of using the eyeD3 Python module. The Linux package seems to work fine.

gcscaglia commented 1 year ago

I know this is an old issue, but I've found the solution: When calling tag.save, you must specify a non-zero max_padding argument, e.g.:

audio_file.tag.save(max_padding=1)

On my tests, specifying max_padding=0 did not resize the file.

nicfit commented 1 year ago

Good call @gcscaglia . If the file has padding already, set to allow padding, the image can be removed and replaced in terms of more padding (null bytes). So a full rewrite of all the audio data does not have to occur.