FFMPEG: convert flac to mp3 and copy id3tags

And again something to ffmpeg: this very sophisticated tool can not only convert video or audio files. It also can handle the associated metadata.

So, when you have a big music-library in the lossless format .flac (or .wav) and want to have it also on mobile devices you probably convert the files to mp3 or similar. Also, I do so, because when I’m travelling around I’ve mostly not the silence and equipment to hear music in best quality, so a little loss of quality through the use of mp3 would not be noticed. But the smaller file sizes (up to factor 10) is recognized by your disc space!

Additionally I want the mp3-files contain the same metadata as the flac-files, so I can search my library comfortable.

As mentioned, this can again done by ffmpeg:

ffmpeg -i inputfile.flac -ab 180k -map_metadata 0 -id3v2_version 3 output.mp3

The two interesting options: - -ab The bitrate - -map_metadata 0 -id3v2_version 3 copy the idv3 tags

But…as lazy as we computer scientist are, we doesn’t want to do this file by file…so, this script may be useful:

#!/bin/bash

RED='\033[0;31m'
NC='\033[0m' # No Color
GREEN='\033[0;32m'


mkdir mp3

for file in ./*.flac; do 
	name=${file##*/}
    base=${name%.flac}
	echo -e "${GREEN} ffmpeg -i $file ./mp3/$base.mp3 ${NC}" 
	ffmpeg -i $file -ab 120k -map_metadata 0 -id3v2_version 3 ./mp3/$base.mp3 
done

This script iterates over every .flac file in the current directory and convert it to mp3 in the created mp3-subdirectory and copies the metadata. Additionally the script do some color in the output to easily follow the progress.

Happy converting!

You have another opinion?
Great! Then let's reduce the fallacy together!


Why are there no comments?