Archive of below {Bluray only}
Alright, there are far too many questions cropping up on the forums here about how to encode Blurays and DVDs to H.264 compatible files, usually MKV Matroska.
I for one am getting tired of seeing these questions (new threads instead of users reading the countless other threads that already exist) so I decided to make a tutorial thread that any more questions can be diverted to. This is that thread, for windows at least. The same steps can be followed in Linux through the use of Wine, or so I am told, I've not tried it personally yet.
[size=16]
To begin with, lets start by describing the process:[/size]
First, your source is "demuxed", then you need to "index" that demuxed source. Once you create an index you need to, if interlaced, "de-interlace" your source, to make it progressive. After this you may need to "Decimate" your source. Add filtering if you want, make edits etc and finally you will need to "encode" your stream and "re-mux" the output with your audio and subtitles etc.
[size=16]
What I will cover:[/size]
[listo]
- How to demux your DVD ISO or DVD "Video_TS" folder
- How to demux your BD stream folder. I'm not going to cover demuxing BD ISO in detail because ADC doesn't accept ISO for BD files, I assume because of the massive size and nobody wants to download the entire thing sometimes, etc. Various reasons, but anyway, if you need to demux from BDISO, just follow the same steps for a BD STREAM folder but using virtual drive software, load the BDISO onto a false BD-ROM drive and navigate the folder like any other on your computer.
- How to index your file
- How to properly turn interlaced material into progressive material (de-interlace) and recreate the original framerate (decimate). - Actually, I briefly skim this over.
- How to encode your file to H.264 using X.264 codec
- How to mux your file to a container such as MKV. In this step you also insert the audio and subtitles you demuxed in step 1 - You will have to make the subtitles the desired format yourself.
[/listo]
I won't be covering it all at once, I'll start with Bluray as this is the most commonly asked about (and the easiest).
Right, everyone clear on what we're doing now then? Lets get started.
Some people use MeGUI, others use AVSPmod, others use ... other software (I'm too lazy to bother remembering the names). Point is, a lot of these people use these programs in conjunction with AviSynth.
Personally, I use AviSynth coupled with AvsPmod. If you don't like my method, disagree with it, or simply think I'm a moron, then go away and do not even bother commenting. If you have a different / better method, feel free to out-do me and make your own guide. Anyone else, please read on.
[size=16]
Bluray[/b][/size]
[size=16]
Demuxing[/size]
Now, for my example file, I'm going to use a progressive M2TS stream. To find this, open the folder to your Bluray downloaded from ADC (or one you ripped yourself) and locate the STREAM folder, like so:

Start by opening HDBRStreamExtractor, run as administrator to avoid any conflicts / errors that may appear due to any administrative restrictions on your computer. You should see this:

Next to "input", click the 'select input file(s)' button, if I need to tell you which of the two it is, please give up on trying to encode x264 right now, the rest of the process gets far more complex.
Navigate to your chosen file and select the .m2ts stream you wish to encode and press OK.
This will load your file into the input command, but this is as much as it does, now you need to go just below the 'input' field to the 'features' field and click on "Feature(s)".
This should return all the files or "Streams" that are part of the file (m2ts is actually the container, H264/AVC/AVCHD should be the codec).
Should look something like this:

Use the check boxes to select the tracks you want and ignore those you don't.
Choose an output type, for video files, select MKV, for Audio files, select FLAC (or if your audio is AC3 don't even extract it right now, we will use a different method) - if you want different, be my guest and choose whatever you desire, but these two are best for my needs. Add some commands for each if you need under the "+options" area. Obviously I want to leave everything untouched, so I'm not going to add anything. Other bluray files may include Subtitle streams and Chapter files, make the subtitles .sup and the chapters .txt as you may need these later.
Choose a destination folder with "output". Again, if I need to tell you how, stop right now, this is too complex for you.
I'd suggest somewhere NOT on your main HDD (usually C:/ or D:/). Encoding from one external/internal HDD to another external/internal is always faster than encoding from and to the same drive or from the drive your OS is located. For neatness's sake, create a special folder called "projects" and inside that, another called whatever you are working on, inside that two more folders called "extracted" and "output" like so:

Once you have selected an output destination, click extract and be patient, this process can be lengthy, sometimes up to an hour or more. Far too many factors affect this, so I cannot give you an accurate estimation on time. For a rough guide, the bigger the files you need to work with, the more streams you select etc, the more time they will take compared to smaller/less files. Chapters and subtitles are pretty fast, but video and audio files can take quite a while.
Once your files are extracted successfully, you should hear a success sound or if unsuccessful, a buzzer, the program also tells you in the log. If you get the buzzer, check the log file - located in the extracted folder - for details. This usually identifies the issue. If the issue is video, change the output to H264, I encountered this once before, it was something to do with muxing to MKV directly from ea3cto. I believe it was a certain release and is now fixed, but if you still experience this issue, extract the file as H264 and remux it to MKV using MMG (MKVToolNix).
If your issue is something else, I cannot help unless I know the specific error, post the error you encounter in the forums here as a reply and I'll help as soon as I can. Most of the errors I have run into are from incomplete torrents, so always make sure your files are 100% hash checked in your torrent client prior to reporting errors, as I can't help with incomplete files

Alright, we are finished with extracting the files and demuxing them, you can now close the program. There are many other methods, but this is just the one I use most frequently. If this method does not work for you, reply in the forum here and I'll help you use a different method. You might also try the DVD method I will add later and use DGAVCindex.
[size=16]
Indexing[/size]
Indexing your file allows you to edit it in a lossless, frame-accurate way in conjunction with AviSynth (and other programs).
To do this, open AvsPmod, you
need to run this as administrator, so I suggest right clicking the shortcut and forcing it to always run as administrator.
Once you start AvsPmod, you should see this screen or similar: Note, I am running an old version of AvsPmod on my desktop and an up-to-date version on my laptop - which currently has a dead HDD

-, but it is effectively the same program setup.

I shrunk the window size, but you get the point.
To create your index file, start by clicking File > Open or hold CTRL and press O
Navigate to your extracted files folder and select the video stream (the MKV) - usually called 1_1_video. To find it make sure you are searching by source files, not avisynth script.

Opening the file will call up the following 'command' text into AvsPmod:
DirectShowSource(
"N:\projects\K-on extras\extracted\1_1_video.mkv")
It will have your path of course, not mine :|
Change this to
FFVideoSource(
"N:\projects\K-on extras\extracted\1_1_video.mkv") and in the bottom left of the window, click the left-most arrow:

This may take a while depending how big the file is and how powerful your System is in general. CPU is not everything.
Once it loads however, you should have a frame accurate, source accurate 'video preview' loaded. I'm not here to teach the inner workings of AvsPmod, go RTFM (Read The F@#$ing Manual - Press F1 dipshit) if you need help with it.
This will have created a small file called "1_1_video.mkv.ffind
ex" in the same directory as the input file. This is the index, do not delete it until you are sure you no longer need it (after you have encoded your file).
[size=16]
De-interlacing[/size]
Assuming your source is interlaced (mine isn't) you will need to de-interlace it. I will not be covering hybrid files (part interlaced, part progressive) as I don't know how to handle them myself.
There are far too many guides on the internet, so to summise, just scroll the timeline in AvsPmod, you'll pretty soon see if the source is interlaced because the frames will all be jagged like so:

How you return these to progressive really depends on your source. For anime, most of the time it is as simple as creating a new line in AvsPmod and typing:
TIVTC_TFM(), but this is not always the case.
Visit
http://forums.doom9.org or
http://avisynth.org for more information on interlaced video and how to identify and de-interlace it properly.
AvsPmod can be used to do a variety of filtering also, read more in
http://avisynth.orgBe careful what filters you use as some are very detrimental to your video. I suggest loading a second, identical tab in AvspMod with just the FFVideoSource command loaded so you can switch between your original file and your edited/filtered file. You can use the number pad to do this really fast after you edit one of the scripts, you should see a number appear on the tabs, RTFM if you don't understand. (F1 dipshit)
[size=16]
Encoding[/size]
Once you are satisfied with any edits, cuts, filtering you have done, you are ready to encode your video so save the AvsPmod file as a ".avs"
There are many ways to do this and more than just AvsPmod supports using .avs files, but I just like AvsPmod, you can use whatever you like, for example: XMedia-Recode, MeGUI, StaxRip, MiniCoder etc, anything that can accept a .avs file (lots of programs do), however, this guide will be using X264 from within AvspMod.
To start, click Tools > Save to MP4 or for the newer version of AvsPmod, Tools > CLI encoder (IIRC - either way, its in the same place.)

You'll see this screen:

Your input file should be automatic, but before you edit the CLI (Command Line) always edit the output destination to your folder named "output", if you don't and do it the other way around, your CLI is returned to default and you'll have to do it all again. Do the same for Configuration.
Be sure to append ".mkv" to the end of the filename when you are choosing what to call your output, this is added automatically, but unless you add it yourself, the file will not be previewable during encoding.
Configuring 10bit or 8bit:Click on the "Configure" button, choose the x264 tab and you will see a new screen like this:

"path to x264.exe" is where you choose the version of x264 you wish to use, be it an outdated version, a different build (I use JEEB builds) or a different bit resolution version (8bit or 10bit)
I'm using 10bit, just navigate to wherever you have 10bit x264.exe located or 8bit x264.exe if you wish to use 8bit.
CLI:NOTE: Read the
x264 parameters first.
Ignore the compression settings completely, this is useless, edit the CLI yourself and add whatever else you need. Personally, for Bluray Anime, I use the following, modified depending on what I am encoding:
x264.exe --fps 24000/1001 --preset placebo --crf 18.6 --tune animation --aq-mode 3 --aq-strength 0.7 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --psy-rd 0.80:0.0 --me=umh --merange=32 --subme=10 --threads=12 --output "path to mkv" "path to avs"
Changing the CRF value and aq modes / strengths as well as psy-rd and the merange etc, all will have a different affect on your output. Again, I am not here to teach you how to use CLI, just the process involved in encoding the video. RTFM if you need help with X264 CLI.
I will give help in this thread to anyone who asks nicely of course.
--colorprim "bt709" --transfer "bt709" --colormatrix "bt709" is used ONLY on HD material, and not on anything less than 720 pixels (height) in resolution. Leave this out if you crop/scale the video to less than HD size (example, 576 pixels is SD, not HD) HD = High Definition, SD = Standard Definition. Upscales are terrible, anyone caught upscaling anything without
GOOD reason, will be hit with a bombardment of eggs.
You will need to also make sure
--fps is accurate to your source, most of the time 23.976, 24, 25, 29.970 or 30 (done in factors - 24000/1001 = 23.976, 24/1 = 24, 25/1 = 25, 30000/1001 = 29.970, 30/1 = 30)
Once you are sure your CLI is how you want, click "Run"
You will get a CMD prompt load and look something like this:

Your file is now encoding, depending on your system specs, filters used, complexity of the source video, CLI commands used and many other factors, this process may take any length of time, there is no way to determine an exact eta, do not trust the eta CMD gives you, it will change as your encode progresses.
If you wish to preview the file as it encodes, simply open it with MPC-HC or VLC etc, it should be fine unless you chose .mp4 as your extension when naming the output file. MPC-HC will allow you to open the incomplete file and the audio together so you can skip through the video and also hear the audio with it, there are many advantages to this.
When the file is finished encoding, you will receive a log of events in CMD:

It is now safe to close CMD prompt, your file is finished.
[size=16]
Muxing[/size]
Now hang on! Your file is not
completely finished once the CMD returns the encode results, your audio, subtitles and chapters etc are still missing from the video.
To put them in, we will use a simple muxing program called MKVToolNix - MMG.
If your audio was AC3 in step 1, use the source video before it was demuxed as an input - MMG will demux the AC3.
You can quickly open the program (once you install it) by pressing the start button and typing "mmg" and hitting enter. Don't wait for it to find the program, just rapidly type and hit enter.
Again, my desktop has a very outdated version which I can't be bothered updating, but it does the same job/looks pretty much identical.

To load files, click the "add" button or drag and drop, there are lots of ways, but for simplicity, I'll explain the "add" button method.
Again, locate your files (the video is in the output folder and your audio should be in the extracted folder, if you need to extract AC3 directly from the source, just load the source .m2ts)
Once all your files are loaded, including subtitles in ass, srt, vobsub etc (I'm not explaining this step here) you should see something like this:

ALWAYS have the video file on top (never include 2 video streams unless you know what you are doing with them)
Go through and edit "General track options" and "Format specific options" for each stream you have. Again, RTFM if you need to know what to set, especially if you have anamorphic video (highly unlikely with Bluray)
If your subtitles need specific fonts, go to the "attachments" tab and add them, name them if you want, RTFM, and then go to the "Global" tab. Name your video, this will appear in media players as the Video Title.
If you want to add chapters, there is a seperate process to add them, again, RTFM. Chapter editor is exactly that, an
editor. You do not mux chapters into your file.
Once everything else is set, at the bottom of the program, choose an output destination and mux (I'm using my projects > Eiga K-On! Teaser folder)

Be SURE to append .mkv to the filename, if you don't and start muxing, just press F2 on the file it creates and at the end type ".mkv" - otherwise your file just won't play.
Now click "Start muxing"
This process shouldn't take
too long, but it does take some time if you have a lot to mux. An average time for me would be 30 seconds or so for one 24 minute 1080p video with 2 subtitle streams and 2 FLAC audio streams.
If you are remuxing something you have already muxed, it will take less time because the header already exists in the file, mmg only needs to change it.

This concludes the Bluray section of basic x264 encoding. Any questions, just ask below.
I get the feeling I was about to type something important, but it has completely slipped my mind.

[size=16]
DVD[/b][/size]
A word of warning: My methods described here are very likely outdated, however, I never bothered to learn anything else, so please bare with me. The process is quite lengthy and involved.
I explain 2 methods here, method one is designed for clipping single episodes and/or extras from a DVD and method 2 is designed for doing the entire DVD at once and any trimming will be done in AviSynth by calling the Trim() command.
[size=16]
Demuxing method 1[/size]
[size=16]
Preparing to Demux[/size]
Before you can demux your DVD, you must first identify what format it is in, folder (VIDEO_TS) or archive (ISO).
For this guide, we will need the files to be in .iso format. If you have a folder, you will need to recreate the .iso - so please read on. If you have .iso already, please skip to the next chapter.
[size=16]
Turning VIDEO_TS into ISO[/size]
For this you will require DVD Decrypter {link} and
IMGBURNDuring the install of imgburn, the program may ask you this:

Click no.
Run imgburn and you should see this:

You should see a list of options and a log, the log for now contains basic information about your computer. What you see will differ from exactly what I see.
The program is pretty self explanatory, but I will explain the basics, just in case.
Click "Create image file from files/folders"

Where it says "Source", click the "browse for a folder" button and find your desired VIDEO_TS folder - make sure there are only the original files in it, no stray oddities that shouldn't be there such as text files etc.
Once you tell the program ok, go down to destination and find a place to store the created ISO.
As with the BD side of this guide, I suggest to create a special folder called "projects" and inside that, another called whatever you are working on, inside that two more folders called "extracted" and "output" like so:

Save the ISO inside the "Projects" folder.
Click the big button (Do I need to explain it?) and you will then be asked this:

Just hit yes and continue, this ISO will be deleted later, if you want to keep it, then change some advanced features before moving onto this step. You'll still have the original VIDEO_TS folder however.
Now you may be asked to create a layerbreak, be sure to click the "Don't update IFO/BUP files" button, then just choose any "good" to "excellent" LBA, usually, there is only one to three. It doesn't matter which you choose.

Now press OK, you will be presented with some more info about the ISO you are making. Click OK and wait for the magic to happen, it won't take long. A few minutes at most.
You now have an ISO file ready for loading in DVDDecrypter and may close imgburn.
[size=16]
Extracting your streams[/size]
Upon starting DVDDecrypter, you will notice it looks similar to imgburn.
The first thing to do is go to MODE and click IFO
Now you will need to tell DVDDecrypter what ISO you wish to load. For this you will need virtual drive software such as alcohol or my personal favourite: Virtual Clone Drive.
Within Windows Explorer, just double click your .iso to load it (if you use VCD like me), then go back to DVDDecrypter and select your "source" as the Virtual Drive your iso is loaded on, P:/ in my case:

Now comes the tricky part, on the right you will see a list of VTS and the PGC inside them. You can consider these as a menu set (VTS) and all the playback material within it (PGC) - to put it simply.
Just go through your PGC's and you will find each one is one full length video contained on your DVD.
Under that is a "Chapters" and "cells" area. This gets kinda complex, so I might let you figure it out for yourself as each DVD is different and I cannot possibly explain everything with a generic explanation.
Just experiment, the basic idea is to select and deselect the check boxes on your Chapters within the PGC inside your VTS that you want (sounds complex right?)
I happen to have a disc with multi-angle here, so think yourself lucky you don't have one of these (or do you?)
Anyway, once you have what you think is the video you want...
-
honestly, once you look at the file structure on the DVD and play each seperate .vob, you'll soon work out what chapter and PGC belong to what part of the video you are actually removing. It is easy once you play around a little.
-
and have only the chapters you desire, select a destination (the folder labelled "extracted") and click the big button on the left.
This will pull everything out of the chosen PGC (everything you selected) - just play it in VLC or MPC-HC or something to be sure it is what you wanted, starts when it should, and finishes when it should.
You should have a .vob, .ifo and a log file; VTS_## - Stream Information < ## being whatever stream you pulled.
Repeat the process for any other video on the DVD you want/need but place each in a seperate folder to avoid naming clashes. Now you can close DVDDecrypter. There are many ways to extract streams using DVDDecrypter, however I find the above method the most useful.
[size=16]
Demuxing[/size]
Finally, we actually reach the Demuxing stage. Here you will need DGIndex. {link}
When you start DGIndex, click FILE > OPEN and find the file(s) you just extracted from your DVD.

If you wish to join several videos, select several files. Don't worry what order, you can move them in the "File List" option after you click ok. I have only a single file however, as should most of you if you followed this guide exactly.
Now you can look through the video using the sliderbar at the bottom, you can also do several tweaks and edits to your file, but unless you know what everything does and how to properly use it, leave everything as default. Your DVD is very likely interlaced or telecined.

Click FILE > SAVE PROJECT, and select an output destination. Make an additional folder inside your project folder called "Demuxed" and save in there. Be sure to save as .d2v

This depends on how large the file you chose was, it can potentially be quite lengthy. Some patience is required sometimes. On the status window that pops up, at the bottom you can see when it is finished when "REMAIN" says "FINISH", you will also see the video slider progress from left to right in the main preview window.
This will create a .d2v file for you, extract the related audio (probably calling it something like:"VTS_01_1 T80 2_0ch 448Kbps DELAY 0ms.ac3") and place a log in the folder where the original file is located. (Extracted)
Once the .d2v is created, it is time to Index your file.
Follow the steps shown for a Bluray, however, you should use the following command line instead or FFVideoSource, to load your video:
loadplugin("C:\Program Files (x86)\AviSynth 2.5\plugins\DGDecode.dll")
MPEG2Source("N:\projects\SeraMyu - MarinaMoon - Spring 2002\Demuxed\VTS_01_1.d2v", cpu=0)
Of course, changing the pathname to your own for whatever you are working on and wherever you have "DGDecode.dll" saved.

Follow the BD process for the rest, remember to drop the colorprim etc as DVD is only SD.

[size=16]
Method 2[/size]
If you plan to trim your video using other means, or if you are doing a DVD which does not require episode by episode encoding, for example a movie, you can completely skip turning VIDEO_TS into .iso, as it is uneccessary - this method will work with both ISO and VIDEO_TS.
Begin by starting DGIndex. Follow the steps shown in the method 1, FILE > OPEN and then;
For ISO, load the ISO using virtual drive software, and navigate to the "false" DVD drive it is loaded/mounted to. Open the folder called VIDEO_TS.
For VIDEO_TS, just open the folder, now the rest of the steps are identical for both archive types.
Choose all the files related to the video you are extracting, usually (but not always) these start at the first file to be 1,048,404 KB, or 0.99GB:

Usually the last file in the titleset (the VTS in this image is 04, that means this is titleset 04) is smaller than the rest, but it is part of the video as well, it just contains the final data that did not fit into 1GB 'chunks' and as such, could be any size up to 0.99GB.
I could go on to explain the inner workings of a DVDs core structuring and what a 'titleset' is and how they affect the menu, etc. But this is hardly the guide for it. All you need to know is, find the "VTS" that contains your desired file(s) and load all related files into DGIndex.
You should see something along the lines of this:

Just make sure they are correctly numbered in the right order and click OK. For any DVD, this should be normal 1 comes first, 7 is last and so on (if you have more / less). Unless you have some screwy weird DVD that has some insane playback methods (quite possible, depends on the Cell actions for each title, but highly unlikely.)
Anyway, it's that simple. Now follow the steps shown in the rest of the DVD section. Have fun and remember, don't kill yourself if it gets too hard:

Anamorphic DVD:
Assuming your DVD is standard, it will be encoded at 720x480, which is NOT 4:3 or 16:9. To fix this, you can either set a SAR when creating your CLI, or the easier method is to scale the video when muxing. Use the FORMAT SPECIFIC OPTIONS tab when you select the video stream and set ASPECT RATIO to the desired ratio. Be sure to check if you cropped anything...
The following image has not been correctly stretched/shrunk. (this particular image should be 720x540)

-K-