« Interlude: A remake of Justin Timberlake's "Like I Love You" by Pete Oak | Main | Batch Trimming a Folder MP3 Files Recursively with PowerShell and FFMPEG »

Merge Many MP3 files into a single MP3 file with PowerShell and FFMPEG  

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
        [String] $FromFolder,
        [String] $ToFile


        $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
        $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

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>