Saturday, February 8, 2020

Powershell - Convert FLAC to MP3, w/ 'folder select' dialog.


If you run into a collection of FLAC audio, and want to put them in your iPod…
Convert them to MP3 using ‘FFMPEG

This script opens a folder select, dialog, where you can point to the folder the FLAC file(s) are, then proceeds to convert them to MP3, as a new file – In the source folder.
C:\Users\Rich\Downloads\Beastie Boys - Studio Discography\Beastie Boys - Licensed to Ill 1986\08. No Sleep till Brooklyn - Beastie Boys.flac

C:\Users\Rich\Downloads\Beastie Boys - Studio Discography\Beastie Boys - Licensed to Ill 1986\08. No Sleep till Brooklyn - Beastie Boys.mp3

C:\Users\Rich\Downloads\Beastie Boys - Studio Discography\Beastie Boys - Licensed to Ill 1986\09. Paul Revere - Beastie Boys.flac

C:\Users\Rich\Downloads\Beastie Boys - Studio Discography\Beastie Boys - Licensed to Ill 1986\09. Paul Revere - Beastie Boys.mp3

In the below script, the bitrate is 320, so the ‘lossy’ nature of MP#’s is less significant.

Change the ‘
$SourceFolder’ path.
Change the path of the ‘
ffmpeg.exe’.

You can change the bitrate (‘
-ab 320k’) as well: 96 to 320

$SourceFolder = "C:\Users\Rich\Downloads"

Add-Type -AssemblyName System.Windows.Forms
    $Folder = New-Object System.Windows.Forms.FolderBrowserDialog
        $Folder.ShowNewFolderButton = $false
        $Folder.SelectedPath = $SourceFolder
        $Folder.Description = "Pick one..."
    [void]$Folder.ShowDialog()

# This just makes sure that a subfolder of the $SourceFolder is selected...
If ($($Folder.SelectedPath) -eq $SourceFolder) {
Write-Host "Pick a sub-folder from the dialog..." -ForegroundColor Yellow
break
}
# -LiteralPath, in case there are square brackets '[ ]', et. in the path
$Titles = gci -LiteralPath $Folder.SelectedPath -Recurse | ? {$_.Name -match "flac"}
$Titles | % {
$In = "$($_.FullName)"
$Out = $($_.FullName).Replace('flac','mp3')
$In
$Out
& "C:\Users\Rich\Extracted Applications\ffmpeg\ffmpegWin64\bin\ffmpeg.exe" -i $In -ab 320k -map_metadata 0 -id3v2_version 3 $Out
}

No comments:

Post a Comment