From eBower Wiki
Jump to: navigation, search

This page describes some hints and tricks about MakeMKV and adjunct tools.

What is MakeMKV?

MakeMKV is a way of ripping your DVDs to your hard drive in unencrypted MKV files. These files are lossless in quality, support multiple audio tracks, plus maintain subtitles. About the only thing that you lose is the DVD navigation, but if you're like me that's a good thing!

Installing MakeMKV

MakeMKV is the meat of both my ripping and local streaming solutions. It provides decryption of BluRay discs and is, sadly, not a free application. Personally I couldn't care less about whether it's open source or not, the application is $50 at the time of this writing. Realistically this isn't a huge price to pay and the application can be used to decrypt the BluRay discs to your hard drive as well. Think of it as replacing the need to buy a BluRay player that sits next to your Linux box. Luckily, while the product is still in beta there is a free key that will unlock the program.

You can download and install MakeMKV for Linux here, but as you can see it's not as simple as a sudo apt-get install makemkv. I've developed an alternative installer which makes things much easier. First you'll need to install my PPA, and then the installer:

sudo add-apt-repository ppa:ubuntu-ebower/ebower
sudo apt-get update
sudo apt-get install makemkv-install

Now whenever there's a new version, you can just run:

makemkv-install latest

This will install the necessary dependencies, download the necessary files, compile them, and then move them to where they should go.

Playing BluRay Discs

This section is near and dear to many Linux users hearts - playing BluRay discs directly on your Linux distribution. This is a replication of an old docbook document I had created which started my use of MakeMKV to get rid of all of my physical media (well, at least to put it into a closet as an archive).

BluRay stinks. The copy protection is embarrassingly strict and shows an incredible lack of knowledge that most piracy is done by a small number of individuals who will ALWAYS be able to break the copy protection without much trouble at all. Strict DRM on a consumer product is like a deadbolt on a screen door - it keeps the polite criminals out.

It's this copy protection that makes playback under Linux a pain. Between the studio's pig-headed attitude towards DRM and Richard Stallman's equally pig-headed attitude against DRM both groups have decided that you can't play BluRay on Linux.

Some Linux fans go as far as to suggest a boycott of BluRay for the DRM issues, most are hypocrites who don't fully understand the issues at play since they're perfectly happy with the DRM on DVDs simply because it's now easy to crack. Most of the anti-BluRay rhetoric is full of half-truths and a fundamental misunderstanding of market forces, personally I don't see a need to upgrade the vast majority of my movies but before I went all cloud-based I briefly bought all BluRay since they're easy enough to decrypt and I'd rather have the resolution available for when hard drive space gets even cheaper.

There are a few methods out there that can be used to play a BluRay disc under Linux. Most are pretty painful and make buying a BluRay player and sitting it next to your monitor look like a viable solution.

Ripping

You can rip the movies to your hard drive first. For DVDs ripping and converting may be practical, a DVD is about 4GB (the movie alone often much less) and at the time of this document's initial writing a 3TB drive can be had for $120. This gives you space for 750 movies before compression - more than enough for most people and it ends up costing roughly 16c per movie. BluRay, on the other hand, runs about five times the size and take much longer to decode. At <$1 a BluRay for storage it's not too bad, but then one must consider that many streaming devices can't handle BluRay quality movies. Now you have to decide to further restrict the number of movies you store by down sampling them to support less powerful devices, or just down sample from the beginning. I typically store movies at DVD quality and use Plex that I stream where I need to. But sometimes you just want to watch a BluRay at the original resolution.

Ripping Software

There are a few options for ripping your BluRays to your hard drive, which may be a better solution for you depending on what your needs are. I use MakeMKV, but it only supports MKV format (which you can convert after the fact to whatever you want). From my experience, MakeMKV seems to handle anything I've thrown at it, and it's much faster than booting up a VM and running another program in this list.

I had been using DVDFab from my Windows days. Sadly it requires a full-blown virtual machine to convert most video formats (WINE is only an option for decrypting), and the purchase options can be confusing. If you want to create ISO images to store on your hard drive go for DVD Copy and/or BluRay Copy. If you want to convert the discs to MPEG files or some other format, get DVD and/or BluRay Ripper. To convert files ripped by MakeMKV you'll want Video Converter - no encryption but you can convert formats easily. Note that ffmpeg/avconv and other solutions may be a better choice over Video Converter for Linux users who don't mind looking up some of the esoteric options. They do have a Mac version that uses Qt rather than .NET as a UI and this may allow the Linux community to pressure them for native Linux support.

Another option is SlySoft AnyDVD and AnyDVD HD. There are plenty of other Windows-based software packages out there that I also haven't tried.

Virtual Machines

You can load up a virtual machine, install Windows, and then a BluRay player. Not only is this annoying in that you need a Windows license and a license for a BluRay player, but you also need a very fast PC. Virtual machines can't really utilize the GPU which is what typically does a lot of the heavy lifting for decryption. Add to that the overhead needed for the VM itself and you've got a recipe for a choppy movie.

External BluRay Player

Some people are lucky enough to have an HDMI input on their PC or monitor. It may make sense to have an external BluRay player by your PC in that case, not only is that a very simple method of doing things but it also gives you the full BluRay experience with all the extras. However, it also means you've now dedicated your PC (or at least one of your monitors) to playing a movie and it's more cumbersome to switch between the film and browsing the web or monitoring your email.

Live Streaming

You can now also rip a BluRay in realtime and stream it to your own PC. By playing this live stream you can simulate playing a BluRay disc on your PC in a fairly integrated manner. This has the benefit of not needing to set aside a huge amount of hard drive space for the movie, but does still require a decent chunk of processor power and you lose a lot of the BluRay extras.

Install Supplemental Software

I'm assuming you've already installed MakeMKV.

The next step is to install VLC, a very popular universal video player. Note that this is installed automatically when you install MakeMKV using my script.

sudo apt-get install vlc

Finally, there's a nice little wrapper script called playBluRay. Unfortunately the script was also slightly broken for Linux, so please feel free to use my version (I made some minor changes and added an optional title number parameter so I claim no credit for anything intelligent here).

Once you've put it someplace in your path (~/bin or /usr/local/bin or something similar). With the official version, just run playBluRay.sh and it will play the first title it finds. With my version, run playBluRay.sh [title_num] and it will start playing the installed disc on the title number you specify. If you omit the title number it will default to title 0 and if you set the title to "auto" it will scan the disc once to find the longest track and then play that title. There's even an icon if you want to add a menu item for it.

Library Management with mkv-rename

MakeMKV creates files of the general format titlenn.mkv where nn is just a counter, renaming this file manually for movies wasn't an issue. The problem was TV series. I like to move an entire series into a single directory so I can watch them sequentially. Luckily these series tend to have a volume label of the format SERIES_Sn_Dm where m is the disc number. I wrote a quick script that renames the files in a directory to SERIES_Sn_Dm.titlenn.mkv, but that quickly evolved to support additional features.

Now you can copy all of these files into a directory like SERIES_Sn. But you're stuck with cryptic filenames involving a disc number, so renaming them with the actual episode number would be useful. I'll go you one better, by using data from epguides.com I can pull the episode name and original air date as well. This yields filenames like Dexter.S5E05.First_Blood.2010-10-24.mkv.

The easiest way to install this is again with my PPA:

sudo add-apt-repository ppa:ubuntu-ebower/ebower
sudo apt-get update
sudo apt-get install mkv-rename

Syntax is easy, and you can run mkv-rename without any options for a more complete list. In the freshly ripped directory just run mkv-rename --directory or mkv-rename -d and it will prepend the current directory name to the existing filename. Don't like the directory name but you're too lazy to change it? Try mkv-rename --directory The Title I Want.

Copy an entire season's worth of files to a directory ending with _Sn and run mkv-rename --tv "Series Name". For example, running mkv-rename --tv Dexter in DEXTER_S5 will assume that the files in this directory are sequentially listed Dexter Season 5 files. Note that you'll need double quotes if there are spaces or parentheses and if you don't get the show name right it will do a slightly fuzzy search for you. If your folder name isn't compliant, you can also use mkv-rename --tv --season 3 'Doctor Who (2005)' to force it to season 3.

Finally, you can also do mkv-rename --movie Audition to rename a single file. If you've got more than one file in a directory try mkv-rename --movie --filename title01.mkv Audition.

All parameters can be shortened to a single dash and the first letter and, as a reminder, running the program without any parameters will show you the help. Also note that I change the title metadata with this command as well, so many of your media library readers will show you something a little nicer.

Special Media

Sometimes mkv-rename doesn't quite work, often because the show doesn't exist in the database. If this happens you can check here for details.

Also note that Plex handles TV data differently from movie data. If you have any collections that have a movie and a TV show component (such as Star Trek) you may be better served putting it in the TV Show folder.

Riget

Lars von Trier's excellent dark comedy miniseries isn't in epguides.com. However, once you search for it you should have /tmp/mkv-getshow.allshows. Edit that file and put this at the end:

"Riget",Riget,999999,Nov 1994,Nov 1997,"8 eps","60 min","DR1",DK

Now, create /tmp/mkv-getepisode.999999.episodelist and add this text:

1,1,1,"",24/Nov/94,"Den hvide flok (The Unheavenly Host)",n,"http://www.tvrage.com/shows/id-18405/episodes/641373"
2,1,2,"",01/Dec/94,"Alliancen kalder (Thy Kingdom Come)",n,"http://www.tvrage.com/shows/id-18405/episodes/641374"
3,1,3,"",08/Dec/94,"Et fremmed legeme (A Foreign Body)",n,"http://www.tvrage.com/shows/id-18405/episodes/641375"
4,1,4,"",15/Dec/94,"De levende døde (The Living Dead)",n,"http://www.tvrage.com/shows/id-18405/episodes/641376"
5,2,1,"",01/Nov/97,"Mors in Tabula (Death on the Operating Table)",n,"http://www.tvrage.com/shows/id-18405/episodes/641377"
6,2,2,"",08/Nov/97,"Trækfuglene (Birds of Passage)",n,"http://www.tvrage.com/shows/id-18405/episodes/641378"
7,2,3,"",15/Nov/97,"Gargantua",n,"http://www.tvrage.com/shows/id-18405/episodes/641379"
8,2,4,"",22/Nov/97,"Pandemonium",n,"http://www.tvrage.com/shows/id-18405/episodes/641380"

You can now run mkv-rename -t -s [n] Riget and it should pick things right up. Note that you can also call it "Riget (The Kingdom)" if you wish.

Postprocessing

Sometimes you need to tweak an MKV file to suit your needs, here's a collection of tricks you can use to do so.

Cropping Black Bars

MakeMKV works great on most movies, but some movies (particularly older ones) are poorly mastered by people who don't understand how DVD players work. If you have a movie with black bars encoded into the video stream to preserve a 4:3 aspect ratio and you play it on a modern TV you may end up with a small video in the middle of your TV surrounded by black bars. Luckily you can fix this with ffmpeg[1] (now renamed avconv) which you can install with:

sudo apt-get install libav-tools

The next step is to figure out what the crop actually is. You can use ffplay to do this:

avplay -i orig.mkv -ss 10:00 -vf "cropdetect=24:16:0" > /dev/null

You can stop it a few seconds in by hitting "q", but make sure you hit an area where there is more than just black (the -ss 10:00 seeks to 10 minutes in). If you've got a long title scene with a black background you may end up overcropping so waiting until the movie actually starts isn't a bad idea. You'll be looking for a line like this:

[cropdetect @ 0x7fbdf00015a0] x1:0 x2:719 y1:43 y2:429 w:720 h:384 x:0 y:46 pos:0 pts:4505 t:4.505000 crop=720:384:0:46

Take the last bit of that line and you can use it to crop your movie:

avconv -i orig.mkv -acodec copy -vcodec mpeg2video -scodec copy -b 5000k -vf "crop=720:384:0:46" cropped.mkv

Alternatively, if you'd like to compress the file at the same time:

avconv -i orig.mkv -acodec copy -vcodec libx264 -scodec copy -vf "crop=720:384:0:46" cropped.mkv

This line says to take orig.mkv, copy the audio codecs, re-encode the MPEG2 video, copy the subtitles, have a variable bitrate peaking at 5Mbps, and crop based on the detected crop settings. There is a side effect to this in that it strips out supplemental audio tracks. This should be able to be fixed with variations of the -map parameter, but it makes for a smaller file and I prefer the original audio track anyway (either English or original language with subtitles).

Changing Resolution

Let say you've got a bunch of BluRay discs that you want to convert. They look great, but they take up 10x the amount of space and you're beginning to wonder if they look 10x as good. Or maybe you've got some old movies that don't really warrant BluRay quality since the original isn't exactly high-def. You could also have a device that can't play back HD quality video. Or you could be regretting that Pauly Shore BluRay collection purchase but you can't bring yourself to just delete them. Whatever the reason, you want to shrink your files by reducing the resolution and you can do this with ffmpeg/avconv again[2]. I'm going to assume you want a DVD resolution which is 720x480.

If you have a widescreen movie you'll want to limit things to the 720 horizontal resolution using this:

avconv -i orig.mkv -acodec copy -vcodec mpeg2video -scodec copy -b 5000k -vf "scale=720:trunc(ow/a/2)*2" orig_DVDQuality.mkv

If you've got a 4:3 file you'll want to limit the vertical resolution, like this:

avconv -i orig.mkv -acodec copy -vcodec mpeg2video -scodec copy -b 5000k -vf "scale=trunc(oh*a/2)*2:min(480\,iw)" orig_DVDQuality.mkv

It appears that the subtitles don't scale well in this case, so you may end up with huge text. I'll work on that problem later...

Merging Two MKV Files

Some DVDs don't fit onto a single disc (Goodfellas, Gangs of New York, the Lord of the Rings series, etc.). In this instance you can easily merge the files together using the following:

mkvmerge -o output.mkv disc1.mkv +disc2.mkv

This, of course, assumes they were mastered in the same way and you don't need to swap tracks or change resolutions. If you do, mkvmerge is still the program for you but you'll want to check out the man page.

References

  1. Understanding FFmpeg – Part III: Cropping
  2. Maintaining FFMPEG aspect ratio