Merge Many MP3 files into a single MP3 file with PowerShell and FFMPEG
Sunday, March 3, 2013 at 12:23PM This a follow up from my post yesterday on using PowerShell and FFMPEG to trim many MP3 files at once. The second part of my task was to merge those MP3 files into one big MP3 file.
The script is below.
Important Note: For a reason I'm not clear on I had to run PowerShell as Administrator for FFMPEG to successfully create the merged MP3.
$ffmpeg_exe = "D:\ffmpeg\bin\ffmpeg.exe"
Function Folder_MP3_Merge
{
Param(
[Parameter(Mandatory=$true)]
[String] $FromFolder,
[Parameter(Mandatory=$true)]
[String] $ToFile
)
Process
{
$count=0
$fromitems = (Get-ChildItem $FromFolder -Filter "*.mp3" -recurse -File)
Write-Verbose "`t$fromitem"
$fromnames = @()
foreach ($fromitem in $fromitems)
{
$basename = $fromitem.Name
Write-Verbose "Item [$count]: $basename"
$from_fullname = $fromitem.FullName
$fromnames += $from_fullname
$count++
}
$fromnames_all = [string]::join('|', $fromnames )
if (Test-Path $ToFile)
{
Remove-Item $ToFile
}
$cmdline = "$ffmpeg_exe -i `"concat:$fromnames_all`" -acodec copy `"$ToFile`" "
Write-Verbose "`t CMD: $cmdline"
invoke-expression -command $cmdline
}
}
Folder_MP3_Merge -FromFolder "D:\mymp3files" -ToFile "D:\single.mp3" -Verbose
Reader Comments