Example command line use of MakeMKV

Everything related to MakeMKV
Post Reply
zephyr451
Posts: 1
Joined: Tue Dec 22, 2009 3:50 pm

Example command line use of MakeMKV

Post by zephyr451 »

I've written a basic script I use to batch convert my collection of DVDs into MKV files. I'm posting it just in case other folks have the same requirement. It's pretty basic and I got much of my info on the command-line options from this forum. I apologize that it's a windows-only script, but the logic can apply if someone wanted to convert it to bash. Just select the text for the script and save it to a file with a .PS1 extension, which is a Windows Power Shell file. The script uses the name of the folder which CONTAINS the VIDEO_TS folder as the name of the MKV file.

The comments, hopefully, describe the script enough for folks to figure out how to use it. I'll be happy to answer questions, of course.

This script is certainly not perfect, but it's a start. It was easier than doing it all manually at any rate :)

-Michael

======= SCRIPT STARTS HERE =======

<#

Createmkvs.ps1

This is a pretty basic powershell script, which is a convenient way to script on
windows platforms. Windows 7 comes with it standard, but it's available for other
Microsoft operating systems via the Microsoft downloads site.

In general, this script iterates through the movies I've copied to my hard disk using
AnyDVD HD (http://www.slysoft.com/en/anydvdhd.html).
I also use MyMovies (http://www.mymovies.dk) to download the cover art, etc. MyMovies adds
folder.jpg, which contains a picture of the cover, and I use it as the art my player displays
on screen. In my case, I use a Western Digital WD TV Live HD Media Player.

The script can be run repeatedly, as you add DVDs to your collection. It will NOT overwrite
any existing .mkv files in the output directory.

The script uses the name of the folder which CONTAINS the VIDEO_TS folder as the name of the MKV file.

#>

# Directory that you store your on-disk movies
$input_dir="G:\Backup\Music\Videos"

# Directory you want to store your .mkv files
$output_dir="j:\videos"

# A temp directory to assist in the naming process. It's sort of a hack as I couldn't
# figure out a way to specify the name of the .mkv file on the commandline.
# It would be most efficient if this was on the same drive as your output_dir
$temp_dir="j:\temp"

# The MKV command to run. I have a 64-bit OS, so I used the 64-bit command line exe
$mkvcmd="C:\Program Files (x86)\MakeMKV\makemkvcon64.exe"

# Minimum freespace percentage. This is a way to make certain that the script doesn't j
# just blindly fill up the disk. The default is 10% (.10), which stops transcoding at 10%
# free space
$minfreespace=.10

# Default title.
$defaultTitle=0


if ((Test-Path -path $temp_dir) -eq $false)
{
New-Item $temp_dir -type directory
}


$files=Get-ChildItem $input_dir

foreach ($file in $files)
{
if ((Test-Path -path $output_dir\$file.mkv) -eq $false)
{
echo "Converting: $file"
&$mkvcmd mkv file:$input_dir\$file\Video_TS $defaultTitle $temp_dir
Move-Item $temp_dir\*.mkv -destination $output_dir\$file.mkv
Copy-Item $input_dir\$file\folder.jpg -destination $output_dir\$file.jpg
}
else
{
echo "$output_dir\$file.mkv already exists, Skipping."
}

$diskData=(get-WmiObject Win32_LogicalDisk -filter "DeviceID = 'j:'")

if (($diskData.FreeSpace / $diskData.Size) -lt $minfreespace)
{
echo "Disk Space Low.."
break
}

}

Remove-Item $temp_dir

echo "done"


======== SCRIPT ENDS HERE =====
Post Reply