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

2019-01-29 23:59发布

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条回答
乱世女痞
2楼-- · 2019-01-30 00:12

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 \;

查看更多
在下西门庆
3楼-- · 2019-01-30 00:14

I was testing the following command to convert infile.flac file to outfile.mp3:

ffmpeg  -i infile.flac  -q:a 0  outfile.mp3

As of Ubuntu 16.04, the above command seems to copy (most of? all of?) the metadata.

-q:a 0 tells ffmpeg to use the highest quality VBR.

However, ffmpeg was transcoding my album art from jpeg to png, which increased the size of the cover art.

Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> png (native))
  Stream #0:0 -> #0:1 (flac (native) -> mp3 (libmp3lame))

(I guess the above conversion sort of makes sense given how ffmpeg works.)

After some digging, I found the -c:v copy option, which specifies that the video stream should be copied, rather than transcoded. The full command is:

ffmpeg  -i infile.flac  -c:v copy  -q:a 0  outfile.mp3

The above command results in:

Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (flac (native) -> mp3 (libmp3lame))
查看更多
4楼-- · 2019-01-30 00:22

One-liner to convert all .flac files to .mp3 in a single directory, keeping most metadata:

for file in *.flac; do ffmpeg -i $file -q:a 0 ${file:r}.mp3; done

(Note: ${file:r} removes the extension of the given filepath)

ffmpeg: flac to mp3

查看更多
淡お忘
5楼-- · 2019-01-30 00:28

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.

查看更多
Viruses.
6楼-- · 2019-01-30 00:29

The following command keep 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
查看更多
Explosion°爆炸
7楼-- · 2019-01-30 00:36

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.

查看更多
登录 后发表回答