Convert MKV to MP4 in PowerShell

This script will retrieve all mkv files in the “input” directory and convert them to mp4, placing the new mp4 files in the “converted” directory

You need the HandbrakeCLI application

Quality 18 seems to be good for DVD video. HD you would want better quality (lower number is better).

This burns subtitles into the output, so get rid of that option if you don’t want it.

$InputDir = Resolve-Path "input"
$OutputDir = Resolve-Path "converted"
$HandbrakeExe = "C:\HandbrakeCLI\HandbrakeCLI.exe"

$Files = Get-ChildItem -Path $InputDir -Filter *.mkv
$Files | ForEach-Object {
    $FileName = $_.FullName
    $Mp4FileName = $_.Name -replace "\.mkv$", ".mp4"
    # Write-Output $FileName
    
    $ConvertedFileName = Join-Path -Path $OutputDir -ChildPath $Mp4FileName
    # Write-Output $ConvertedFileName

    Start-Process -FilePath $HandbrakeExe -ArgumentList "--input `"$FileName`" --output `"$ConvertedFileName`" --format av_mp4 --quality 18 --subtitle 1 --subtitle-burn" -Wait -NoNewWindow
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s