I quite often want to convert mp3 files to m4b, Apple’s proprietary nastiness. There is pacpl of course but that has issues these days, particularly with copying the id3 tags to the new file.
FFmpeg can do it when you build from source (I just found a nice script that will build it from source for you). So I came up with this way to do it from the command line. It uses an awesome feature of xargs which will run it in parallel, so one for each core.
find -type f -name \*.mp3 \
| xargs -n 1 -P $(getconf _NPROCESSORS_ONLN || echo 1) -i \
bash -c \
'i="{}"; ffmpeg -y -i "$i" -map_metadata 0 \
-c copy -c:a libfdk_aac -b:a 128k\
-map_metadata:s:a 0:s:a -f ipod "${i%.*}.m4b"'
What that does is:
- find all the mp3 files and pipe their names into xargs
- then get the number of cores available and pass that to the -P argument
- and run ffmpeg and map all the metadata to the new file
- and strip off the mp3 file extension and add m4b to it
There! Nothing to it!
Update 2017-03-23: Added double quotes around the bash variable $i to cope with spaces. You should always do this (and so should I)
Update 2018-12-20: Added “-c copy” so ffmpeg can cope with album art in the file
Leave a Reply