Summary of the invention
Coding/decoding method and the system of video in a kind of embedded system provided by the invention, the technical problem that solve are slow at decoding speed in the embedded system in the prior art, are difficult to the problem that big format video is play in the real-time online decoding.
For solving the problems of the technologies described above, the invention provides following technical scheme:
The coding/decoding method of video in a kind of embedded system comprises:
It is the residual error coefficient matrix that the residual error coefficient matrix of 8x8 of element i frame from video flowing of first row first row extracts a 4x4 with the DC coefficient;
Residual error coefficient matrix to described 4x4 carries out inverse quantization and inverse transformation, obtains the residual image of the video of i frame;
Be reference frame with the i-1 frame that is reduced into original 1/4 video, adopt the motion vector of the macro block of each position in the i frame that described i frame is carried out motion compensation, obtain the motion compensated image of the video of i frame, with motion compensated image and residual image addition, obtain being reduced into i frame and the output of original 1/4 video.
Preferably, described method also has following characteristics: described inverse transformation is undertaken by following expression:
Wherein, (μ v) is the residual error coefficient matrix of the 4x4 after the inverse quantization processing to F, and (x is y) for carrying out the matrix after inverse transformation is handled for f.
Preferably, described method also has following characteristics: adopt the motion vector of the macro block of each position in the i frame that described i frame is carried out motion compensation, comprising:
The motion vector of the macro block of each position in the described i frame is done processing divided by 2, obtain result, with the integer part of the described result size as the target motion vectors of the macro block of this position;
Adopt the target motion vectors of the macro block of each position in the described i frame to carry out motion compensation.
Preferably, described method also has following characteristics: adopt the target motion vectors of the macro block of each position in the described i frame to carry out motion compensation, comprising:
The result of motion vector is included the macro block of fractional part as macro block to be compensated, the motion vector of described macro block to be compensated is carried out vector compensation divided by the result after 2, be compensated the result, with described compensation result as revised target motion vectors;
Carry out motion compensation according to revised target motion vectors.
Preferably, described method also has following characteristics: the motion vector of described macro block to be compensated is carried out vector compensation divided by the result after 2, be compensated the result, described compensation result as revised target motion vectors, being comprised:
On the nearest frame of judging distance i frame whether the macro block that satisfies following condition is simultaneously arranged, comprising:
Condition 1: with the macro block of described macro block co-located to be compensated;
Condition 2: motion vector includes the macro block of fractional part divided by the result after 2;
Condition 3: never carry out the macro block that vector compensation is handled;
If have, the macro block that then will satisfy above-mentioned condition simultaneously is macro block by way of compensation, the motion vector of described macro block to be compensated is carried out vector superposed operation divided by the motion vector of the fractional part in the result of the motion vector of the result after 2 and described compensation macro block, obtain described compensation result, with described compensation result as revised target motion vectors.
Preferably, described method also has following characteristics: adopt the motion vector of the macro block of each position in the i frame that described i frame is carried out motion compensation, comprising:
Adopt the motion vector of the macro block of each position in the described i frame that described i frame is carried out the motion compensation of bilinear interpolation.
The decode system of video in a kind of embedded system comprises:
Draw-out device, being used for the DC coefficient is that the element of first row, first row is from the residual error coefficient matrix of the 4x4 of residual error coefficient matrix extraction of the 8x8 of video flowing i frame;
Inverse quantization device is used for the residual error coefficient matrix of described 4x4 is carried out inverse quantization;
Inverse transformation device is used for carrying out the inverse transformation processing for the residual error coefficient matrix of the 4x4 after the inverse quantization processing, obtains the residual image of the video of i frame;
Motion compensation unit, the i-1 frame that is used for to be reduced into original 1/4 video is reference frame, adopts the motion vector of the macro block of each position in the i frame that described i frame is carried out motion compensation, obtains the motion compensated image of the video of i frame;
Output device is used for motion compensated image and residual image addition, obtains being reduced into the i frame of original 1/4 video and exports.
Preferably, described system also has following characteristics: described inverse transformation device is that the residual error coefficient matrix of the 4x4 after by following expression described inverse quantization being handled carries out inverse transformation:
Wherein, (μ v) is the residual error coefficient matrix of the 4x4 after the inverse quantization processing to F, and (x is y) for carrying out the matrix after inverse transformation is handled for f.
Preferably, described system also has following characteristics: described motion compensation unit comprises:
Acquisition module is used for the motion vector of the macro block of each position of described i frame is done processing divided by 2, obtains result, with the integer part of the described result size as the target motion vectors of the macro block of this position;
Compensating module, the target motion vectors that is used for the macro block of each position of the described i frame of employing is carried out motion compensation.
Preferably, described system also has following characteristics: described compensating module comprises:
Revise submodule, be used for the result of motion vector is included the macro block of fractional part as macro block to be compensated, the motion vector of described macro block to be compensated is carried out vector compensation divided by the result after 2, is compensated the result, with described compensation result as revised target motion vectors;
The compensation submodule is used for carrying out motion compensation according to revised target motion vectors.
Preferably, described system also has following characteristics: described compensation submodule comprises:
Judging unit is used on the nearest frame of judging distance i frame whether the macro block that satisfies following condition simultaneously being arranged, and comprising:
Condition 1: with the macro block of described macro block co-located to be compensated;
Condition 2: motion vector includes the macro block of fractional part divided by the result after 2;
Condition 3: never carry out the macro block that vector compensation is handled;
Amending unit, be used in described judgment unit judges sometimes, with the macro block that satisfies above-mentioned condition simultaneously macro block by way of compensation, the motion vector of described macro block to be compensated is carried out vector superposed operation divided by the motion vector of the fractional part in the result of the motion vector of the result after 2 and described compensation macro block, obtain described compensation result, with described compensation result as revised target motion vectors.
Preferably, described system also has following characteristics:
Described motion compensation unit, the motion vector that is used for the macro block of each position of the described i frame of employing carries out the motion compensation of bilinear interpolation to described i frame.
A plurality of embodiment provided by the invention, by extracting the residual error coefficient matrix of important residual error coefficient structure 4x4, make that the amount of calculation of the follow-up inverse quantization that carries out and idct transform operation only is original 1/4, reduced the amount of calculation of video decode, improved decoding speed, it is original 1/4 that decoded two field picture size has been become, and reaches the purpose of dwindling video image, satisfied the application demand of real-time decoding video image.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, the present invention is described in further detail below in conjunction with the accompanying drawings and the specific embodiments.Need to prove that under the situation of not conflicting, the embodiment among the application and the feature among the embodiment be combination in any mutually.
Embodiment one
The schematic flow sheet of the coding/decoding method embodiment of video in the embedded system that Fig. 1 provides for the embodiment of the invention one.Method embodiment shown in Figure 1 comprises:
The motion vector of the macro block of each position in step 101, the 8x8 residual error coefficient matrix that obtains i frame in the video flowing and the described i frame.
For example, carry out the entropy decoding by the code stream to i frame in the video flowing and obtain above-mentioned information.
Step 102, be the element of first row first row extracts a 4x4 from the residual error coefficient matrix of described 8x8 residual error coefficient matrix with the DC coefficient.
Coefficient in the residual error coefficient matrix of wherein said 4x4 except the DC coefficient is 15 nearest with the DC coefficient in the residual error coefficient matrix of 8x8 AC coefficients, and these 15 AC coefficients in the residual error coefficient matrix of 4x4 with respect to the azimuth-range of DC coefficient identical with in the residual error coefficient matrix of 8x8.
The residual error coefficient matrix of the following 8x8 of being followed successively by and the residual error coefficient matrix that extracts the corresponding 4x4 that obtains behind the coefficient:
By reducing the number of element in the residual error coefficient matrix, can effectively reduce the amount of calculation of follow-up IDCT part and sport interpolation compensated part, and because image detail mainly concentrates on the position near the DC coefficient, keep the image detail that can maximum minimizing dwindles to lose in the process with nearest 15 parameters of DC coefficient, guarantee picture quality.
Step 103, the residual error coefficient matrix of described 4x4 is carried out inverse quantization;
The residual error coefficient matrix of step 104, the 4x4 after inverse quantization handled carries out inverse transformation, obtains the residual image of the video of i frame, specifically comprises:
Wherein, (μ v) is the residual error coefficient matrix of the 4x4 of inverse quantization to F, and (x y) carries out matrix after inverse transformation is handled for the residual error coefficient matrix of the 4x4 after inverse quantization is handled to f.
Be the 4x4 matrix through the matrix exported after the inverse transformation, totally 16 residual error coefficients have been realized the purpose of downscaled images.
Step 105, the motion vector of the macro block of each position in the described i frame is done processing divided by 2, obtain result, with the integer part of the described result size as the target motion vectors of the macro block of this position;
Step 106, with the i-1 frame that is reduced into original 1/4 video as the reference frame, adopt described target motion vectors that the i frame is carried out motion compensation, obtain motion compensated image;
Wherein, motion compensation mainly is to carry out interpolation according to motion vector, and interpolation method is the method for standard code, but the size of IOB becomes output 8x8 piece by original 16x16.Here use the choice criteria algorithm, can not increase the complexity of interpolation algorithm on the one hand, calculate simply on the other hand, the piece of exporting 8x8 simultaneously can reduce amount of calculation, realizes the decoding convergent-divergent.
Step 107, with motion compensated image and residual image addition, obtain being reduced into i frame and the output of original 1/4 video.
Wherein in the above-mentioned steps, step 102~104 do not have tangible execution sequence with step 105~106.
Need to prove, after extraction and idct transform through the conversion residual error coefficient, the image of I frame decoding reconstruct has been wide and high-shrinkage image half as large, when i frame during as the reference frame of i+1 frame, need carry out dwindling in proportion to the motion vector of i frame.The reference frame that reconstruct is finished need carry out interim storage, unlike the prior art be that the memory space that needs is reduced into 1/4 of canonical solution code space.
The technical scheme that the embodiment of the invention one provides, by extracting the residual error coefficient matrix of important residual error coefficient structure 4x4, the data volume that makes the follow-up inverse quantization that carries out, idct transform and operation of motion compensation calculate only is 1/4 of original data volume, reduced the data volume of decoding, improved decoding speed, it is original 1/4 to make also that simultaneously the size of decoded frame image has become, and reaches the purpose of dwindling video image, has satisfied the application demand of real-time decoding video image.
Embodiment two
Because in the step 106, the reconstruct of i frame need use the i-1 frame of having decoded the front as the reference frame, compare with the i-1 frame that coding side uses, the i-1 frame of reconstruct wide and high is half of coding side i-1 frame, so when carrying out the motion compensation of i frame, the motion vector that the decoding of each macro block need be obtained is divided by two, namely is reduced into original half, compensates with the motion vector after dwindling.The reconstruct of same i-1 frame also is processing like this.If the size of motion vector is odd number, motion vector divided by two processing in, the motion vector that has half-pixel is lost, and causes the error of motion vector precision.After handling multiframe, the motion vector accumulation of losing is more and more, and the image after feasible the dwindling has when playing beats, and influences the video playback effect.Therefore after the step 105 among the embodiment one, also comprise:
Steps A, the result of motion vector is included the macro block of fractional part as macro block to be compensated, the motion vector of described macro block to be compensated is carried out vector compensation divided by the result after 2, be compensated the result, with described compensation result as revised target motion vectors;
Accordingly, step 106 can adopt revised target motion vectors to carry out motion compensation among the embodiment one.
Wherein preferably, in the following way macro block to be compensated is carried out vector compensation, comprising:
On the nearest frame of steps A 1, judging distance i frame whether the macro block that satisfies following condition is simultaneously arranged, comprising:
Condition 1: with the macro block of described macro block co-located to be compensated;
Condition 2: motion vector includes the macro block of fractional part divided by the result after 2;
Condition 3: never carry out the macro block that vector compensation is handled;
If steps A 2 has, the macro block that then will satisfy above-mentioned condition simultaneously is macro block by way of compensation, the motion vector of described macro block to be compensated is carried out vector superposed operation divided by the motion vector of the fractional part in the result of the motion vector of the result after 2 and described compensation macro block, obtain described compensation result, with described compensation result as revised target motion vectors.
At first to how selecting compensating macro block describe:
This compensation macro block should belong to the frame before the i frame, and the position in frame is identical in the position of i frame with this macro block to be compensated; The result of the motion vector of this compensating module after divided by 2 should include fractional part in addition, and namely size is the motion vector of half-pixel; Also will not carry out vector compensation, namely this compensation macro block has abandoned the motion vector of half-pixel in movement compensation process.
Below describe with the vector compensation of the macro block to be compensated of a certain position:
Situation 1: if the motion vector of macro block to be compensated divided by after 2 result direction vector and compensation macro block motion vector divided by after 2 the direction vector of result identical, carry out vector superposed divided by the motion vector of the fractional part in the result after 2 and macro block to be compensated divided by the result after 2 motion vector of compensation macro block, then make the motion vector of macro block to be compensated increase the motion vector of half-pixel divided by the result after 2, become the result that does not have fractional part, realized simultaneously the compensation of the motion vector on the i frame, the compensation macro block lost again;
On the contrary, if the motion vector of macro block to be compensated divided by after 2 result direction vector and compensation macro block motion vector divided by after 2 the direction vector of result opposite, carry out vector superposed divided by the motion vector of the fractional part in the result after 2 and macro block to be compensated divided by the result after 2 motion vector of compensation macro block, then make the motion vector of macro block to be compensated lose the motion vector of half-pixel divided by the result after 2, become the result that does not have fractional part, realized simultaneously the compensation of the motion vector on the i frame, the compensation macro block lost again; Be that the motion vector information that the macro block of same position is lost has been cancelled out each other.
Wherein among the present invention, the motion vector of compensation macro block is called vector compensation divided by the motion vector of the fractional part in the result after 2 and macro block to be compensated divided by the process that the result after 2 superposes.
Situation 2: to the macro block in the i frame, be reduced into the situation that does not have motion vector information to lose for an original half at motion vector, then the motion vector information of losing in the i-1 frame is compensated to the co-located macro block of i frame other frames afterwards, to finish the compensation deals to the motion vector information of losing on the i-1 frame.Can be understood as when first co-located macro block has the frame of the motion vector of losing after the i frame, this frame and i-1 frame are compensated processing.
In actual applications, can handle by adopting following formula:
Mv=(sign(Mv_prev))(1)*(Mv_prev&1)+Mv_vlc
In the formula, Mv_prev is the true motion vector (being that decoded stream obtains motion vector) of macro block to be compensated, opens up such buffer specially and preserve the motion vector that each macro block decoded stream obtains in program.Mv_vlc is the true motion vector (also opening up buffer specially stores) that compensation macro block decoded stream obtains.Mv is the motion vector of the macro block to be compensated behind the vector compensation, directly covers Mv_vlc during storage, and the vector compensation that is used for the motion vector of macro block to be compensated calculates.Mv is divided by the motion vector of the result who obtains after 2 for using in the interpolation compensation, and this motion vector does not need to preserve.Sign (Mv_prev) is the symbol that obtains the former frame macroblock motion vector, Mv_prev﹠amp; The 1st, obtain the decimal place of motion vector of compensation macro block.Because the motion vector precision is half-pix herein, so in program, be 1 o'clock with lowest bit bit representation 0.5(lowest order) or the 0(lowest order be 0 o'clock) pixel motion vector.
By top formula, the fractional part motion vector that realization is lost with the previous frame macro block, the purpose of the motion vector of compensation present frame macro block.
Macro block by same position on subsequent frame carries out the compensation of the motion vector information lost in the previous frame, can reduce the amount lost of motion vector information, avoids occurring the problem that video pictures is beated.
Embodiment three
Different with embodiment one and two is that in order to reach the purpose of decoding video images, present embodiment has adopted following means:
Step B1, be the residual error coefficient matrix that the residual error coefficient matrix of 8x8 of element i frame from video flowing of first row first row extracts a 4x4 with the DC coefficient;
Step B2, the residual error coefficient matrix of described 4x4 is carried out inverse quantization and inverse transformation, obtain the thumbnail image of image in the i frame;
Step B3, to be reduced into original 1/4 i-1 frame with video be reference frame, adopts the motion vector of the macro block of each position in the described i frame that described i frame is carried out the motion compensation of bilinear interpolation, and the result of output movement compensation.
The motion vector of the macro block of each position is original motion vector when wherein carrying out the motion compensation of bilinear interpolation.
Need to prove that embodiment one to three is that example describes with Sorenson Spark standard decoding framework, but is not limited thereto, for MPEG4SP and H.263 the decoding processing framework of standard use equally, because method and flow process are similar, repeat no more herein.
Fig. 2 is the structural representation of the decode system embodiment of video in the embedded system provided by the invention.System shown in Figure 2 embodiment comprises:
Draw-out device 201, being used for the DC coefficient is that the element of first row, first row is from the residual error coefficient matrix of the 4x4 of residual error coefficient matrix extraction of the 8x8 of video flowing i frame;
Inverse quantization device 202 links to each other with described abstraction module 201, is used for the residual error coefficient matrix of described 4x4 is carried out inverse quantization;
Inverse transformation device 203 links to each other with described inverse quantization module 202, is used for carrying out the inverse transformation processing for the residual error coefficient matrix of the 4x4 after the inverse quantization processing, obtains the residual image of the video of i frame;
Motion compensation unit 204, the i-1 frame that is used for to be reduced into original 1/4 video is reference frame, adopts the motion vector of the macro block of each position in the i frame that described i frame is carried out motion compensation, obtains the motion compensated image of the video of i frame;
The output module device links to each other with described motion compensating module 204 with described inverse transform block 203, is used for motion compensated image and residual image addition, obtains being reduced into the i frame of original 1/4 video and exports.
Wherein, the residual error coefficient matrix of the 4x4 after described inverse transformation device can be handled described inverse quantization by following expression carries out inverse transformation, but the expression formula of inverse transformation is not limited in this:
Wherein, (μ v) is the residual error coefficient matrix of the 4x4 of inverse quantization to F, and (x is y) for carrying out the matrix after inverse transformation is handled for f.
Fig. 3 is the structural representation of middle motion compensation unit 204 embodiment illustrated in fig. 2.Motion compensation unit 204 shown in Figure 3 comprises:
Acquisition module 301 is used for the motion vector of the macro block of each position of described i frame is done processing divided by 2, obtains result, with the integer part of the described result size as the target motion vectors of the macro block of this position;
Compensating module 302 links to each other with described acquisition module 301, and the target motion vectors that is used for the macro block of each position of the described i frame of employing is carried out motion compensation.
Fig. 4 is the structural representation of middle compensating module 302 embodiment illustrated in fig. 3.Compensating module 302 shown in Figure 3 comprises:
Revise submodule 401, be used for the result of motion vector is included the macro block of fractional part as macro block to be compensated, the motion vector of described macro block to be compensated is carried out vector compensation divided by the result after 2, be compensated the result, with described compensation result as revised target motion vectors;
Compensation submodule 402 links to each other with described correction submodule, is used for carrying out motion compensation according to revised target motion vectors.
Fig. 5 is the middle structural representation of revising submodule 401 embodiment illustrated in fig. 4.Correction submodule 401 shown in Figure 5 comprises:
Judging unit 501 is used on the nearest frame of judging distance i frame whether the macro block that satisfies following condition simultaneously being arranged, and comprising:
Condition 1: with the macro block of described macro block co-located to be compensated;
Condition 2: motion vector includes the macro block of fractional part divided by the result after 2;
Condition 3: never carry out the macro block that vector compensation is handled;
Amending unit 502, link to each other with described selected cell, be used in described judgment unit judges sometimes, with the macro block that satisfies above-mentioned condition simultaneously macro block by way of compensation, the motion vector of described macro block to be compensated is carried out vector superposed operation divided by the motion vector of the fractional part in the result of the motion vector of the result after 2 and described compensation macro block, obtain described compensation result, with described compensation result as revised target motion vectors.
Optionally, described motion compensation unit, the motion vector that is used for the macro block of each position of the described i frame of employing carries out the motion compensation of bilinear interpolation to described i frame.
System embodiment provided by the invention, by extracting the residual error coefficient matrix of important residual error coefficient structure 4x4, make that the amount of calculation of the follow-up inverse quantization that carries out and idct transform operation only is original 1/4, reduced the amount of calculation of video decode, improved decoding speed, it is original 1/4 that decoded two field picture size has been become, and reaches the purpose of dwindling video image, satisfied the application demand of real-time decoding video image.
In addition, the present invention also can at first obtain the 16x16 residual error coefficient matrix of i frame in the video flowing, and improves decoding speed by extracting operations such as important residual error coefficient, inverse quantization and idct transform, reaches the purpose of dwindling video image.For succinctly, omit the description of specific implementation.
The all or part of step that one of ordinary skill in the art will appreciate that above-described embodiment can use the computer program flow process to realize, described computer program can be stored in the computer-readable recording medium, described computer program (as system, unit, device etc.) on corresponding hardware platform is carried out, when carrying out, comprise one of step or its combination of method embodiment.
Alternatively, all or part of step of above-described embodiment also can use integrated circuit to realize, these steps can be made into integrated circuit modules one by one respectively, perhaps a plurality of modules in them or step is made into the single integrated circuit module and realizes.Like this, the present invention is not restricted to any specific hardware and software combination.
Each device/functional module/functional unit in above-described embodiment can adopt the general calculation device to realize, they can concentrate on the single calculation element, also can be distributed on the network that a plurality of calculation elements form.
Each device/functional module/functional unit in above-described embodiment is realized with the form of software function module and during as independently production marketing or use, can be stored in the computer read/write memory medium.The above-mentioned computer read/write memory medium of mentioning can be read-only memory, disk or CD etc.
The above; only be the specific embodiment of the present invention, but protection scope of the present invention is not limited thereto, anyly is familiar with those skilled in the art in the technical scope that the present invention discloses; can expect easily changing or replacing, all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the described protection range of claim.