home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / ppc / creatempeg / mpeg2enc.doc < prev    next >
Text File  |  1994-06-26  |  25KB  |  655 lines

  1.  
  2.                                  mpeg2encode
  3.                                  ===========
  4.  
  5.                    MPEG-2 Video Encoder, Version 1.1, June 1994
  6.  
  7.                         MPEG Software Simulation Group
  8.                              (MPEG-L@netcom.com)
  9.  
  10.  
  11. Contents:
  12. =========
  13.  
  14. 1. Overview
  15. 2. Features and Limitations
  16. 3. Usage
  17. 4. Interpreting the status information
  18. 5. Description of the Encoder Model
  19. 6. References
  20.  
  21.  
  22. 1. Overview
  23. ===========
  24.  
  25.   This is the second public release of our MPEG-2 encoder. It converts an
  26.   ordered set of uncompressed input pictures into a compressed bitstream
  27.   compliant with ISO/IEC 13818-2 DIS [1] (MPEG-2).
  28.  
  29.   This program will evolve to become: ISO/IEC 13818-5 Software Simulation
  30.   of MPEG-2 Systems, Video, and Audio.
  31.  
  32.  
  33. 2. Features and Limitations
  34. ===========================
  35.  
  36.  2.1 Features
  37.  
  38.   - generates constant bit rate streams
  39.   - encoder model based on MPEG-2 test model 5 (TM5) rev. 2 [2]
  40.   - progressive and interlaced video
  41.   - also generates ISO/IEC 11172-2 (MPEG-1) sequences
  42.   - input formats: separate YUV, combined YUV, PPM
  43.   - trace and statistics output
  44.   - verifies user parameter settings are legal within Profile and Level
  45.  
  46.  
  47.  2.2 Current limitations
  48.  
  49.   The encoder currently does not support
  50.  
  51.   - scalable extensions
  52.   - MPEG-1 integer pel vectors (half-pel is typically 1 dB better anyway) 
  53.     and D frame sequences.
  54.   - checking for maximum number of generated bits per macroblock
  55.   - automatic 3:2 pulldown detection or irregular 3:2 pulldown signaling.
  56.   - intra refresh slices (e.g. low delay)
  57.   - concealment motion vectors 
  58.   - special low delay mode rate control
  59.   - editing of encoded video 
  60.   - variable bit rate encoding
  61.   - scene change rate control
  62.  
  63. 3. Usage
  64. ========
  65.  
  66.   The execution template for the encoder is:
  67.  
  68.       mpeg2encode parameter_file output.m2v
  69.  
  70.   Coding parameters can be modified by editing the parameter_file. Since the
  71.   parser expects the operating parameters to be on certain line numbers, 
  72.   kindly do not insert or delete lines from the file.
  73.  
  74.   We have provided a couple of sample parameter files in the par directory.
  75.   It is recommended to use the one closest to your application as a starting
  76.   point for customization.
  77.  
  78.   The first line of the parameter file is a comment which is inserted near
  79.   the beginning of the MPEG bitstream as a user_data field, and can be 
  80.   used for arbitrary purposes.
  81.  
  82.   The remaining lines are described below:
  83.  
  84.  /* name of source frame files */
  85.  
  86.   A printf format string defining the name of the input files. It has to
  87.   contain exactly one numerical descriptor (%d, %x etc.):
  88.  
  89.   Example: frame%02d 
  90.   Then the encoder looks for files: frame00, frame01, frame02
  91.  
  92.   The encoder adds an extension (.yuv, .ppm, etc.) which depends on the 
  93.   input file format. Input files have to be in frame format, containing 
  94.   two interleaved fields (for interlaced video).
  95.  
  96.  /* name of reconstructed frame files */
  97.  
  98.   This user parameter tells the encoder what name to give the reconstructed 
  99.   frames. These frames are identical to frame reconstructions of decoders 
  100.   following normative guidelines (except of course for differences caused by 
  101.   different IDCT implementation). Specifying a name starting with - (or just 
  102.   - by itself) disables output of reconstructed frames.
  103.  
  104.   The reconstructed frames are always stored in Y,U,V format (see below),
  105.   independent of the input file format.
  106.  
  107.  /* name of intra quant matrix file     ("-": default matrix) */ 
  108.  
  109.   Setting this to a value other than  -  specifies a file containing
  110.   a custom intra quantization matrix to be used instead of the default 
  111.   matrix specified in ISO/IEC 13818-2 and 11172-2. This file has to contain 
  112.   64 integer values (range 1...255) separated by white space (blank, tab, 
  113.   or newline), one corresponding  to each of the 64 DCT coefficients. They 
  114.   are ordered line by line, i.e. v-u frequency matrix order (not by the 
  115.   zig-zag pattern used for transmission). The file intra.mat contains the 
  116.   default matrix as a starting point for customization. It is neither 
  117.   necessary or recommended to specify the default matrix explicitly.
  118.  
  119.   Large values correspond to coarse quantization and consequently more
  120.   noise at that particular spatial frequency.
  121.  
  122.   For the intra quantization matrix, the first value in the file (DC value)
  123.   is ignored. Use the parameter intra_dc_precision (see below) to define
  124.   the quantization of the DC value.
  125.     
  126.  /* name of non intra quant matrix file ("-": default matrix) */
  127.  
  128.   This parameter field follows the same rules as described for the above 
  129.   intra quant matrix parameter, but specifies the file for the NON-INTRA 
  130.   coded (predicted / interpolated) blocks. In this case the first 
  131.   coefficient of the matrix is NOT ignored.    
  132.  
  133.   The default matrix uses a constant value of 16 for all 64 coefficients.
  134.   (a flat matrix is thought to statistically minimize mean square error). 
  135.   The file inter.mat contains an alternate matrix, used in the MPEG-2 test
  136.   model.
  137.  
  138.  /* name of statistics file */
  139.  
  140.   Statistics output is stored into the specified file. - directs statistics
  141.   output to stdout.
  142.  
  143.  /* input picture file format */ 
  144.  
  145.   A number defining the format of the source input frames.
  146.   
  147.   Code  Format description
  148.   ----  ------------------------------------------------------------------
  149.   0     separate files for luminance (.Y extension), and chrominance (.U, .V)
  150.         all files are in headerless 8 bit per pixel format. .U and .V must 
  151.         correspond to the selected chroma_format (4:2:0, 4:2:2, 4:4:4, see
  152.         below).  Note that in this document, Cb = U, and Cr = V. This format
  153.         is also used in the Stanford PVRG encoder.
  154.  
  155.   1     similar to 0, but concatenated into one file (extension .yuv).
  156.         This is the format used by the Berkeley MPEG-1 encoder.
  157.  
  158.   2     PPM, Portable PixMap, only the raw format (P6) is supported.
  159.  
  160.  
  161.  /* number of frames */
  162.  
  163.   This defines the length of the sequence in integer units of frames.
  164.  
  165.  /* number of first frame */
  166.  
  167.   Usually 0 or 1, but any other (positive) value is valid.
  168.  
  169.  /* timecode of first frame */
  170.  
  171.   This line is used to set the timecode encoded into the first 'Group of
  172.   Pictures' header. The format is based on the SMPTE style:
  173.  
  174.   hh:mm:ss:ff (hh=hour, mm=minute, ss=second, ff=frame (0..picture_rate-1)
  175.  
  176.  /* N (# of frames in GOP) */
  177.  
  178.   This defines the distance between I frames (and 'Group of Pictures'
  179.   headers). Common values are 15 for 30 Hz video and 12 for 25 Hz video.
  180.  
  181.  /* M (I/P frame distance) */
  182.  
  183.   Distance between consecutive I or P frames. Usually set to 3.
  184.   N has to be a multiple of M.   M = 1 means no B frames in the sequence.
  185.   (in a future edition of this program, M=0 will mean only I frames).
  186.  
  187.  /* ISO/IEC 11172-2 stream */
  188.  
  189.   Set to 1 if you want to generate an MPEG-1 sequence. In this case some
  190.   of the subsequent MPEG-2 specific values are ignored.
  191.  
  192.  /* picture format */
  193.  
  194.   0 selects frame picture coding, in which both fields of a frame are coded
  195.   simultaneously, 1 select field picture coding, where fields are coded
  196.   separately. The latter is permitted for interlaced video only.
  197.  
  198.  /* horizontal_size */
  199.  
  200.   Pixel width of the frames. It does not need to be a multiple of 16. 
  201.   You have to provide a correct value even for PPM files (the PPM 
  202.   file header is currently ignored).
  203.  
  204.  /* vertical_size */
  205.  
  206.   Pixel height of the frames. It does not need to be a multiple of 16. 
  207.   You have to provide a correct value even for PPM files (the PPM file 
  208.   header is currently ignored).
  209.  
  210.  /* aspect_ratio_information */
  211.  
  212.   Defines the display aspect ratio. Legal values are:
  213.  
  214.   Code    Meaning
  215.   ----    --------------
  216.   1       square pels
  217.   2       4:3 display
  218.   3       16:9 display
  219.   4       2.21:1 display
  220.  
  221.   MPEG-1 uses a different coding of aspect ratios. In this cases codes
  222.   1 to 14 are valid.
  223.  
  224.  /* frame_rate_code */
  225.  
  226.   Defines the frame rate (for interlaced sequences: field rate is twice 
  227.   the frame rate). Legal values are:
  228.  
  229.   Code  Frames/sec    Meaning
  230.   ----  ----------    -----------------------------------------------
  231.   1     24000/1001    23.976 fps -- NTSC encapsulated film rate 
  232.   2     24            Standard international cinema film rate
  233.   3     25            PAL (625/50) video frame rate
  234.   4     30000/1001    29.97 -- NTSC video frame rate 
  235.   5     30            NTSC drop-frame (525/60) video frame rate
  236.   6     50            double frame rate/progressive PAL 
  237.   7     60000/1001    double frame rate NTSC
  238.   8     60            double frame rate drop-frame NTSC
  239.  
  240.  /* bit_rate */
  241.  
  242.   A positive floating point value specifying the target bitrate.
  243.   In units of bits/sec.
  244.  
  245.  /* vbv_buffer_size (in multiples 16 kbit) */
  246.  
  247.   Specifies, according to the Video Buffering Verifier decoder model,  
  248.   the size of the bitstream input buffer required in downstream 
  249.   decoders in order for the sequence to be decoded without underflows or 
  250.   or overflows.  You probably will wish to leave this value at 112 for
  251.   MPEG-2 Main Profile at Main Level, and 20 for Constrained Parameters
  252.   Bitstreams MPEG-1.
  253.  
  254.  /* low_delay */
  255.   
  256.   When set to 1, this flag specifies whether encoder operates in low delay 
  257.   mode.  Essentially, no B pictures are coded and a different rate control 
  258.   strategy is adopted which allows picture skipping and VBV underflows.  
  259.   This feature has not yet been implemented. Please leave at zero for now.
  260.  
  261.  /* constrained_parameters_flag */
  262.  
  263.   Always 0 for MPEG-2. You may set this to 1 if you encode an MPEG-1 
  264.   sequence which meets the parameter limits defined in ISO/IEC 11172-2 
  265.   for constrained parameter bitstreams:
  266.  
  267.     horizontal_size <= 768
  268.     vertical_size   <= 576
  269.     picture_area    <= 396 macroblocks
  270.     pixel_rate      <= 396x25 macroblocks per second
  271.     vbv_buffer_size <= 20x16384 bit
  272.     bitrate         <= 1856000 bits/second
  273.     motion vector range <= -64...63.5
  274.  
  275.  /* Profile ID */
  276.  
  277.   Specifies the subset of the MPEG-2 syntax required for decoding the 
  278.   sequence. All MPEG-2 sequences generated by the current version of 
  279.   the encoder are either Main Profile or Simple Profile sequences.
  280.  
  281.   Code  Meaning                       Typical use
  282.   ----  --------------------------    ------------------------
  283.   1     High Profile                  production equipment requiring 4:2:2
  284.   2     Spatially Scalable Profile    Simulcasting 
  285.   3     SNR Scalable Profile          Simulcasting
  286.   4     Main Profile                  95 % of TVs, VCRs, cable applications
  287.   5     Simple Profile                Low cost memory, e.g. no B pictures
  288.  
  289.  /* Level ID */
  290.  
  291.   Specifies coded parameter constraints, such as bitrate, sample rate, and 
  292.   maximum allowed motion vector range.
  293.  
  294.   Code  Meaning         Typical use
  295.   ----  --------------- -----------------------------------------------
  296.   4     High Level      HDTV production rates: e.g. 1920 x 1080 x 30 Hz
  297.   6     High 1440 Level HDTV consumer rates: e.g. 1440 x 960 x 30 Hz
  298.   8     Main Level      CCIR 601 rates: e.g. 720 x 480 x 30 Hz
  299.   10    Low Level       SIF video rate: e.g. 352 x 240 x 30 Hz
  300.  
  301.  /* progressive_sequence */
  302.   
  303.   0 in the case of a sequences containing interlaced video (e.g. 
  304.   video camera source), 1 for progressive video (e.g. film source).
  305.  
  306.  /* chroma_format */
  307.  
  308.   Specifies the resolution of chrominance data
  309.   Code  Meaning
  310.   ----  ------- ----------------------------------------
  311.   1     4:2:0   half resolution in both dimensions (most common format)
  312.   2     4:2:2   half resolution in horizontal direction (High Profile only)
  313.   3     4:4:4   full resolution (not allowed in any currently defined profile)
  314.  
  315.  /* video_format: 0=comp., 1=PAL, 2=NTSC, 3=SECAM, 4=MAC, 5=unspec. */
  316.  
  317.  /* color_primaries */
  318.  
  319.   Specifies the x, y chromaticity coordinates of the source primaries.
  320.  
  321.   Code   Meaning
  322.   ----   -------
  323.   1      ITU-R Rec. 709 (1990)
  324.   2      unspecified
  325.   4      ITU-R Rec. 624-4 System M
  326.   5      ITU-R Rec. 624-4 System B, G
  327.   6      SMPTE 170M
  328.   7      SMPTE 240M (1987)
  329.  
  330.  /* transfer_characteristics */
  331.  
  332.   Specifies the opto-electronic transfer characteristic of the source picture.
  333.  
  334.   Code   Meaning
  335.   ----   -------
  336.   1      ITU-R Rec. 709 (1990)
  337.   2      unspecified
  338.   4      ITU-R Rec. 624-4 System M
  339.   5      ITU-R Rec. 624-4 System B, G
  340.   6      SMPTE 170M
  341.   7      SMPTE 240M (1987)
  342.   8      linear transfer characteristics
  343.  
  344.  /* matrix_coefficients */
  345.  
  346.   Specifies the matrix coefficients used in deriving luminance and chrominance
  347.   signals from the green, blue, and red primaries.
  348.  
  349.   Code   Meaning
  350.   ----   -------
  351.   1      ITU-R Rec. 709 (1990)
  352.   2      unspecified
  353.   4      FCC
  354.   5      ITU-R Rec. 624-4 System B, G
  355.   6      SMPTE 170M
  356.   7      SMPTE 240M (1987)
  357.  
  358.  
  359.  /* display_horizontal_size */
  360.  
  361.  /* display_vertical_size */
  362.  
  363.   Display_horizontal_size and display_vertical_size specify the "intended
  364.   display's" active region (which may be smaller or larger than the
  365.   encoded frame size).
  366.  
  367.  /* intra_dc_precision */
  368.  
  369.   Specifies the effective precision of the DC coefficient in MPEG-2 
  370.   intra coded macroblocks. 10-bits usually achieves quality saturation.
  371.  
  372.   Code    Meaning
  373.   ----    -----------------
  374.   0       8 bit
  375.   1       9 bit
  376.   2       10 bit
  377.   3       11 bit
  378.  
  379.  /* top_field_first */
  380.  
  381.   Specifies which of the two fields of an interlaced frame comes earlier.
  382.   The top field corresponds to what is often called the "odd field," and 
  383.   the bottom field is also sometimes called the "even field."   
  384.  
  385.   Code  Meaning
  386.   ----  -----------------
  387.   0     bottom field first
  388.   1     top field first
  389.  
  390.  /* frame_pred_frame_dct (I P B) */
  391.  
  392.   Setting this parameter to 1 restricts motion compensation to frame 
  393.   prediction and DCT to frame DCT. You have to specify this separately for 
  394.   I, P and B picture types.
  395.  
  396.  /* concealment_motion_vectors (I P B) */
  397.   
  398.   Setting these three flags informs encoder whether or not to generate 
  399.   concealment motion vectors for intra coded macroblocks in the 
  400.   three respective coded picture types.  This feature is mostly useful
  401.   in Intra-coded pictures, but may also be used in low-delay applications
  402.   (which attempts to exclusively use P pictures for video signal refresh, 
  403.   saving the time it takes to download a coded Intra picture across a 
  404.   channel). concealment_motion_vectors in B pictures are rather pointless 
  405.   since there is no error propagation from B pictures. This feature is 
  406.   currently not implemented.  Please leave values at zero.
  407.  
  408.  /* q_scale_type (I P B) */
  409.   
  410.   These flag sets linear (0) or non-linear (1) quantization scale type 
  411.   for the three respective picture types.
  412.  
  413.  /* intra_vlc_format (I P B) */
  414.  
  415.   Selects one of the two variable length coding tables for intra coded blocks.
  416.   Table 1 is considered to be statistically optimized for Intra coded 
  417.   pictures coded within the sweet spot range (e.g. 0.3 to 0.6 bit/pixel)
  418.   of MPEG-2.
  419.   
  420.   Code  Meaning
  421.   ----  -----------------
  422.   0     table 0 (= MPEG-1) 
  423.   1     table 1
  424.  
  425.  /* alternate_scan (I P B) */
  426.  
  427.   Selects one of two entropy scanning patterns defining the order in 
  428.   which quantized DCT coefficients are run-length coded.  The alternate 
  429.   scanning pattern is considered to be better suited for interlaced video 
  430.   where the encoder does not employ sophisticated forward quantization 
  431.   (as is the case in our current encoder).
  432.   
  433.   Code  Meaning
  434.   ----  -----------------
  435.   0     Zig-Zag scan (= MPEG-1)
  436.   1     Alternate scan 
  437.  
  438.  /* repeat_first_field */
  439.  
  440.   If set to one, the first field of a frame is repeated after the second by
  441.   the display process. The exact function depends on progressive_sequence
  442.   and top_field_first.  repeat_first_field is mainly intended to serve as 
  443.   a signal for the Decoder's Display Process to perform 3:2 pulldown.
  444.  
  445.  /* progressive_frame */
  446.  
  447.   Specifies whether the frames are interlaced (0) or progressive (1).
  448.   MPEG-2 permits mixing of interlaced and progressive video. The encoder
  449.   currently only supports either interlaced or progressive video.
  450.   progressive_frame is therefore constant for all frames and usually
  451.   set identical to progressive_sequence.
  452.  
  453.  /* intra_slice refresh picture period (P factor) */
  454.    
  455.    This value indicates the number of successive P pictures in which  
  456.    all slices (macroblock rows in our encoder model) are refreshed 
  457.    with intra coded macroblocks.  This feature assists low delay mode
  458.    coding.  It is currently not implemented.
  459.  
  460.  /* rate control: r (reaction parameter) */
  461.  /* rate control: avg_act (initial average activity) */
  462.  /* rate control: Xi (initial I frame global complexity measure) */
  463.  /* rate control: Xp (initial P frame global complexity measure) */
  464.  /* rate control: Xb (initial B frame global complexity measure) */
  465.  /* rate control: d0i (initial I frame virtual buffer fullness) */
  466.  /* rate control: d0p (initial P frame virtual buffer fullness) */
  467.  /* rate control: d0b (initial B frame virtual buffer fullness) */
  468.  
  469.   These parameters modify the behavior of the rate control scheme. Usually
  470.   set them to 0, in which case default values are computed by the encoder.
  471.  
  472.  /* P:  forw_hor_f_code forw_vert_f_code search_width/height */
  473.  /* B1: forw_hor_f_code forw_vert_f_code search_width/height */
  474.  /* B1: back_hor_f_code back_vert_f_code search_width/height */
  475.  /* B2: forw_hor_f_code forw_vert_f_code search_width/height */
  476.  /* B2: back_hor_f_code back_vert_f_code search_width/height */
  477.  
  478.   This set of parameters specifies the maximum length of the motion
  479.   vectors. If this length is set smaller than the actual movement
  480.   of objects in the picture, motion compensation becomes ineffective
  481.   and picture quality drops. If it is set too large, an excessive
  482.   number of bits is allocated for motion vector transmission, indirectly
  483.   reducing picture quality, too.
  484.  
  485.   All f_code values have to be in the range 1 to 9 (1 to 7 for MPEG-1),
  486.   which translate into maximum motion vector lengths as follows:
  487.  
  488.   code  range (inclusive)  max search width/height
  489.   ================================================
  490.   1        -8 ...    +7.5       7
  491.   2       -16 ...   +15.5      15
  492.   3       -32 ...   +31.5      31
  493.   4       -64 ...   +63.5      63
  494.   5      -128 ...  +127.5     127
  495.   6      -256 ...  +255.5     255
  496.   7      -512 ...  +511.5     511
  497.   8     -1024 ... +1023.5    1023
  498.   9     -2048 ... +2047.5    2047
  499.  
  500.   f_code is specified individually for each picture type (P,Bn), direction
  501.   (forward prediction, backward prediction) and component (horizontal,
  502.   vertical). Bn is the n'th B frame surrounded by I or P frames
  503.   (e.g.: I B1 B2 B3 P B1 B2 B3 P ...).
  504.  
  505.   For MPEG-1 sequences, horizontal and vertical f_code have to be
  506.   identical and the range is restricted to 1...7.
  507.  
  508.   P frame values have to be specified if N (N = # of frames in GOP) is
  509.   greater than 1 (otherwise the sequences contains only I frames).
  510.  
  511.   M - 1 (M = distance between I/P frames) sets (two lines each) of values
  512.   have to specified for B frames. The first line of each set defines
  513.   values for forward prediction (i.e. from a past frame), the second
  514.   line those for backward prediction (from a future frame).
  515.  
  516.   search_width and search_height set the (half) width of the window used
  517.   for motion estimation. The encoder currently employs exhaustive
  518.   integer vector block matching. Execution time for this algorithm depends
  519.   on the product of search_width and search_height and, too a large extent,
  520.   determines the speed of the encoder. Therefore these values have to be
  521.   chosen carefully.
  522.  
  523.   Here is an example of how to set these values, assuming a maximum
  524.   motion of 10 pels per frame in horizontal and 5 pels per frame in
  525.   vertical direction and M=3 (I B1 B2 P):
  526.  
  527.   search width / height:
  528.  
  529.   forward  hor.  vert.     backward  hor.  vert.
  530.   I -> B1  10     5        B1 <- P   20    10
  531.   I -> B2  20    10        B2 <- P   10     5
  532.   I -> P   30    15
  533.  
  534.   f_code values are then selected as the smallest ones resulting in a range
  535.   larger than the search widths / heights:
  536.  
  537.   3 2  30 15 /* P:  forw_hor_f_code forw_vert_f_code search_width/height */
  538.   2 1  10  5 /* B1: forw_hor_f_code forw_vert_f_code search_width/height */
  539.   3 2  20 10 /* B1: back_hor_f_code back_vert_f_code search_width/height */
  540.   3 2  20 10 /* B2: forw_hor_f_code forw_vert_f_code search_width/height */
  541.   2 1  10  5 /* B2: back_hor_f_code back_vert_f_code search_width/height */
  542.  
  543.  
  544. 4. Interpreting the status information 
  545. ======================================
  546.  
  547.  4.1 Description of the macroblock_type map
  548.  
  549.   The status information routine prints a two-character code for 
  550.   each macroblock in the picture currently being coded:
  551.  
  552.   First character:
  553.  
  554.  S: skipped
  555.  I: intra coded
  556.  0: forward prediction without motion compensation
  557.  F: forward frame/16x8 prediction (in frame/field pictures resp.)
  558.  f: forward field prediction
  559.  p: dual prime prediction
  560.  B: backward frame/16x8 prediction
  561.  b: backward field prediction
  562.  D: frame/16x8 interpolation
  563.  d: field interpolation
  564.  
  565.  Second character:
  566.  
  567.  space: coded, no quantization change
  568.  Q:     coded, quantization change
  569.  N:     not coded (only predicted)
  570.  
  571.  4.2 Description of the mquant map
  572.  
  573.   The mquant map displays the dynamically changing quantization
  574.   parameter as determined by the rate control algorithm. Larger
  575.   values correspond to coarser quantization. Not displayed values
  576.   indicate same quantization as in the previous macroblock.
  577.  
  578.   Note that for for MPEG-1 sequences the displayed values are twice
  579.   as large as the quant_scale parameter defined in ISO 11172-2.
  580.  
  581. 5. Encoder model
  582. ================
  583.  
  584.   The encoder model describes the "algorithm" or "intelligence" of the 
  585.   encoder.
  586.  
  587.  5.1 Motion estimation
  588.  
  589.   Exhaustive search pattern with L1 (Minimum Absolute Difference) matching
  590.   criteria on the original (non-coded) reference frame.  Performed only
  591.   on luminance samples.  Half pel search is done on a neighborhood of 8
  592.   bi-linearly interpolated luminance samples from the reconstructed 
  593.   reference frame.
  594.  
  595.  5.2 Rate control and adaptive quantization
  596.  
  597.   The encoder adheres to a single-pass coding philosophy (no a priori
  598.   measurements guide the allocation of bits at the global layers).
  599.   Target bit allocation for the current picture being encoded is based
  600.   on global bit budget for the Group of Pictures (dependently coded
  601.   sequence of pictures), and a ratio of weighted relative coding
  602.   complexities of the three picture types.  Coding complexity (X) is
  603.   estimated as a picture's product of: average macroblock quantization
  604.   step size (Q) and the number of bits (S) generated by coding the picture
  605.   (e.g.   X = Q*S).
  606.  
  607.   Local bit allocation is based on two measurements: 
  608.   1. deviancy from estimated buffer fullness for the Nth macroblock
  609.   2. normalized spatial activity
  610.  
  611.   The picture is approximated and estimated to have a uniform distribution 
  612.   of bits. If the local trend of generated bits begin to stray from this 
  613.   estimation, a compensation factor emerges to modulate the macroblock 
  614.   quantization scale (mquant). The compensation factor is the difference 
  615.   between where the buffer fullness was predicted at the Nth macroblock 
  616.   and where the buffer fullness truly is) 
  617.  
  618.  
  619.   Local spatial activity is estimated as the minimum variance of the 
  620.   four luminance 8x8 frame blocks and the corresponding four luminance 8x8
  621.   field blocks of the original picture being coded.  The variance measure
  622.   is then normalized against the average variance of the most recently coded
  623.   picture.  The scaled product of the local activity measure and the buffer
  624.   compensation factor are combined to modify the final mquant value which
  625.   will be used in the quantization stage of the subsequent block coding
  626.   processes.
  627.  
  628.  5.3 Decision
  629.  
  630.   The macroblock decision process selects the various prediction
  631.   switches (yes/no coding of prediction error, yes/no motion 
  632.   compensation) which provide the best quality for the relative coding 
  633.   bit cost.  The decision process follows the piecewise path of least 
  634.   distortion, approximating that the decision stages (whether to use 
  635.   forwards, backwards compensation or none at all..., etc.) are mostly 
  636.   uncorrelated (i.e. can be independently decided).
  637.  
  638.  5.4 Macroblock coding
  639.   
  640.   The forward DCT is based on the fast Chen-Wang 1984 algorithm.
  641.  
  642.   Quantization is a mirror of the normative inverse quantizer, as
  643.   specified in the MPEG-2 Test Model.  No special dithering or
  644.   entropy-constrained methods are currently employed.
  645.  
  646.  
  647. 6. References
  648. =============
  649.  
  650. [1] ISO/IEC 13818 Draft International Standard: Generic Coding of
  651.     Moving Pictures and Associated Audio, Part 2: video
  652.  
  653.  
  654. [2] Test Model 5, ISO/IEC JTC1/SC29/WG11/ N0400, MPEG93/457, April 1993.
  655.