< < |
- MPlayer is a multimedia player which supports a very broad
range of file formats and media codecs: MPEG1, AVIs
(including all Windows codecs, all DivX? codecs), DVDs, VCDs, SVCDs
and so on. I use it for watching all kind of files.
- MEncoder is part of the MPlayer package and is used
for encoding video and sound. It is capable of transcoding DVDs.
- transcode is a set of tools that allow to transcode from
a broad list of formats to a broad list of other formats including
transcoding from DVD to AVI or (S)VCD.
- You know that most DVDs are encrypted. libdvdcss is a library
that decrypts DVD contents.
- DVDs contain information about the titles / chapters / angles and
audio languages contained in the files. These information are stored
in
.IFO files. libdvdread is often used to parse
these files and extract the informations that are needed.
- lame (Lame Ain't an MP3 Encoder) encodes MP2/WAV audio
to the MP3 format.
- vobcopy can be used to copy VOBs from a DVD. Decryption
is done on the fly.
- dvd::rip is a graphical frontend for transcode.
I'll present you two methods for DVD transcoding - using MEncoder
and transcode. Nevertheless you need some files for both method.
2.1. A word on codecs
In an ideal world there would be only one codec - the best one. But this
world is far from ideal. The result is that there is a wide range of
video and audio codecs to chose from. First I'll explain the different
types of codecs:
- Native codecs are normal Linux binaries (most often shared
objects, libCODECNAME.so). Support for them is trivial.
- Windows codecs are the original or slightly modified
Windows dynamic libraries (DLLs, AX and the likes). These codecs do
not work natively under Linux - you need a special library to use
these codecs. This library is called avifile. Some months
ago this was the only way to watch AVIs under Linux.
Today most codecs come with a native version for Linux (like XviD,
DivX 4/5 and others).
Here's a list of supported video codecs:
- MPEG4 is an official video compression standard. There is no
codec whose name is simply MPEG4. If you talk about MPEG4 you don't
talk about a specific codec - you talk about a set of techniques to
compress videos. MPEG4 compliant means that a codec produces
files that can be played by other MPEG4 compliant codecs.
- DivX ;-) is the "original" hacked Microsoft MPEG4 codec that
started all those ripping frenzies. It does not support all MPEG4 features
like b-frames* or
global movement compensation (GMC
*). Some still use it
under Windows with the excellent tool Nandub. It is seldom used
under Linux because there are codecs that provide better quality. It comes
as a Windows dynamic library (
divx.dll and some others) and
requires avifile.
- DivX 4 and 5 are the official successors. DivX 5
replaces DivX 4. That's why you can't have both codecs installed
at the same time (well technically you can, but you shouldn't, for
obvious reasons). These are native Linux shared objects called
libdivxdecore.so and libdivxencore.so. This
is closed source. For Windows there are different versions available and
only the commercial version supports all encoding options like
b-frames*,
GMC*
or quarter PEL*. The
free version can still be used to view all files
created with even the commercial version. Unfortunately there's only
the free version for Linux which doesn't support all those nice options.
DivXNetworks? are thinking about providing a commercial solution for
Linux as well. But don't expect that codec to be available soon.
- XviD (it's
DivX read backwards) is an Open
Source MPEG4 implementation that is really good considering compression
and picture quality. Support for advanced MPEG4 features
(b-frames*,
GMC*)
is being worked on or has already been implemented.
- libavcodec or short lavc is another Open Source MPEG4
compliant video codec which is superior in performance and quality to
DivX 5 and even to XviD. This codec supports
b-frames*. It is part
of the ffmpeg project.
- Of course there are the MPEG1 compliant codecs that you need for
VCDs and the MPEG2 compliant codecs for SVCDs or DVDs. At the moment
this guide aims at producing AVIs so I won't go into detail about
either one of these.
- Most other codecs are either outdated (like Intel Indeo 5) or
other cracked version of Microsoft's MPEG4 codec (like AngelPotion).
Still other codecs are under heavy development (like VP4) and do
not present a workable solution for us here.
This guide tries to focus on two codecs: XviD and lavc.
Reasons are that both provide excellent quality, both are fast and you only
need a MPEG4 compliant decoder (like DivX 5 or XviD) on a
Windows system for playback. Playback under Linux is no problem at all -
MPlayer or Xine do happily play DivX 4/5, XviD? and
lavc encoded movies.
Again a list, this time for audio codecs:
- MP3 is short for MPEG1 layer 3 and is an official
audio compression standard. If you talk about MP3 you actually
talk about a compression technique, not about a codec in particular. There
are more codecs for MP3 than I can name in a full day.
- lame is an acronym for "Lame Ain't an MP3 Encoder" (although
it is ;-)). It provides a encoder that produces high quality MP3 files.
Both transcode and MEncoder use lame for
audio compression.
- AC3 is again an official audio compression standard. Almost all
DVDs contain AC3 encoded audio. Today there are decoders for
both Windows and Linux that work with AC3 sound inside AVIs.
The advantage is that no re-compression is necessary (recompressing
always loses quality) and that multi channel sound (Dolby Surround and
the likes) will be preserved. The disadvantage is that AC3 sound
needs more space than MP3 encoded sound.
- Vorbis is a new Open Source audio compression. It is available
for both Windows and Linux. Its advantages are a better quality : size
ratio compared to MP3 and multi channel support. Unfortunately
you cannot safely include Vorbis audio into AVI files - but I'm working
on a tool that can join video and Vorbis audio in an OGG container.
As soon as it is ready I will include it in this guide.
I hope this clears things up a bit.
2.2. Common libraries / codecs
I won't go into too much detail in this chapter. There is more documentation
on how to install included with each package. Refer to that if you have
problems. Also note that MPlayer has rather strong requirements
regarding versions of gcc, binutils and other central system components.
Refer to the
MPlayer installation documentation.
Note: Before downloading software check if your distribution
already contains that software. I use Debian Woody (testing) and have found
that a lot of software is already available prepackaged.
- libdvdcss - Head over to
<a href="http://www.dtek.chalmers.se/groups/dvd/downloads.shtml"
target="_blank">the Ogle project page and download
libdvdcss-0.0.3.ogle3.tar.gz (note that version numbers may
differ as software is always under development). Un-tar-gz it, compile
it, and install it in /usr/local . Please note that
there different versions of this library floating around (0.0.3,
1.0.1). MPlayer still suggests that you use 0.0.3.
- libdvdread - Get it from the same web page as libdvdcss.
Note that Debian Woody already contains libdvdread. A simple
apt-get install libdvdread2 libdvdread2-dev should do the trick.
- XviD codec - Needed if you want to use transcode.
Short instructions taken from the MPlayer documentation:
cvs -z3 -d:pserver:anonymous@cvs.xvid.org:/xvid login
When asked for a password simply hit enter.
cvs -z3 -d:pserver:anonymous@cvs.xvid.org:/xvid co xvidcore
cd xvidcore/build/generic
- Edit Makefile.linux to fit your needs.
make -f Makefile.linux
- Copy the
xvidcore/src/divx4.h file to
/usr/local/include/decore.h and to
/usr/local/include/encore2.h. Be sure to make a backup
of the files you will overwrite!
- Copy
libxvidcore.so and libcore.a to
/usr/local/lib/
For the compilation you might need a special version of nasm
which you can get
<a href="http://homepage1.nifty.com/herumi/soft/petit/nasmsse2.tgz"
target="_blank">here.
- vobcopy - Get it from
<a href="http://lin-prog-newbie.sourceforge.net/projects/c/index.html"
target="_blank">the homepage.
- avifile - As explained it is needed to access Windows
codecs for which there are no native Linux binaries. Head over to
the homepage.
Before you do that check again if your Linux distribution already
provides avifile (Debian Woody does). You still need the
Windows codecs from the avifile homepage or directly
from
<a href="http://www2.mplayerhq.hu/MPlayer/releases/w32codec-0.60.tar.bz2"
taget="_blank">MPlayer's homepage.
- DivX 5 - although this guide does not focus on DivX 5
you can get it from
http://www.divx.com/. If you have some time to spare than I suggest
make some comparisons between DivX 5 and XviD or
lavc and see for yourself that it is worse than the two latter
codecs.
2.3. MPlayer
You need MPlayer. It doesn't matter if you'll use MEncoder
or transcode later on - you still need this. So get MPlayer
from
http://www.mplayerhq.hu/. I prefer the CVS version as it often has
features that the official releases lack! In fact I base this guide on
features have been committed to CVS just a few days earlier (today is April 30,
2002). Just do the same - be brave and get the CVS version.
If you want to encode using MEncoder I suggest you also get
a version of libavcode for encoding. You only need to download it
if you are using a CVS version of MPlayer. Releases come pre-packaged
with libavcodec. These instructions are taken from the
MPlayer documentation:
- Check out the ffmpeg project from CVS:
cvs -d:pserver:anonymous@cvs.ffmpeg.sourceforge.net:/cvsroot/ffmpeg
login. Just hit enter when you're prompted for a login or
password.
cvs
-d:pserver:anonymous@cvs.ffmpeg.sourceforge.net:/cvsroot/ffmpeg co
ffmpeg
- Move the libavcodec directory from the Ffmpeg sources to the root of the
MPlayer CVS tree. Symlinking is not enough, you have to copy/move it!!!
A note on compiling: Be sure not to include XviD? support.
Instead include support for libavcodec. Installation instructions
are provided in the MPlayer docs. Yes, you've read correctly:
compile transcode with XviD and MPlayer
without XviD but with libavcodec. The
reason is that MPlayer can't contain support for both codecs at
the same time as both use variables that have the same name.
2.4. transcode
Get transcode from the
<a href="http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/"
target="_blank">homepage. Make sure that it compiles with XviD
support as well as with support for MPlayer's post processing
functions. Again I advice you to chose the CVS version.
Additionally you really want to download dvd::rip, an excellent
Gtk+ based frontend for transcode. Get it from
here. Installation
instructions are included.
2.5. getting RPMs
I know of at least two places where you can find some RPMs for the software
mentioned above:
- Penguin Liberation
Front lair - RPMs for Mandrake
- <a href="http://www.piorunek.pl/~dominik/linux/pkgs/mplayer/"
target="_blank">http://www.piorunek.pl/~dominik/linux/pkgs/mplayer/
-
RPMs for Redhat 7.2
Back to the table of contents
3. Ripping the VOBs
This part is rather easy. All you need is some free space (a lot
of free space actually). Depending on what you want to transcode you should
have 10G of free space available. If you don't spend some bucks on a new
drive, they are really cheap at the moment (like 150€ for a 80G drive).
Before you do anything else think about the region code. All drives shipped
today have RPC mode 2 protection - that means that you can only switch your
region code five times before it is locked. You can get information about how
to remove the region code from your drive over at <a href="http://www.digital-
digest.com/" target="_blank">Digital Digest. So why am I mentioning this?
The ripping methods mentioned below rely on the drive to have the correct
region code (read: the same as the DVD that's inserted) or no region code at
all. All error messages are kind of cryptic and it's often not very clear that
you have a region code related problem when ripping fails. So keep that in
mind.
First test the DVD. Fire up MPlayer and watch the first title:
mplayer -dvd 1. Do you like it? Cool. Make sure you
remember whether the video is interlaced or not (see below). Close
MPlayer.
3.1. Interlaced video
What you see on television are not 25 frames per second. In fact you see
50 half-frames per second (I'm talking about PAL here - NTSC has 29,97 fps
or nearly 60 half-frames per second). One frame contains the odd rows, one
frame contains the even rows. That way you'll get 25 fps. The problem is
that those half frames are taken from different times. If you have fast
horizontal movement you will then see that an object (or person) is at one
position for the odd rows and at another for the even rows. These are
artifacts you don't want to have in your final video. Now take a look at
this interlaced
picture taken from my Ally McBeal? DVD. With the appropriate filters
you can eliminate the effect of interlacing (called de-interlacing... what
a surprise ;)). Here's the <a href="../images/deinterlaced-tc.png"
target="_blank">same picture with de-interlacing enabled.
Now that you have an idea what interlacing looks like you should be able to
decide for yourself whether your DVD contains interlaced material or not.
For the rest of this guide I'm assuming the following:
- The DVD drive is available under
/dvd. There is an
entry in /etc/fstab for /dvd.
- You have a lot of free space under
/space.
- Your DVD's title 1 is the one you want (Robos, creator of
vobcopy, told me that on most DVDs the main title is
number 2. Your mileage may vary.).
Please substitute these paths with paths that apply to your system.
There are a lot of ways to rip the VOBs. I'll present two: using a command
line tool (vobcopy) and using the transcode GUI
dvd::rip. You don't have to do both :-)
3.2. ...using the command line interface
Now run vobcopy. It will automagically copy all VOBs that belong
to the title with the most chapters onto your hard disk.
- First, mount your DVD:
mount /dvd
- Let vobcopy grab those VOBs:
vobcopy -i /dvd -m
This will copy the VOBs from the DVD, decrypt them (this is where
libdvdcss is needed) and write them to the current directory (which
you can alter with e.g. -o /space). They will be named after the
DVD's title (e.g. I have ALLY_MCBEAL_DISC21-1.vob,
ALLY_MCBEAL_DISC21-2.vob etc.). The -m switch causes
vobcopy to actually mirror the DVD's contents including the
.IFO files - useful because you can then use the local copy
with MPlayer/MEncoder or transcode just like it was a real
DVD. It will take some time. Just be patient.
Note from the author (Robos): vobcopy has some problems
following angles. You might get duplicate scenes with e.g. "The Matrix". I'm
working on it.
Another note from Robos: There's another new utility called
dvdbackup
that can also copy DVDs.
3.3. ...using dvd::rip
dvd::rip can do the same job for you.
Fire up dvd::rip by typing dvdrip. You'll see the main
window. Chose Edit / Preferences and dvd::rip will come
up with the preferences
dialog. Here you'll have to enter your paths. The first is the path to the
DVD device and not the mount point. Often it is
/dev/dvd which is a symlink to the real device, e.g.
/dev/hdc.
Close that dialog. Now start a new project (File / New Project).
It will start with the <a href="../images/dvdrip-storage.png"
target="_blank">storage tab. Again enter the correct paths. Note how the
other name fields change when you change the project title.
Change over to the Rip
Title tab and press the Read DVD Table of Contents button.
After a second or two the list below will be populated with the titles that are
stored on the DVD. Just select the title you want to rip (you can select
multiple titles by holding CTRL and clicking on them). Chose the
language and the angle. Leave Specify Chapter Mode on
No. Last step: press Rip selected
Title(s)/Chapter(s). Again be patient. Drink some milk. Have a nice chat
with your girlfriend.
The rest of dvd::rip will be covered later in
chapter 4.
Back to the table of contents
4. Transcoding the DVD to an AVI
Here you really have two choices - it's either transcode or
MEncoder. Both have pros and cons. Here's a very short list that
is true at least for the CVS versions from April 28, 2002:
- MEncoder can't adjust audio delays. If audio and video are
not synchronized when you play it back with MPlayer then
you should use transcode instead.
- transcode can't handle
VBR/ABR* MP3, only
CBR*. If you
really need VBR MP3 audio then you'll have to stick with
MEncoder. Note that the AVI tools that come with transcode
won't work with AVIs that contain VBR MP3 audio. Therefore you cannot
fix synchronization problems in MEncoder generated AVIs with the
avisync utility.
- According to the documentation MEncoder should only be used
with VBR/ABR MP3 encoding. CBR encoded files won't play on Windows
systems (while they play fine with MPlayer).
- There's no nice GUI for MEncoder at the moment. This makes
cropping/resizing rather painful.
4.1. Aspect ratios
Before we start let me introduce you to the most common aspect ratios you
might encounter. DVDs are always encoded at 720x576 (5:4) although the
picture will be scaled at playback. Common video formats are 4:3 = 1.33
for TV, 16:9 = 1.78 for normal cinema movies and 2.35:1 for Cinemascope.
Here is a list of common scenarios:
- 4:3 movies that fill the whole picture (no letterboxing<a
href="index.html#glossary_letterbox">*
): scale 5:4 to 4:3
16:9 movies that fill the whole picture (again no letterboxing):
scale 5:4 to 16:9
16:9 movies that are letterboxed: scale 5:4 to 4:3 and cut away
some of the black bars
2.35 movies that are letterboxed: scale 5:4 to 16:9 and cut away
some of the black bars
Don't worry if you don't understand all that at once. Take a look at
dvd::rip's clipping and scaling options for a more intuitive
overview.
4.2. Using dvd::rip
Using dvd::rip is by far the best and easiest method to get your
AVI. As stated earlier it relies heavily on transcode to do its job.
After starting dvd::rip you rip the titles you wish to transcode
to your hard disk. Refer to chapter
3 for a detailed description.
4.2.1. Clipping and zooming
Now head over to the <a href="../images/dvdrip-clipzoom.png"
target="_blank">Clip & Zoom tab. Here's where you set all parameters
regarding picture size and cropping (called "clipping" here). First get
yourself a picture to work with: simply enter a frame number (like 200)
into the Grab Preview Frame input line and press Grab
Frame from ripped VOB. After a few seconds the three views below
show the frame you requested.
transcode uses three steps to bring the picture to its final size:
first it clips the unscaled image, then it does resizing and last it
clips again. Each of this steps can be left out by selecting 0 for clipping
and the original width and height for resizing. Each window shows the result
of those three steps. If you want to see how big the pictures really are
then just click onto any of them and a pop-up window will be opened containing
the result.
You may have noticed the drop-down listbox below the three preview windows.
dvd::rip offers a wide rage of presets for you to work with. Simply
select one of those gives you a place to start. You can still change the
values manually after selecting such a preset. All presets that are named
"autoadjust..." try to guess the correct clipping regions. After selecting
a preset hit the Apply Preset Values button. Now adjust the
values you got until you're happy.
The big frame, medium frame and small
frame parts refer to the final image size that is to be achieved.
big keeps almost full DVD resolution, medium is
somewhere between 500 to 600 for the width and small is somewhere
around 350.
One note about resizing: Use fast resizing has a big impact upon
image processing but requires that the target width and height are divisible by
32. Don't worry, dvd::rip will tell you if you can't use fast
resizing. Note also that while it is possible to actually enlarge the picture I
strongly advise against it. There are several drawbacks: the encoder needs a
lot more bits to achieve the same quality you'd get when encoding a smaller
picture and then scaling it up while playing it back, and you might even get
distorted pictures (Peter Schuller reported such a case to me). Always scale
down.
4.2.2. Choosing encoding parameters
We're done with this tab. Open the <a href="../images/dvdrip-transcode.png"
target="_blank">Transcode tab. First decide about the video codec you
want to use. If you've installed DivX5 for Linux then you can use
that, but I would recommend using XviD. If you've downloaded
XviD from CVS then the option to chose is xvidcvs
(obviously). If transcode later aborts with some obscure error
then you can try xvid.
Do you remember that I asked you to check if the video was interlaced? Now we
need it. If your video is not interlaced then simply leave
deinterlacing to and antialias off. Otherwise
select 3 - Zoom To Full Frame. This is the slowest but best
looking deinterlacer. Again here's the <a href="../images/interlaced.png"
target="_blank">interlaced sample from Ally McBeal?. You can see
the result from 3 - Zoom To Full Frame in the
first deinterlaced
picture.
Another filter for deinterlacing is provided by an external plugin (don't
worry you've already installed it with transcode itself).
Have a look at the lower right. There's a input box labeled
transcode options. All options entered here are simply passed
along to transcode. We can use this for deinterlacing. Here's the same
picture as above
deinterlaced with other deinterlacer. This deinterlacer
is faster than the 3 - Zoom To Full Frame option. If you want
to use this deinterlacer then set deinterlace to off
and enter -J dilyuvmmx in the input line.
dvd::rip tries to autodetect your framerate. If it failed you can
correct it here. Use YUV internal should always be
yes unless the output codec does not support YUV modes.
XviD does. Leaving it on gives a huge speed boost. DivX
multipass should be yes as well unless you only want
to do a preview. For final results always chose two pass encoding. Although
this is labeled DivX multipass it works nicely with XviD
as well.
The audio options should be self explanatory. You chose either to reencode
the audio to MP3 using the specified bitrate or to use the original AC3
sound without reencoding. AC3 audio provides surround sound and all those
advantages but is bigger than MP3 sound. It's really your choice. If you
use MP3 then make sure that the MP3 Quality setting is at
2. According to lame's documentation (lame
is used for MP3 compression) higher quality settings like 1 or
0 - best but slower are at lot slower but do not produce
significantly higher quality. The volume rescale allows
normalization the audio which does not require a separate (external) program.
dvd::rip automagically scans the sound and provides a rescale value.
In the upper right is the bitrate option. You can easily chose the rip size
by selecting the count and size of CDs you want to use. Manipulating
the Target Size or the Video Bitrate works as well.
dvd::rip automatically updates the calculated values below so
finding the optimal bitrate is rather easy.
4.2.3. Generating a quick preview
Most of the times you should let dvd::rip generate a small preview.
You do that by providing a Frame Range. I usually take a 30 second
sample which would be 750 frames at 25fps (<number of seconds> *
<fps> = <number of frames to encode>) and start sometime into the
movie (like 200, 300 frames). Good values might be 200 - 950. You
should also give transcode a high nice level (which results in a low
process priority) so it will only use spare time. If you really want your
preview right here right now you can also temporarily disable DivX
Multipass. Just remember to turn it back on later!
When you're done click Transcode. After a couple of minutes
at most your AVI/MPEG will be ready. Now have a look at it (like
mplayer my-new-file.avi). This is a good moment to see if
deinterlacing works as expected and to check if audio and video perfectly
synchronized. If they are, you're set. If they aren't, then read on:
4.2.4. Preventing audio/video desynchronization
If your audio and video are not synchronized in the preview (or when you
play back the DVD itself) then you can give transcode a frame
offset for the a/v synchronization. You do that by providing the parameter -D nr
in the transcode options input line on the
Transcodetab. The nr is the number of frames the
audio is delayed. This number can be negative. A frame is 40msecs long
at 25fps. In general the frame length is (1000 / fps)msecs long. For my
Ally McBeal? DVD I need a correction of -2 which amounts to -80msecs:
-D -2. Now regenerate your preview video (the other parameters
should still be the same) and check the audio again. If needed redo this
step until you're satisfied.
4.2.5. Doing the whole thing
When the preview is fine you can start your transcode. Make sure that
DivX Multipass is turned on again if you disabled it for
the preview. Either click on Transcode or on Transcode
+ Split if you want your files to be split automatically according
to the settings under Video Bitrate Calculation.
Now is really a fine time for some socialising :-)
4.2.6. For advanced users: transcode command line arguments
This chapter explains the transcode command line options used by
dvd::rip. It is not crucial to the transcoding process so you may
as well skip it. I provide it for those who wish to have some deeper insight
into what dvd::rip and transcode do.
In dvd::rip press CTRL-t to see what the commands
dvd::rip executes look like. For now let's concentrate on the last
set of commands, Transcode command. Here's an example for my
Star Trek: The Next Generation DVD without all those mkdir
and cd commands:
transcode -i /space/tng-biggoodbye/vob/004 -w 4357,250,100
-a 1 -b 128,0,0 -s 3.311 -V -f 25 -B 12,10,8 -R 1 -x vob,null -o /dev/null
-y xvidcvs,null
transcode -i /space/tng-biggoodbye/vob/004 -w 4357,250,100
-a 1 -b 128,0,0 -s 3.311 -V -f 25 -B 12,10,8 -R 2 -x vob
-o /space/tng-biggoodbye/avi/004/tng-biggoodbye-004.avi -y xvidcvs
Let's take a look at the first command and its parameters:
-i /space/tng-biggoodbye/vob/004 obviously tells
transcode where to find the files. It can be a file, a device
or a directory containing the files.
-w 4357,250,100 sets the video encoding parameters: bit rate,
maximum key frame interval and crispness.
-a 1 selects audio track number 1 (starting with 0).
-b 128,0,0 sets the audio encoding parameters for
lame: bit rate, VBR and quality. Have a look at lame's
man page for an explanation of the parameters -V and
-q.
-s 3.311 causes lame to scale the audio
and thus normalizing it on the fly.
-V causes transcode to do image processing
in the YUV color space. Without -V images would be converted
to the RGB color space. Note that some external filters only work with
either color space. YUV processing gives a huge speed boost.
-f 25 sets the frame rate.
-B 12,10,8 sets the fast scaling options: the picture
will be scaled down to height - 12 * 8 rows and to
width - 10 * 8 columns.
-R 1 is the marker for the first (of two) encoding pass.
-x vob,null - the video input comes from VOB files and
the audio input will be skipped (it isn't needed for the first pass anyway).
-o /dev/null - We don't need the video either, so just
discard it.
-y xvidcvs,null - Output video using XviD and
discard audio.
The second command line is not that different. It just skips all options
that would discard output (like -o real-file-name and
-y xvidcvs). For a more complete reference have a look at
transcode's and lame's man pages.
As a last note you will find that transcode as of version
0.6.0pre6-20020529 contains support for libavcodec via a still
experimental export module written by me. You can activate it by using -y
ffmpeg4 (remember: libavcodec is part of ffmpeg)
instead of your previous codec. dvd::rip does not support it at the
moment (read: it is not in the list of selectable codecs).
4.3. Using MEncoder
As mentioned earlier there is no GUI for MEncoder at the moment.
Therefore I won't provide screenshots and you have to do everything by hand.
This is a process called "three pass encoding".
4.3.1. Encoding the audio
The first step is to encode only the audio. Make sure you know what audio
language you want to use - you need either the audio id (which is 128 for
the first stream, 129 for the second etc.) or the two-letter country code
(like en for English or de for German). You can
find out about these codes by running MPlayer in verbose mode:
mplayer -dvd 1 -v. It should print a lot of lines. Search
these for lines similar to:
[open] audio stream: 0 audio format: ac3 language: en aid: 128
[open] audio stream: 1 audio format: ac3 language: de aid: 129
[open] audio stream: 2 audio format: ac3 language: es aid: 130
Here I have three audio streams: English, German, Spanish and their IDs.
Now call MEncoder to encode the audio for you:
nice -+19 cat /space/*vob | nice-+19 mencoder -ovc frameno
-o frameno.avi -oac mp3lame -lameopts abr:br=128 -alang de -
Here's an explanation for the command line arguments used:
nice -+19 - Gives MEncoder the lowest process
priority so it won't disrupt your normal work.
-ovc frameno - Output Video Codec is frameno
which means that no video data is actually written or processed at all.
-o frameno.avi - Write the output to the file called
frameno.avi. The audio must be written to a file
with that name as MEncoder will read the audio from exactly
this file with the exact name in the next step.
-oac mp3lame - Output Audio Codec is the lame
encoder library.
-lameopts abr:br=128 - options for lame. It tells
lame to produce a ABR (average bitrate, it's a variable bitrate
setting with the average supplied by the user) with the average bitrate
of 128kbit/s.
-alang de - use the German sound track. An alternative
is using -aid 129.
Wait some time and you'll have your audio. MEncoder even prints
some suggestions for the video bitrate:
Recommended video bitrate for 650MB CD: 1845
Recommended video bitrate for 700MB CD: 1992
Recommended video bitrate for 800MB CD: 2287
As you can see these values are rather high - but that's because an Ally
McBeal? episode is only 41minutes long. So I'd go for two episodes per
CD and give the video a bitrate of about 1000.
4.3.2. Generating a preview (first pass)
Now's the time to decide about the video codec you're going to use. I'm
assuming that AVI is the desired result with one of the different DivX
encoders. MEncoder has support for DivX 4 or
DivX 5 (same under Windows actually, you have either v4 or v5
running) as well as for XviD or lavc. Although most of you
won't have heard of libavcodec or the ffmpeg-project before
you should be advised that lavc is far superior to DivX 4 or 5
and at least as good as XviD. So I will only provide examples
for lavc as you don't even need special codecs for playback:
MPlayer plays them just fine (naturally), and for Windows you simply
need DivX 5 (free edition is absolutely sufficient). So here we go.
Let's assemble the command line options one by one:
-oac copy - MEncoder needs the audio information
from the first pass in order to keep audio/video synchronization.
You mustn't use -nosound, although I suggested it in earlier
versions of this guide. If you want the technical details then have a look
at <a href="http://mplayerhq.hu/pipermail/mplayer-users/2002-August/019551.html"
target="_blank">the MPlayer mailing list .
-o /dev/null - The output of the first pass isn't needed
either, so just dump it.
-ovc lavc - chose lavc as the Output Video
Codec.
-lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vqmin=2:vqmax=31:vpass=1
-
libavcodec actually supports a handful of different video codecs.
With vcodec=mpeg4 we chose the MPEG4 compliant encoder.
vbitrate=1000 is the desired bitrate. vhq
(very high quality) tells the encoder to spend a lot of time
optimizing the results. It is worth it. vpass=1 finally
tells the encoder that this is the first pass only. Using
vqmin and vqmax tells the codec how much
it may compress the video at least and at most. Keeping these
at their defaults (see man mencoder) restricts the
achievable output bitrate a lot so I advice choosing a broader range.
Note that I'm no expert on quantizers. If I'm wrong here please
drop me a line.
-vop scale=640:480 - scale the picture down to
640 by 480 pixels. I've read on the mailing list that a new switch
has been added that automatically calculates the height from the width
or the other way round so that the aspect ratio will be kept. I haven't
tried it myself but it should look like this: -vop scale -xy 640
. Note that while it is possible to actually enlarge the picture
I strongly advise against it. There are several drawbacks: the encoder
needs a lot more bits to achieve the same quality you'd get when
encoding a smaller picture and then scaling it up while playing it back,
and you might even get distorted pictures (Peter Schuller reported
such a case to me). Always scale down.
If your picture is interlaced you can deinterlace it with
-npp lb.
We only want a preview so we provide the start position and the length:
-ss 0:20 specifies 20seconds into the movie as our beginning,
and -endpos 0:30 says that we want 30seconds to be processed.
This parameter is named badly as it's not the end position but the
duration that it specifies.
Put together the complete command line looks like this:
nice -+19 mencoder -oac copy -o /dev/null -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=1000:vhq:vpass=1 -vop scale=640:480 -npp lb
-ss 0:20 -endpos 0:30 /space/first.vob
4.3.3. Generating a preview (second pass)
For this step we can keep most of our previous command line. Of course we
change the vpass=1 to vpass=2 to tell the encoder
that it's the second pass this time. Of course we should save the final output
and replace -o /dev/null with something useful, e.g. -o
ally-preview.avi.
Here's the command line:
nice -+19 mencoder -oac copy -o ally-preview.avi -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=1000:vhq:vpass=2 -vop scale=640:480 -npp lb
-ss 0:20 -endpos 0:30 /space/first.vob
After MEncoder finishes take a look at your preview. Adjust parameters
if needed. Redo the preview until you're happy with it.
4.3.4. Generating the final AVI (both passes)
The calls for the final options simply leave out -ss and
-endpos. Unfortunately MEncoder can't handle multiple
input files on the command line. That's what the cat is for.
Just enter:
cat /space/*vob | nice -+19 mencoder -oac copy -o /dev/null -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=1000:vhq:vpass=1:vqmin=2:vqmax=31 -vop scale=640:480
-npp lb -
cat /space/*vob | nice -+19 mencoder -oac copy -o ally.avi -ovc lavc -lavcopts
vcodec=mpeg4:vbitrate=1000:vhq:vpass=2:vqmin=2:vqmax=31 -vop scale=640:480
-npp lb -
Note that -ss does not seem to work with the cat *vob |
mencoder... variant. So for the preview just specify the first
vob as the last argument on the command line (just look up).
Now go get a beer and a nice book.
Back to the table of contents
5. Subtitles
On a DVD subtitles are stored as pictures that are shown on top of the movie
by your movie player. That way the authors have a wide choice of how their
subtitles look like (and it makes subtitles in Asian languages much easier
to implement). For us this may or may not be a problem - depending on
whether we want to include subtitles directly into the picture of have
them as a separate file/stream.
5.1. Converting subtitles to text format
Very often you don't want to be forced to see the subtitles. This is not
possible if you include the subtitles in the picture during encoding. You
have to extract the subtitles from the DVD into an external file/stream
that the user can activate (or not). I will describe the process of
converting the DVD subtitles into a text format that is widely used. Text
subtitles can be easily scaled by the player (by selecting an appropriate
font) and they are really small (most often below 100KB).
For this process you must have transcode and its sources. You need
tccat and tcextract from transcode itself and the
files in transcode/contrib/subrip from the transcode
sources.
5.1.1. Compiling the tools
Unfortunately no binary package (RPM, deb) that I know of includes
subrip so we have to compile and install it ourselves. But this is
rather easy.
- Make sure you have gocr and ispell installed on
your system. They come with most modern distributions. But if yours
does not contain gocr then head over to <a
href="http://jocr.sourceforge.net/" target="_blank">its website
.
Change into subrip's source directory (cd
transcode/contrib/subrip) and invoke make.
Copy the three programs srttool, subtitle2pgm
and pgm2txt to a directory in your PATH.
You may have to change the script pgm2txt if your
gocr does not support the -p option: at the end
there are two lines containing -p ${DBPATH}. Simply remove
it (after consultin gocr's manpage).
5.1.2. Extracting the subtitle stream
Here I assume that you've copied your DVD with vobcopy -m meaning
that it has been completely mirrored including the .IFO files.
If not then you'll have to adjust the sources.
First let's see which subtitles are available. We can use mplayer
for this task:
mplayer -dvd-device /space/st-tng/disc1/ -dvd 1
-vo null -ao null -frames 0 -v 2>&1 | grep sid This causes
mplayer to just print a lot of information about the source and
not to play anything at all. It should give you a list of subtitles:
[open] subtitle ( sid ): 0 language: da
[open] subtitle ( sid ): 1 language: de
[open] subtitle ( sid ): 2 language: en
[open] subtitle ( sid ): 3 language: es
[open] subtitle ( sid ): 4 language: fr
[open] subtitle ( sid ): 5 language: it
[open] subtitle ( sid ): 6 language: nl
[open] subtitle ( sid ): 7 language: no
[open] subtitle ( sid ): 8 language: sv
[open] subtitle ( sid ): 9 language: en
Now that we have the sid (subtitle ID) for the language that we want we can
fire up the transcode tools and let them extract the raw subtitle
stream:
tccat -i /space/st-tng/dic1/ -T 1 -L | tcextract -x ps1 -t vob
-a 0x22 > subs-en The -a 0x21 is the subtitle
stream's hexadecimal number: 0x20 + sid. Here I use the English subtitles.
5.1.2. Converting the raw stream
Ok, we have a raw subtitle stream - but what can we do with it? First we have
to convert each subtitle entry into a picture. This can be easily done
with
subtitle2pgm -o english -c 255,255,0,255 < subs-en
Here's a catch however. With -c you can specify the grey levels
used in the conversion. The idea is to make the job for gocr as
easy as possible. Therefore you might have to experiment with the parameters -
but this is easy, too. I've taken the following samples from my Star Trek -
The Next Generation DVD:
-
-c 0,255,255,255 - this is obviously wrong.
-
-c 255,0,255,255 - this looks good.
-
-c 255,255,0,255 - we don't want this one.
-
-c 255,255,255,0 - we don't want this either.
As you can see you need a picture that does not contain outlined characters.
subtitle2pgm creates a lot of images - one for each subtitle -
and a control file, called english.srtx in my case, that contains
the duration for each subtitle. The next step is to let gocr recognize
the text:
pgm2txt english
Be warned - gocr will ask you often about charcters that it can't
recognize. This is normal. Once you're done you should run ispell
over all the newly created text files:
ispell -d american english*txt
Adjust the languange to your needs, of course.
The last step is to let srttool include the actual text into the
.srtx file:
srttool -s -w < english.srtx > english.srt
Voila, you have a working subtitle file. You can watch them with e.g.
mplayer -sub english.srt mymovie.avi
Back to the table of contents
6. Additional tricks
There are some more topics involved in video production.
6.1. Fixing desynched audio
This does not work with AVIs that use VBR/ABR MP3s. This step uses
avisync which is part of the transcode package.
avisync is easy to use: just provide an input file
(-i name.avi), an output file (-o newname.avi)
and the synchronization offset in frames (-n count). From
avisync's help: count>0: audio starts with frame 'count'.
count>0: prepend 'count' padding audio frames. An example:
avisync -i ally-not-synched.avi -o ally-synched.avi -n -2
6.2. Splitting AVIs
This does not work with AVIs that use VBR/ABR MP3s. This step uses
avisplit which is part of the transcode package. Use
it only with AVIs generated by transcode.
avisplit is easy to use: just provide an input file
(-i name.avi) and when it should split. You can split after
a fixed size (-s size_in_megs), after a number of frames
(-f f1-f2) or after a number of seconds (-t s1-s2).
An example:
avisplit -i ally-big-file.avi -o ally -s 700
This will produce files named ally-0000.avi, ally-0001.avi etc.
that are each 100megs big at most.
6.3. Extracting audio from VOBs/MPEGs/AVIs
MPlayer can be used easily to extract sound. The -vo null
options tells MPlayer not to show the video.
- VOB -> AC3:
mplayer -vo null -nogui -alang de -dumpaudio
-dumpfile lang-de.ac3 *vob This will extract the German audio to
a file called lang-de.ac3.
- VOB -> WAV:
mplayer -vo null -nogui -aid 128 -ao pcm
-aofile lang-de.wav *vob This will extract audio track no. 128,
downmix the AC3 sound to PCM and write the results to
lang-de.wav.
- MPG -> MP2:
mplayer -vo null -nogui -dumpaudio
-dumpfile audio.mp2 myvideo.mpg This will extract the audio to
a file called audio.mp2.
- AVI -> WAV:
mplayer -vo null -nogui -ao pcm -aofile audio.wav
myvideo.avi This will extract the audio, convert it to PCM
and write the resulting .WAV to audio.wav.
I'm not listing all possible options. Generally use -dumpaudio -dumpfile
newaudio.extension if you want to extract the audio without processing
and -ao pcm -aofile newaudio.wav if you want the WAV itself.
6.4. Using separate audio files
Sometimes you want to play another audio file along with your video.
MPlayer makes this rather easy: mplayer -audiofile
anotherlang.mp3 myvideo.avi plays video from myvideo.avi
and audio from anotherlang.mp3. A lot of Windows media players
support external audio files, too. This way you can provide several language
versions as separate audio files. A combination often used is to have the AVI
include the English audio track and to provide additional audio tracks in
separate files.
6.5. A visual AVI editor: avidemux
If you've done video editing with Windows before you probably know the
excellent OpenSource? editor <a href="http://www.virtualdub.org/"
target="_blank">VirtualDub. An OpenSource? utility for Linux that aims
at providing the user with a similar set of features is
avidemux.
You can use it in order to easily cut specific parts from a movie, to
apply filters, to reencode movies and to do a lot more. I suggest you take
a look at it even if using the command line is as natural to you as it is for
me.
Back to the table of contents
7 Links
7.1. Libraries, codecs
- libdvdread and libdvdcss:
<a href="http://www.dtek.chalmers.se/groups/dvd/downloads.shtml"
target="_blank">http://www.dtek.chalmers.se/groups/dvd/downloads.shtml
DivX 5:
http://www.divx.com/
XviD: http://www.xvid.org/
ffmpeg (the home of libavcodec):
http://ffmpeg.sourceforge.net/
7.2. Media players
Xine:
http://xine.sourceforge.net/
Ogle: <a href="http://www.dtek.chalmers.se/groups/dvd/index.shtml"
target="_blank">http://www.dtek.chalmers.se/groups/dvd/index.shtml
7.3. Media encoders
transcode: <a href="http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/"
target="_blank">http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/
dvd::rip (GUI for transcode): <a href="http://www.exit1.org/dvdrip/"
target="_blank">http://www.exit1.org/dvdrip/
some Perl scripts for transcode:
<a href="http://www9.informatik.uni-erlangen.de/~Vogelgsang/bp/tctools.html"
target="_blank">http://www9.informatik.uni-erlangen.de/~Vogelgsang/bp/tctools.html
7.4. Other documentation
Both MPlayer and transcode come with standard Unix
man pages: man mplayer, man mencoder and
man transcode show these pages. Additionally providing
-h or --help as the only parameter to one
of these programs will give you a listing of command line options (which
might not be complete).
- MPlayer's documentation: <a href="http://www.mplayerhq.hu/DOCS/"
target="_blank">http://www.mplayerhq.hu/DOCS/
transcode's documentation and examples:
<a href="http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/examples.html#top"
target="_blank">http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/examples.html#top
The best place on the 'net for DVD ripping and conversion is
doom9. Although it
focuses on Windows it still provides a lot of insight on DVDs, codecs in
general. Also the forum is quite excellent. If your really interested
in video processing then this is the place for you.
7.5. Mailing lists
I strongly suggest that you search/browse the mailing lists for information
and subscribe yourself. A lot of information is available there that has
not made it into the main documentation or the command line reference.
- MPlayer's user mailing list: <a href="http://mplayerhq.hu/mailman/listinfo/mplayer-users"
target="_blank">http://mplayerhq.hu/mailman/listinfo/mplayer-users
MPlayer's developer mailing list: <a href="http://mplayerhq.hu/mailman/listinfo/mplayer-dev-eng"
target="_blank">http://mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
transcode's user mailing list: <a href="http://www.theorie.physik.uni-goettingen.de/pipermail/transcode-users/"
target="_blank">http://www.theorie.physik.uni-goettingen.de/pipermail/transcode-users/
dvd::rip's mailing list: <a href="http://www.exit1.org/dvdrip/list.cipp"
target="_blank">http://www.exit1.org/dvdrip/list.cipp
Back to the table of contents
8. Glossary
8.1. CBR, VBR and ABR
These three acronyms stand for Constant Bit Rate, Variable
Bit Rate and Average Bit Rate.
With CBR the encoder spends the same amount of bits on each
frame, regardless of how much it would really need. This has the disadvantage
that for example complete black pictures or complete silence in an audio
frame would waste a lot of bits while pictures or audio frames with a lot
of elements would benefit from these bits.
VBR now takes as much bits as it needs. So black pictures get
very few bits and complex pictures get as much as they need. While this
provides the best quality the final size can't be predicted at all.
This is were ABR kicks in. You specify an average bit rate you
want to achieve and the encoder distributes the bits it has available. Those
bits it saves on black pictures it spends on complex pictures. It is
a compromise between quality and size predictability.
8.2. Global Motion Compensation (GMC)
Global motion compensation (GMC) helps in zooming (bringing the camera closer)
and panning (swiveling the camera), if the objects remain static in type and
only change in size and position within an image. Activation of GMC is
advisable if nature films or landscape documentation are to be compressed.
8.3. Letterboxing
Perhaps you've noticed that video is sometimes surrounded by black bars
prior to encoding. This process is called letterboxing. It can help to
maintain the correct aspect ratios for some players. Others use the black
bars for displaying subtitles. The disadvantage is that these bars enlarge
the picture and therefore require more bandwidth to encode although completely
black parts shouldn't need much space - but the transition between the picture
and the black bars does need a lot of bits that could be used elsewhere.
8.4. P/I/B-Frames, GOPs
This was taken from doom9's
Forum:
This is a quick explanation of an MPEG "GOP", or, "Group Of Pictures".
GOP:
- begins with an "I" frame, followed usually by a number of "P"
and "B" frames
- each GOP is independent: all frames needed for predictions are
contained within each GOP
- GOPs can be as small as a single I frame, or as large as
desired, but usually no more than 15 frames in length for MPEG2.
With MPEG4 GOPs can be as large as the maximal keyframe interval
(usually 200 - 300 frames). Most codecs permit GOPs of unlimited
length.
- The longer the GOP, the more efficient, but less robust the
coding
I frame:
- "Intra-coded" frames : average 7:1 reduction.
- like JPEG, every video frame is broken into blocks of 8x8
pixels of Y, R-Y, and B-Y
- blocks are grouped into "macroblocks" of 16x16
- The standards say that macroblocks are grouped horizontally into slices
which have similar average block levels although real life codecs
don't necessarily follow that rule.
- Again the standards say that multiple slices form a frame, and that
these frames are the resulting "I" frames, although codecs don't
really follow that either.
P frame:
- P frames are predicted based on prior I or P frames plus
the addition of data for changed macroblocks.
- average about 20:1 reduction, or about half the size of I
frames
B frame:
- Bidirectionally predicted frames based on appearance and
positions of past and future frames macroblocks.
- B frames require less data than P frames, averaging about
50:1 reduction.
- B frames require more decoder buffer memory because 2
frames are compared during the reconstruction process.
- B frames also require manipulation of the coding order:
frames moving from the coder to the decoder are NOT in
presentation sequence.
For every macroblock in a P frame the encoder decides whether it
already knows this block from the preceding frame or whether it's completely
new. In the former case it only encodes the differences (INTER mode). In
the latter case it encodes the whole macroblock (INTRA mode).
The situation for B frames is like this: "I don't know that block" (INTRA
mode), "I know that block from the preceding I or P frame (backward mode)",
"this block looks like the block in the following frame (forward mode)" or
"this block looks like a mixture of the blocks from the preceding and the
following frames (bidirectional mode)".
MPEG1 GOPs are always "IBBPBBPBBPBB" (this is the order in which the frames
are displayed, not necessarily the order in which they were encoded/saved).
MPEG2 GOPs look like that as well. They may as well contain three B frames.
The DivX5? MPEG4 codec only uses "IBPBPBPBPB" because it's easier to implement
and because B frame support for MPEG4 codecs is rather new. You may expect
to see more B frames in the future.
8.5. Quarter Pixel (QP)
Quarter pel or quarter pixel affects the precision in filtering of macro
blocks. DivX? 4 works with half pel (1.5, 1.5); 1.25, 1.75, etc. are possible
starting with DivX? 5. Conventional division of an image into macro blocks is
refined on the basis of integers - 16x16 or 8x8 - using the supplementary
information from what are known as virtual blocks. This allows the motions of
objects in images to be reproduced more realistically.
Back to the table of contents
9. Changelog
TODO list:
- Add chapter about subtitles and letterboxing
- Add chapter about DVD -> (S)VCD transcoding
- Add more documentation about what to clip when you have letterboxed
material
- Add information about using DivX5? despite its inferior quality because
a lot of people want to use it :)
- Add chapter about including multiple audio tracks in an AVI
August 23, 2002:
- Changed the mencoder command line from
-nosound
to -oac copy.
- Added a hint about avidemux in the 'tricks' chapter.
- Added
-m to vobcopy's command line.
- Finally changed my recommendation from
vqmin=1 to
vqmin=2 as lavc might produce buggy files with 1.
- Fixed a lot spelling mistakes (thanks to ispell :)).
June 3, 2002:
June 3, 2002:
- Changed
mencoder ... /space/*vob to cat /space/*vob |
mencoder ... - for the audio processing (thanks to E. Kevin
Hall).
- Added a note about region codes as they are a source for cryptic error
messages during the ripping process (thanks to Bradley Alexander).
- Added a note about transcode's new export module for
libavcodec,
export_ffmpeg4.
May 5, 2002:
- Fixed the glossary entry about P/I/B frames and GOPs (thanks to
Christoph Lampert)
- Added a subchapter about aspect ratios (thanks to Christoph Lampert)
- Fixed some typos (VBR -> ABR and others, thanks to various readers
who reported them)
- Fixed mencoder command lines for multiple vob files (thanks to
Christoph Terhechte and Frank Otto)
May 3, 2002:
- Fixed
vpass=1 which should be vpass=2 in
several places (thanks to Markus Liebl)
May 2, 2002:
- Added explanations for transcode's command line options
- Added warnings about scaling pictures up (thanks to Peter Schuller)
- Added
vqmin and vqmax to the recommended
options for libavcodec (thanks to Peter Schuller)
- Added some links, fixed some typos
May 1, 2002:
- Added explanations about audio and video codecs
- Fixed a lot of grammatical errors (thanks to Doug Shea)
- Added this changelog ;)
- Made two versions available - one big file or or file per chapter
- Guide available as one tar ball for download
- Provided an explanation and some sample images for interlaced video
(thanks to Jason Smith)
- Started a glossary (thanks to Robos, creator of vobcopy)
- Added some links, fixed some errors
April 30, 2002:
Back to the table of contents
10 About
This guide was written by Moritz Bunkus. I'm a 24 year old student of
computer science at the Technical University Braunschweig, Germany.
Obviously I have too much spare time to waste :-)
This is the first release of this guide. Please provide feedback - what
did you like? What did you dislike? Where should I provide more information?
Please also correct mistakes that I have made. And please tell me about
programs / tools / scripts / documentation that I've missed. I can be reached
via email: moritz@bunkus.org
Back to the table of contents
|