[FFmpeg-user] Overwriting metadata with other existing metadata

Zoe Blade zoe at bytenoise.co.uk
Thu Sep 6 19:53:20 EEST 2018


So I've got a lot of FLAC files, meticulously maintained using MusicBrainz's Picard.  And from those, I derive a lot of messier, not at all meticulously maintained MP3 files.  I do this using FFMPEG rather than LAME because it preserves the metadata.  FFMPEG is great for this conversion.  Specifically, I wrote some scripts that at their core use this command:

ffmpeg -i "$song" -codec:a libmp3lame -q:a 4 -c:v copy "${song%.flac}.mp3" 2> /dev/null

So far, so good.  The issue is that MP3 players, be they by Apple or Sony or anyone in between, tend to not use the metadata properly.  For example, they pay attention to the "artist" tag when they should instead look at the "album_artist" tag, to group compilations together properly.  Or, better yet, "albumartistsort", which also fixes alphabetisation when it comes to artists whose name starts with "The" and so on.

I can add to the above line something like this:

-metadata artist='Test'

This overwrites the artist tag with custom data, great.  I specifically want to overwrite it with whatever's in the source file's albumartistsort tag.

Is there a way to do this, so I can overwrite one key with the value of another?

This inelegant Bash solution seems to work:

artist=`exiftool "$song" | grep --color=never Albumartistsort | sed 's/^Albumartistsort *: //'`; ffmpeg -i "$song" -metadata artist="$artist" -codec:a libmp3lame -q:a 4 -c:v copy "${song%.flac}.mp3"

But if there's a simpler way to do it in ffmpeg, I'd love to know!


More information about the ffmpeg-user mailing list