Apr 29

Use avconv to tag mp3 files with metadata

Category: Linux,multimedia  , — Published by goeszen on April 29, 2013 at 3:41 pm

I often splice audio out from videos to have the audio track as a separate audio file, a mp3 or aac file depending on what's in the original video so the audio is copied over unchanged, lossless. When doing so, the simple metadata syntax of ffmpeg (or avconv now) is very handy to properly tag the resulting file with metadata.

First, inspect the source video with ffmpeg -i <videofile> to find out if the audio stream is mp3 or aac encoded, after that, you can issue the command below to extract the audio. This command uses the -vn ("video none") switch to throw away the video stream and then -acodec copy to copy the audio part.
Note that in case the input video carries aac audio, you have to use a mpeg-4 container, m4a ("mpeg 4 audio") to embed the metadata tags. That's required as aac doesn't allow for the embedding of metadata or because the aac-tagging implementation in ffmpeg is currently not there - I don't remember...

avconv -i <input video file> -vn -acodec copy -metadata artist="Some artist" -metadata title="Some title" -metadata album="If you know it" -metadata comment="Ripped from video <some url>" "<output audio filename ending in .mp3 or .m4a for aac>"

Often, videos have some intro or outro you might want to shave off, for example if your input video is some video you've downloaded from YouTube with youtube-download... Simple editing on processing-time, without transcoding (lossless), can be done with a combination of -ss <seconds or position timecode> (seek in to) and -t <seconds or duration timecode> (duration).

Leave a Reply

=