Convert flac to mp3 using ffmpeg, retain ID3 tags

Finally found the info I needed in the ffmpeg docs to keep the ID3 tags when converting from flac to mp3:

for FILE in *.flac;
do
    ffmpeg -i "$FILE" -ab 320k -map_metadata 0 "${FILE%.*}.mp3";
done

ETA 8/27/2012: updated "-map_meta_data 0:0" command to "-map_metadata 0" for the new version of ffmpeg.

10 Comments

  1. JDT says:

    Thanks for your help with the command. Was your do loop for a Linux shell script?

    Windows users can use a simple batch file like this to convert every *.flac file in a folder to *.mp3 – the batch file is in the same folder as the flacs.

    @ECHO OFF

    FOR %%f IN (*.flac) DO (
    echo Converting: %%f
    ffmpeg -i "%%f" -ab 320k -map_metadata 0 "%%~nf.mp3"
    )

    echo Finished

    PAUSE

    • François says:

      Great! It works perfectly well!
      I was looking for a free software but they were all sh***ty (convert 50% only, does not take tags, install other softwares….)
      ffmpeg is great and your simple batch file is perfect.
      Thank you very much!

  2. Chris says:

    Thanks a lot, worked great!

  3. maxauthority says:

    Thanks a lot for sharing this tip! Worked like a charm (it only missed the embedded cover art).

  4. ogodon says:

    Thanks a lot, it was so simple it took me a while to figure out all I needed was:
    – Paste that into a txt file.
    – Save it with .sh extension
    – chmod the file to make it executable.
    – put the whole path to execute it (or put it into /usr/bin or /bin).

    Four years with Linux and still a noob so many many times…. :-)

  5. Biapy says:

    Hi,

    thank you for this post. I've based a real music library conversion an synchronization script on it.

    https://github.com/biapy/howto.biapy.com/blob/master/various/mussync-tools

    The script is a little explained in this page (french):

    https://howto.biapy.com/fr/ubuntu-gnu-linux/logiciels/exporter-une-bibliotheque-musicale-dun-format-flac-vers-un-autre-mp3-ogg-aac-avec-mussync-tools/

    Mainly, it can convert from a music library in flac to an output library in mp3 while keeping the folder structure and most of the metadata. It support other input and output formats. It track already converted files and can remove them if the original file is missing.

    Thank you for your help in converting my music library :D.

  6. foxy says:

    You can copy all id3 tags using ffmpeg its just not very well documented.
    Use this format:
    ffmpeg -i inputfile … map_metadata 0 -id3v2_version 3 -write_id3v1 1 ….

  7. Joe Bowbeer says:

    Use -vcodec copy to avoid re-encoding the album art, e.g., from jpeg to png.

    Avoids lines like the following:

    [swscaler @ 0000000002bb07e0] deprecated pixel format used, make sure you did set range
    correctly
    [mp3 @ 0000000002b5af20] Frame rate very high for a muxer not efficiently supporting it
    .
    Please consider specifying a lower framerate, a different muxer or -vsync 2

    Stream #0:1 -> #0:0 (mjpeg -> png)

Leave a Reply