|
©1994-2007 Kevin Boone | ||||||||||||||||||||||
|
*** I have changed my e-mail address: please see the contact page for details *** Home > Computing > Gadgets Using the transcode utility on Linux to rip DVDs for the Archos AV500 (and similar devices) Last modified: Fri Jan 26 10:40:21 2007 [Updated January '07 to deal with 16:9 content presented anamorphically in a 4:3 frame] This article explains how to use Thomas Oestreich's `transcode' utility, which is available for most flavours of Linux, to rip DVDs to play on the Archos AV500. While the AV500 will play a variety of video frame sizes, I'm assuming here that you want to optimise the video file so it fits exactly -- or as exactly as possible -- on the AV's 480x272 screen. As we shall see, it won't always be possible to get a perfect fit, and compromises will have to be made. I assume in this article that you want to rip DVDs to watch on the internal LCD screen, not on an external video display. The AV500 is quite tolerant of a wide range of video frame sizes, so if you ripped a DVD into an MPEG4 file with a fairly large frame size (e.g, 640x480) it would probably play OK on both an external display and the LCD. However, if you just want to play on the internal screen, you can do a lot better -- you can size it to fit the LCD, and get the best compromise between file size and image quality. Because the AV500 has such an amazing screen, it's worth spending a bit of time and effort getting things just right. This is where transcode comes in -- because it allows for incredibly fine control over all aspects of the format conversion, if you have the patience you can achieve far better results than are obtainable by point-and-click converters. In addition, because there's no graphical interface, all the CPU power goes into crunching the data, so the job gets done quicker (but it's still time-consuming, even on fast hardware). The disadvantage is that transcode is fiddly to use, and takes some getting used to. However, once you've figured out which settings work for you, you've done all the hard work, and after that it's easy. This article also provides some background on how DVDs are encoded, in the hope that it will help the reader deal with situations that aren't specifically covered here. Please note that I only have much experience with PAL DVDs. The image sizes and frame rates are slightly different with NTSC, so you'll need to calculate accordingly. I'm assuming also that the reader is tolerably familiar with Linux and the use of the command line -- if you've never used a sophisticated command-line utility before, I venture to suggest that getting stuck into transcode is not the way best way to learn. If the idea of using a command line brings you out if a cold sweat, read no further -- there are no shortage of point-and-click converters out there. What follows applies to devices other than the AV500, provided they have the same, or at least similar, screens. That includes the more recent Archos 504 and 604, as well as the Sony PSP. This article doesn't really apply to the PMA430 or to the newer Archos 404, because these units have 4:3 screens. BackgroundRegardless of how they are intended to be displayed, all PAL DVDs are encoded at a frame size of 720x576 pixels, 25 frames per second (fps). All, without exception. The aspect ratio of this frame is 1.25:1, or 4:3 as it's usually expressed. I'm going to call this frame the physical frame. However the programme material is encoded, and whatever the aspect ratio of the actual programme presentation, the physical frame remains the same, and the presentation has to be inserted into it wherever it will fit most comfortably. The 720x576 physical frame is approximately the shape of most TV screens and computer monitors. So if you're ripping a DVD that is intended to be shown on a 4:3 screen, and you have a 4:3 screen, you don't have to worry any more about aspect ratio. All you have to do is to shrink the picture down by scaling the width and height by the same factor. The AV500, however, has a 16:9 screen. It will show a video file encoded with a 4:3 aspect ratio, but it won't fill the screen unless you take certain steps -- more on this later.Although all PAL DVDs have a physical frame of 720x576 pixels, there are two different `encodings': 4:3 encoding, and 16:9 encoding. In 4:3 encoding, image data fills the entire physical frame. The studio will use this encoding for programmes that are indended for 4:3 displays -- television series, for example. The intention is that the programme will be displayed in approximately the same (4:3) aspect ratio as the DVD frame size. Ripping this kind of DVD is generally quite straightforward, because you don't need to worry about aspect ratio that much. Movie studios will use 16:9 encoding for most wide-screen presentations, whatever the final aspect ratio is intended to be on the display. In the first version of this article, I said that 16:9 encoding was used for [i]all[/i] widescreen presentations but, since then, this situation has changed.More on this point later. In 16:9 encoding, the program image is placed into the middle of the physical frame, leaving some blank areas at the top and bottom. In most cases the blank areas are about 85 pixels high both above and below the image. This leaves an image area about 406 pixels high in the middle of the 576-pixel-high physical frame. Note that 720/406 is approximately equal to 16/9, hence the designation `16:9 encoding'. The simplest wide-screen situation to consider is where the programme itself is presented with 16:9 aspect ratio, and the DVD is encoded as 16:9. To talk about `encoding' here is to give the process a grandeur it doesn't really deserve -- all the studio is really doing is taking the 16:9 picture, and putting it into the DVD's physical frame where it fits best -- across the middle. It is important to realize that if the programme itself is of 16:9 aspect ratio, and you play a DVD of that programme on a 4:3 display device, the aspect ratio as it is displayed is [i]still correct[/i]. Remember that DVD technology was developed for use with the humble television set, not the whizzbang gadgets we've got these days, so it has to be possible to play most programme formats without any messing around with the aspect ratio. Television sets have not been able to do this kind of thing until recently. Of course, if you do show a programme encoded this way on an ordinary television or 4:3 monitor, what you'll see is a wide image on a square-ish screen, with black bars at the top and bottom. This is not an defect: a 16:9 presentation does not fill a 4:3 screen, and that's the end of the matter. Now, if you have the good fortune to possess a 16:9 display device, you should be able to watch the presentation so that it fills the entire screen. All you need to do is to throw away the blank areas at the top and bottom of the DVD frame, and then scale the image uniformly. Because the programme is of 16:9 aspect ratio, and the display device is of 16:9 aspect ratio, the programme should fit perfectly on the display, with no black bars. The scaling we need is about 30% -- we need to make 406 vertical pixels fit into a space normally occupied by 576 pixels. I said earlier that you can't make a 16:9 picture fit a 4:3 screen, which is true as far as it goes -- you can't make it fit without losing some of the programme image. But what happens if you apply the same scaling on a 4:3 screen, as works on a 16:9 screen? You will end up with an image that is too big for the screen -- it will fill the vertical area, but some of the left and right edges will be `off the screen' -- they just won't fit. However, for many people the resulting image will be better than one with black bars: most of the action will be in the middle of the frame anyway. There is a similar problem if you want to fit a 4:3 programme into a 16:9 display. This time you will normally see black bars at the sides of the display, because the programme is not as wide as the display device. If you scale the image by 20% in both directions, you'll fill the width of the screen, but some of the top and bottom will be off the screen. Again, many viewers will find this preferable to watching the picture with black bars to the left and right, and most widescreen TV's have a facility to do this scaling. The AV500 -- which has a 16:9 screen -- also offers such a facility.
To sum up... if we have a 16:9 output device (like the AV500 screen), and we
have a DVD encoded as 16:9, and a 16:9 programme, we don't have to change the
aspect ratio at all. We just scale the width and height equally to give the
right pixel size for the screen. Optionally we crop off the black bars at the
top and bottom of the physical frame, because there's no point filling the
ripped file with black bits we aren't going to watch.
So now we move on to the real trouble-spot -- `anamorphic' DVD
presentations. These are presentations that are intended to be
played at a different aspect ratio from that of the physical
frame. Remember that the aspect ratio of the physical frame is
always 4:3, and even a 16:9 programme retains this aspect ratio,
by the simple expedient of what amounts to padding it out at
the top and bottom to make it fit the physical frame.
A problem that you will encounter when ripping any DVD is that the studios don't normally put any technical information on the packaging. It's very rare (to say the least) to find a DVD sleeve that says ``This movie is presented in an aspect ratio of 2.45:1, encoded as 16:9, with 402 vertical programme scan lines and 87 blank scan lines above and below the programme content. The image is compressed vertically by 30.1% over the horizontal''. If they did, we could write a piece of software that would use that information to rip a DVD with no trial-and-error at all. Alas, what you'll see on the sleeve is something like ``Wide-screen presentation'' or ``Enhanced 16:9'' -- which are meaningless terms. You might need to try a few different ripping protocols until you get the one that produces the best results. After all, the best rip is the one that looks best when you watch it. It is nearly always necessary, in my experience, to rip part of the DVD first without any kind of transformation at all, to get an idea how it is presented and encoded. An overview of transcodetranscode is a command-line utility for converting one AV format to another, with modifications in the size, aspect ratio, interlacing, frame rate, etc., as required. transcode can operate directly from a DVD -- you don't need to extract the DVD to MPEG files or even VOBs first. Transcode can do single-pass or multi-pass encoding; I'll assume initially that you want to do single-pass encoding, and explain how to adapt the technique to multi-pass at the end.A basic transcode command looks like this: transcode -a 0 -T NN,-1 -x dvd -i /dev/dvd -w NNN -b N,N,N \ -V -f N -j NN,NN,NN,NN -B NN,NN,NN -y divx4 -I 1 \ -o outputfile.aviAll the `NN's are to be replace by numbers according to how you want to do the rip. Here's what the command-line arguments mean.
-b switch accordingly. You may
want to experiment with the -w bitrate setting. In any case,
once you've decided what suits you best, you shouldn't need to vary these
very much from DVD to DVD. What you will need to change are the
-B and -j switches.
-j 84,0,84.0(but see the transcode manual for how this command can be abbreviated in certain circumstances). -B is the fiddly one. This switch controls transcode's
`fast downscaling' algorithm. Bear in mind we're taking about `fast'
in the context of ice ages here -- ripping a DVD is never a fast
operation. But it's fast compared to doing a full downscale
using the -Z switch, and
the quality does not seem to be noticeably worse, so it's worth
getting the hang of -B. More recent versions of
transcode can calculate the -B parameters automatically,
but it's better to do it yourself because you can be sure you know
what the result will be.
The paramters to -B are the number of pixel groups to
remove from the image to downscale it:
-B blocks_to_remove_vertically,blocks_to_remove_horizontally,block_sizeThe block_size can be 8, 16, or 32. The larger the block size, the quicker it works, but the limitation is that the source image size must be an exact multiple of the block size. Otherwise you'll get an error message. In my experience it's easiest to work with a block size of 8 all the time, and that's what I assume in all the examples. Suppose you have an image that is 720x576 pixels, and you want to downscale it to 344x272, work out the -B values as
follows.
Number of vertical lines to remove is (576-272) = 304 Number of vertical pixel groups is (304/8) = 38 Number of horizonal columns to remove is (720-344) = 376 Number of horizontal pixel groups is (376/8) = 47So we need `-B 38,47,8'. : And that's all (!) there is to it, but bear in mind that -B is
applied after -j, so the image that is downscaled
is the cropped image, not the original. Armed with this information we can
proceed to look at some real examples.
And so to businessHere are some examples, based on the DVD formats described above. You may want to experiment with different values of-w and -b
to get the compromise you want between file size and image quality.
4:3 programme material4:3 programme material will always be encoded at 4:3 aspect ratio, filling the full physical frame. We need to downscale this material to fit the height of the AV500 screen, which is 272 pixels. If we scale uniformly, we want a target frame size of 344x272 pixels (note 344/272 = 720/565 = 4/3 -- we aren't changing the aspect ratio).We already know the -B values (computed above), and we don't
need to
clip the source at all (so no -j). So the transcode command
we need is:
transcode -a 0 -T NN,-1 -x dvd -i /dev/dvd -w 500 -b 128,0,0 \ -V -B 38,47,8 -y divx4 -I 1 -o outputfile.aviThe only thing you'll have to experiment with is the -T
switch, to make sure you get the correct titles off the DVD. The
`-V' is not required on the latest versions of transcode, and you'll get
a warning message if you specify it. [Update: `-y xvid' is generally a
better choice these days, as the divx4 codec is no longer maintained.]
Because we are dealing with Linux here, there's nothing to stop you watching the generated outputfile.avi using mplayer
or whatever, while it is being generated (so long as your computer
is fast enough). So if it turns out that you're grabbing the wrong title,
you can stop transcode and try again. If it's correct, just leave it
to run. Don't forget to ensure that you've got the right audio track
as well.
Note that the resulting 344x272 image won't fill the AV500 screen, but the unit will scale the image to fill the screen (chopping off a bit of the top and bottom) if you ask it nicely. 16:9 programme material, not anamorphicThis will generally be encoded as 16:9, that ism with 84 blank lines above and below the programme content. We need to clip off these 84 lines first, which will give a working frame size of 720x406 pixels. We want to reduce this to 480x272 -- the exact size of the AV500 screen -- but we can't; at least, we can't with fast downscaling. We would need to remove 134 lines vertically (406-272) but we can't, because 134 is not a multiple of 8. So, instead, we'll remove 136 lines (136 is 17x8), giving a final frame height of 270. To fit the screen width, we need to remove 240 columns (=30*8). So the-B values are 17,30,8:
transcode -a 0 -T NN,-1 -x dvd -i /dev/dvd -w 500 \ -b 128,0,0 -V -j 84,0,84,0 -B 17,30,8 \ -y divx4 -I 1 -o outputfile.aviAs before, put in the correct value for the title number. The final frame size will be 480x270 pixels. 2.35:1 programme material, encoded anamorphically in 16:9We can do this in two ways. If you remember from the discussion above, the reason the studio stretches 2.35:1 material to fit a 16:9 frame, and not a 4:3 frame, is that if you dont' correct the aspect ratio it doesn't look too bad, and most TVs can't do aspect ratio correct (or, at least, could not do so when the DVD format was introduced). So one way you could proceed with this kind of programme material is to treat it exactly as 16:9 programme material, as described in the previous section. You'll end up with an image size that will almost exactly fill the AV500 screen, but of course it will be stretched a bit vertically -- the AV500 screen is too tall for a 2.35:1 source to fill it without stretching.If you prefer the original aspect ratio of 2.35:1, you'll have to put back the black bars at the top and bottom of the image. The easiest way to do this is to crop the image to a size that will give the correct aspect ratio, and let the AV500 centre it on the display. You don't need to insert the black bars into the output file, although transcode does provide a facility for this if you need to. Since the width of the AV500 screen is 480 pixels, the height required to give a 2.35:1 aspect ratio is 204.26 pixels. We can't have fractional pixels and, in any case, for fast downscaling we need to remove an integral number of 8-line groups. If we aim for a final image size of 480x208, this will give an aspect ratio of 2.31:1, which is close enough for practical purposes. If you want it spot-on, you'll need to use the slow (-Z) downscaling method. As for 16:9 programme material, we still need to strip 84 lines above and below the image -- because they will be empty. But instead of scaling down to 270 lines, we will scale down to 208. So the only difference between this case and the previous one is the first argument to -B,
which will be 25 (because (576-(2*84)-208)/8 = 25):
transcode -a 0 -T NN,-1 -x dvd -i /dev/dvd -w 500 \ -b 128,0,0 -V -j 84,0,84,0 -B 25,30,8 \ -y divx4 -I 1 -o outputfile.aviThe final frame size will be 480x208 pixels. 16:9 programme material, encoded anamorphically in 4:3As I said before, this is increasingly common, probably because everybody now realizes that encoding as 16:9 throws away 30% of the frame. We don't need to crop, but we do need to scale anamorphically to 480x272. This is the one case where I use -B with a 16-pixel group size, because I can still get an exact fit and exact scaling:transcode -a 0 -T NN,-1 -x dvd -i /dev/dvd -w 500 \ -b 128,0,0 -V -B 19,15,16 \ -y divx4 -I 1 -o outputfile.aviThe final frame size will be 480x272 pixels. Academy Standard (1.85:1) material is also often encoded this way, and can be processed using the same command. However, you'll get some thin black bars around the picture which you might want to crop off, if you're really fussy. I normally don't bother. Two-pass encodingIn all the examples above, we have used one-pass encoding. Two-pass encoding will give a considerable increase in image quality for a given file size, or a smaller file for a given image quality. Of course, it will take nearly twice as long. In my view, the AV500 display is sufficiently good that it's worth the extra time to do a two-pass operation. Here's how.On the transcode command line, for the first pass add the switch -R 1 to the command lines given above. For the second pass,
add -R 2 instead of -R 1. And that's it.
Using this method, both passes produce a video file -- if you're using the command-ine arguments described in this article. This is fine if you're in a hurry to watch -- you can watch the first pass while the second is encoding. However, the only necessary output from the first pass is the file divx.log, which contains
transcode's calculations of the frame-to-frame variablility. It
is this information which drives the variable bitrate encoding
in the second pass. So if you want to get the fastest two-pass
rip, you should dump the video output from the first pass, and
stop the audio being encoded at all. So instead of
-o outputfile, say -o /dev/null; and
instead of -y divx, say -y divx,null.
Note that the transcode xvid codec, unlike divx4, does not benefit from, or support, multi-pass encoding. New Archos modelsSince the first version of this article, Archos has released three new models: the 404, 504, and 604; and more are rumoured to be coming. The 504 and 604 have the same screen geometry as the AV500, while the 404 has a TV-shaped 4:3 screen.But there are two other developments in these later devices which are potentially important. First, they support formats other than MPEG4, and MP3, and file types other than AVI. I find AVI and MPEG4 satisfactory for the built-in LCD, so I still use them. But for optimal image quality you might be better investigating MPEG2 format. The 504 and 604 will, in fact, play a direct rip of the MPEG stream out of the DVD (so the ripping process consists only of format conversion, not encoding, and is therefore very fast). However, ripping this way results in vast files, which aren't all that suitable to a portable device. The other development is support for multi-channel (e.g., 5.1) audio. Of course you can't usefully listen to 5.1 audio on headphones, but if you have a docking station and a compatible 5.1 amplifier, you can use the S/PDIF (coaxial) digital audio output. Since MP3 is limited to stereo, you can't rip your DVD audio tracks to MP3 if you want to take advantage of this feature. AC3 is probably a better bet. Closing observationsHere are a few final things to think about. Make usage decisions carefully Ripping DVDs is not a quick process, even on the fastest computer hardware. It's not quick enough, at any rate, that you'll want to do it twice for the same programme. If you plan on watching your programmes on a larger device than the AV500 screen, it's probably best to take that into account when ripping. After all, the AV500 will play larger frame sizes than its own screen. For best results, consider ripping to a size which is of the same aspect ratio as the LCD screen, e.g., 720x406. This is a relatively fast thing do to with transcode, because you haven't got to scale the image at all -- just crop out the 406 lines from the middle of the physical frame. Similarly, if you always prefer to crop off a part of the image rather than having black bars at the left and right, consider doing the crop in transcode rather than having the AV500 zoom the image to remove the black bars. Why? Well, if you scale up the image on the AV500, it will tend to exacerbate any defects in the encoding -- you'll never get better quality by making pixels stretch further. But if you crop the image in transcode and end up with something that exactly fits the AV500 screen the way you like it, the unit won't have to scale anything. Of course, this is not a sensible thing to do if you plan to watch on other screens -- you're throwing away part of the source material. File size considerations The settings I describe above will generate AVI files whose size is about 260 Mb for each hour of programme. At a bitrate of 500 kbits/sec (-w 500), and two-pass
encoding, you're effectively watching a DVD on a small screen. You'll see
some encoding artefacts if you put your face up to the screen, but for normal
viewing the quality is as good as it needs to be, in my opinion.
However, if minimizing file size is your goal, you'll find that with the
divx codec, and two-pass encoding, you can turn the bitrate
down to about 200 kbits/sec, and still end up with something watchable.
You wouldn't want to put your face up to the screen, and you certainly
wouldn't want to play it on a large screen, but for watching on the
train, for example, it should be fine. At this bitrate setting, your
file sizes will be about 160 Mb/hour.
|
|
|||||||||||||||||||||