Lost artwork while converting .m4a to .mp3 (Python)

487 Views Asked by At

I'm trying to convert m4a audio file with artwork (cover) to mp3. I'm using ffmpeg to convert the audio.

Once it copies, the artwork is lost. I'm quite not sure, how to retain the cover. I found some reference about mutagen library but not sure again how to use to copy the artwork.

Any help would be great.

ffmpeg -i source/file -acodec libmp3lame -ab 128k destination.mp3

Update:

I'm reading the artwork and m4a to be able to attache it back. I can get the artwork by using

artwork = audio.tags['covr']

Now my problem is how do I save the artwork as image in a new file?

I tried the Following:

with open(path/to/write, 'wb') as img: img.write(artwork)

This gives me an error

'list' does not support the buffer interface line

Any suggestion, how I can save the artwork extracted covr data?

2

There are 2 best solutions below

1
Bernhard On

I can't test it right now, but map_metadata should help if the album cover is part of the metadata.

ffmpeg -i source/file -acodec libmp3lame -ab 128k -map_metadata 0:s:0 destination.mp3
0
Webghost On

If anyone is having the same issue;

I ended up reading the artwork from original file and attaching it back to mp3

if audioFileNameWithM4AExtension.startswith("covr"): #checks if it has cover cover = audioFileNameWithM4AExtension.tags['covr'][0] #gets the cover