Copy song info from mp3 file to aac file from terminal

audioid3-tagm4amp3terminal

I am trying to create a script that performs various conversions between formats of audio files. In one particular step, I use afconvert in Terminal to convert an mp3 to aac(mpeg4/m4a), but in this process all of the info attached to the audio file (name, artist etc) is lost. I tried to id3cp to copy over the info but this doesn't work (I think because aac files don't use ID3 tags…).

Could someone suggest a way of copying all of the associated info on the mp3 files to the aac (m4a) file? Is there a way it can be retained during the conversion (preferable) or alternately a Terminal command to copy the info over?

Best Answer

I prefer the mutagen Python library for tag editing, since it has good support for a wide variety of formats with a consistent interface. Here’s a script for copying the metadata of a file:

import mutagen
import mutagen.easyid3
old = mutagen.easyid3.EasyID3('example.mp3') 
new = mutagen.File('example.m4a') 
new.update(old)
new.save()

You can open any file with mutagen.File, but that gives you raw access to the coded ID3 tags like 'TPE1', instead of human-readable tags like 'artist', so EasyID3 is used instead.