Difference between revisions of "Bluray"
Line 1: | Line 1: | ||
− | State of play as of | + | State of play as of December 2010. |
== Rip == | == Rip == |
Revision as of 23:07, 14 December 2010
State of play as of December 2010.
Rip
Until recently the only way to rip Bluray discs on a PC is with AnyDVD HD in Windows. Now you can skip several steps by using MakeMKV instead. This will produce a Matroska file with the desired streams you select - leave out all the subtitles and foreign language dub tracks.
Modified MPEG-TS Container
Bluray video is stored in a modified version of the MPEG-TS container format in the BDMV/STREAM folder. The modification is an extra 4 byte time code on each MPEG-TS packet, increasing the packet size from 188 bytes to 192 bytes, apparently in order to better support buffering and out-of-order writing to random-access media. It is unclear whether this is an MPEG Committee sanctioned modification, but there appears to be some standardisation through something called AVCHD. So in theory, a decrypted M2TS file should be sufficient for playback, but many players still choke on it expecting the normal MPEG-TS format.
We can also use tsmuxer[1] to deal with M2TS files, and in particular extract the AC3 and DTS cores from TruHD and HD Master Audio tracks respectively.
Transcode
Transcode to H.264
In this example, I am processing my Bluray copy of Baraka.
Now we can use ffmpeg to squash the video track from 28 GB down to about 10 GB using the constant rate factor quality setting:
ffmpeg -i Baraka.mkv -acodec copy -vcodec libx264 -crf 20 Baraka.mkv
Crop
Since Baraka has 102 pixels of letterbox top and bottom, we crop thus:
ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 \ -croptop 102 -cropbottom 102 -aspect 1920:876 Baraka.mkv
Note in the -aspect option we need to subtract the crops from the normal 1920:1080 aspect ratio.
H.264 options
For best quality, we can improve the H.264 options on the ffmpeg command line.[2]
Single pass constant rate factor (CRF) is best, since two-pass is only relevant if we care about exact file size. Since quality is paramount, I should also use B frames as references, turn CABAC and trellis encoding on, bump up the motion estimation and subpixel searching methods, and use multiple threads to speed it up:
ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 \ -croptop 102 -cropbottom 102 -aspect 1920:876 \ -bf 16 -refs 5 -coder 1 -trellis 2 -me_method umh -subq 7 -threads 4 Baraka.mkv
Or for a crazy HQ encode that takes ages, increase the motion estimation range (good for HD), turn on the 8x8 DCT, enable weighted B frame prediction and mixed reference frames (especially if using multiple B frame references), and disable the fast P frame skip for smoother skies and plain areas:
ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 \ -croptop 102 -cropbottom 102 -aspect 1920:876 \ -bf 16 -refs 5 -coder 1 -trellis 2 -me_method umh -subq 7 -threads 4 -me_range 32 -flags2 +dct8x8+wpred+bpyramid+mixed_refs-fastpskip Baraka.mkv
This produces great quality, highly efficient encoding (small file size), at the expense of very long encoding time and high CPU demand at decoding time.
Cartoons
For anime and cartoons, bump up the deblocking and noise reduction filters:
ffmpeg -deblockalpha 2 -deblockbeta 2 -nr 150 ...
Subtitles
Bluray subtitle streams currently need converting to SUB/IDX format before they will reliably go in Matroska files. This conversion can easily be done with BDSup2Sub[3]. Choose Lanczos3 for best quality if changing resolution.
M2TS file MIME Type
Ubuntu still doesn't see these files as video files - edit /usr/share/mime/packages/bluray.xml and copy in this:
<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> <mime-type type="video/bluray"> <alias type="application/bluray"/> <alias type="video/avchd"/> <sub-class-of type="video/mpeg"/> <comment>Blu-ray/AVCHD Video</comment> <magic priority="50"> <match value="\x47\x40\x00\x10\x00\xb0\x00\x11" type="string" offset="4"/> </magic> <generic-icon name="video-x-generic"/> <glob pattern="*.m2ts"/> <glob pattern="*.mts"/> </mime-type> </mime-info>
Then update your MIME database:
sudo update-mime-database
You should then be able to open M2TS files with an mplayer-based media player.
Playback
NVidia has VDPAU. Dear ATI, where's that fancy video acceleration you promised? In the meantime, we can speed up playback using multithreaded mplayer[4]:
git clone git://repo.or.cz/mplayer cd mplayer git checkout origin/mt git submodule init git submodule update sudo apt-get build-dep mplayer ./configure --prefix=/usr make sudo checkinstall --fstrans=no --install=no --pkgname=mplayer-mt --pkgversion "1:0.svn`date +%Y%m%d`-0.0ubuntu1" --default
mplayer -lavdopts threads=4 Baraka.mkv
And if it still sucks,
mplayer -lavdopts skipframe=nonref:skiploopfilter=all:fast=1:threads=4 Baraka.mkv