Bluray encoding
A guide on encoding Blurays with x264 and Avisynth.
Obsah
A word of introduction
It’s now about 8 months since I started my „encoder career“ in a group ripping anime DVDs known as Animecorpx (ACX). I work for them as an encoder and what we do is basically ripping anime DVDs released in the USA to make them accessible for the rest of the world, where you can’t buy them. But I actually hate DVDs. They have low quality video, cleaning their image up is pain and they generally suck. It came out I’m not the only one in ACX who hates low res and that shitty image of DVDs. It was shitsu, my Swiss colleague, who actually made me think about an option, that I could encode BDs and that it might not be as impossible as I thought it is. As I started some research on this topic, I found out, that it’s not difficult at all. However, it requires somewhat different approach and different tools, so it took me a while to get into it and I relied on other guides and blog posts scatter on multiple pages. That’s why I decided I should write something simple to follow about encoding BDs.
Note that this text assumes some level of knowledge about encoding.
Getting BD
I’ll leave getting sources up to you, and I also won’t cover how to copy files from BD disk to HDD, since I’ve never done it. What you should get for your encoding is directory with subdirectories such as Auxdata, Clipinf, Meta, Playlist and STREAM (STREAM is the one you really need, equivalent to VIDEO on DVDs). Note that BD sources, depending on disk, have from 25 to 50 GB, so what you really need (even more than powerful CPU) is disk space.
Video
Loading to Avisynth
First, let’s look on video encoding. It’s pretty easy, you will usually find one .m2ts file per episode (or movie), so you can forget about DGIndex and creating some files as d2v. Look to STREAM
dir, you’ll find loads of .m2ts files. As in DVDs, look for those big ones, size in gigabytes or tens of GB (movies have on main file e.g 40 GB, episodic anime usually 4 to 6 GB per episode, one file per episode). Good thing is, you can load them to avisynth directly, so directshowsource
will do:
directshowsource("c:\path\STREAM\00032.m2ts", fps=23.9759856527702, audio=false)
Having set fps is probably not crucial, but I keep it there for safety purposes as well as audio=false, but you won’t get any from it anyway.
Resize
Now frame (image) size. If you rip a live-action movie, you’ll probably want to keep full HD, but as for anime, note that almost no anime has resolution of fHD and is either upscaled directly or, in better case, drawn with „thicker lines“. Means that you can resize it to 720p without any loss of details. You will probably want to sharpen it before resize too (never do it afterwards!), so it looks better. Add line with sharpener and resizer like this:
MSharpen(strength=90) #or whatever shapener you use; don't use Warpsharp.
LanczosResize(1280, 720)
Be careful about ratio, if you are cropping image (do that before resize), you’ll have to worry about ratio divergence after cropping and you may get to pretty ridiculous dimensions, but try to keep the divergence below 1% (or you will break Steins Gate!). For these purposes, you can use AVSPmod (links @ the end of article).
And that’s pretty much it, at least for avisynth!
Encoding
Now you will load your AVS script to encoder. Now, we’re in modern times, so do not use constant bitrate! Forget about constant sizes, that doesn’t matter anymore, and use that –crf option in x264 encoder. That’ll keep the quality constant ad you won’t have problems with insufficient bitrate in grainy or other bitrate greedy parts. 2-pass encoding might do, but still I don’t see any reason why to use it. Values of CRF might differ on what you’re encoding, anime in 720p should be in 17-19 range if you don’t want compress artifacts. Generally applies a rule that higher resolution you have, higher CRF value you may use to maintain the quality. For fHD it’s in 19-21 range, even more sometimes. So you’re encoder line (in CLI interface) will be like this (for anime):
x264.exe --profile high --crf 18.5 --preset medium --tune animation --output ..\encoded\video.mp4 skript.avs
Be prepared that encoding a movie might take like 10 or more hours; I on my dual core Intel Centrino2 laptop encode a movie for 8 to 16 hours (depends on resize, sharpen, some other cleaning, –preset option used). Be sure to have you computer well cooled. :P
Some ethics
Have you ever seen a movie BD rip from THORAnime fansub group? Well, their movies have like 12GB (sometimes less, i know). That’s about at least 3 times more than a fHD BD rip in h264 codec with two audios each 300MB should have. Always try to keep your movies (their finals size with audio and everything) under 4 GB, so it can fit DVD. (Not that many people burn them on DVD, but it’s a good rule to stick to.) Full HD episode shouldn’t exceed 500 MB or so. As for 720p, try to stick with 3 GB resp. 350 MB limit, if possible. (Not applicable to live action stuff, although 8 GB should be enough for anything up to 2.5 hours of playtime.)
Audio
Up to here, it was pretty much the same as any other encoding. Now, for extracting of streams from BD you will need a tool called HdBrStreamExtractor (download below).
Work with HdBrStreamExtractor
It’s pretty simple – load a path to you STREAM folder to it (Input) and path where you want it to spill out the extracted streams (Output) and click „Features“. It’ll show you the files in folder with their lengths, so you can easily recognize, which file is the one you need. Clicking on it will result to displaying streams in the file in the list below, where you can choose which streams and in which format you want to extract (see pic below). Note that chapters are also a stream and eventual subtitles need to be extracted this way too. Audio formats are a bit above this article’s frame, but usually you can use AC3 or THD and then encode it to AAC/AC3. Always try to take streams with highest possible channel count, or extract both (e.g. 5.1 and 2.0) if possible.
Extraction may take even half an hour, so be patient, it’s ten times bigger than DVD. As for audio transcoding, try using MeGUI or FooBar2000. Then proved useful to me.
Subtitles
Now you have your subtitle stream extracted into some strange .sup file, what to do with it? Remember SubRip? Well, there’s SupRip for BDs (download below). It’s in some ways smarter than SubRip, in some ways more stupid, but you’ll get over it.
Load the .sub file and just write in the letters for each letter in the image (yea, subs are stored in BDs same way as in DVDs). Good thing is that you can control the output for the whole line, bad thing is you can’t edit the matrix as you could in SubRip and you don’t have such good OCR auto-correct engine there either. (Actually, I still use this feature of SubRip for subtitles outputted from SupRip.)
Well, and that’s it. Edit subtitles‘ style, mux toghether and you’re done. Not that hard, isn’t it?
Problems
As with anything, you might encounter some problems. Since I haven’t encountered any yet, I can’t write here anything, sorry. I will try adding here (or to a new post) issues that I or my ACX colleges will stumble on. Also, please, if you encounter any issues, try sharing you experiences here in comments! It might help other. If you won’t be able to find solution, you can also use comments to ask for help.
Tools
HdBrStreamExtractor and SupRip in one pack
BD_tools_suprip+eac.zip – you will find HdBrStreamExtractor in /eac3to317 directory, SupRip is in its own. There are also some other tools in /eac3to317 directory, you may play around with them, I don’t remember anymore what they do.
You can find encoding tools in my earlier guide here, but I haven’t translated that one to English yet, sorry. Download links are at the end as here.
Epilogue
I wanted to write it shorter, but when I write, I write long… Hope it helped you a bit and shall you encounter any issues, share them in comments. Thanks.
Version 1.0., revision 2.
Kopie komentářů
- LastMarita 2018-01-03 @ 19:37 I have noticed you don’t monetize your website, don’t waste your traffic, you can earn additional cash every month because you’ve got high quality content. If you want to know how to make extra $$$, search for: Mertiso’s tips best adsense alternative
- BestShelia 2018-08-12 @ 20:49 I see you don’t monetize your blog, don’t waste your traffic, you can earn extra bucks every month. You can use the best adsense alternative for any type of website (they approve all websites), for more details simply search in gooogle: boorfe’s tips monetize your website