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

后端 未结 8 840
暗喜
暗喜 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 18:19

    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)

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

    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))
    
    0 讨论(0)
提交回复
热议问题