Compressing DVDs

Once you've created your DVD library and filled up all of the disks with content, you may decide that buying a new hard disk every few weeks isn't such a great idea. Compression may prove to be a more attractive option.

Bear in mind that nobody compresses video files to improve their quality. But, fortunately, most of the content that appears on DVDs is encoded with the MPEG2 algorithm, which uses much more space than the latest encoding algorithms. Re-encoding them with Xvid or H.264, for example, can often lead to a 3 to 1 compression ratio, thereby allowing you to triple your video server's capacity, obviating the need to buy more disks, with little observable degradation in quality.

The mencoder component of the MPlayer package works quite well for compressing DVDs into hiqh-quality AVI files, which can be played by Mythbuntu. You can use the version of MPlayer that comes with your system but it is better to use the latest version and build it yourself. Here are the steps that are necessary to build it.

There are a number of basic tools that are required to build MPlayer. You can install them (or make sure that they are already installed) with apt-get:

     sudo apt-get install build-essential subversion checkinstall yasm git-core

Next, all of the sound and video development libraries must be installed. These can be installed (or checked for installation) with apt-get:

     sudo apt-get install libaa1-dev libasound2-dev libcaca-dev \
       libcdparanoia-dev libdca-dev libdirectfb-dev libggi-target-fbdev \
       libenca-dev libesd0-dev libfontconfig1-dev libfreetype6-dev \
       libfribidi-dev libgif-dev libgl1-mesa-dev libjack-jackd2-dev \
       libmp3lame-dev libmpg123-dev libopenal1 libpulse-dev librtmp-dev \
       libsdl1.2-dev libsvga1-dev libvdpau-dev libxinerama-dev libxv-dev \
       libxvmc-dev libxxf86dga-dev libxxf86vm-dev

The MPlayer Web site has a single tar file that contains many of the useful codecs that make MPlayer work so well. You should download the latest file to your installation directory from:

     http://www.mplayerhq.hu/MPlayer/releases/codecs

If you have a 32-bit system, you should look for the codecs file that is named something like:

     all-20110131.tar.bz2

If you have a 64-bit system, you should look for the codecs file whose name is like:

     essential-amd64-20071007.tar.bz2

In this case, you won't get nearly as many codecs as are in the 32-bit tar file. So sad.

Whichever set of codecs you download, the next step is to extract them and install them where MPlayer can find them:

     cd mplayer-build
     tar xvjf all-20110131.tar.bz2
     su
     mkdir /usr/lib/codecs
     cp all-20110131/* /usr/lib/codecs

Most compression, these days, is done either with the Xvid or x264 (also known as H.264) codecs. If your system does not already have these codecs installed or the versions installed are out of date, you should build them from the latest source and install them separately, before you try to build MPlayer. You should especially make sure that you have the latest source for the x264 codec, if you'll be using it for high quality videos (e.g. those that you won't be watching on an iPod, tablet or laptop with a small screen), since earlier versions of this codec produced some pretty crappy results (in our opinion).

The latest source for building the Xvid codec can be downloaded from http://www.xvid.org/downloads.html. Once you have it, proceed to unpack the source. The last time we looked, the unpacked directory was given an unfortunate choice of names so we like to move the generic "xvidcore" directory to a directory that mirrors the version of the codec that is downloaded:

     cd mplayer-build
     tar -xvjf xvidcore-1.3.2.tar.bz2
     mv xvidcore xvidcore-1.3.2
     cd xvidcore-1.3.2

Now, configure and build the Xvid core, which contains the codec itself:

     cd build/generic
     ./configure --prefix=/usr
     make

To install the Xvid core, do so like this:

     su
     make install

Next, we want to make sure that the system will use the latest Xvid shared library, that you just built and installed. To check if there is an existing Xvid core dynamic library already installed, as well as to check for the newly installed library, do this:

     su
     cd /usr/lib
     ls -l libxvidcore.so.*

If you don't see a symlink to the xvidcore that you installed, that contains only the major version number, you should add it something like this:

     ln -s libxvidcore.so.4.3 libxvidcore.so.4

Before you can build the x264 codec, the newest goat rope in this respect is that the build requires yasm-1.2.0. Too baddie that the most current version of Ubuntu (for example) only includes yasm-1.1.0. Since the assembler probably hasn't changed for the last 20 years, its dubious that this requirement is indeed real but that's the way it is.

Oh, well. Its easiest enough to build. Obtain the source from: http://yasm.tortall.net/Download.html. Switch to the download directory, extract the source, and get ready to configure the build:

     cd yasm-build
     tar -xvzf yasm-1.2.0.tar.gz
     cd yasm-1.2.0

Now, configure and build the assembler:

     ./configure --prefix=/usr
     make

To install the assembler core, do so like this:

     su
     make install

The latest source for building the x264 codec can be downloaded from http://www.videolan.org/developers/x264.html. If you have trouble getting to the FTP directory or you prefer to use HTML, you can look in the snapshots directory, http://download.videolan.org/pub/videolan/x264/snapshots/. Once you have the source, proceed to unpack it:

     cd mplayer-build
     tar -xvjf x264-snapshot-20130906-2245-stable.tar.bz2
     cd x264-snapshot-20130906-2245-stable

Now, configure and build the x264 codec:

     ./configure --prefix=/usr --enable-shared
     make

To install the x264 codec, do so like this:

     su
     make install

Next, we want to make sure that the system will use the latest x264 shared library, that you just built and installed. To check if there is an existing x264 dynamic library already installed, as well as to check for the newly installed library, do this:

     su
     cd /usr/lib
     ls -l libx264.so*

If you don't see a symlink to the libx264 that you installed, that contains only the major version number, you should add it something like this:

     ln -s libx264.so.129 libx264.so

If you anticipate that you'll want live streaming media support in your version of MPlayer (i.e. you won't be just using mencoder to compress files and you may want to look at any of the online media sites), you should get the latest version of Live555, since it is used by MPlayer to handle live streams such as RTP/RTCP, RTSP and SIP. Live streaming protocols are constantly being tuned for performance, so it is always best to have the latest and greatest version.

You can find the latest Live555 source in the public directory on the Live555 Web site:

     http://www.live555.com/liveMedia/public/

The easiest way to get the latest source is to download the live555-latest.tar.gz file. This will be symlinked to the latest version, whatever it is. Once you have the Live555 source, unpack it. We like to move the generic "live" directory to a directory that mirrors the version of the software that is downloaded:

     cd mplayer-build
     tar xvzf live.2011.09.19.tar.gz
     mv live live-2011.09.19
     cd live-2011.09.19

Now, depending on whether you wish to build the 32-bit version, build the makefiles like this:

     ./genMakefiles linux

Or, for the 64-bit version, build the makefiles like this:

     ./genMakefiles linux-64bit

Then make the Live555 server and development files like this:

     make

The Live555 package doesn't include any install procedure. They suggest that you simply copy the entire build tree to /usr/lib. If you think this is a reasonable way to do things, have at it. We prefer to move only the files that are actually necessary (you know, like the way a real install works):

     su
     mkdir /usr/include/liveMedia
     install -m 644 BasicUsageEnvironment/include/.hh /usr/include/liveMedia
     install -m 644 groupsock/include/.hh /usr/include/liveMedia
     install -m 644 groupsock/include/.h /usr/include/liveMedia
     install -m 644 liveMedia/include/.hh /usr/include/liveMedia
     install -m 644 UsageEnvironment/include/*.hh /usr/include/liveMedia
     install -m 644 BasicUsageEnvironment/libBasicUsageEnvironment.a /usr/lib
     install -m 644 groupsock/libgroupsock.a /usr/lib
     install -m 644 liveMedia/libliveMedia.a /usr/lib
     install -m 644 UsageEnvironment/libUsageEnvironment.a /usr/lib
     install mediaServer/live555MediaServer /usr/bin

If you ever need to do a reinstall of a newer version of Live555, you can simply delete all of the files in the "liveMedia" directory and recopy the newer files:

     su
     rm -f /usr/include/liveMedia/
     install -m 644 BasicUsageEnvironment/include/.hh /usr/include/liveMedia
          .
          .
          .
     install mediaServer/live555MediaServer /usr/bin

There is no real version numbering scheme for MPlayer. Rather, you go to the MPlayer site and download the latest stable source from the source code control system. If you go to the MPlayer site (www.mplayerhq.hu) and follow the source download links, you'll eventually end up here:

     http://www.mplayerhq.hu/MPlayer/releases/

Once in this directory, you can download either the checkout or source snapshot (we prefer the source snapshot):

     mplayer-export-snapshot.tar.bz2

After you've downloaded the snapshot, you can unpack it:

     cd mplayer-build
     tar -xvjf mplayer-export-snapshot.tar.bz2

We prefer to then rename the snapshot tar file to the same name as the directory that it unpacks to, just to keep things straight. Then we change to the extracted directory:

     mv mplayer-export-snapshot.tar.bz2 mplayer-export-2013-09-07.tar.bz2
     cd mplayer-export-2013-09-07

The next step is to configure MPlayer so that we can build it. Note that during the configure step, you will also be asked to download the FFmpeg git source. You must allow this by pressing "Enter", when you are asked if you want to do so, otherwise the configure step will not complete. Here is the configure command we use:

     ./configure --prefix=/usr --confdir=/etc/mplayer \
                 --codecsdir=/usr/lib/codecs \
                 --enable-live --extra-cflags="-I /usr/include/liveMedia"

If you didn't build Live555 or keep the system's version of Live555 (or if Live555 is still broken like it used to be), you should use this configure command to disable it:

     ./configure --prefix=/usr --confdir=/etc/mplayer \
                 --codecsdir=/usr/lib/codecs --disable-live

The build is simple:

     make

Likewise, the install is simple:

     su
     make install

#>>>>>>
After
#))))))
make && \
sudo checkinstall -D --install=yes --fstrans=no --pakdir "$HOME/mplayer_build" \

     --pkgname mplayer --backup=no --deldoc=yes --deldesc=yes --delspec=yes --default \
     --pkgversion "2:1.0~svn$(LC_ALL=C svn info 2> /dev/null | \
       grep Revision | cut -d' ' -f2)" && \

make distclean

#((((((

Two pass compression:

     mencoder ISOFiles/Path/movie.iso \
       -nosub -vf pullup,softskip,harddup -nosound \
       -ovc x264 -x264encopts bitrate=2400:subq=1:frameref=1:threads=auto:pass=1 \
       -o /dev/null
     mencoder ISOFiles/Path/movie.iso \
       -nosub -vf pullup,softskip,harddup -oac copy \
       -ovc x264 -x264encopts bitrate=2400:subq=5:8x8dct:frameref=2:bframes=3: \
         b_pyramid=normal:weight_b:partitons=all:me=umh:threads=auto:pass=2 \
       -of avi -o movie.avi

#))))))

Xvid Options - VirtualDub

Filter - deinterlace

     x  interpolate using Yadif
     x  keep top field, interpolate/discard bottom field

Frame Rate

     Source Rate: No Change
     Frame Rate Conversion: Process all frames

Color Depth

     Decompression format: x  4:2:2 TCbCr (YUY2)
     Output format: x  24-bit RGB (888)

Profile (Xvid Home)

     Quantization: MPEG
     Adaptive Quantizer: off
     B-VOPs
       Max Consecutive B-VOPs: 2
       Quantizer ratio: 1.50
       Quantizer offset: 1.00
     Packed bitstream: v

Level

     720 x 576 x 25
     Max frame size (macro blocks): 1620
     Max processing rate (mbps): 40500

Video Buffer Verifier

     Max Buffer Size: 3145728
     Max Bitrate (kbps): 4854.000
     Max Bits over any 1 second interval: 8000000

Aspect Ratio

     Display aspect ratio:  x
       16:9

Encoding Type

     Twopass - 1st pass
       Filename: .\video-pass
       Discard 1st pass:  x
     Twopass - 2nd pass
       I-frame boost (%): 10
       I-frames closer than (frames): 1
         are reduced by (%): 20
       Overflow Control Strength (%): 5
       Max overflow improvement (%): 5
       Max overflow degradation (%): 5
       High bitrate scenes degrade (%): 0
       Low bitrate scenes improve (%): 0
       Target bitrate (kbps): 1200
     Quality Preset: General Purpose