Bulk Converting M4A files to MP3

Bulk Converting M4A files to MP3

Let's say you suddenly realize some of your older music collection is in the wrong format. Everything is organized into folders for albums, etc. and you don't want to have to go into every subdirectory and individually convert the files.

Here's a little bash script for you. Place this in the top level directory of the tree you want to convert and it will bulk convert all m4a files into mp3 files. It's an easy way to convert all the files in a specific tree and could easily be modified for different file formats.

#!/bin/bash

# Convert m4a to mp3 in subdirectories
# Make sure the file list will support the wildcard character:
shopt -s globstar

for F in **/*.m4a
do
  newname=`basename "$F" .m4a`
  mypath=`dirname "$F"`
  ffmpeg -i "$F" -acodec libmp3lame -ac 2 -ab 192k -ar 44100 "$mypath/$newname.mp3"
done
Posted by Tony on Aug 30, 2013 | Linux Tricks