Simple FLAC to MP3 PowerShell Script

By
Code · Music · Windows

This PowerShell script automates the process of converting FLAC files to MP3 format while preserving audio quality. It’s designed to be run in a directory containing FLAC music files.

Prerequisites

Before using this script, ensure you have the following command-line tools installed:

flac2mp3.ps1

$flac = "c:\program files\flac\flac"
$lame = "c:\program files\lame\lame"
$tmp = "flac2mp3temp.wav"

foreach ($f in Get-ChildItem *.flac) {
    $fn = [System.IO.Path]::GetFileNameWithoutExtension($f.Name)
    & $flac -d $f.FullName -o $tmp
    & $lame -b 320 -h -m s $tmp "$fn.mp3"
    Remove-Item $tmp
}

How to Use

  1. Open PowerShell and navigate to the directory containing your FLAC files.
  2. Run the flac2mp3.ps1 script.

The script will process all FLAC files in the current directory, converting them to high-quality MP3 files.

Script Breakdown

  • Line 1-3: Define paths for FLAC and LAME executables, and set a temporary WAV filename.
  • Line 5: Iterate through all FLAC files in the current directory.
  • Line 6: Extract the filename without extension.
  • Line 7: Decode the FLAC file to a temporary WAV file.
  • Line 8: Encode the WAV file to MP3 format using LAME with high-quality settings.
  • Line 9: Remove the temporary WAV file.

Customization

You can adjust the LAME encoding parameters in line 8 to suit your preferences. The current settings (-b 320 -h -m s) produce a high-quality 320kbps stereo MP3 file.

This script provides an efficient way to batch convert your FLAC music collection to MP3 format while maintaining excellent audio quality.

Explore
Reply
Notifications: 
How is my info protected?
  • Your email address is kept private and is never shown.
  • You are not signing up for anything.
  • You only get email for reply activity if notifications are enabled.
  • You can edit or delete your reply (using same device and browser).
  • Your info is not shared or used in any other way.
Message
How is my info used and protected?
  • Your email address and message are kept private.
  • You are not signing up for anything.
  • Your info is not shared or used in any other way.