get feed

KDE3.5 and other stuff

Computer related problems and solutions, tips, tricks, hacks and so on

:: How to use ffmpeg to convert .m4a files into .mp3 keeping tags

I have been using SoundKonverter to convert audio formats. Overall, it is a very nice application. There are, however, several coveats. First of all the version thatI have on my old system has a problem with dealing with files having the character"#" in their name. This bug has been solved in more recent versions, butthere is another persistent bug that might interest you. When converting a .m4afile into mp3 format, the composer tag gets lost. Now this is not much of a problem if you convert an album dedicated to a single composer, but it may become really annoying if you convert an album in which each title has adifferent composer. One solution I found was the script here . This worksif your .m4a is in aac codec. However, if you have a lossless .m4a file, thenyou will end up with empty mp3 files. The problem is that the lossless .m4afiles use alac codec and not aac codec, so that faad can't decode. If you try faad from command line, you see better, you get the following error:

Unable to find correct AAC sound track in the MP4 file.

So what can I do to decode .m4a file in alac? Well, a relatively recent versionof ffmpeg should do the job, but what about thetags? It turns out that now ffmpeg takes care of the tags! So, I use thefollowing script to convert my .m4a files into mp3.

#!/bin/bash
# converts m4a files to mp3
# song tags should be preserved
while read m4afile; do
mp3file=$(echo "$m4afile" | sed s/\.m4a/.mp3/g)
ffmpeg  -i "$m4afile" -ab 128k  "$mp3file" < /dev/null
done < <(find . -iname '*.m4a' -or -iname '*.M4A')
Call this file, say, m4atomp3, put it in your path, go to the top level directorywhere your m4a files are, and launch the command. Then it will convert all yourm4a files in subdirectories into mp3, keeping the original tags. Well, it converts "year" tag to "TDRL" tag, there is a workaround for this, but I thinkthe article is long enough for the day. By the way, the actual script I use isas follows:
#!/bin/bash
# converts m4a files to mp3
# song tags should be preserved

export LD_LIBRARY_PATH=~/soft/src/ffmpegwebm/dist/lib
while read m4afile; do
mp3file=$(echo "$m4afile" | sed s/\.m4a/.mp3/g)
~/soft/src/ffmpegwebm/dist/ffmpeg/ffmpeg  -i "$m4afile" "$mp3file" < /dev/null
done < <(find . -iname '*.m4a' -or -iname '*.M4A')
Here, ~/soft/src/ffmpegwebm/dist/ffmpeg/ is the path to a ffmpeg that I compiledfrom the source, and ~/soft/src/ffmpegwebm/dist/lib is the path to the directorywhere I installed the related shared object files. I hope to come back to thistopic later.

posted by kde35 in id3tag, alac, ffmpeg, conversion, sound, soundkonverter, mp3, m4a, aac on 2014-08-22 17:13