fun with DVDs

i’ve recently come into possession of a Playstation 3 and decided to augment it with a second-hand projector and a proper surround AV receiver.

now, because linux/pulse-audio still isn’t quite there with regards to surround sound, the PS3 is the only device i own capable of playing 5.1 nicely. it also does quite a good job of displaying the video content too.

however, most of my content is on UK or US DVDs … and this is a JP PS3. so i can’t play them direct, but thanks to mediatomb i can stream them over the network instead!

so i’ve been revisiting the vexing question – how best to rip DVDs into video files.

the main problem i’d like to solve is the difference between the television display, the DVD contents and the original film in terms of frame rate, aspect ratio and interlacing.

i’ve found another good reference on those issues here.  as with my last attempts, i’m finding that each new DVD i examine contains a different combination of problems.

so far i’ve found a number of DVDs where things are quite easy.  i can type:

mencoder dvd://${title} -ovc copy -oac copy -of mpeg -mpegopts format=dvd:tsaf -o ${name}.mpg

and ten minutes later all is well with the world.

this appears to have worked well for 月姫 (“Tsukihime” – UK), Star Wars (UK) and The Matrix (US).  But then i tried it on Spirited Away (UK) and the result has the wrong aspect ratio – it displays super-wide!  (mencoder doesn’t realise it needs to copy the aspect ratio from the mpeg headers even if there’s an aspect ratio specified in the stream as well.  specifying the 4:3 in both header and stream sorted it.)

so far i’ve been unable to sort that out without re-encoding the entire video content – which is silly.  still, it’s given me a chance to check a few other things about that DVD.  for one, there’s no interlacing (well, it’s “progressive encoded as interlaced” in effect), no telecine and no blending.  so the frames are very clean … but doesn’t that mean it’s playing a 24 frames per second film at 25 frames per second?  why yes it does.

so that should mean it’s 4% shorter – and it is!  the reported running time on the case is 120mins (actually 119:37) but the film running time reported round the net is 124 minutes.  not a big problem you might think and you’d be right .. but it still drives me up the wall.

it’s very easy to play the video at 24 fps but slowing down the audio turns out to be annoyingly fiddly .. and, so far, impossible.  each tool i use to demultiplex, convert, modify, re-convert and re-multiplex fails in new and interesting ways.  so i’ve given up for now – we’ll just have to enjoy this film slightly faster than intended.  *sigh*

so, what’s next?  that’d be Appleseed (UK).  Problems?  sure.  firstly it’s got a nice DTS soundtrack .. which the PS3 refuses to play.  Apparently there’s a trick to it where you can add fake PCM headers to the file to fool the PS3 into passing the audio stream direct to the AV receiver – which spots the DTS data and plays it.  but i’ve been unable to do that either so it’s AC3 for me.  *sigh again – but not quite as much*

more of an issue with this film is that the aspect ratio is just plain wrong.  there’s plenty of nice detail about the real numbers regarding aspect ratios on wikipedia but the key thing to note is that, despite rumours to the contrary, 1.85 is not equal to 1.78!

the reason i mention those numbers is that many films (including Appleseed and Spirited Away) are filmed with an aspect ratio of 1.85:1.  Widescreen televisions have an aspect ratio of 16:9 – which is 1.78:1.  So the film is a bit wider than the telly – for it to appear correctly there should be black bars at the top and bottom of the screen – but there aren’t.  (in the Spirited Away DVD there are black bars all the way round but you can see that the ones at the top and bottom are thicker than the ones at the sides.)

again, i can make mplayer play with the correct 1.85:1 aspect ratio either by forcing it with “-aspect 1.85:1” on the command line or by doing a simple rip and applying the correct setting in the mpeg headers – but again, the PS3 (and totem) ignore that setting – so the only option i’m left with is to re-encode.

why not leave it slightly stretched?  most of the time it looks fine but as objects rotate the distortions annoy me intensely – it looks wrong in a niggling, vague way which i find more frustrating than an obvious error.

how can i be sure it’s the aspect ratio that’s the problem?  luckily there’s a nice round circle near the start of the film.  at 16:9 it’s oval but at 1.85:1 it’s properly circular:

screenshot of the view through futuristic rifle sights in the film Appleseed
screenshot of the view through futuristic rifle sights and/or night-vision goggles in the film Appleseed

i’m still not completely certain that the DVD wouldn’t play correctly (with black bars) on a regular DVD player but i don’t have one so perhaps i’ll never know!

from the work on Spirited Away i have an mencoder command which generates an XVID AVI file which the PS3 will accept:

mencoder dvd://${title} -oac copy -ovc xvid -xvidencopts bitrate=16000:qpel:cartoon:chroma_opt:vhq=4:quant_type=mpeg\
:pass=${pass}:min_iquant=1:min_bquant=1:min_pquant=1 -o ${name}.avi

the “bitrate=16000” sets the highest target bitrate (and, therefore, the largest filesize) that mencoder will create.  in combination with the three “min_?quant=1” options it forces the maximum image quality.

the “cartoon” option might be good for anime – i haven’t done any serious comparison yet.

you mustn’t use the “gmc” option or the PS3 will refuse to play the file.  “qpel” is okay though.

unfortunately, as gorgeous as it looks, the appleseed DVD is encoded interlaced with what looks suspiciously like “partial field blending”.  this is my favourite field so far:

screenshot from appleseed movie
screenshot from appleseed movie

that single field from the DVD contains two blended film frames but note the strange horizontal banding – spooky.  looks like they just pointed a 25 fps camera at the cinema screen and pressed ‘play’ and ‘record’ at the same time – like the eighties with vinyl and cassettes!  retro.

the best image quality i’ve been able to get from this DVD is by using the “-vf tfields=1 -fps 50 -ofps 50” filter option to convert each field into its own frame.  for some reason this also messes up the audio sync so you also have to add “-delay 0.3”

that little trick doubles the frame rate.  that, combined with the fantastic level of detail in this film means that my final rip comes in at 7.5G per hour – more than six times the size of the Spirited Away rip with the same quality settings, which is about 1.7G per hour – about the same as the simple ‘copy’ rip straight from the DVDs.

screenshot from Appleseed showing dust motes floating in a beam of sunlight.
screenshot from Appleseed showing dust motes floating in a beam of sunlight.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s