Skip to content

Instantly share code, notes, and snippets.

@scytalezero
Created April 18, 2017 19:03
Show Gist options
  • Save scytalezero/ea2d7f79c8bc59b7a2998db5411b2ea1 to your computer and use it in GitHub Desktop.
Save scytalezero/ea2d7f79c8bc59b7a2998db5411b2ea1 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
For a given path, converts any MKV files to MP4 format using ffmpeg.
.EXAMPLE
PS C:\> Convert-MKVtoMP4 c:\temp
Explanation of what the example does
.PARAMETER Path
Path that will be processed.
.PARAMETER Extension
Extension to search for, defaults to MKV
#>
#List the parameters we expect to get. Path is mandatory, and Extension has a default value if not specified
Param([Parameter(Mandatory=$true)]$Path, $Extension="*.mkv")
#Find the drive letter
$driveLetter = Split-Path $Path -Qualifier
#Make the recycle bin path
$recyclePath = Join-Path $driveLetter "@Recycle"
#Get the list of MKV files in an array
$fileList = Get-ChildItem $Path -Filter $Extension
foreach ($file in $fileList) {
$newName = $file.BaseName + ".mp4"
#EchoArgs would be replaced with ffmpeg path
EchoArgs.exe -i $file.Name -codec copy $newName
#Take off the -WhatIf to make these actually delete
Remove-Item $file.FullName -WhatIf
#Recursively search the recycle bin on that drive and delete the file if found
Get-ChildItem $recyclePath -Filter $file.Name -Recurse | Remove-Item -WhatIf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment