This application claims the benefit of Korean Patent Application No. 2003-93158, filed Dec. 18, 2003, in the Korean Intellectual Property Office the disclosure of which is incorporated herein by reference.
1. Field of the Invention
The present invention relates to encoding moving picture data, and more particularly, to an apparatus for and a method of determining an encoding mode at a high speed by omitting variable block motion estimation and spatial prediction encoding when an encoding mode is determined by using rate-distortion optimization and a method of motion estimation.
2. Description of the Related Art
Motion estimation in video coding standards, such as H.263, MPEG-4, and H.264, is performed in units of blocks. That is, motion estimation is performed in units of macro blocks, or in units of sub-blocks that are obtained by dividing a macro block into two or four sub-blocks. Motion estimation is performed to reduce bit rate by removing temporal redundancy when moving pictures are encoded. In particular, H.264 uses variable block-based motion estimation and therefore has a high encoding efficiency. In addition, H.264 performs motion vector prediction in units of ¼ pixels such that more accurate motion estimation than MPEG-4 is enabled.
Prediction of a motion vector is performed by referring to a previous picture on a time axis, or by referring to both a previous picture and a subsequent picture. Frames that are referenced when a current frame is coded or decoded are called reference frames. Since H.264 supports multiple reference frames and selects a block of a frame most similar to a current block as a reference frame, H.264 achieves a higher encoding efficiency than methods using only a previous frame as a reference frame.
In order to select an optimum mode among all available encoding modes, a rate-distortion optimization technology is used such that the encoding efficiency of H.264 baseline profile (BP) is further improved. Examples of available encoding modes include the variable block mode used in motion estimation, three spatial prediction modes (Intra16×16, Intra4×4, IBLOCK), and a SKIP mode. Based on the rate-distortion optimization technology, encoding technology, H.264 can compress 1.5 to 2 times more data than conventional H.263 or MPEG-4 simple profile (SP), while achieving a same picture quality.
However, as described above, there are multiple encoding modes in H.264 and in order to select an optimum encoding mode among them, motion estimation should be performed in all encoding modes. Accordingly, calculation is complicated and an amount of computation is huge such that calculations which are approximately 16 times more complicated than MPEG-4 SP encoding are needed. Therefore, a method of determining an encoding mode by which this complexity is reduced and H.264 may be easily applied is needed.
The present invention provides a method of encoding mode determination by which when encoding is performed complying with the H.264 standard, variable block motion estimation and spatial prediction encoding, which require the largest amount of computation and time, are efficiently omitted and an encoding mode is fast determined through rate-distortion optimization.
According to an aspect of the present invention, there is provided a method of determining an encoding mode comprising: performing motion estimation of a macro block in an inter16×16 mode, an inter16×8 mode, and an inter8×16 mode; determining whether to further perform motion estimation in a P8×8 mode; according to the determination result, omitting or performing motion estimation in the P8×8 mode and then selecting one mode from among the modes for which motion estimation has been performed; omitting or performing spatial prediction encoding according to a rate-distortion cost value of the selected mode and determining a final encoding mode.
In the method, the performing of the motion estimation and then determining whether to further perform motion estimation in P8×8 mode comprises: performing motion estimation of a macro block in Inter16×16 mode, Inter16×8 mode, and Inter8×16 mode; in each of the modes, for each of the modes, calculating a sum of absolute difference (SAD) value that is the difference of the pixel value of a current picture and the pixel value of a previous picture, and an MVcost that is a difference value of the motion vector of a current picture and the motion vector of a previous picture; and comparing a sum of the SAD and the MVcost values (SAD+MVcost) of respective modes and according to the result of comparison, determining whether to further perform motion estimation in the P8×8 mode.
According to another aspect of the present invention, there is provided a method of motion estimation of a macro block comprising: performing motion estimation by using the entire macro block; dividing the macro block into two blocks in the horizontal direction or the vertical direction and then performing motion estimation by using each divided block; dividing the macro block into four blocks of an identical size and performing motion estimation by using each divided block; dividing each of the four divided blocks into two blocks in the horizontal direction or the vertical direction and performing motion estimation by using each further divided block; and dividing each of the four divided blocks into four and performing motion estimation by using each further divided block.
According to still another aspect of the present invention, there is provided an encoding apparatus comprising: a DCT+Q performing unit which receives picture data and performs discrete cosine transform (DCT) and quantization; a rate-distortion optimization unit which calculates a rate-distortion cost of the picture and determines an encoding block mode to be used in encoding the picture, and transfers the determined block mode to the DCT+Q performing unit; and a motion estimator and a motion compensator which by using a reference frame and the input picture, performs motion estimation and compensation and transfers the result to the DCT+Q performing unit.
Additional aspects and/or advantages of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the invention.
These and/or other aspects and advantages of the invention will become apparent and more readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings of which:
Reference will now be made in detail to the embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like reference numerals refer to the like elements throughout. The embodiments are described below to explain the present invention by referring to the figures.
For determining an encoding mode, in order to select an optimum mode among all available encoding modes, such as the variable block mode used in H.264, three types of spatial prediction modes, and SKIP mode, rate-distortion optimization is performed and a mode minimizing a rate-distortion cost (RDcost) is determined as the encoding mode. The spatial prediction mode means an intra prediction mode, SKIP mode corresponds to a case where a pixel value of a macro block of a previous frame is the same as a pixel value of a macro block of a current frame such that encoding is not needed. The RDcost is calculated, considering distortion and rates for each mode, according to equation 1.
RDcost=Distortion+λMode×Rates (1)
In the equation 1, Distortion denotes a difference of pixel values between a current picture and a restored picture and is calculated according to equation 2. Rates denotes a transmission bitrate of the encoded data.
In the equation 2, B(k,l) and B′(k,l) denote (k,l)-th pixel values of the current macro block and the restored macro block, respectively. The λMode is a Lagrangian constant and is calculated according to equation 3:
λMode=0.85×2(QP−12)/3 (3)
In the equation 3, QP denotes an integer from 0 to 51 and is an H.264 quantization value.
When an input picture is input to the DCT+Q performing unit 310, DCT and quantization are performed and then, in the variable length coder 320, context-based adaptive variable length coding is performed. At this time, the input picture is also input to the rate-distortion optimization unit 330 and (DCT+Q)−1 is performed. Then, an optimum block mode is determined and output to the DCT+Q performing unit 310.
With the DCT+Q performed picture, (DCT+Q)−1 is performed in the (DCT+Q)−1 performing unit 340, low pass filtering is performed in the loop filter 350 to smooth block boundaries, and then the picture is stored in the reference frame storing unit 360. With the thus stored reference frame and input picture, the motion estimator 370 performs motion estimation and transfers the result to the motion compensator 380. The motion compensator 380 determines whether to subtract the reference frame from the input picture, according to whether the input picture to be encoded is an inter frame or an intra frame, and transfers the reference frame to the DCT+Q performing unit 310.
In Intra4×4 mode, RDcost is calculated for all nine prediction directions. In order to calculate RDcost using the equation 1, 4×4 integer DCT+quantization, Entropy encoding, Entropy decoding and (DCT+Q)−1 should be performed. Since DCT+quantization, Entropy encoding, Entropy decoding and (DCT+Q)−1 are performed in units of 4×4 blocks, if the frequencies of the RDcost calculations in the P8×8 mode and the Inter16×16 mode in a macro block unit are compared, the RDcost calculation is performed 16 times in the Inter16×16 mode (because there are 16 4×4 blocks), while the RDcost calculation is performed 208 times in the P8×8 mode (4 times (4 4×4 blocks)×4 times (Inter8×8, Inter8×4, Inter4×8, Inter4×4)+4 times (4 8×8 blocks)×4 times (4 4×4 blocks)×9 times (9 prediction modes)=208 times. Accordingly, the frequency of the RDcost calculations needed in the P8×8 mode is 13 times more than that in the Inter16×16 mode.
That is, the P8×8 mode needs a much larger computation amount because the P8×8 mode should calculate RDcost for every encoding mode. Accordingly, if an encoding mode of a macro block is fast determined, unnecessary RDcost calculation and motion estimation are omitted such that complexity and computation amount of an encoder are reduced.
Table 1 shows the performances of Simple H.264 and H.264 when quantization parameter (QP) is 28. H.264 performs encoding by performing 7 variable block motion estimation and spatial prediction encoding, while under the same encoding conditions as in H.264, Simple H.264 performs encoding not by using 7 variable block motion estimation and spatial prediction encoding, but by using only inter motion estimation in units of 16×16 blocks. The 7 variable blocks refer a 16×16 block, a 16×8 block, an 8×16 block, an 8×8 block, an 8×4 block, a 4×8 block and a 4×4 block used for motion prediction in H.264. The encoding conditions are explained below.
Referring to Table 1, the effects of variable block motion estimation and spatial prediction encoding on the encoding efficiency and time are shown.
The encoding conditions commonly applied to H.264 and Simple H.264 are as follows. For 300 pictures stored at 30 frames/sec, a picture was compressed at a frame rate of 10 frames/sec, and only a first frame was encoded as Intra frame and all the remaining frames were encoded as Predictive frames. One reference frame was used and encoding was performed by using ±16 search area, motion estimation and compensation in units of ¼ pixel, Hadamard transform, and context-based adaptive variable length coding (CAVLC) for (4×4 integer DCT+Q) coefficient. The pictures used for the experiment is a Foreman QCIF (176×144) picture and quantization parameter values used for the experiment were 28, 32, 36, and 40, respectively.
Table 1 shows the performances in numbers of Simple H.264 and H.264 when QP was 28. Simple H.264 showed a PSNR lower than that of H.264 by 0.49 dB, and a bitrate higher by 22.9%, but an entire encoding time of Simple H.264 is only 48.3% of that of H.264. Accordingly, when variable block motion estimation and spatial prediction encoding are used, the performance of an encoder improves but the complexity increases.
Therefore, in the present invention, a method of encoding mode determination is provided where variable block motion estimation and spatial prediction encoding that need the most amount of computation in an encoder are efficiently omitted and the speed of encoding mode determination is improved through rate-distortion optimization, thus maintaining performance of the encoder while improving the speed of the decoder.
Next, each 8×8 block is divided into two 8×4 blocks and block matching is performed in operation S650. Each 8×8 block is divided into two 4×8 blocks and block matching is performed in operation S660. Each 8×8 block is divided into four 4×4 blocks and block matching is performed in operation S670.
If variable block motion estimation is performed in the order shown in
From a viewpoint of rate-distortion, if a macro block has motion vectors of various directions and where a block is divided, distortion decreases, motion estimation should be performed with blocks being further divided into much smaller blocks. However, if a block is divided into smaller blocks and the degree of increase in bitrate is greater than the degree of decrease in distortion, it is preferable to maintain a larger block mode.
In the present invention, after motion estimation is performed in the Inter16×16, the Inter16×8, and the Inter8×16 modes, motion estimation and RDcost calculation in the P8×8 mode are omitted for macro blocks in which it is determined that a larger block mode is advantageous in the rate-distortion aspect. In addition, for fast calculation, sum of absolute difference (SAD) and MVcost, instead of distortion and bitrate defined in the equation 2, are used to determine whether to perform motion estimation and RDcost calculation in the P8×8 mode. MVcost is determined by a value obtained by universal variable length coding (UVLC) a difference between a predicted motion vector before motion estimation and a motion vector obtained after motion estimation. If the difference between a predicted vector and an actual motion vector is large, MVcost becomes large, and if the predicted vector is similar to the actual motion vector, MVcost becomes small. SAD+MVcost in Inter16×16, Inter16×8, and Inter8×16 modes are calculated according to equations 4a, 4b and 4c, respectively.
Inter16×16—SAD+MVcost=SAD1+MVcost1 (4a)
Inter16×8—SAD+MVcost=SAD21+SAD22+MVcost21+MVcost22 (4b)
Inter8×16—SAD+MVcost=SAD31+SAD32+MVcost31+MVcost32 (4c)
In equations 4a, 4b and 4c, SAD, denotes a SAD value of a 16×16 block, SAD21 denotes a SAD value of a first 16×8 block in the macro block, SAD22 denotes a SAD value of a second 16×8 block, MVcost21 and MVcost22 denote MVcosts of respective 16×8 blocks, and SAD31, SAD32, MVcost31, MVcost32 denote SADs and MVcosts of 8×16 blocks. Generally, SAD1 SAD21+SAD22 and SAD1 SAD31+SAD32. This is because as blocks are further divided into smaller blocks, the difference from an actual motion vector decreases.
A value ΔSAD may be determined according to equation 5.
ΔSAD=SAD1−(SAD21+SAD22) (5)
The value ΔSAD denotes a difference value of SAD value in Inter16×16 mode and SAD value in Inter16×8 mode. Accordingly, where two 16×8 blocks in a macro block have motions vectors of different directions, the ΔSAD value increases; where the two 16×8 blocks have motions vectors of similar directions, the ΔSAD value decreases. When two 16×8 blocks have motions vectors of an identical direction, the ΔSAD value is 0.
The difference of the SAD values in the 16×16 block mode and the 8×16 block mode may be thus obtained. Inter16×16_SAD+MVcost of the Inter16×16 mode where motion estimation for a macro block is performed with a 16×16 block, Inter16×8_SAD+MVcost of the Inter16×8 mode where a 16×16 block is horizontally divided into two blocks, and Inter8×16_SAD+MVcost of the Inter8×16 mode where a 16×16 block is vertically divided into two blocks are compared. If the Inter16×16_SAD+MVcost value is the smallest among the compared values, motion vectors of divided blocks are similar where a macro block is divided horizontally, and where divided vertically. Accordingly, the entire macro block moves in a similar direction without being divided into a horizontal direction or a vertical direction, because the degree of increases in MVcost is greater than ΔSAD that is the degree of decreases in SAD.
In this case, even in the P8×8 mode, which requires more motion vectors, MVcost is greater than ΔSAD, motion estimation and RDcost calculation that require more computation may be omitted. As described above, the amount of computation in the P8×8 mode is larger than in the other modes, and if the P8×8 mode motion estimation and rate-distortion optimization processes are omitted when necessary, the amount of computation performed and complexity in an encoder may be greatly reduced. In H.264, after performing motion estimation of a variable block, the RDcost in spatial prediction mode and the RDcost in the SKIP mode are compared and a mode minimizing the RDcost is determined as the encoding mode. In this process, spatial prediction encoding is performed for all macro blocks. Meanwhile, when a picture is encoded, if spatial prediction encoding is performed, a greater number of bits than in Inter prediction encoding by motion estimation are required. However, a case where spatial prediction encoding mode is determined as an encoding mode of a macro block seldom happens, except in special cases such as a scene change.
When encoding is performed complying with conditions recommended by H.264 standardization group, a ratio of a macro block encoded in spatial prediction mode in a predictive frame of a picture is small in all of a variety of pictures. Performing spatial prediction encoding for all macro blocks despite this fact performs unnecessary calculations when the ratio of macro blocks actually encoded in spatial prediction mode is considered.
A method of efficiently omitting unnecessary spatial prediction encoding will now be explained. First, mean M of RDcosts of all Intra macro blocks encoded in spatial prediction mode in previous frames and a current frame is calculated. An Initial M value begins with RDcost mean value of an I frame that is the first frame of a picture, and is updated whenever a macro block encoded in spatial prediction mode occurs. At this time, update M is calculated according to equation 6:
In equation 6, M′ denotes the RDcost value when an Intra macro block occurs, and n denotes the number of Intra macro blocks occurring previously. By performing the calculation of the equation 6, M may be continuously updated.
After an encoding mode of an optimum Inter macro block is determined through variable block size motion estimation and rate-distortion optimization, the RDcost of the optimum Inter macro block is compared with M. If the RDcost of the optimum Inter macro block is less than M, motion estimation is efficiently performed and it is highly probable that if spatial prediction mode is performed, the RDcost in the spatial prediction mode becomes greater than the RDcost in the optimum Inter mode. Accordingly, the spatial prediction mode encoding is omitted.
The present invention may also be used for rate-distortion optimization in the P8×8 mode. In the P8×8 mode, the RDcost calculation in IBLOCK mode may be omitted by comparing the RDcost of an optimum mode among the Inter8×8, Inter8×4, Inter4×8, and Inter4×4 modes with M/4 in each 8×8 block.
Spatial prediction encoding omission algorithm of the present invention can be expressed in a pseudo code form as follows.
Motion estimation in three modes, including Inter16×16, Inter16×8, and Inter8×16 modes, is performed in units of macro blocks in operation S710. The operation S710 further includes a process of SAD+MVcost calculation after performing motion estimation. The SAD and MVcost calculation is performed as described above. According to the calculated SAD+MVcost, it is determined whether motion estimation (ME) in the P8×8 mode is needed in operation S720. That is, it is determined whether the Inter16×16_SAD+MVcost is smallest among the three values, by comparing the SAD+MVcost in each mode. If the Inter16×16_SAD+MVcost is the smallest among the three values, maintaining a larger block mode is better than dividing blocks into smaller blocks. Accordingly, the motion estimation (ME) and the RDcost calculation in the P8×8 mode that require a large amount of computation are omitted and the RDcosts in the Inter16×16, Inter16×8, Inter8×16, and SKIP modes are calculated in operation S730.
If a determination result of the operation S720 indicates that the Inter16×16_SAD+MVcost is not the smallest, motion estimation in the P8×8 mode is performed in operation S740.
As described above, motion estimation in the P8×8 mode is omitted or performed and then an optimum Inter mode is determined in operation S750. That is, the optimum Inter mode is determined among the Inter16×16, Inter16×8, Inter8×16, SKIP, and P8×8 modes. Then, it is determined whether spatial prediction encoding may be omitted in operation S760. That is, when the RDcost in the mode determined as an optimum Inter mode is compared with the M value, if the RDcost of the optimum Inter mode is less than the M value, motion estimation is efficiently performed, and accordingly, spatial prediction encoding in units of macro blocks is omitted and the Inter mode selected in the operation S750 is determined as the encoding mode in operation S780. If the RD cost of the optimum Inter mode is not less than the M value, spatial prediction encoding is further performed and the RDcost in the spatial prediction mode is calculated, and by comparing the RDcost in the spatial prediction mode with the RDcost in the optimum Inter mode, the encoding mode of a macro block is determined in operation S770.
Table 2 shows experimental conditions to explain the effect when an encoding mode is determined according to a method of the present invention.
That is, the experiment was conducted complying with experiment conditions recommended by the H.264 standardization group. In addition, by using joint model 42 (JM42) codec, the performance of a method of encoding mode determination of the present invention was experimented.
Tables 3a and 3b compare the performances of the method of encoding mode determination of the present invention and JM42:
In Tables 3a and 3b, ΔBits and ΔPSNR denote differences of bitrates and PSNRs, respectively, of H.264 and the method of mode determination of the present invention, and are calculated according to equations 7a and 7b, respectively.
A minus sign (−) of ΔBits and ΔPSNR means that performance is improved. In Tables 3a and 3b, A(%) denotes an amount of RD calculation decrease in the spatial prediction encoding process, B(%) denotes an amount of RD calculation decrease in variable block mode used in motion estimation, and Total(%) denotes an amount of RD calculation decrease in the total encoding process. The amount of RD calculation decrease can be calculated according to equation 8:
Amount of calculation decrease=(Frequency of RDcost calculations of JM42−Frequency of RDcost calculations)÷(Frequency of RDcost calculations of JM42)×100(%) (8)
Referring to Tables 3a and 3b, if the method of mode determination of the present invention is used, the amount of computation in a spatial prediction encoding process used in Intra coding decreases by at least 94% in average, and the amount of computation in variable block motion estimation used in Inter coding decreases by at least 31% to 39%. In addition, the total frequency of RD calculations, including spatial prediction mode, variable block mode and even SKIP mode, decreases by at least 75% in average. Compared with the decreases in the amount of computation, the loss in the bitrate is 0.69% in average and the loss in PSNR is 0.55 in average. However, where the degree of decrease in the amount of computation is considered, the effect to the picture quality is not so large.
The graphs of
The method of mode determination according to the present invention may be implemented as a computer program. Codes and code segments forming the program may be implemented based on the description provided herein. and stored in a computer readable media. When read and executed by a computer a method of reference frame determination and motion compensation according to the present invention may be performed. The computer readable media may include a magnetic storage media, an optical storage media and a carrier wave media.
According to the present invention as described above, by omitting variable block motion estimation and spatial prediction encoding that are the most complicated operations in an H.264 encoder, determining an encoding mode is fast performed through rate-distortion optimization such that encoding speed increases.
Where the method of encoding mode determination of the present invention is used, and rate-distortion is optimized, the frequency of RDcost calculations may be reduced by at least 75% in average, while the losses of bitrate and PSNR, which are two criteria indicating encoding efficiency, are very low. Accordingly, the method of the present invention may be used usefully to implement a high speed encoder.
Although a few embodiments of the present invention have been shown and described, it would be appreciated by those skilled in the art that changes may be made in this embodiment without departing from the principles and spirit of the invention, the scope of which is defined in the claims and their equivalents.
Number | Date | Country | Kind |
---|---|---|---|
2003-93158 | Dec 2003 | KR | national |