DMPEG V1.0 Public Domain MPEG decoder by Stefan Eckart 0. Features =========== DMPEG/DMPLAY is another MPEG decoder/player for the PC: - decodes (nearly) the full MPEG video standard (I,P,B frames, frame size up to at least 352x240 supported) - saves decoded sequence in 8 or 24bit raw file for later display - optional on-screen display during decoding (requires VGA) - several dithering options: ordered dither, Floyd-Steinberg, grayscale - color-space selection - runs under DOS, 640KB RAM, no MS-Windows required - very compact (small code / small data models, 16 bit arithmetic) - real time display of the raw file by a separate player for VGA and many Super-VGAs 1. Introduction =============== This program is similar in concept to MPEG386 (a port of the Berkeley player by Greg Ennis, see appendix) which was posted a while ago. DMPEG, however, works also for fully fledged MPEG files and is not based on the Berkeley decoder. It is very compact and somewhat optimized for a 16 bit architecture but still much slower than the Xing Decoder. Therefore I hesitate to call it a real-time decoder, although it can decode directly to the screen (and to a file in parallel). I suggest to use this program in addition to Xing's MPEG.EXE 320x200 DOS player. The latter is appropriate for real-time display of '160x120, I-frame only' Xing files, DMPEG is more suitable for larger size 'real' MPEGs containing I, P and B type, 352x240 sized frames or for faster and better quality 'off-line' display of the 160x120 MPEGs. Try it on one of the larger MPEG files (see appendix, my recommendation: flowg.mpg) to see that MPEG can also be used (and is intended) for storing really sharp, virtually noise-free sequences. To give an impression of the attainable speeds, here are some figures measured on a 386DX/33 with 4MB RAM and a Conner 3104 100 MB hard disk. The decoding time for flowg.mpg (352x240) was about 7 sec per frame, 18 minutes for 150 frames. waterski.mpg (also 352x240, but lower quality) required only 3.5 sec per frame. A decoded 150 frame raw data file is 12 MB long and can be displayed at 5.2 frames/s. 160x120 MPEGs reach 22 frames/s while the decoding time is 1.9 s/frame. The display frame rate is limited by the transfer speed from hard disk to memory (about 550 kByte/s on my PC). If you have enough RAM, you can obtain much higher speed by playing from a large RAM-disk (e.g 23 frames/s for a 352x240 sequence). This program is Public Domain and I don't take any responsibility regarding its fitness, usefulness etc. (#include ). This software is not related to my employment at the Technical University of Munich. Comments, bug reports, questions to: Stefan Eckart Kagerstr. 4 W-8000 Muenchen 80 Germany email: stefan@lis.e-technik.tu-muenchen.de 2. Usage ======== dmpeg [options] input.mpg [output.raw] input.mpg any MPEG DIS 11172 compliant non multiplexed compression layer stream (D frame streams unsupported) output.raw the decoded and dithered 8 or 24bit raw output file; if omitted: output to screen only Options: -q quiet mode; no text output (except error messages) -v verbosity level; can be increased by repeating this option; enables display of decoded information (start codes, frame size, quantization scales etc.), can't be combined with the -s option -dx dithering options: -d0 ordered, saturation dominant 4x4 dither (default) -d1 Floyd-Steinberg error-diffusion / blue-noise-shaping (2 weights) -d2 Floyd-Steinberg error-diffusion / blue-noise-shaping (4 weights) -d3 undithered grayscale output -d4 24 bit true color output -p0 use full color range palette -p1 use restricted color range palette (default) -s display the decoded image (or its top left part if larger than 320x200) on a standard VGA while decoding Options can be combined. Example: dmpeg -d2s flowg.mpg flowg.raw decodes MPEG file flowg.mpg to raw file flowg.raw using FS4 dithering and displaying it on the screen. dmpeg -vvv flowg.mpg flowg.raw as above but using ordered dither and printing much information on startcodes, headers and parameters. 3. The decoded file player ========================== This is a rather simple program for transferring the decoded file to the screen. It currently supports 8 bit files only (no HiColor/TrueColor). Usage: dmplay [options] input.raw input.raw the raw date file to be played Options: -sx select video driver (x=0..10): -s0 standard VGA or Super-VGA in 320x200x256 mode (default) -s1 VESA -s2 ET4000 -s3 ET3000 -s4 Video 7 -s5 Paradise -s6 Trident -s7 Chips & Technologies -s8 ATI -s9 Orchid -s10 Oaktech -dn delay (0..65535, default 0) -b 8 bit transfer (default: 16 bit) All SVGA drivers use the 640x480x256 display mode and require at least 512 kB of video memory. If your graphics card is not listed, the best you can do (besides trying all drivers in the hope that one of them might work) is to obtain a VESA BIOS extension for your card and use mode -s1. A collection of such drivers had been posted to comp.binaries.ibm.pc some two months ago and is also available at ftp.rahul.net:/pub/bryanw/pc/vesadrv2.zip (anonymous ftp). All drivers except the standard VGA, ET4000 and the VESA driver in conjunction with the mentioned public domain VESA BIOS extension TSR for the ET4000 are untested. I'm very interested in email feedback which drivers work and which don't. The -d option controls playback speed. It is implemented as a simple delay loop without synchronization to a timer or vertical retrace. The -b option is probably superfluous. I don't have much experience in PC graphics programming and since I saw some example driver routines using bytewise transfer (rep movsb) instead of wordwise (rep movsw) I preferred to include this as a fudge factor. You should try it only in case of problems. Speed is reduced considerably upon activation of this switch (at least for cards with 16 bit bus interface). Display can be controlled with the following keys: any key except space, return or escape halt display at current frame and step one frame forward each time a key is pressed space step one frame backwards return continue display escape quit program 4. Technical information ======================== The player is a rather straightforward implementation of the MPEG spec [1]. The IDCT is based on the Chen-Wang 13 multiplication algorithm [2] (not quite the optimum, I know). Blocks with not more than eight non-zero coefficients use a non-separated direct multiply-accumulate 2D-IDCT (sounds great, doesn't it?), which turned out to be faster than a 'fast' algorithm in this (quite common) case. Dithering is pretty standard. Main difference to the Berkeley decoder (except for the fewer number of supported algorithms) is the use of 256 instead of 128 colors, the (default) option to use a restricted color-space and the implementation of a color saturation dominant ordered dither. This leads to a significantly superior quality of the dithered image (I claim, judge yourself). Restricted color-space means that the U and V components are clipped to +/-0.25 (instead of +/-0.5) and the display color-space points are distributed over this restricted space. Since the distance between color-space points is thus reduced by a factor of two, the color resolution is doubled at the expense of not being able to represent fully saturated colors. Saturation dominant ordered dither is a method by which a color, lying somewhere between the points of the display color space, is approximated by primarily alternating between two points of constant hue instead of constant saturation. This yields subjectivly better quality due to the lower sensitivity of the human viewing system to saturation changes than to hue changes (the same reasoning as used by the PAL TV standard to improve on NTSC). The improvement is particularly visible in dark brown or redish areas. 5. File formats =============== If you want to write your own player or to post-process the results, here is the format of the 8 bit raw file: Byte 0..7 compatibility bytes (to be ignored) 8..9 image width (MSB first) 10..11 image height (MSB first) 12..31 compatibility / unused 32..799 color table, R[0],G[0],B[0], ... R[255],G[255],B[255] 800.. image data in natural order (top left to bottom right, all frames concatenated without any gaps or repeated headers) The format of 24bit true color files (-d4 option) is: 0..7 compatibility bytes (to be ignored) 8..9 image width (MSB first) 10..11 image height (MSB first) 12..31 compatibility / unused 32.. image data (3 bytes per pixel: R,G,B, top left to bottom right, all frames concatenated without any gaps or repeated headers) These formats happen to be compatible with the raw format used by a shareware program called Image Alchemy. In fact you can use that program to view the first frame of the sequence and to convert it into other formats. 6. Future ========= Obviously this program is still in its early infancy with many improvements to be done. I assume it to be relatively bug-free in the MPEG part, at least it decodes all the MPEG scenes I could get hold of up to now (note that some of the MPEGs at toe.cs.berkeley.edu seem to contain errors, e.g. bicycle.mpg, which show up both on the Berkeley decoder and on DMPEG). Some improvements which come into mind: speed-up, better graphic support (Hi/TrueColor), better user interface, other output formats. I hope to be able to include some of these points into a new release. 7. References ============= 1. Coding of moving pictures and associated audio for digital storage media up to about 1,5 Mbit/s, Draft International Standard ISO/IEC DIS 11172, 1992. 2. Chen, Wang, IEEE ASSP-32, pp. 803-816, Aug. 1984. Appendix A: Related Software ============================ This list is probably incomplete, but it's all I'm aware of. Of course there are programs for other systems as well (Mac, Amiga etc.). mpeg_play MPEG Video Software Decoder (Version 2.0; Jan 27, 1993) Authors: Lawrence A. Rowe, Ketan Patel, and Brian Smith Computer Science Division-EECS, Univ. of Calif. at Berkeley toe.cs.berkeley.edu:/pub/multimedia/mpeg/mpeg-2.0.tar.Z mpgplay Online port of mpeg_play for DOS by: Giampero Caprino, scompx@milano.oas.olivetti.com (evaluation version, works only with Xing files) mpeg386.exe Offline port of mpeg_play for DOS by: Greg Ennis, 93gke@cs.williams.edu (based on mpgplay, works only with Xing files) mpegwin Online port of mpeg_play for MS-Windows by: Michael Simmons, msimmons@ecel.uwa.edu.au toe.cs.berkeley.edu:/pub/multimedia/mpeg/Ports/mpegw32.tar.Z (HiColor & TrueColor support, Shareware) mplay.exe, mpeg.exe DOS MPEG players from Xing Technologies (very high speed, but decodes only a small subset of the MPEG standard) ? a variety of MS-Windows MPEG players from Xing Technologies (sorry I lost the overview...) MPEGv1.1 MPEG Software Encoder Authors: Portable Video Research Group havefun.stanford.edu:/pub/mpeg/MPEGv1.1.tar.Z APPENDIX B: MPEG files ====================== Two good sources for MPEG files: toe.cs.berkeley.edu:/pub/multimedia/mpeg/movies havefun.stanford.edu:/pub/mpeg High quality MPEGs you simply can't afford to miss: tennis.mpg flowg.mpg bike.mpg -- Stefan Eckart, stefan@lis.e-technik.tu-muenchen.de, April 1993.