eyeD3 icon indicating copy to clipboard operation
eyeD3 copied to clipboard

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

Open kevinkt1 opened this issue 4 years ago • 2 comments

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...

kevinkt1 avatar Jul 06 '20 02:07 kevinkt1

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.

nicfit avatar Jul 16 '20 17:07 nicfit

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.

kevinkt1 avatar Jul 17 '20 03:07 kevinkt1

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.

gcscaglia avatar Mar 29 '23 19:03 gcscaglia

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.

nicfit avatar Mar 29 '23 23:03 nicfit