Convert .flac to .mp3 with ffmpeg, keeping all metadata

后端 未结 8 839
暗喜
暗喜 2020-12-22 17:38

How can I convert .flac to .mp3 with ffmpeg, keeping all metadata (that is converting Vorbis comment in .flac files to ID3v2 metadata of .mp3)?

相关标签:
8条回答
  • 2020-12-22 17:57

    The following command keeps high quality on .mp3 (320 kbps), and metadata from .flac file are converted to ID3v2 format, which can be included in .mp3 files:

    ffmpeg -i input.flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3
    
    0 讨论(0)
  • 2020-12-22 18:07

    This flac2mp3.sh script uses ffmpeg to convert a folder tree of FLAC files into another folder tree of MP3 files. Cover art is included, when present. You can set a CORES variable to create background jobs to convert several files at a time.

    0 讨论(0)
  • 2020-12-22 18:10

    If you want to save a little space, try the recommendation of hydrogenaud.io:

    Very high quality: HiFi, home, or quiet listening, with best file size -V0 (~245 kbps), -V1 (~225 kbps), -V2 (~190 kbps) or -V3 (~175 kbps) are recommended. These VBR settings will normally produce transparent results. Audible differences between these presets may exist, but are rare.

    Source: http://wiki.hydrogenaud.io/index.php?title=LAME

    If you want use this option in ffmpeg, you should use the -q:a 0 alias.

    Control quality with -qscale:a (or the alias -q:a). Values are encoder specific, so for libmp3lame the range is 0-9 where a lower value is a higher quality. 0-3 will normally produce transparent results, 4 (default) should be close to perceptual transparency, and 6 produces an "acceptable" quality. The option -qscale:a is mapped to the -V option in the standalone lame command-line interface tool.

    Source: https://trac.ffmpeg.org/wiki/Encode/MP3

    If you want ID3v1 metatags too, you should add the -write_id3v1 1 parameter.

    So my final command is:

    ffmpeg.exe -y -i input.flac -codec:a libmp3lame -q:a 0 -map_metadata 0 -id3v2_version 3 -write_id3v1 1 output.mp3
    
    0 讨论(0)
  • 2020-12-22 18:16

    To recursively convert in mp3 all the flac files in nested folders, I used this command:

    find '~/Music/' -iname '*.flac' -exec bash -c 'D=$(dirname "{}"); B=$(basename "{}"); mkdir "$D/mp3/"; ffmpeg -i "{}" -ab 320k -map_metadata 0 -id3v2_version 3 -acodec libmp3lame "$D/mp3/${B%.*}.mp3"' \;
    

    It will create a folder named "mp3" inside the one with flac files and, inside the mp3 folder, it will save relative mp3 files with a bitrate of 320kbps, without keeping the old file extension in the name.

    0 讨论(0)
  • 2020-12-22 18:16

    I know that this was not asked, but considering that one of the reasons that this is done (at least that's what I wanted to do) is so that the music can be imported into Apple iTunes which doesn't support FLAC. In such case it makes more sense to convert FLAC to Apple's own lossless format, m4a. I used this command to convert all the files in the current folder, while retaining similar file sizes.

    find . -name "*.flac" -exec ffmpeg -i {} -map_metadata 0 -acodec alac {}.m4a \;

    0 讨论(0)
  • 2020-12-22 18:19

    Perfect answer above. I use it together with find to add all FLAC files in a subtree to iTunes with this command

    find . -name "*.flac" -exec ffmpeg -i {} -ab 160k -map_metadata 0 -id3v2_version 3 {}.mp3 \;
    

    To automatically add the resulting files to iTunes, get the iTunes import directory with

    find ~/Music/ -name "Automatically Add*"
    

    result e.g.

    /Users/sir/Music//iTunes/iTunes Media/Automatically Add to iTunes.localized
    

    Then run e.g.

    find . -name "*.mp3" -exec mv {} "/Users/sir/Music//iTunes/iTunes Media/Automatically Add to iTunes.localized/" \;
    

    To automatically add all the converted tracks to iTunes.

    0 讨论(0)
提交回复
热议问题