Converting Bluray to Matroska (MKV)

Since you may not want to spend over 300$ USD for a 25pk BD-R DL here’s how one can convert a Bluray to the well known Matroska format, bringing down the total size to 8.5GB. Of course, one may also just buy the Bluray… 😉

What you’ll need for this manual conversion guide:

  1. CUDA capable system
  2. Blu-ray Video and Audio Analysis Tool
  3. Demuxer
  4. AVC/MPG/VC1 Decoder and Frame Server
  5. AviSynth Frame Server
  6. H.264 Video Encoder
  7. Bluray Subtitle OCR Processor
  8. Matroska Muxer

First step is to find out where is the main movie inside the Bluray structure. Open up BDInfo and browse to the Bluray drive. Once scanning has completed you should be able to determine the main movie’s playlist by its length:

In this case, there are 2 playlist with the same length however they both link to the same stream so we’ll just use 00000.mpls.  Next is to extract the chapter timecodes so click on “View Report…” and scroll to your main playlist. Once there, scroll down a bit and you should see the chapters listing:

1               0:00:00.000     0:04:06.913     0 kbps          0 kbps          00:00:00.000    0 kbps          00:00:00.000    0 kbps          00:00:00.000    0 bytes         0 bytes         00:00:00.000
2               0:04:06.913     0:05:44.260     0 kbps          0 kbps          00:00:00.000    0 kbps          00:00:00.000    0 kbps          00:00:00.000    0 bytes         0 bytes         00:00:00.000
3               0:09:51.173     0:02:17.262     0 kbps          0 kbps          00:00:00.000    0 kbps          00:00:00.000    0 kbps          00:00:00.000    0 bytes         0 bytes         00:00:00.000
...

Copy/paste the chapters listing into a text file and put it aside for now. We’ll need it at the end during the muxing phase.

Now that we know which playlist to process we need to demux its linked stream. Open up tsMuxer GUI and add your main movie playlist file:

Now uncheck all the streams except for the video/audio/subtitles you’re interested in then under “Output” select “Demux” then set your output folder and click “Start demuxing”. Now is a good time to take a break as this may take some time.

Once everything is demuxed load DGIndexNV and open the video stream (may be saved as .264 or .vc1):

Next go to File -> Save Project and save your project as .DGI file. This may also take some time.

Now create a new AviSynth script that looks something like this:

LoadPlugin("C:\Program Files (x86)\AviSynth 2.5\plugins\DGDecodeNV.dll")
DGSource("00115.track_4113.dgi")
Crop(0, 20, -0, -20)

In my case I used the “Crop” function to strip out tiny black borders. Be warned that if you also do so your DAR will be affected and will need to be adjusted accordingly. In my case it went from 1.78 (16:9) to 1.85 (24:13). Also, in order for DGDecodeNV to work you’ll need to fire up CUVIDServer.exe which comes with DGIndexNV.

Now is the time to re-encode the video stream. Use a bitrate calculator to find out the bitrate you should be using to fit this converted movie onto the media of your choice. I used this very basic calculator:

Next open up a command prompt to your output folder and launch the encoding. The encoding options are almost endless but I usually stick with standard profiles so in this case I opted for a high profile at level 4 and a 2-pass encode:

K:\9>x264.exe --profile high --level 4 --bitrate 12751 --pass 1 --output 00115.track_4113.dgi.avs.mkv 00115.track_4113.dgi.avs
K:\9>x264.exe --profile high --level 4 --bitrate 12751 --pass 3 --output 00115.track_4113.dgi.avs.mkv 00115.track_4113.dgi.avs

Depending on your hardware this may take quite a while especially for a 2-pass or more encode.

Next we need to take care of the subtitles. Open up SupRip and load your first (and maybe only) subtitle file (.sup):

Click on the first character in red and at the bottom type in the right text for that character and press enter to switch to the next missing character. Yes, this is a long process which may not suit your level of patience… Once done, switch to the “SRT” tab and review the final text then save to a .SRT file. Repeat for all other subtitles you want to keep (because of the process I usually tend to keep as least subtitles as possible).

We’re getting close now but there is one remaining task before we mux everything back, we need to set up the chapters. Open up mkvmerge GUI (mmg.exe) then switch to the “Chapter Editor” tab. Click Chapter Editor -> New Chapters and click “– (new chapter file)” in the “Chapters:” listbox then click “Add chapter”. Under “EditionEntry 1” click “(unnamed) [eng]” – this is your first chapter. At the bottom, click “(unnamed)” and enter a name for the chapter. Here I like to play the bluray menu and go to the chapters section to see all the chapter names then I use those names in the chapter editor.

For the timecodes, you’ll need that text file we saved at the beginning. Open that up and copy/paste the start/end timecodes in the corresponding “Start:” and “End:” boxes then click “Add chapter” again to create a new chapter. Repeat the process until you’ve managed to enter all the chapters you want to keep. You may also want to set the language/country by clicking the “Set values” button (if you click the root node first you can apply those values to all children quickly). Now save your chapters into an XML file by going to Chapter Editor -> Save as.

Finally we can setup everything to start muxing. Under the “Input” tab drag/add all your streams (in order: video, audio, subtitles). For each stream, click on it then at the bottom make sure to set as much information as possible from the first 2 tabs (“General track options”, “Format specific options”). I usually set the language, default track (default for video/audio and no for each subtitles), aspect ratio or display width and FPS. Under the “Global” tab, make sure to put in a “File/segment title” and load your chapters file then click “Start muxing”.

Enjoy the final result: