ChetOS.net

Metadata conversion in ffmpeg

Ffmpeg is a program that sets you convert various multimedia file formats into other multimedia formats.  For example, you can convert Ogg Vorbis to MP3, or back.  You can convert avi video files into divx files, or back.  There are dozens of supported formats.

The particular ability that I care about is converting m4a files to mp3 files.  This is because iTunes provides m4a files, but my Sansa Fuse doesn't play them.  M4a files are unprotected audio files, so it is pretty simple to convert them.  I use something like this ffmpeg -i "input.m4a" -ab 256000 "output.mp3".  This will convert the m4a input file to a 256Kbit mp3 file.

The problem is that the metadata (title, artist, album, etc) is not converted in the process.  However, I found a command line parameter that will allow it to do this.  Just add -map_meta_data 0:0 to the command line (I usually do it before the output filename).  There is another problem though.  For some reason it maps the m4a "composer" field to the mp3 "artist" field, which isn't right.

The biggest drawback to ffmpeg is that you, for the most part, cannot download the executable.  It is only available as source code.  I compiled the executable a few months ago but didn't have my development environment setup anymore.  So, after much searching to see if there was a fix, I decided to install MinGW, MSYS, and the ffmpeg and mp3lame source code (using http://ffmpeg.arrozcru.org/wiki/ as my guide) on my machine and fix it myself.

I don't know the "right" way to fix it, but the method that worked for me involved modifying the libavformat/mov.c file.  In the mov_read_udta_string function is a mapping between the raw data "table of contents" and the human-readable tag name.  In order to get the AAC decoder to give the tags to the MP3 encoder in a way that it would understand, I changed the key name.  I changed "author" to "artist", and "year" to "date", since these are the tag names as MP3 knows them.

I probably could have modified the libavformat/id3v2.c file to change the MP3 names into the AAC/M4A names, but I tried it the first way and it works.

Now, I say that this might not be the right way because other downstream components (that I am not using) might not like the new tag names for the AAC format.  But I don't care because it suits my needs.
Posted by Chet at 7:46 AM

Comments

No Comments have been Posted.

Post a Comment

Feel Free To Share Your Thoughts
You can use [b], [u], [i], and [url]
Simple CAPTCHA: If green is 9 and blue is 25, what color is red?
Optional
Name
Website
© 2010 Chet Zema π