Tuesday, April 5, 2016

Powershell Script to Convert Alac to Mp3

This blog shows you how to use PowerShell with ffmpeg to convert Apple Lossless files (ALAC, *.m4a) to mp3 using LAME. First, I have to give credit to the original source of this script: Scott Wood on his blog Abstract Labs. Second, you'll need ffmpeg. Grab a Windows build at Zeranoe Ffmpeg and extract the 7zip file to somewhere readily accessible. I put mine at C:\ffmpeg. Next, open up Windows PowerShell ISE to copy-and-paste the script below.

I modified Scott's script to follow Hydrogenaudio's recommended LAME settings. Using a variable bit rate at the point of producing transparent results creates the best balance between quality and file size. I used to not care about file size when hard drives were huge and storage was cheap, but in an increasingly connected world, I care about how much these files are sucking up my bandwidth, my smartphone storage, and my cloud storage. So, size became more important for me, especially where my ears can't tell the difference.

#Set the path to crawl
$path = 'M:\Downloads\Ministry of Sound_ The Annual 2016 (Apple Lossless)'
#The source or input file format
$from = '.m4a'
Get-ChildItem -Path:$path -Include:"*$from" -Recurse | ForEach-Object -Process: {
        $file = $_.Name.Replace($_.Extension,'.mp3')
        $input = $_.FullName
        $output = $_.DirectoryName
        $output = "$output\$file"
        $arguments = "-i `"$input`" -id3v2_version 3 -c:a libmp3lame -q:a 0 `"$output`" -y"
        $ffmpeg = ".'C:\ffmpeg\bin\ffmpeg.exe'"
        Invoke-Expression "$ffmpeg $arguments"
        Write-Host "$file converted to $output"
        Remove-Item -Path:$_
    }

Scott's blog post mentions using MusicBrainz Picard to improve the mp3 tags. I also use MusicBrainz Picard and highly recommend using it when updating your music library.


No comments:

Post a Comment