Difference between revisions of "Bluray"

From Jon's Wiki
Line 16: Line 16:
 
  ffmpeg -i 00017.M2TS -acodec copy -vcodec libx264 -crf 15 Baraka.mkv
 
  ffmpeg -i 00017.M2TS -acodec copy -vcodec libx264 -crf 15 Baraka.mkv
  
However since it can't, mplayer comes to the rescue by extracting everything first to eliminate the container from the equation:
+
However since it can't, let's use tsmuxer<ref>http://www.smlabs.net/tsmuxer_en.html</ref> to fish out the video, audio and subtitle tracks:
mplayer 00017.M2TS -dumpvideo -dumpfile 00017.vc1
 
mplayer 00017.M2TS -dumpaudio -dumpfile 00017.ac3
 
ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 Baraka.mkv
 
  
;NOTE: With other films, you may need to fiddle about with the mplayer -aid option to get it to fish out the right audio track, otherwise you'll end up with Spanish or something. I suppose that's fine if it's a Spanish film.
+
[[Image:tsmuxer.png]]
;UPDATE: Just use tsmuxer, which lets you extract AV and subtitle streams from the M2TS file - see http://www.smlabs.net/tsmuxer_en.html
 
  
 +
Now we can use ffmpeg:
 +
ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 Baraka.mkv
  
 
Since Baraka has 102 pixels of letterbox top and bottom, the ffmpeg command is:
 
Since Baraka has 102 pixels of letterbox top and bottom, the ffmpeg command is:
Line 30: Line 28:
  
 
=== H264 Options ===
 
=== H264 Options ===
See http://ffmpeg.x264.googlepages.com/mapping
+
For best quality, we can improve the H264 options on the ffmpeg command line.<ref>http://ffmpeg.x264.googlepages.com/mapping</ref>
  
Single pass constant rate factor (CRF) is sufficient. 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:
+
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 \
 
  ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 \
 
     -croptop 102 -cropbottom 102 -aspect 2.19 \
 
     -croptop 102 -cropbottom 102 -aspect 2.19 \
Line 43: Line 41:
 
     -me_range 32 -flags2 +dct8x8+wpred+bpyramid+mixed_refs-fastpskip Baraka.mkv
 
     -me_range 32 -flags2 +dct8x8+wpred+bpyramid+mixed_refs-fastpskip Baraka.mkv
  
== Playback ==
+
=== Cartoons ===
 +
For anime and cartoons, bump up the deblocking and noise reduction filters:
 +
ffmpeg -deblockalpha 2 -deblockbeta 2 -nr 150 ...
 +
 
 +
== MIME Type ==
  
 
Edit /usr/share/mime/packages/bluray.xml and copy in this:
 
Edit /usr/share/mime/packages/bluray.xml and copy in this:
Line 68: Line 70:
 
You should then be able to open M2TS files with an mplayer-based media player.
 
You should then be able to open M2TS files with an mplayer-based media player.
  
== Other Tools ==
+
== 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<ref>http://www.videohelp.com/tools/BDSup2Sub</ref>. Choose Lanczos3 for best quality if changing resolution.
 +
 
 +
== References ==
  
Convert Bluray subtitles to SUB/IDX with BDSup2Sub: http://www.videohelp.com/tools/BDSup2Sub
+
<references />
Star Trek movies require either playback that can handle Dolby TruHD soundtracks or the eac3to tool to extract the AC3 core: http://www.videohelp.com/tools/eac3to
 

Revision as of 02:51, 10 May 2009

State of play as of March 2009. Hopefully things will improve...

Rip

Currently the only way to rip Bluray discs on a PC is with AnyDVD HD in Windows. In Linux, one can run Windows XP with AnyDVD HD installed in a VM, then share the Bluray drive and mount it with samba in the host. In theory, the mounted share should be the decrypted Bluray disc, as AnyDVD HD should decrypt on the fly. I tried this once and it didn't work.

Transcode

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 most players choke probably due to the modified MPEG-TS format. Currently only mplayer works reliably.

VC-1 Support

Players based on mplayer and ffmpeg 0.5 can decode VC-1. It is more CPU intensive than H264, probably due to code maturity.

Transcode to H264

In this example I'm transcoding my copy of Baraka. If ffmpeg could deal with the M2TS container, I could go

ffmpeg -i 00017.M2TS -acodec copy -vcodec libx264 -crf 15 Baraka.mkv

However since it can't, let's use tsmuxer[1] to fish out the video, audio and subtitle tracks:

Tsmuxer.png

Now we can use ffmpeg:

ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 Baraka.mkv

Since Baraka has 102 pixels of letterbox top and bottom, the ffmpeg command is:

ffmpeg -i 00017.ac3 -acodec copy -i 00017.vc1 -vcodec libx264 -crf 20 \
    -croptop 102 -cropbottom 102 -aspect 2.19 Baraka.mkv

H264 Options

For best quality, we can improve the H264 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 2.19 \
    -bf 16 -refs 6 -coder 1 -trellis 2 -me_method umh -subq 9 -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 2.19 \
    -bf 16 -refs 6 -coder 1 -trellis 2 -me_method umh -subq 9 -threads 4
    -me_range 32 -flags2 +dct8x8+wpred+bpyramid+mixed_refs-fastpskip Baraka.mkv

Cartoons

For anime and cartoons, bump up the deblocking and noise reduction filters:

ffmpeg -deblockalpha 2 -deblockbeta 2 -nr 150 ...

MIME Type

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.

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.

References