DMPEG V1.1 Public Domain MPEG decoder by Stefan Eckart June 1993 1. Features =========== DMPEG 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 352x288) - can save decoded sequence in 8 or 24bit raw file for fast off-line display (two pass mode) - optional on-screen display during decoding - several dithering options for 8 bit displays: ordered dither, Floyd-Steinberg, grayscale - selectable color-space - runs under DOS, 640KB RAM, no MS-Windows or '386 required - compact (small code / small data models, 16 bit arithmetic) - supports VGA, many Super-VGAs (including VESA) and some TrueColor SVGAs 2. Introduction =============== DMPEG is a Public Domain decoder for files containing MPEG video sequences. MPEG is a standardized format for compressed storage of video (and audio), similar in concept to JPEG for individual images. It, however, provides higher compression by exploiting the similarity of consecutive images of a sequence, so called interframe coding. As with JPEG, the compression factor depends on the source material and the desired quality of the coded sequence. A compression to less than 5% of the original material is not uncommon. DMPEG supports the full MPEG video standard, except D-frame sequences. Decoding is not very fast, therefore a two-pass mode was implemented: during the first pass the sequence is decoded and stored in an unencoded file which then can be played at maximum speed during the second pass. Of course DMPEG also has a one-pass mode where the sequence is displayed immediately but at lower speed. The speed is about one seventh of that of the Xing MPEG decoder (see appendix A). The Xing player, however, can only decode I frame sequences of size 160x120 and needs a '386. I suggest to use DMEG 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, 352x288 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 4 sec per frame, 9 minutes for 150 frames. waterski.mpg (336x208 and higher compression) required only 2.4 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 speed is 1.9 sec/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 ). Comments, bug reports, questions to: Stefan Eckart Kagerstr. 4 D-81669 Muenchen Germany email: stefan@lis.e-technik.tu-muenchen.de Any feedback is welcome. 3. Usage ======== dmpeg [options] input.mpg [output.raw] dmpeg [options] input.raw input.mpg any MPEG DIS 11172 compliant non multiplexed compression layer video stream (D frame streams unsupported) output.raw the decoded and dithered 8 or 24bit raw output file; if omitted: output to screen only input.raw previously decoded raw file to be displayed at maximum speed 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) -sn select graphics adapter: -s0 either standard VGA or Super-VGA in 320x200x256 mode (default) (options -d0..3) or a TrueColor VGA with VESA BIOS in 320x200x16M mode (option -d4) -s1 VESA BIOS, either 640x480x256 (-d0..3) or 640x480x16M (-d4) -s2 ET4000 \ -s3 ET3000 | -s4 Video 7 | -s5 Paradise | 640x480x256 -s6 Trident | (options -d0..3 only) -s7 Chips & Technologies | -s8 ATI | -s9 Orchid | -s10 Oaktech / -lx delay (x=0..65535, default 0), used only for offline display -b use 8 bit transfer (default: 16 bit) into (S)VGA memory Options can be combined. Example: dmpeg -d2s0 flowg.mpg flowg.raw decodes MPEG file flowg.mpg to raw file flowg.raw using FS4 dithering and displays it on the screen in 320x200x256 mode. dmpeg -vvv flowg.mpg flowg.raw as above but using ordered dither and printing much information about startcodes, headers and parameters. 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 and is also available at ftp.rahul.net:/pub/bryanw/pc/vesadrv2.zip (anonymous ftp). All drivers except the standard VGA, ET4000, the VESA driver in conjunction with the mentioned public domain VESA BIOS extension TSR for the ET4000 and the TrueColor driver with a Cirrus Logic VGA are untested. I'm very interested in email feedback which drivers work and which don't. The -l 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 if you activate this switch (at least for cards with 16 bit bus interface). Decoding can be terminated by pressing any key. Offline 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 11 multiplication algorithm [2] which was coded in assembler but does not use tables for multiplication. Blocks with not more than two non-zero coefficients use a non-separated direct multiply-accumulate 2D-IDCT, 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 somewhat superior quality of the dithered image. 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: B,G,R, top left to bottom right, all frames concatenated without any gaps or repeated headers) The 8 bit format happens 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. Changes ========== This is a list of major changes relative to version 1.0. - speed improved by a factor of two through recoding of the IDCT and interframe prediction routines in assembler and optimization of the dithering algorithms - support of TrueColor VGAs with VESA BIOS (only tested with Cirrus Logic) - DMPEG and DMPLAY merged into one program - SVGA / TrueColor support for immediate display during decoding - increased robustness against errors in the file to be decoded: program tries to resynchronize on the next slice/frame header instead of terminating - format of the 24 bit raw file changed (B,G,R instead of R,G,B) 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.). cmpeg an MPEG encoder for the PC (DOS, 640K, no '386 req.) for Targa, PBMPLUS and Alchemy RAW images Author: myself 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/mpegw* (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) MPEGv1.1/1.2alpha MPEG Software Encoder/Decoder Authors: Portable Video Research Group (PVRG) havefun.stanford.edu:/pub/mpeg/MPEGv*.tar.Z mpgcodec PVRG encoder/decoder for PC compiled with GNU gcc ('386 required) posted in alt.binaries.pictures.utilities 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, June 1993.