Background technology
Along with the fast development of digital product, increasing electronic product has possessed video playback capability, as PMP, mobile phone, DPF, GPS etc.These electronic products often all have broadcast such as MPEG-2, MPEG-4, the function of format video files such as AVS.Generally, this class video file all be video is divided into a width of cloth width of cloth image again with it as a frame, realize compressing by compression dual mode in interframe compression and the frame.
At present, three kinds of different frame types being arranged, is respectively I frame, P frame and B frame.Wherein, the I frame is a key frame, and the I frame can be decoded separately, does not need the data with reference to other frames; The P frame is the single directional prediction frame, need decode with reference to I frame or the P that has decoded frame; The B frame is a bi-directional predicted frames, need decode with reference to former and later two I frames or P frame.Therefore, generally need to store three frame data at least, promptly need to store two reference frames at least, a B frame to be decoded.And, need store more reference frame toward contact if will consider playback problem.
In addition, video file more and more develops towards clear direction, resolution is more and more higher, the video of FULL HD size has the resolution of 1920*1080 size, intermediate data when this just needs very big memory space to store decoding, yet the resolution of present most playback equipments is far smaller than the resolution of video itself, and this has just caused a large amount of storage data in fact can not be revealed, and has caused data redundancy.
Along with the fierceness all the more of electronic product competition, also more and more higher to the requirement of cost, if can reduce the size of intermediate storage data, will reduce memory space, thereby reduce cost, improve product competitiveness.
Summary of the invention
The invention provides a kind of method for video coding and system that saves memory space.
In first aspect, the invention provides a kind of video encoding/decoding method, this method is:
The first step, first I frame in the decoded video file, and store this I frame;
Second step was reference with the I frame in the first step, first P frame of decoding, and store this P frame;
In the 3rd step, frame data as subsequent reference frame are not compressed, and store data after this compression, the frame data that deletion is simultaneously stored at first;
The 4th step was reference with the frame data in second step, data in the 3rd step after the compression, whole B frames before the decode successive P frame successively, and compress this B frame data respectively;
The 5th step, the whole frames of deletion in the memory block, and be reference with current not compressed P frame, next P frame of decoding, each frame data in this video file are all decoded to be finished.
Preferably, in the whole B frame data processes of the 4th step decoding, when the current B frame data of decoding, delete the packed data of last B frame, to save memory space.
Preferably, after jumping to for the 3rd step, comprise the step of compressing current P frame, and the step of the step of the current P frame of this compression and next P frame of decoding in the 5th step is carried out simultaneously.
Preferably, before the first step, comprise each reference frame in the video file is numbered, and this coding rule is represented by one-bit digital for I frame, P frame in this video file, the B frame is represented by two digits, and the I frame is since 0 order label, the P frame is since 1 order label, and first bit digital of B frame is identical with the P frame of its front, and second-order digit is since 1 serial number.
The present invention makes its image that narrows down to video playback apparatus show required size, and then stores the frame after this compression by particular reference frame is compressed, and is reference frame decoding next frame data with the frame after this compression.The present invention has reduced the needed memory space of decoded video, the bandwidth cost that has been produced when having saved reading of data simultaneously greatly.
Embodiment
For general video file (as MPEG-2, MPEG-4, AVS etc.), each reference frame coded sequence is that I frame back is the P frame, has 0 between two P frames to a plurality of B frames.As I, P, B, B, P, B, B, B, P, B...... structure, wherein, I is that I frame, P are the P frame, and B is the B frame.
Now each reference frame in the video file (comprising I frame, P frame, B frame) is numbered, each frame that is about in I, P, B, B, P, B, B, B, P, the B...... structure is numbered.Coding rule is that I frame, P frame are represented by one-bit digital, and the B frame represented by two digits, and the I frame is since 0 order label, and the P frame is since 1 order label, and first bit digital of B frame is identical with the P frame of its front, and second-order digit is since 1 serial number.Therefore, I, P, B, B, P, B, B, B, P, B...... can be expressed as I0, P1, B11, B12, P2, B21, B22, B23, P3, B31.......This shows that the referring-to relation between each frame is, the P frame is with reference to a last I frame or P frame, and the B frame is with reference to its front I frame or the P frame nearest with it, and promptly P1 is with reference to I0, and P2 is with reference to P1, and P3 is with reference to P2; B11, B12 are with reference to I0 and P1, and B21, B22, B23 are with reference to P1 and P2.
Each frame playing sequence is in the video file, all B frames that each P frame need play before the next P frame in its back are just play oneself then, so the playing sequence of I0, P1, B11, B12, P2, B21, B22, B23, P3, B31...... is I0, B11, B12, P1, B21, B22, B23, P2, B31.......
Fig. 1 is the video decode schematic diagram of one embodiment of the invention.This Fig. 1 is to be that example is set forth with decoding I0, P1, B11, B12, P2, B21, B22, B23, P3, B31.......
In step 110, according to the normal decoder mode I0 frame of decoding, and this I0 frame is stored in the buffering area, so that provide reference for subsequent frame.
In step 120, be first P frame of reference decoder with the I0 frame, the P1 frame of promptly decoding, and store this P1 frame.
In step 130, the image that is not compressed into video playback apparatus as the frame (being the I0 frame) of subsequent reference frame is shown required size, and replaces storage that the I0 frame that is about to be stored in buffering area replaces to the P1 frame.
Particularly, since the I0 frame in the P frame only as the reference frame of P1 frame (and not as P2, P3, P4 ... reference frame), therefore after the P1 frame decoding finishes, this is not compressed into the I0s frame as the I0 frame of reference frame, I0s frame sign after this compression shows that with the image of video playback apparatus required size is identical, and stores this condensed frame I0s; And store the P1 frame simultaneously, the I0 frame in the delete buffer.
In step 140, with I0s frame and P1 frame is reference frame, whole B frames before the decode successive P frame successively, promptly decode successively B11 frame, B12 frame, and B11 frame, B12 frame be compressed into B11s frame, B12s frame respectively, this B11s frame, B12s frame sign show that with the image of video playback apparatus required size is identical, delete the B11s frame simultaneously when decoding B12 frame, to save memory space.
In step 150, clear buffer, i.e. whole frames in the delete buffer, and be reference with existing not compressed frame, be reference promptly with the P1 frame, the next P frame of decoding (being the P2 frame) jumps to step 130 then, up to next I frame occurring.
Need to prove, jumping to step 130 described in the step 150 is that the P1 frame is compressed into P1s, and the P1 that will be stored in buffering area replaces to the P2 frame, that is to say, redirect described herein is not the compression I0 frame in the repeated execution of steps 130 and buffering area is replaced to the P1 frame, but will be as the frame compression of subsequent reference frame, and make respective stored and replace.Equally, next also be to be reference frame with P1s frame, P2 frame, the B21 frame of decoding successively, B22 frame, B23 frame, and, delete B21s frame, B22s frame simultaneously with its corresponding B21s frame, B22s frame, B23s frame of being compressed into.
Preferably, step 120 is carried out simultaneously with step 130, that is to say, simultaneously to compressing with reference to intact I0 frame, can further save memory space like this in the process of decoding P1 frame.
Preferably, step 150 with carry out simultaneously by the step 130 after this step 150 redirect, that is to say, in the process of decoding P2 frame, compressing with reference to intact P1 frame.
This shows, prior art needs to store three frame data (comprising two reference frames and a B frame to be decoded) at least, and the present invention only needs to store two frame data, perhaps only storing frame data adds two and is used to show sized frames data (as B11s and B12s), therefore, the present invention has saved memory space greatly.
Obviously, under the prerequisite that does not depart from true spirit of the present invention and scope, the present invention described here can have many variations.Therefore, the change that all it will be apparent to those skilled in the art that all should be included within the scope that these claims contain.The present invention's scope required for protection is only limited by described claims.