Embodiments of the present disclosure relate to the technical field of video transmission, for example, to a method for coding videos, a device and a storage medium.
With the rapid development of Internet technologies and the increase of users' demand for high-definition videos, the amount of interactive video data of multimedia resources is also increasing. During video transmission, video compression and decoding technologies are usually used to effectively extract redundant information from video data, so as to achieve the rapid transmission and off-line storage of video data in the Internet. In order to adapt to the bandwidth and device situations of different transmission users, source videos are coded under corresponding bit rates. In video coding in related arts, in the case that the coding complexity is higher, the coding quality is better, however, the coding time is longer, and excessive coding time causes a user to experience video lag. Therefore, on the basis of ensuring high-quality coding, it is also necessary to improve the coding speed to reduce the coding time in a video transmission process.
According to embodiments of the present disclosure, a method for coding videos, device and a storage medium are provided.
According to some embodiments of the present disclosure, a method for coding videos is provided. The method includes:
According to some embodiments of the present disclosure, a computer device for coding videos is provided. The computer device includes:
The at least one processor, when loading and running the at least one program, is caused to perform the method for coding videos as defined in any embodiments of the present disclosure.
According to some embodiments of the present disclosure, a non-volatile computer readable storage medium is provided. The non-volatile computer readable storage medium stores a computer program, wherein the computer program, when loaded and run by a processor, causes the processor to perform the method for coding videos as defined in any embodiments of the present disclosure.
The present disclosure is described in detail hereinafter with reference to the accompanying drawings and embodiments. It should be understood that the particular embodiments described herein are illustrative only rather than restrictive. It should also be noted that, for the purpose of description, only some, but not all, of the structures associated with the present disclosure are shown in the drawings. Furthermore, embodiments of the present disclosure and features in the embodiments may be combined with one another without conflict.
At present, most fast video coding modes in related arts are based on the modification of a coder itself, from frame-level coding to block coding, under the influence of an expected network bandwidth, the image complexity of multiple video frames is continuously analyzed through a large quantity of recursive algorithms adopted at a coding decision part, and then the coding bit rate of each coding block in the video frames is calculated. For this approach, the coding cost of each coding block at each recursive depth needs to be calculated by analyzing the image complexity, which causes a large computational burden and increases the coding overhead in the video transmission process.
Referring to
In S110, a precoding bit rate of a current macroblock subset is predicted in response to coding the current macroblock subset in a current video frame, based on an actual coding weight of each macroblock subset of the current video frame in a previous video frame, and an actual coding bit rate of each coded macroblock subset in the current video frame.
In order to ensure the high transmission efficiency and storage accuracy of video data, when transmitting video data rapidly between different user equipment, the to-be-transmitted video data need to be compressed and coded first, and the compressed and coded video data need to meet the fluctuating requirement of network bandwidth, such that a video lag caused by slow transmission is avoided. In the related art, when any video data is coded and compressed, the video data is first decapsulated to acquire a plurality of video frames in sequence, and then the plurality of video frames are coded in sequence. However, two adjacent frames in the video data are usually very similar, and only the fluctuation of the network bandwidth need to be adapted. Thus, in the embodiment of the present disclosure, in process of coding videos, the actual coding mode of the previous video frame is utilized in combination with the influence of a current network bandwidth, which can effectively guide the coding mode of the current video frame, such that the stability of the video coding quality is improved based on that the coding of the video frames meets the fluctuating requirement of network bandwidth.
Further, according to video coding technologies in related arts, each video frame is usually divided into a plurality of macroblocks, and then using one macroblock as a unit, each macroblock in the video frame is coded separately to realize the coding of the video frame. The coding specification of the macroblocks is preset, usually 16*16. Because the macroblocks in two adjacent frames in one video data have the same size and position, the coding modes of the same macroblocks in the two adjacent frames are relatively similar. Therefore, in the embodiment of the present disclosure, the actual coding mode of each macroblock in the previous video frame is utilized to guide the coding mode of the same macroblock in the current video frame. Because adjacent macroblocks in the same video frame have similar video picture complexity, the plurality of macroblocks are coded with the same coding quantization parameter. Therefore, in order to improve the efficiency of video coding, in the case that each of the video frames is coded, all macroblocks in each of the video frames are grouped into a plurality of macroblock subsets based on coding requirements in the embodiment of the present disclosure. Then the same coding quantization parameter is set for each of the macroblock subsets, such that each of the macroblocks within the macroblock subsets is coded with the same coding quantization parameter.
It should be noted that each macroblock subset in the embodiment of the present disclosure is composed of only one macroblock, or is composed of a plurality of macroblocks. For example, a plurality of macroblocks on the same line in the current video frame compose a macroblock subset, and the embodiment does not limit the quantity of macroblocks in each macroblock subset. The quantity of the macroblocks in each macroblock subset should be as small as possible, such that the coding mode of each macroblock is specifically analyzed to improve the coding quality of each macroblock.
In the embodiment, in the case that the macroblock subset in the current video frame is coded, the current video frame is divided first into a plurality of macroblocks to acquire an effective coding guide for the current video frame by the actual coding mode of the previous video frame, as shown in
Based on the actual coding weight of each macroblock subset of the previous video frame in the current video frame, the ratios of the coding weights of the coded macroblock subsets to the coding weights of the macroblock subsets are calculated. The actual coding bit rates of the coded macroblock subsets are calculated through the actual coding bit rate of each coded macroblock subset, and then the coding bit rates of the macroblock subsets in the current video frame, i.e., the precoding bit rates of the current macroblock subsets in response to coding the current macroblock subsets in the current video frame, are predicted, based on the coding weight ratios and the actual coding bit rates of the coded macroblock subsets. The precoding bit rate of the current video frame is predicted, based on the coding quality represented by the actual coding weight of each macroblock subset in the previous video frame in combination with the actual coding bit rates of the coded macroblock subsets of the current video frame, which can ensure the consistency of the coding quality between the previous video frame and the current video frame.
It should be noted that because the macroblock subsets in the current video frame are coded in order in the embodiment, the precoding bit rate of the current video frame is predicted in response to coding each macroblock subset in the current video frame based on the actual coding weight of each macroblock subset in the previous video frame and the actual coding bit rate of each coded macroblock subset in the current video frame, so as to ensure the stability of the coding quality of each macroblock subset in the current video frame.
In S120, a target coding quantization parameter of the current macroblock subset in the current video frame is acquired by adjusting an actual coding quantization parameter of the current macroblock subset in the previous video frame, based on a bit rate difference between the precoding bit rate and a pre-allocated bit rate of the current video frame at a current network bandwidth.
For example, in the case that the precoding bit rate of the current video frame for coding of the current macroblock subset is predicted, the precoding bit rate can only ensure the consistency of the coding quality between the previous video frame and the current video frame, but does not meet the requirement of network bandwidth fluctuation. Therefore, in the embodiment, the current network bandwidth of the current video frame needs to be analyzed when coding the current video frame. As shown in
In addition, because the network bandwidth fluctuates constantly in a video coding process, there is usually a corresponding frame loss mechanism to ensure the requirement of the network bandwidth for video transmission. In this case, the situation that the coding of the previous video frame is not completed exists due to frame loss when coding the current video frame. In the case that the previous video frame is not coded, a corresponding quantization parameter is specifically set for the current video frame by analyzing the picture complexity of the current video frame, and each macroblock in the current video frame is coded based on the quantization parameter.
Meanwhile, in view of the feature that the network bandwidth fluctuates constantly in the video coding process, in order to ensure the coding accuracy of the current video frame, the embodiment evaluates, based on the coding request of each video frame in a to-be-coded video, the current network bandwidth corresponding to the video frame. In other words, in the case that a video frame is requested to be coded, a current network state is reevaluated to acquire a current network bandwidth matching the to-be-coded current video frame, such that the coding quantization parameter of each macroblock subset in the current video frame can meet the requirement of the current network bandwidth.
In the technical solution according to the embodiment of the present disclosure, because the current video frame is coded only after the previous video frame is coded, and the plurality of macroblock subsets in the current video frame are also coded in sequence, each macroblock subset in the current video frame has a corresponding coding mode in the previous video frame. Coded macroblock subsets and uncoded macroblock subsets are present in the current video frame in response to coding the current macroblock subset in the current video frame. The precoding bit rate of the current macroblock subset of the current video frame for coding is predicted by referring to the actual coding weight of each macroblock subset of the current video frame in the previous video frame and the actual coding bit rate of each coded macroblock subset in the current video frame. The actual coding quantization parameter of the current macroblock subset in the previous video frame is adjusted by analyzing the bit rate difference between the precoding bit rate and the pre-allocated bit rate of the current video frame at the current network bandwidth, so as to acquire the target coding quantization parameter of the current macroblock subset in the current video frame and realize the accurate coding of the current video frame, without calculating the coding cost of each coded block at each recursion depth by analyzing the image complexity, which greatly reduces the coding cost and coding complexity in the video coding process and improves the efficiency of video coding. A corresponding adjustment is performed based on the current network bandwidth by directly referring to the actual coding mode of each macroblock subset in the previous video frame, so as to perform coding guidance and adjustment for the current video frame by using the coding mode of the previous video frame and the fluctuation of the current network bandwidth, and improve the stability of the video coding quality on the basis of ensuring that the requirement of network bandwidth fluctuation is met.
For example, as shown in
In S201, whether coded macroblock subsets are present in the current video frame is determined, S203 is performed based on the result that the coded macroblock subsets are presented in the current video frame, and S202 is performed based on the result that the coded macroblock subset are not presented in the current video frame.
For example, prior to coding the current video frame in a to-be coded video frame, the current video frame is divided into a plurality of macroblocks in advance, and the macroblocks are combined to acquire a plurality of macroblock subsets. Subsequently, a corresponding coding quantization parameter is set for each macroblock subset, and each macroblock subset is coded as required. However, the coding quantization parameter need to be calculated by virtue of actual coding modes of the coded macroblock subsets in the current video frame. Therefore, when coding a certain macroblock subset in the current video frame, it is first necessary to determine whether the coded macroblock subsets is present in the current video frame, that is, to determine whether the to-be-coded current macroblock subset in the current video frame is the first to-be-coded macroblock subset in the current video frame. Because coding prediction cannot be performed by virtue of the actual coding modes of the other macroblock subsets when coding the first macroblock subset in the current video frame, based on the existence or inexistence of the coded macroblock subsets in the current video frame, it is necessary to employ different methods to calculate the coding quantization parameter of the to-be-coded current macroblock subset in the current video frame, so as to ensure the coding accuracy of the current macroblock subset.
In S202, an actual coding quantization parameter of the current macroblock subset in a previous video frame is determined as a target coding quantization parameter of the current macroblock subset in the current video frame.
For example, in the case that the coded macroblock subset is not present in the current video frame, it indicates that the to-be-coded current macroblock subset in the current video frame is the first macroblock subset in the current video frame, and a current coding mode cannot be estimated by virtue of the actual coding modes of the other macroblock subsets in the current video frame. In this case, an actual coding mode of the current macroblock subset in the previous video frame is also applicable to the coding of the current macroblock subset in the current video frame to some extent because video pictures of the same macroblock subset in the two adjacent frames are substantially the same. Therefore, in order to improve the high efficiency of video coding, in the embodiment, the actual coding quantization parameter of the current macroblock subset in the previous video frame can be directly determined as the target coding quantization parameter of the current macroblock subset in the current video frame, and each macroblock in the current macroblock subset is coded based on the target coding quantization parameter, so as to ensure the stability of the video coding quality to a certain extent.
In S203, an actual coding bit rate of each coded macroblock subset in the current video frame, and ratios of weights of the uncoded macroblock subsets and the coded macroblock subsets in the current video frame are calculated.
For example, in the case that the coded macroblock subsets are present in the current video frame, it indicates that the to-be-coded current macroblock subset in the current video frame is not the first macroblock subset in the current video frame, and thus the current coding mode can be estimated by virtue of the actual coding modes of the plurality of coded macroblock subsets in the current video frame, so as to further improve the coding accuracy of the current macroblock subset.
In this case, firstly, each coded macroblock subset is found out from the current video frame to acquire the plurality of coded macroblock subsets. Then the actual coding situation of each coded macroblock subset is analyzed, as shown in
In S204, the precoding bit rate of the current macroblock subset is acquired in response to coding the current macroblock subset in the current video frame by estimating coding bit rates of the uncoded macroblock subsets in the current video frame, based on the actual coding bit rates and the weight ratios.
In the embodiment, the actual coding bit rates of the coded macroblock subsets in the current video frame are added to acquire the overall coding bit rate of the coded macroblock subsets in the current video frame. Based on the product of the ratios of weights of the uncoded macroblock subsets to weights of the coded macroblock subsets in the current video frame and the overall coding bit rate, the to-be-coded bit rates of the uncoded macroblock subsets in the current video frame are estimated. The precoding bit rate of the current video frame for coding of the current macroblock subset are predicted by adding the overall coding bit rate of the coded macroblock subsets in the current video frame and the to-be-coded bit rates, so as to ensure the stability of the video coding quality.
For example, the prediction equation of the precoding bit rate of the current video frame for coding of the current macroblock subset is:
wherein predframesize is the precoding bit rate of the current video frame for coding of the current macroblock subset, realsize is the actual coding bit rates of the coded macroblock subsets in the current video frame, welghtleft is the actual coding weights of the uncoded macroblock subsets in the current video frame in the previous video frame, and weightused is the actual coding weights of the coded macroblock subsets in the current video frame in the previous video frame.
In S205, whether a bit rate difference between the precoding bit rate and a pre-allocated bit rate of the current video frame at a current network bandwidth exceeds a preset bit rate fluctuation range is determined, and S207 is preformed based on the result that the bit rate difference between the precoding bit rate and the pre-allocated bit rate of the current video frame at the current network bandwidth exceeds the preset bit rate fluctuation range, and S206 is performed based on the result that the bit rate difference between the precoding bit rate and the pre-allocated bit rate of the current video frame at the current network bandwidth is within the preset bit rate fluctuation range.
For example, in the case that the precoding bit rate of the current video frame for coding of the current macroblock subset is predicted, because the precoding bit rate is predicted by means of the actual coding situation of the previous video frame, only the stability of the video coding quality can be ensured, while to meet the transmission requirement of the current network bandwidth cannot be ensured. Therefore, an appropriate bit rate is allocated in the embodiment to the current video frame according to the current network bandwidth, i.e., the pre-allocated bit rate in the embodiment. In this case, whether the bit rate difference between the precoding bit rate and the pre-allocated bit rate exceeds the preset bit rate fluctuation range is determined to analyze whether the actual coding quantization parameter of the current macroblock subset in the previous video frame is applicable to the coding of the current macroblock subset in the current video frame, such that the coding of the current macroblock subset in the current video frame can not only ensure the stability of the video coding quality, but also ensure that the transmission requirement of the current network bandwidth is met.
In S206, the actual coding quantization parameter of the current macroblock subset in the previous video frame is determined as a target coding quantization parameter of the current macroblock subset in the current video frame.
In the case that the bit rate difference between the precoding bit rate and the pre-allocated bit rate is within the preset bit rate fluctuation range, it indicates that the precoding bit rate also meets the transmission requirement of the current network bandwidth within a certain error range. In this case, because the precoding bit rate is predicted by the actual coding situation of the previous video frame, the actual coding quantization parameter of the current macroblock subset in the previous video frame is directly determined as the target coding quantization parameter of the current macroblock subset in the current video frame, so as to ensure the stability of the video coding quality on the basis of ensuring that the requirement of the current network bandwidth is met.
In S207, whether the precoding bit rate is greater than the pre-allocated bit rate is determined, and S208 is performed based on the result that the precoding bit rate is greater than the pre-allocated bit rate, and S209 is performed based on the result that the precoding bit rate is less than the pre-allocated bit rate.
For example, in the case that the bit rate difference between the precoding bit rate and the pre-allocated bit rate exceeds the preset bit rate fluctuation range, there are two cases: 1) the precoding bit rate is greater than the pre-allocated bit rate; and 2) the precoding bit rate is less than the pre-allocated bit rate. Different quantization parameter adjustment methods are employed in different cases. Therefore, in the case that it is determined that the bit rate difference between the precoding bit rate and the pre-allocated bit rate exceeds the preset bit rate fluctuation range, it is also necessary to further determine whether the precoding bit rate is greater than the pre-allocated bit rate, so as to implement the corresponding quantization parameter adjustment method on the current macroblock subset to ensure the coding accuracy of the current macroblock subset in the current video frame.
In S208, the target coding quantization parameter of the current macroblock subset in the current video frame is acquired by raising the actual coding quantization parameter of the current macroblock subset in the previous video frame.
For example, in the case that it is determined that the precoding bit rate is greater than the pre-allocated bit rate, it indicates that the precoding bit rate exceeds the preset bit rate fluctuation range as compared with the pre-allocated bit rate, and cannot meet the requirement of the current network bandwidth, and the precoding bit rate is predicted based on the actual coding condition of the previous video frame. Therefore, by analyzing the bit rate difference between the precoding bit rate and the pre-allocated bit rate, the actual coding quantization parameter of the current macroblock subset in the previous video frame is raised based on a ratio related to the bit rate difference, so as to acquire the target coding quantization parameter of the current macroblock subset in the current video frame. In this case, raising the coding quantization parameter can reduce spatial coding details of the current macroblock subset, such that the precoding bit rate is reduced to get closer to the pre-allocated bit rate, thereby ensuring the stability of the video coding quality on the basis of ensuring that the requirement of the current network bandwidth is met.
In S209, the target coding quantization parameter of the current macroblock subset in the current video frame is acquire by reducing the actual coding quantization parameter of the current macroblock subset in the previous video frame.
For example, in the case that it is determined that the precoding bit rate is less than the pre-allocated bit rate, it indicates that the precoding bit rate is within the preset bit rate fluctuation range as compared with the pre-allocated bit rate, and cannot meet the requirement of the current network bandwidth, and the precoding bit rate is predicted based on the actual coding condition of the previous video frame. Therefore, by analyzing the bit rate difference between the precoding bit rate and the pre-allocated bit rate, the actual coding quantization parameter of the current macroblock subset in the previous video frame is reduced based on a ratio related to the bit rate difference, so as to acquire the target coding quantization parameter of the current macroblock subset in the current video frame. In this case, reducing the coding quantization parameter increases the quantity of the spatial coding details of the current macroblock subset, such that the precoding bit rate is increased to get closer to the pre-allocated bit rate, thereby ensuring the stability of the video coding quality on the basis of ensuring that the requirement of the current network bandwidth is met.
In S210, each macroblock in the current macroblock subset is coded in sequence with the target coding quantization parameter.
In the embodiment, in the case that the target coding quantization parameter of the current macroblock subset in the current video frame is acquired, the target coding quantization parameter is directly used to code each macroblock in the current macroblock subset in sequence, then the target coding quantization parameter of the next macroblock subset in the current video frame is calculated, and the process is repeated in sequence until the coding of each macroblock subset in the current video frame is completed, so as to realize the accurate coding of the current video frame and continue to code the next video frame.
In S211, in response to completing the coding of each macroblock subset in the current video frame, the actual coding weight of each macroblock subset in the current video frame is calculated, based on the actual coding bit rate of each macroblock subset in the current video frame and the actual coding bit rate of the current video frame.
For example, in the case that the coding of each macroblock subset in the current video frame, i.e., the coding of the current video frame, is completed, the actual coding weight of each macroblock subset in the current video frame needs to be calculated to facilitate accurate coding of each macroblock subset in the next video frame. The actual coding bit rate of each macroblock subset in the current video frame and the overall actual coding bit rate of the current video frame are first calculated based on the actual coding situation of each macroblock subset in the current video frame. Then the bit rate ratio of the actual coding bit rate of each macroblock subset to the overall actual coding bit rate of the current video frame is determined as the actual coding weight of the macroblock subset in the current video frame.
For example, in the embodiment, the calculation equation of the actual coding weight of each macroblock subset in the current video frame is:
wherein curweight is the actual coding weight of each macroblock subset, curbits is the actual coding bit rate of the macroblock subset in the current video frame, and framesize is the actual coding bit rate of the current video frame.
Regarding to the technical solution according to the embodiment, the precoding bit rate of the current macroblock subset of the current video frame for coding is predicted by referring to the actual coding weight of each macroblock subset of the current video frame in the previous video frame, and the actual coding bit rate of each coded macroblock subset in the current video frame. The actual coding quantization parameter of the current macroblock subset in the previous video frame is adjusted by analyzing the bit rate difference between the precoding bit rate and the pre-allocated bit rate of the current video frame at the current network bandwidth, so as to acquire the target coding quantization parameter of the current macroblock subset in the current video frame and realize the accurate coding of the current video frame, without calculating the coding cost of each coded block at each recursion depth by analyzing the image complexity, which greatly reduces the coding cost and coding complexity in the video coding process and improves the efficiency of video coding. A corresponding adjustment is performed based on the current network bandwidth by directly referring to the actual coding mode of each macroblock subset in the previous video frame, so as to perform coding guidance and adjustment for the current video frame by using the coding mode of the previous video frame and the fluctuation of the current network bandwidth, and improve the stability of the video coding quality on the basis of ensuring that the requirement of network bandwidth fluctuation is met.
For example, as shown in
In S310, a video pre-buffer amount during video transmission at a current network bandwidth is estimated based on a pre-allocated bit rate of a current video frame at the current network bandwidth and lower coding bit rate limits of associated video frames.
For example, the fluctuation requirement of the network bandwidth is not met in the case that each video frame is coded and transmitted, and therefore, considering that video pictures of adjacent frames are approximately the same, a frame loss mechanism is set in the embodiment to meet the fluctuation requirement of the network bandwidth, that is, in the case that the transmission requirement of the current network bandwidth is not met, the coding of a certain video frame is appropriately discarded to relieve the transmission pressure of the current network bandwidth.
In the embodiment, a virtual video buffer is preset in order to accurately analyze whether the video coding meets the transmission requirement of the current network bandwidth, a video frame that is coded but not successfully transmitted is buffered in the virtual video buffer, and meanwhile the total buffer capacity of the virtual video buffer is determined to analyze the pre-allocated bit rate that is applicable to the current network bandwidth and allocated to the current video frame under the influence of video buffer of the virtual video buffer. Because the virtual video buffer buffers a plurality of subsequent associated video frames when transmitting the current video frame at the current network bandwidth, it is also necessary to refer to the influence of the subsequent associated video frames when the coding bit rate of the current video frame is required to meet the transmission requirement of the current network bandwidth. It should be noted that the associated video frames in the embodiment may be eight consecutive frames upon the current video frame, however, it should be noted that the quantity of the associated video frames is not limited.
Therefore, the embodiment can determine the real-time coding bit rates of the virtual video buffer for the current video frame and the associated video frames by analyzing the pre-allocated bit rate of the current video frame at the current network bandwidth and the lower coding bit rate limits of the associated video frames. The video transmission rate of the virtual video buffer at the current network bandwidth is analyzed, and the buffer capacity during video transmission at the current network bandwidth is estimated based on the current actual buffer occupancy of the virtual video buffer in combination with a difference between the real-time coding bit rate and the real-time transmission rate.
For example, in order to improve the estimation accuracy of the video pre-buffer amount, as shown in
In the case that the previous video frame is coded, the actual video buffer amount of the virtual video buffer upon actually coding the previous video frame is calculated based on an actual buffer situation, and then occupied space in the virtual video buffer is determined by analyzing a ratio of the actual video buffer amount to the buffer capacity of the virtual video buffer. Because the occupied space in the virtual video buffer is too large, certain negative pressure is generated on the video transmission and coding at the current network bandwidth. The longer the idling time of the virtual video buffer is, the easier the video transmission and coding at the current network bandwidth are. The buffer vacancy factor in the embodiment is set to represent positive pressure on the video transmission and coding at the current network bandwidth. A bit rate of the current network bandwidth for the current video frame at a current frame rate is correspondingly adjusted by virtue of the negative pressure produced by the occupied space and the positive pressure produced by the buffer vacancy factor, so as to acquire the pre-allocated bit rate of the current video frame and the transmission bit rate of video transmission at the current network bandwidth. The pre-allocated bit rate and the transmission bit rate are related to the current network bandwidth, and is calculated using the same equation:
wherein sendbits is the transmission bit rate of video transmission at the current network bandwidth, framebits is the pre-allocated bit rate of the current video frame, bitwidth is the current network bandwidth, is the current frame rate, 1.05 is an adjustment factor existing when the virtual video buffer is vacant, 0.2 is a fast compression factor existing when the virtual video buffer is full, bufferfill is the actual video buffer amount upon the actual coding of the previous video frame, buffersize the buffer capacity, and const_zero_factor is the buffer vacancy factor.
For example, in the case that the pre-allocated bit rate of the current video frame and the transmission bit rate of video transmission at the current network bandwidth are calculated, a dynamic change rate of the virtual video buffer is determined by analyzing a bit rate difference between the pre-allocated bit rate of the current video frame and the transmission bit rate and a bit rate difference between the lower coding bit rate limits of the associated video frames, and then the current actual video buffer amount is adjusted based on the dynamic change rate, so as to acquire the video pre-buffer amount at the time of video transmission at the current network bandwidth. For example, the calculation equation of the video pre-buffer amount may be: buffer2=buffer1+framebits−sendbits+Σn=08curframebitsn−sendbits*8 wherein buffer2 is the video pre-buffer amount of video transmission at the current network bandwidth, buffer1 is the actual video buffer amount, framebits is the pre-allocated bit rate of the current video frame, sendbits is the transmission bit rate of video transmission at the current network bandwidth, and curframebitsn is the lower coding bit rate limit of the nth frame of the associated video frames.
It should be noted that in order to ensure the coding accuracy of the current video frame, the lower coding bit rate limit of the current video frame is also analyzed in the embodiment, such that the coding bit rate is not lower than the lower coding bit rate limit. Therefore, in the case that the pre-allocated bit rate is lower than the lower coding bit rate limit of the current video frame, the pre-allocated bit rate needs to be updated to be the lower coding bit rate limit of the current video frame, so as to use the lower coding bit rate limit of the current video frame to perform a bit rate analysis on the current video frame to improve the coding accuracy of the current video frame.
In S320, whether the video pre-buffer amount exceeds a preset coding threshold value is determined, and S330 is performed based on the result that the video pre-buffer amount exceeds the preset coding threshold value, and S340 is performed based on the result that the video pre-buffer amount is within the preset coding threshold value.
For example, in order to accurately analyze whether the current network bandwidth supports the coding of the current video frame, that is, whether the coding of the current video frame produces transmission pressure on the current network bandwidth, a preset coding threshold value is preset in the embodiment. In the case that the video pre-buffer amount upon the coding analysis of the current video frame exceeds the preset coding threshold value, it indicates that the transmission pressure on the current network bandwidth is produced. The preset coding threshold value in the embodiment is set as 0.1*buffersize, wherein buffersize is the buffer capacity.
In S330, the current video frame is discarded.
For example, in the case that the video pre-buffer amount exceeds the preset coding threshold value, the current video frame is discarded rather than coded, so as to relieve the transmission pressure of the current network bandwidth. However, in the case that the video pre-buffer amount is within the preset coding threshold value, it indicates that the coding of the current video frame does not produce transmission pressure on the current network bandwidth, and then the target coding quantization parameter of each macroblock subset in the current video frame needs to be accurately estimated to realize the accurate coding of the current video frame.
In S340, a precoding bit rate of the current macroblock subset is predicted in response to coding the current macroblock subset in a current video frame, based on an actual coding weight of each macroblock subset of the current video frame in the previous video frame, and an actual coding bit rate of each coded macroblock subset in the current video frame.
In S350, a target coding quantization parameter of the current macroblock subset in the current video frame is acquired by adjusting an actual coding quantization parameter of the current macroblock subset in the previous video frame, based on a bit rate difference between the precoding bit rate and a pre-allocated bit rate of the current video frame at the current network bandwidth.
In S360, a corresponding actual video buffer amount is updated based on the actual coding amount of the current video frame.
For example, in the case that the coding of the current video frame is completed, in order to ensure an accurate analysis of the video pre-buffer amount of coding of the next video frame, the actual coding amount of the current video frame is analyzed in the embodiment, and then a current actual video replacement amount is updated with reference to an actual transmission situation and the actual coding amount, so as to improve the coding analysis of the next video frame.
In the technical solution according to the embodiment, prior to coding the current video frame, whether a transmission pressure is produced at the current network bandwidth is determined firstly by estimating the video pre-buffer amount during video transmission at the current network bandwidth, so as to set a corresponding frame loss mechanism to improve the accuracy and efficiency of video coding on the basis of ensuring that the requirement of the current network bandwidth is met.
In the technical solution according to the embodiment, because the current video frame is coded only after the previous video frame is coded, and the plurality of macroblock subsets in the current video frame are also coded in sequence, each macroblock subset in the current video frame has a corresponding coding mode in the previous video frame. Coded macroblock subsets and uncoded macroblock subsets are present in in the current video frame in response to coding the current macroblock subset in the current video frame. The precoding bit rate of the current macroblock subset of the current video frame for coding is predicted by referring to the actual coding weight of each macroblock subset of the current video frame in the previous video frame and the actual coding bit rate of each coded macroblock subset in the current video frame. The actual coding quantization parameter of the current macroblock subset in the previous video frame is adjusted by analyzing the bit rate difference between the precoding bit rate and the pre-allocated bit rate of the current video frame at the current network bandwidth, so as to acquire the target coding quantization parameter of the current macroblock subset in the current video frame and realize the accurate coding of the current video frame, without calculating the coding cost of each coded block at each recursion depth by analyzing the image complexity, which greatly reduces the coding cost and coding complexity in the video coding process and improves the efficiency of video coding. A corresponding adjustment is performed based on the current network bandwidth by directly referring to the actual coding mode of each macroblock subset in the previous video frame, so as to perform coding guidance and adjustment for the current video frame by using the coding mode of the previous video frame and the fluctuation of the current network bandwidth, and improve the stability of the video coding quality on the basis of ensuring that the requirement of network bandwidth fluctuation is met.
The apparatus for coding videos according to the embodiment is applicable to the method for coding videos according to any of the above embodiments, and has corresponding functions and beneficial effects.
The computer device according to the embodiment is configured to perform the method for coding videos according to any of the above embodiments, and has corresponding functions and beneficial effects.
An embodiment of the present disclosure further provides a computer readable storage medium, the computer readable storage medium stores a computer program, wherein a processor, when loading and executing the program, is caused to perform the method for coding videos according to any of the above embodiments. The method includes:
A storage medium containing computer-executable instructions according to some embodiments of the present disclosure is not limited to operation in the above method, and also executes related operation in the method for coding videos according to any embodiments of the present disclosure.
According to the above descriptions of the embodiments, those skilled in the art can clearly understand that the present disclosure can be implemented by software and necessary general hardware, and of course by hardware. Based on such understanding, the technical solution of the present disclosure, either essentially or in part making a contribution to the prior art, may be embodied in the form of a software product. The computer software product may be stored in the computer-readable storage medium, such as a floppy disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk or an optical disk of a computer, includes a plurality of instructions that are used to enable the computer device (such as a personal computer, a server or a network equipment) to perform the methods according to embodiments of the present disclosure.
It should be noted that in the embodiment of the above apparatus for coding videos, the units and modules included in the apparatus for coding videos are merely grouped according to functional logic, but are not limited to the above division, and all that is required in division is to realize corresponding functions. In addition, the specific names of the multifunctional units are merely for the convenience of mutual distinguishing and are not intended to limit the scope of protection of the present disclosure. The computer readable storage medium may be a non-transient computer readable storage medium.
Number | Date | Country | Kind |
---|---|---|---|
202011360060.6 | Nov 2020 | CN | national |
The present disclosure is a U.S. national phase application of international application No, PCT/CN2021/129185, filed on Nov. 8, 2021, which claims priority to Chinese Patent Application No. 202011360060.6, filed on Nov. 27, 2020 with the Patent Office of China, the disclosures of which are incorporated herein by reference in their entireties.
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/CN2021/129185 | 11/8/2021 | WO |