While I’m working on some longer posts, I thought I’d share a quick snippet I came up with this weekend as I was backing up a number of old DVDs of family movies.
FFMPeg has the awesome ability to join a number of video files together for you, but the syntax can be kind of strange. Once I learned the syntax, I sought to make sure I never had to do it again, and created this cmdlet.
Usage notes
In this basic version, it will join every file in a directory, giving you Output.mkv
. Be sure your files in the directory are sequentially ordered as well, to control their position.
Ensure that FFMpeg’s binaries are available in your Path variable as well.
Later on, I may add the ability to provide which specific files you want to join, if desired 🙂
Enjoy 🙂
Function Join-VideoDirectory { | |
$fileArray = New-Object System.Collections.ArrayList | |
$items = Get-childitem *.mkv,*.vob,*.mp4,*.ts | |
$itemCount = $items.Count | |
$i = 0 | |
$cmdScript = "" | |
ForEach ($item in $items){ | |
$i++ | |
$cmdScript += "ffmpeg -i `"$($item.Name)`" -f mpegts -c copy file-0$i.mpeg.ts`n" | |
$fileArray.Add("file-0$i.mpeg.ts") | |
} | |
$cmdScript+="ffmpeg -isync -i `"concat:$($fileArray -join '|')`" -f matroska -c copy output.mkv" | |
Invoke-Expression $cmdScript | |
} |