Summary of the invention
In view of this, the invention provides a kind of method and apparatus of transmitting coding result of video compression, can save system resource.
For achieving the above object, the present invention adopts following technical scheme:
A kind of method of transmitting coding result of video compression comprises:
A, the heap(ed) capacity that push-up storage FIFO is set and output threshold value; If the coding result data after the basic data piezometric of coding contracts can be finished output in the time in the absolute free of present frame coding, then output threshold value and the heap(ed) capacity of FIFO are set to: the coding result data volume after the basic data piezometric that equals to encode contracts; If the coding result data after the basic data piezometric of coding contracts fail to finish output in the absolute free of present frame coding in the time, the output threshold value that FIFO then is set is: the coding result data volume after contracting less than the basic data piezometric of encoding; The heap(ed) capacity that FIFO is set is the coding result data volume after contracting greater than the output threshold value of FIFO and less than the basic data piezometric of encoding;
B, the current frame data coding to importing are in coding result data input FIFO; In the cataloged procedure of present frame, when the data volume in FIFO reaches the output threshold value, the coding result data among the control output FIFO;
After c, current frame data coding are finished, remaining coding result data among the control output FIFO, and return step b, up to all frame of video coding result data of output.
Heap(ed) capacity and the output threshold value of FIFO preferably, are set according to the output speed of data among the generation speed of the coding result of present frame and the FIFO among the step a.
Preferably, determine that according to the image complexity of pixel data in the size of encoded video frame, the frame, the coding rate of coding unit and the target frame rate of coding described coding result produces speed.
Preferably, the output speed of determining data among the described FIFO for the response time of FIFO read signal according to message transmission rate and this transmission channel of transmission channel between the receiving equipment of FIFO and coding result data.
Preferably, the coding result data of the each output of FIFO are among the step b: with the coding result data of the output threshold value equivalent that is provided with.
Preferably, control described in the step b is output as: the receiving equipment to outside coding result data sends first control signal, notifies this receiving equipment to read coding result data among the FIFO.
Preferably, remaining coding result data are among the output of control described in the step c FIFO: the receiving equipment to outside coding result data sends second control signal, and carry remaining data amount among the FIFO, notify this receiving equipment to read remaining coding result data among the FIFO.
A kind of device of transmitting coding result of video compression comprises: buffer unit, coding unit, FIFO and transmission control unit;
Described buffer unit is used to receive the current frame data of input, and triggers coding unit and begin coding;
Described coding unit is used for after receiving the triggering signal of described buffer unit, reading video data from buffer unit, and encoding, with coding result data sequential storage in FIFO;
Described FIFO is used to store the coding result data that described coding unit sends;
Described transmission control unit, be used to be provided with heap(ed) capacity and the output threshold value of described FIFO, if the coding result data after the basic data piezometric of coding contracts can be finished output in the time in the absolute free of present frame coding, then output threshold value and the heap(ed) capacity of FIFO are set to: the coding result data volume after the basic data piezometric that equals to encode contracts; If the coding result data after the basic data piezometric of coding contracts fail to finish output in the absolute free of present frame coding in the time, the output threshold value that FIFO then is set is: the coding result data volume after contracting less than the basic data piezometric of encoding; The heap(ed) capacity that FIFO is set is the coding result data volume after contracting greater than the output threshold value of FIFO and less than the basic data piezometric of encoding; Monitor the data volume among the described FIFO, in the cataloged procedure of present frame, when the data volume in described FIFO reaches the output threshold value, control described FIFO output encoder result data; After present frame is finished coding, control described FIFO and export remaining coding result data.
Preferably, described transmission control unit is used for when the data volume that monitors described FIFO reaches the output threshold value of setting, sends first control signal to the receiving equipment of coding result data, notifies this equipment to read coding result data among the described FIFO; Also be used for after present frame is finished coding, send second control signal to the receiving equipment of coding result data, and carry the remaining data amount among the described FIFO, notify this equipment to read remaining coding result data among the described FIFO.
As seen from the above technical solution, among the present invention, utilize the memory cell of push-up storage (FIFO) as the memory encoding result, heap(ed) capacity and the output threshold value of FIFO at first are set, the as a result sequential storage of coding unit after with each macroblock coding is in FIFO then, in the cataloged procedure of present frame, when the readable code result data amount among the FIFO reaches the output threshold value, i.e. the coding result data of the output threshold value equivalent of output and setting; After the present frame end-of-encode, export remaining data among the FIFO again.Because in method and apparatus of the present invention, the memory cell of coding result is FIFO, carry out when therefore can realize the coding result read-write, before not finishing whole codings of present frame, can hop coding result data, specifically the time of read data is controlled by the output threshold value that is provided with from FIFO.Like this, in the cataloged procedure of present frame, can utilize the bus resource in the idle time slot that comprises relative free time and absolute free time well, hop coding result data, significantly reduced after present frame coding is all over, the time that is used for the transfer encoding result data is to save the system resource that takies in whole coding and the transmission course.
Further, for making system resource obtain optimum utilization, when heap(ed) capacity that FIFO is set and output threshold value, to take all factors into consideration in conjunction with the output speed of data among the generation speed of present frame coding result and the FIFO, to utilize system's idling-resource to greatest extent and not influence taking of other resources such as coding.
Embodiment
For making purpose of the present invention, technological means and advantage clearer, below in conjunction with accompanying drawing, the embodiment that develops simultaneously is described in further detail the present invention.
Basic thought of the present invention is: make full use of the idle time slot that comprises relative free time and absolute free time, with the maximize system resource utilance, save the total system resource that takies in coding and the transmission course.
Fig. 3 is the method overview flow chart of transmitting coding result of video compression provided by the invention.As shown in Figure 3, this method comprises:
Step 301 is provided with the heap(ed) capacity of coding result memory cell FIFO and exports threshold value.
Step 302 is carried out compressed encoding to the current frame data of importing, and coding result is imported among the FIFO; In the cataloged procedure of present frame, when the readable data amount among the FIFO reaches the output threshold value, the coding result data among the control output FIFO.
Step 303, after the current frame data coding is finished, remaining coding result data among the output FIFO, and return step 302, up to all frame of video coded datas of output.
So far, the method overall procedure of transmitting coding result of video compression provided by the invention finishes.The present invention also provides the device of transmitting coding result of video compression.Fig. 4 is the equipments overall structure figure of transmitting coding result of video compression among the present invention.As shown in Figure 4, this device comprises: buffer unit, coding unit, FIFO and transmission control unit.
In device shown in Figure 4, buffer unit is used to receive the present frame video data of input, and when the data volume of input reached the integral multiple of basis of coding data volume, buffer unit triggered coding unit and begins coding.
Coding unit, receive the triggering signal of buffer unit after, reading video data from buffer unit, and by macro block begin the coding, with the coding result sequential storage in FIFO.
FIFO is used for the coding result data that the memory encoding unit sends.
Transmission control unit is used to be provided with the heap(ed) capacity of FIFO and exports threshold value, the readable data amount among the monitoring FIFO, and in the cataloged procedure of present frame, when reaching the output threshold value, control FIFO output encoder result data; After present frame was finished coding, control FIFO exported remaining coding result data.
Particularly, transmission control unit can be implemented in the different phase of present frame coding by sending different control signals, coding result data among the control output FIFO.Preferred mode can for: in cataloged procedure, send first control signal, notify this receiving equipment to read quantitative coding result data to the receiving equipment of outside received code result data; After coding is finished, send second control signal, the notice receiving equipment reads remaining coding result data.
By as seen above-mentioned, in the method and apparatus of the present invention, the coding result of coding unit is stored among the FIFO, like this, in the cataloged procedure of present frame, can utilize the idle time slot that comprises relative free time and absolute free time to realize the transmission of coding result, so, when the present frame end-of-encode, need the coding result data volume of transmission to reduce greatly, save expending of non-scramble time of being used for interframe transmission, saved system resource.
Above-mentionedly being overview of the present invention, is example with transmission MPEG4 coding result below, and the specific embodiment of the present invention is described.
Embodiment:
In the present embodiment, the encryption algorithm of employing is MPEG4, and its macroblock size is 16 * 16, and the basic data amount that is to say coding is 16 row.Coding result is transferred to the receiving terminal module, carries out subsequent treatment or decoding and watches.
Fig. 5 is the method particular flow sheet of transmitting coding result of video compression in the embodiment of the invention.As shown in Figure 5, this method comprises:
Step 501 is provided with the heap(ed) capacity of coding result memory cell FIFO and exports threshold value.
In this step, be provided with FIFO heap(ed) capacity and output threshold value concrete mode can for: according to the output speed setting of data among the average generation speed of coding result and the FIFO, make not only limit the shared memory space of FIFO as far as possible little, but also prevent that the data among the FIFO from overflowing.Preferably, make the output of data among the FIFO utilize the absolute free time of current video coding to carry out as far as possible, in the present embodiment, just utilize the absolute free time of per 16 row to carry out the transmission of coding result data.Particularly, the target frame rate of the coding rate of the image complexity of pixel data, coding unit and coding is relevant in the size of the average generation speed of coding result and encoded video frame, the frame.The output speed of data is relevant for the response speed of FIFO read signal with this transmission channel with the message transmission rate of transmission channel among the FIFO.Obviously, those skilled in the art can carry out the setting of FIFO heap(ed) capacity and output threshold value according to These parameters.
Preferably, the matching relationship according to data output speed among coding result generation speed and the FIFO can followingly be provided with output threshold value and heap(ed) capacity:
If the coding result data volume after the 16 line data compressions can be at the absolute free of per 16 row end of transmission in the time, output threshold value in so can FIFO is set to the coding result data volume after the compression of 16 line data, and heap(ed) capacity is set to and exports threshold value and equate.Like this, can guarantee after coding unit is finished the coding of 16 line data, to begin to carry out the transmission of coding result, thereby guarantee in the most idle stage transmission data of bus.Usually, for undersized frame of video (as the frame of video of VGA, CIF and QCIF size), because the data volume of its coding result is less, the coding free segment of its per 16 row is much larger than the time period of encoding, that is to say, large percentage among Fig. 2 between free segment A2 and busy section A1 is easier to satisfy above-mentioned condition for the frame of video ratio of this class, is fit to adopt the setting of above-mentioned output threshold value;
But frame of video for the coding result data volume after the 16 line data compressions very big (as the coding of the large scale frame of video of D1 form etc.), the absolute free time of its per 16 row is very short, even can be 0, because the absolute free time shortens, need the result data amount transmitted bigger in addition, the frame of video of this class is difficult in absolute free times of per 16 row the data result end of transmissions behind the 16 row codings; In addition, under the very slow situation of the output speed of coding result data, also might can't be in the time with the data result end of transmissions behind the 16 row codings in the absolute free of per 16 row; For the above-mentioned frame of video that these can't finish the coding result transfer of data in the time in absolute free, can be when the output threshold value be set, coding result data volume after making this threshold value less than the compression of 16 line data, thereby can begin the transfer encoding result data earlier, to utilize transfer encoding result data as often as possible of relative free time.Like this, significantly reduced the coding result data space size, shortened the time that interframe is used for the transfer encoding result data.According to above-mentioned setting, the heap(ed) capacity of FIFO can be set promptly in conjunction with aforesaid every index again to the output threshold value.
Below by a concrete example above-mentioned output threshold value and heap(ed) capacity setting are described:
Suppose that be IN_N the input time of frame data before 16 trades, IN_N depends on the size of current video frame and frame per second etc.;
The frame data compression time is ENC_N before 16 trades, and ENC_N depends on the image complexity of pixel data in the frame and compression work clock etc.;
The absolute free time in 16 row, (being the idle time slot of the coding described in the present invention) IDLE_A_N was the poor of input time and compression time, i.e. IDLE_A_N=IN_N-EN_N;
Relative free time IDLE_R_N is the free time in the cataloged procedure in 16 row.16 row packed data output times are TRN_N=(TRN_A_N+WAIT_N*COMPRESSED_N/THD_N); Wherein, TRN_A_N was 16 row packed data output actual transmissions times, and TRN_A_N depends on the coding result data volume of 16 line data and the data channel transmission rate of output etc.; WAIT_N is each packed data output request stand-by period, and WAIT_N depends on the reaction rate of coding result data receiver etc.; COMPRESSED_N is the coding result data volume of 16 line data; The FIFO output threshold value of THD_N for being provided with; The heap(ed) capacity of FIFO is FIFO_N.
Based on the expression of above-mentioned each physical quantity, FIFO output threshold value and heap(ed) capacity can followingly be provided with:
One, when TRN_N<=IDLE_A_N, that is to say, 16 row coding result data can be in the absolute free time (being the idle time slot in the cataloged procedure) end of transmission, the heap(ed) capacity of then FIFO being exported threshold value and FIFO all is set to equate with coding result data volume behind the 16 line data coding, i.e. THD_N=FIFO_N=COMPRESSED_N.Like this,, will after per 16 line data coding be finished, promptly begin transmission, and finish transmission in the time, simultaneously, guarantee that the FIFO occupation space is as far as possible little in absolute free for the coding result data of present frame.
Two, as TRN_N=(IDLE_A_N+IDLE_R_N*X), and 0<X<1 o'clock, that is to say that 16 row coding result data can not be at absolute free end of transmission in the time, but can be in the total time of the absolute free time in 16 row and relative free time end of transmission.At this moment, FIFO exports threshold value and is set to coding result data volume less than 16 line data, be specifically as follows THD_N<=COMPRESSED_N* (1-X), and the heap(ed) capacity of FIFO is set to greater than COMPRESSED_N* (1-X) and less than the coding result data volume of 16 line data, to guarantee that FIFO does not overflow on the one hand, save the FIFO occupation space on the other hand as far as possible; Can dynamically adjust simultaneously output threshold value and the heap(ed) capacity of FIFO according to WAIT_N, make TRN_N get minimum value.Because the coded data of 16 row can't be finished transmission in the time in the absolute free of 16 line data, therefore, the output threshold value of FIFO is set to the coding result data volume less than 16 line data, when encoding with the partial data in finishing 16 line data, promptly begin the transfer encoding result data, thereby utilize the relative free time transfer encoding result data in the cataloged procedure as much as possible, simultaneously the heap(ed) capacity of FIFO is done suitably to adjust with assurance not overflow, and save occupation space as far as possible.
Three, as TRN_N〉(IDLE_A_N+IDLE_R_N) time, that is to say, 16 row coding result data can't be in the total time of the absolute free time in 16 row and relative free time end of transmission, in this case, soon FIFO output threshold value is set to the coding result data volume less than 16 line data, specifically can be according to the value of WAIT_N, suitably be provided with one greater than 0 and smaller or equal to 1 Y, FIFO exports threshold value and is set to THD_N=COMPRESSED_N*Y, so that TRN_N gets minimum value, the heap(ed) capacity of FIFO is set to greater than the output threshold value and less than COMPRESSED_N, to save the shared space of FIFO.Similar with second kind of situation, will be when not finishing the coding of 16 line data in this situation yet, begun to utilize the relative free time transfer encoding result data in the cataloged procedure, be with the difference of second kind of situation, the time of beginning transfer encoding result data is morning more, to utilize the idling-resource of system as much as possible; Simultaneously, the heap(ed) capacity of FIFO is set suitably, guarantees not overflow and take up room less as far as possible.
In the setting up procedure of above-mentioned output threshold value and heap(ed) capacity, why select 16 behavioral standards to be because in numerous Coding Compression Algorithm, the macroblock size of encoding is 16 row * 16 row.Prove through experimental result, after the heap(ed) capacity and output threshold value of FIFO is set according to aforesaid way, when the present frame end-of-encode, remaining coding result data volume minimum among the FIFO, therefore it is also the shortest that interframe is used for time of transfer encoding result, farthest saved system resource.
Realize the coding of sequence of frames of video and the transmission of coding result by following step.
Step 502 is made as present frame with first frame in the sequence of frames of video.
Step 503 is encoded to current frame data, and controls the coding result data of exporting among the FIFO according to being provided with in the step 501.
In this step, when current frame data is encoded, with the macro block is that unit carries out, macroblock size in the present embodiment is 16 * 16 as previously mentioned, the specific coding process comprises: the first group coding data (i.e. 16 line data) of input present frame, coding unit is encoded by macro block to these group coding data, and stores into each macroblock encoding result data among the FIFO successively; Then, coding unit waits the input of next group coding data and finishes, and begins next group coding data is encoded and stored, up to all data of the present frame of having encoded.
In the process that above-mentioned current frame data is encoded, the data among the FIFO are constantly accumulated.After the data volume among the FIFO reaches the output threshold value that is provided with in the step 501, the coding result data data among the control output FIFO.
Particularly, the mode of control output can for: after the data volume among the FIFO reaches the output threshold value, send first control signal, notify this equipment to read coding result data among the FIFO to the receiving equipment of coding result data; This equipment responds this notice after receiving this first control signal, reads the coding result data from FIFO.Because the process of its response is changeable, therefore, as previously mentioned, this response time has also just been exported one of reference factor of threshold value and heap(ed) capacity as FIFO is set in the step 501.
When the output encoder result data, the data volume of output can be provided with voluntarily, and preferred output data quantity is, with the output threshold value equivalent that is provided with.As previously mentioned, preferably, the output threshold value can be set to the coding result data volume of 16 line data, like this, can wait in the process that group coding data input finishes at coding unit, and also be that free segment shown in Figure 2 is carried out the transmission of coding result data.During this period of time, system bus is the notst busy, can reach the highest coding result data transmission efficiency.
Step 504 is after finishing the coding of present frame, with remaining coding result data output among the FIFO.
Because after finishing the coding of present frame, the remaining data amount among possible the FIFO is lower than in the step 501 the output threshold value of setting, therefore, after the present frame end-of-encode, disposable remaining coding result data among the FIFO are all exported.Particularly, can send second control signal, and the remaining data amount among the FIFO is carried at wherein, notify this equipment to read this remaining data to the receiving equipment of coding result data; The receiving equipment of coding result data receives this second control signal, and according to the remaining data amount of wherein carrying, reads all residue coding result data from FIFO.
So far, the coding and the transmission of current frame data have promptly been finished.Fig. 6 is for always expending schematic diagram according to aforesaid way MPEG4 one frame compressed encoding and transmission time.By with Fig. 2 more as can be seen, the time is always expended greatly and reduces.
Step 505 judges whether present frame is the last frame of sequence of frames of video, if, process ends then, otherwise, execution in step 506.
Step 506 is made as present frame with the next frame in the sequence of frames of video, returns step 503.
So far, finished the coding and the transmission of all sequence of frames of video, method flow of the present invention finishes.Here be noted that after execution of step 504, direct execution in step 505 and 506, the transmission of beginning next frame data like this, can improve the frame per second behind the coding; Also can before step 505, in the free time before next frame is encoded, utilize idle system resource to carry out other operation.In a word, use method of the present invention after, reduced always expending of a frame compressed encoding and transmission time, saved system resource.
The above-mentioned method embodiment that is transmission compressed encoding result in the present embodiment.Present embodiment also provides transmission compressed encoding result's system, can be used to implement said method.Fig. 7 is the concrete structure figure of system of transmission MPEG4 coding result in the present embodiment.As shown in Figure 7, this system comprises MPEG4 encoder and receiving terminal module.Wherein, the MPEG4 encoder is a kind of embodiment of transmission of video coding result device shown in Figure 4.This MPEG4 encoder comprises: buffer unit, coding unit, FIFO and transmission control unit.
In system shown in Figure 7, the buffer unit of MPEG4 encoder is used to receive the present frame video data of input, when the data volume of input reaches the integral multiple of basis of coding data volume, just during the integral multiple of 16 line data, buffer unit triggers coding unit and begins coding.
Coding unit, receive the triggering signal of buffer unit after, from buffer unit, read 16 the row video datas, and by macro block begin the coding, with the coding result sequential storage in FIFO.
Transmission control unit is used to be provided with the heap(ed) capacity of FIFO and exports threshold value, the data volume among the monitoring FIFO, in the cataloged procedure of present frame, when reaching the output threshold value, export first control signal to the receiving terminal module, notice receiving terminal module reads the coding result data among the FIFO; After present frame is finished coding, to export second control signal to the receiving terminal module, and carry the remaining data amount among the FIFO, notice receiving terminal module reads remaining coding result data among the FIFO.
The receiving terminal module is used to receive the control signal of transmission control unit, and judges the type of this control signal, when definite this control signal is first control signal, by reading quantitative coding result data among the FIFO; When definite control signal is second control signal, extract the remaining data amount of carrying in the control signal, from FIFO, read all residue coding result data.
Utilize said system, promptly can realize the purpose that cataloged procedure and transmission course are carried out simultaneously, final residue coding result data after the whole frame compressed encoding will be far smaller than the coding result data of whole frame, then reduced greatly facing the non-scramble time that is used for the result data transmission between the frame coding mutually, saved the resource of system.Simultaneously, for the transmission of coding result data,, therefore can relatively realize the even output of coding result data owing to during intraframe coding, carry out to timesharing the transmission of coding result data.
In the specific embodiment of the invention described above, all to carry out the specific embodiment of the present invention that is encoded to the example explanation of MPEG4.In fact, when adopting other when H.263 waiting coded system, method and apparatus of the present invention stands good, and difference is that the basic data amount of encoding may change to some extent because of the difference of macroblock size.Here just repeat no more.
Being preferred embodiment of the present invention only below, is not to be used to limit protection scope of the present invention.Within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.