Device and method for video encoding

A video encoding device calculates number of frames into which the current image needs to be encoded. The video encoding device divides the current image into a plurality of macro blocks, identifies importance of the respective macro blocks according to content of the current image and ranks the macro blocks from high to low according to the assigned importance. The video encoding device labels each macro block with a label, and encodes the macro blocks according to its label to form frames.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application claims priority to Taiwanese Patent Application No. 103119450 filed on Jun. 4, 2014 in the China Intellectual Property Office, the contents of which are incorporated by reference herein.

FIELD

The present disclosure generally relates to video encoding and decoding.

BACKGROUND

H.264 is a format common in video transmission. The H.264 format comprises intra-coding and inter-coding, where the intra-coding refers to complete encoding, and inter-coding refers to partial encoding. A video frame is divided into a sequence of I frames, P frames and B frames, where each I frame is intra-coded for complete encoding, and where each P frame and B frame are inter-coded.

DETAILED DESCRIPTION

FIG. 1is a diagrammatic view of an environment of the video coding device. In the present embodiment, the video sent by sender30is first encoded by video encoding device10, then transmitted to the decoding device50and receiver60through the network transmission channel40. The sender30may be a personal computer, a monitor device, or an imaging device. The video encoding device10may be located on the sender30, or may be a separate component. The maximum allowable transmit threshold value of the network transmission channel40is Smax-frame. The receiver60may be a personal computer, a smartphone, or a display device, and the number of the receivers60may be more than one. The present disclosure is not limited thereto.

FIG. 2is a block diagram of one embodiment of the video coding device. The video coding device10comprises a determining module101, a calculating module103, a dividing module105, a labeling module107, a encoding module109, a storage system111, and a processor113. The module101-109can include computerized code in the form of one or more programs. The one or more programs are stored in the storage system111, and the storage system111can be a non-transitory memory device. The computerized code includes instructions executed by the processor113to provide functions for the modules101-109.

In the present embodiment, the determining module101determines whether to encode current image into I frame. Encoding the current image into I frame is required when the current image has a great or a great number of differences compared to the previous image. Since I frame and P frame are all defined in format H.264, there are other ways to determine whether to encode current image into I frame, the present disclosure is not limited thereto. When encoding of the current image into I frame is needed, the process proceeds to block303.

In the present embodiment, the calculating module calculates number of frames that the current image needs to be broken down into. Since the network transmission channel40has a maximum allowable transmit threshold, a total coding size of the current frame to being larger than the threshold will result in an unclear image, therefore the current image needs to be dispersed into several frames, and calculation of the number of the dispersed frames must be done. The number of the dispersed frames is N, where N is a positive integer starting at one. The calculating module103calculates total coding size of the current image when encoding with intra-coding, and compares with the maximum allowable transmit threshold Smax-frame. The formula can be N=ROUND{[ MaxI-Frame/(100*k/m*r)]+1}, wherein MaxI-Frameis the total coding size of the current image when encoding with intra-coding, k is transmission rate of the video, m is number of the transmission channels, and r is the frame rate of the video. For instance, if MaxI-Frame=75 kb, k=8 Mbps, m=1, then it can be calculated that N=3. It indicates that the current image should be dispersed into 3 frames.

In the present embodiment, the dividing module105divides the current image into a plurality of macro blocks, and identifies importance of the respective macro blocks according to content of the current image. The number of the macro blocks is M, wherein M is a positive integer starting at one. The dividing module105divides the current image into M macro blocks with 8×8 or 16×16 mode. After dividing into macro blocks, the dividing module105identifies the content of the current image. Since the image in video usually comprises actors or other significant object, the human character or significant object can be identified by technology of face recognition or object detection. The macro blocks are divided into high importance, into medium importance, and into low importance according to content of the current image. For instance, when there is a face in the current image, the macro blocks of the facial part will be identified as high importance, the macro blocks of the body part will be identified as medium importance, and the macro blocks of the background part will be identified as low importance.

In the present embodiment, the labeling module107ranks the macro blocks, from high to low according to the importance and labeling of each macro block, with a label x, wherein x is a positive integer from 1 to N, and x indicates that the macro block will be intra-coded.

In the present embodiment, the encoding module109encodes the current image. The encoding module109encodes the macro blocks which have a label x equaling 1 with low QP value and intra-coding and the macro blocks which have label x greater than 1 with high QP value and intra-coded to form a first frame. Moreover, the encoding module109encodes the macro blocks with label x of less than n with inter-coding to form an nthframe, wherein n is a positive integer from 2 to N. In the present embodiment, the high QP value can be between 22-51, and the low QP value can be between 0-24, and the QP value can be set according to the actual environment.

FIG. 3is a flowchart of one embodiment of a method for video coding. In one embodiment, the method functions by the modules inFIG. 2in the following manner.

In block301, the determining module101determines whether to encode current image into I frame. In the present embodiment, encoding of the current image into I frame is needed when the current image has a great or a great number of differences compared to the previous image. Since I frame and P frames are all defined in format H.264, there are also other ways to determine whether to encode current image into I frame, the present disclosure is not limited thereto. When encoding of the current image into I frame is needed, the process proceeds to block303.

In block303, the calculating module calculates number of frames into which the current image needs to be dispersed. In the present embodiment, the number of the dispersed frames is N, where N is a positive integer starting at one. The calculating module103calculates total coding size of the current image when encoding with intra-coding, and compares with the maximum allowable transmit threshold Smax-frame. The formula can be N=ROUND{[ MaxI-Frame/(100*k/m*r)]+1}, wherein MaxI-Frameis the total coding size of the current image when encoding with intra-coding, k is transmission rate of the video, m is the number of the transmission channels, and r is the frame rate of the video.

In block305, the dividing module105divides the current image into a plurality of macro blocks, and identifies importance of the macro blocks according to content of the current image. In the present embodiment, the number of the macro blocks is M, wherein M is a positive integer starting at one. The dividing module105divides the current image into M macro blocks with 8×8 or 16×16 mode. After dividing into macro blocks, the dividing module105identifies the content of the current image. The macro blocks are divided into high importance, medium importance, and low importance according to content of the current image. For instance, when there is a face in the current image, the macro blocks of the face part will be identified as high importance, the macro blocks of the body part will be identified as medium importance, and the macro blocks of the background part will be identified as low importance.

In block307, the labeling module107ranks the macro blocks from high to low according to the assigned importance and labels each macro block with an label x, where x is a positive integer from 1 to N. The x indicates in which frame the macro block will be intra-coded.

In one embodiment, the labeling module107assigns the M macro blocks into N frames on an average basis, where the number of macro blocks in each frame is M/N, and the label x of each macro block is the number of the corresponding frame.

In another embodiment, the labeling module107estimates size of the encoded macro block and compares with the maximum allowable transmit threshold, calculates the number of macro blocks in each frame, then divides all the macro blocks into individual frames.

FIG. 4shows a flowchart of one embodiment of labeling macro blocks in a method for video coding. In block401, the labeling module107calculates size of the current image when encoding with a high QP value SHQPand size of the current image when encoding with inter-coding SPSKIP, and sets the initial value of x to 1. In the present embodiment, the high QP value can be between 22-51.

In block402, the labeling module107sets macro block list, and the initial macro block list is empty.

In block403, the labeling module107selects macro block sequentially one by one to add to macro block list according to the sequence in block307.

In block404, the labeling module107calculates total coding size STotalof the macro block list and size of the macro block list when encoding with intra-coding SINTRA. In the present embodiment, when x=1, STotal=[1−(Cmb-list/Cmb-total)]*SHQP+SINTRA. When x is larger than 1, STotal=[1−(Cmb-list/Cmb-total)]*SPSKIP+SINTRA, wherein Cmb-listis a number of list macro block list and Cmb-totalis i a number of all of the macro blocks.

In block405, the labeling module107compares the STotalwith the Smax-frame. When STotalis less than Smax-frameit indicates that the macro block list is able to add more macro blocks, and the process proceeds to block407. In block407, the labeling module107determines whether all the macro blocks have been calculated, and if not, adds another macro block to the macro block list and calculates the STotalagain. When STotalis larger than Smax-frame, it indicates that the size of macro block list has exceeded the maximum allowable transmit threshold, and the process proceeds to block406.

In block406, the labeling module107labels the macro blocks in the macro block list with label x. In the present embodiment, labeling with an x indicates that the macro blocks so labeled will be intra-coding in the frame x, where x is a positive integer from 1 to N.

In block408, the labeling module107compares x with N. If x is less than N, it indicates that there are other macro blocks needing to be labeled, then label x plus one can be applied, and the process proceeds to block402. The labeling module107clears the macro block list and selects the remaining macro blocks sequentially one by one to add to macro block list.

In block409, when x is equal to N, it indicates that all the macro blocks have been labeled.

Through the above blocks, the labeling module107will apply label x to all of the macro blocks.

In block309, the encoding module109encodes the current image. The encoding module109encodes the macro blocks which have a label x equaling 1 with low QP value and intra-coding and the macro blocks with label x which is greater than 1 with high QP value and intra-coded to form a first frame. Moreover, the encoding module109encodes the macro blocks with a label x which is less than n with inter-coding to form an nthframe, where n is a positive integer from 2 to N. In the present embodiment, the high QP value can be between 22-51, and the low QP value can be between 0-24, and the QP value can be set according to the actual environment.

FIG. 5is a flowchart of one embodiment of encoding macro blocks in a method for video coding. In block501, the encoding module109encodes the nthframe.

In block502, the encoding module109determines whether n is equal to 1. When n is equal to 1, it indicates that the nthframe is encoded in intra-coding and the process proceeds to block503, otherwise proceeding to block507.

In block503, the encoding module109determines whether the label x of each macro block is equal to 1. When the label x is equal to 1, it indicates that the macro block is high importance, and it will be encoded with low QP value and intra-coding in block504, otherwise it will be encoded with high QP value and intra-coding in block505.

In block506, the encoding module109determines whether all of the macro blocks have been processed. If some macro blocks remain to be analyzed, the process proceeds to block503, otherwise the process proceeds to block501.

In block507, the encoding module109determines whether the label x of each macro block is less than n. When the label x is less than n, the encoding module109encodes the macro block with low QP value and inter-coding. Otherwise, the process proceeds to block509.

In block509, the encoding module109determines whether the label x of each macro block is equal to n. When the label x is equal to n, the encoding module109encodes the macro block with low QP value and intra-coding in block510. When the label x is larger than n, the encoding module109encodes the macro block with high QP value and inter-coding.

In block512, the encoding module109determines whether all the macro block have been analyzed. If there some macro blocks remaining to be analyzed, the process proceeds to block507, otherwise it proceeds to block501.

The device and the method for video encoding can calculates the number of frames into which the current image needs to be dispersed, identifies importance of the parts of current image, and encodes the current image with different coding. This not only reduces the size of the I-frame, but also ensures the video quality.