                    MPEGPLAY 2.0 - The Gcc Port
             
         DOS port of the famous Berkeley MPEG player using Gcc.

                      coded by Thanassis Tsiodras
     email: ttsiod@softlab.ntua.gr (for as long as I have an account)


1. Introduction.
================

    This program  is  an  MPEG-1 coded video decoder.  It is based on  the
Berkeley decoder (mpeg_play version 2.0).  However, some vital parts of it
have been optimized for the DOS platform. I will specifically mention them
so that anyone can take up on where I stopped and optimize further. 
    Included in the archive are  also  the sources for this program, ready
for compilation with the gnu C++.

2. Installation.
================

    This is a gcc program, so it inherits the capability of using any
resolution you want. However, this means that before running this program,
YOU MUST SET an environment variable. This variable will provide the 
program with the neccesary display driver information. 
    If for example you only have a simple VGA adapter, you must first
write at the DOS prompt the following line:

 set go32=nodpmi driver d:\gccmpeg\drivers\stdvga.grn gw 320 gh 200 nc 256

(if you installed the package under a different directory, just give the
location of the stdvga.grn file, in the drivers subdirectory).
This will make the program use the standard VGA resolution of 320x200. If
you see the name of your card in the drivers directory, you can display 
video in higher resolutions by setting the go32 variable like this:

 set go32=nodpmi driver d:\gccmpeg\drivers\tr8900.grn gw 640 gh 480 nc 256

where d:\gccmpeg\drivers\tr8900.grn is the location of the driver you want
( in this case, for a trident card). The numbers  640  and 480 define  the
resolution you want (try 800,600 or 1024,768 if you have enough memory  in
your card). A nice place for the previous command is the last line of your 
autoexec.bat, giving an easy selection of the desired resolution.

   If you don't want the sources, you can delete the src subdirectory.

3. Usage.
=========

    Usage is as simple as this:

    gccmpeg -dg frisco.mpg

for grayscale playback, or

    gccmpeg -dc frisco.mpg

for 8-bit colour dithering. You can also add a -nb after the filename,  so
that B frames (check the bottom of this file for what's a B frame) will be
skipped. This will produce a faster (though jerkier) playback:

    gccmpeg -dc star-tre.mpg -nb


4. Technical Info. 
==================

    First: A bit of history.
    About one and a half year ago,  I stumbled across the very first MPEG
file I found in a friend's account. I was amazed by the compression ratio
and the  superb  quality of MPEG  coded video, and I  immediately started 
hunting down anything relevant with video. I  quickly found out the specs
of  FLI/FLC and  made  players of my own.  Then, I made an AVI  (Video 1)
player of my own, based on the XAnim's code. By that time, I realized the
wealth of programming  experience  within  XWindows  sources, like  XAnim
and XV.  But anything I had made had really  big  disadvantages  compared 
with MPEG: FLI/FLC was nice, but only for computer generated,  noise free
animations (rendering, etc). AVI (Microsoft Video 1) on  the  other hand,
was easy and fast to decode, but it only had good quality at  compression
ratios of (max) 3:1 when used for real life, video  sequences.  MPEG  was
still the great mystery. 
    A graphics and image processing course came then, to illuminate me on
matters  such as the inverse DCT, the Huffman  coding, etc  (if all these
names sound like abra cadabra, try the MPEG faq and a good book on  algo-
rithms). At that point, I decided to dive into mpeg_play.tar.Z.  And when
I had almost understood everything, up came the  mpeg_lib.zip  from  none
other than Gregory Ward, making me a happy man. At last, I would  be able 
to make my own  MPEG decoder!
    And so I did. 
    However, the sources you are now seeing are somewhat  different  from
what the  original  mpeg_lib was.  First of all, mpeg_lib  was  using the
Silicon Graphics GL, while what you have here, zaps things on VGA ram.
Then, the mpeg_lib was using the GL's 24 bit functions, which, erm, don't
exist on the poor PC (at least not yet). So, I needed dithering to show a
colour 24 bit colour frame to the 256 colour VGA. Hmm. The Berkeley  code
had some dithering options, but, well, I didn't like them. The output was
ugly (you could tell it was dithering  even from a few meters away),  and
yes, it was slow, too. So, I changed the dithering algorithm, to a better
one, used by some other sources, and here goes a 10% speed increase.  The
inverse DCT is also tweaked: it uses the  best  parts of the two  options
given from the Berkeley code: the sparse coeffs, plus the straightforward
implementation in the general case. This gives the top speed in my tests,
and yes, another 10% speedup is most welcome. Finally, Gnu C++ optimizing
gave the whole thing a boost, and after some more tweaking'o'src,the best
Berkeley deriven MPEG code is now in your hands (modest, eh?).
    I have also removed  any other dithering code  except the 24 bit one,
since maybe someone will wanna have a go at it. Be warned though: I  have 
not written any code for it, so if you have any 24 bit plans,study what I
did, in say, Gray.c, and try to do it in the correct places in the code.

5. Compiling.
=============

    Type make or nmake or ndmake or whatever maker you use. The  makefile 
uses the standard way of declaring dependencies, so any make utility will
(probably) work. After compiling, gccmpeg will be created.  Use  aout2exe 
or coff2exe or whatever the utility is called in your version  of  gcc to
build gccmpeg.exe .
    Notice that I use -O to ask for optimizing the code. Probably you 'll
know a better  way to optimize this code, maybe a different  parameter in
your version of gcc. However, with my trusty  2.4.1  version of Gcc,  the
final  speed  is  very close to the one achieved by a commercial compiler 
I use in my windows version (a part of my degree project).
    If you do find  ways to improve this code, I would appreciate it very 
much if you sent them to me (even if its just a  compilation switch).  My 
email address is on top of this file.
    And if you are still wondering about B frames...

6. What's a B-Frame ?
=====================

    MPEG video is basically a series of I,P & B frames. B's are the  most 
troublesome to decode, so by skipping them, decoding is alot faster.  For 
more details check out the FAQ.

7. Disclaimer.
==============

   This program comes without any warranty.  Your  are using it at your own
risk. However, during the vast amount of time  using this software, no harm
was done  to my computer, and theoretically, there is no danger whatsoever.
You may use, copy and distribute this program without restrictions but only 
in unmodified form and without charging money for it. 
   If you use the sources  to make any kind of software, you are obliged to 
mention it in the credits list. 


Signing off,

Thanassis Tsiodras.

