A coding method, a coding device and an electronic device
By dynamically adjusting code control parameters based on frame-specific characteristics, the method optimizes video encoding to reduce storage requirements and resource waste in electronic devices.
Patent Information
- Application Number
- CN202210560986.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-23
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2042-05-23
AI Technical Summary
In the prior art, electronic devices use fixed code control parameters when encoding videos, resulting in waste of resources and increased storage space.
By determining the acceptable quantization parameter QP of the current video frame, the static average number of bits is calculated, and compared with the preset maximum average number of bits, the target code control parameters are dynamically adjusted according to the comparison result and the frame type proportion.
It realizes dynamic intelligent adjustment of code control parameters, saves the storage space of the encoded video stream, and improves the encoding efficiency and image quality experience.
Smart Images

Figure CN114938450B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of video processing, and particularly relates to an encoding method, an encoding device, an electronic device, and a computer-readable storage medium. Background Art
[0002] With the rapid development of social economy and science and technology, more and more electronic devices are equipped with video shooting functions. However, the rich video information in the video stream often results in a huge storage space occupied, thereby increasing the cost of the electronic device. Currently, electronic devices usually encode each frame image of the video stream before storing it.
[0003] Based on the consideration of image quality, when an electronic device performs encoding, it often sets rate control parameters according to the maximum bit rate it can support, which leads to a certain degree of resource waste. Summary of the Invention
[0004] This application provides an encoding method, an encoding device, an electronic device, and a computer-readable storage medium, which can realize dynamic and intelligent adjustment of rate control parameters, and save the storage space of the encoded video stream.
[0005] In a first aspect, this application provides an encoding method, including:
[0006] Determine the acceptable quantization parameter (Quantizer Parameter, QP) of the current video frame;
[0007] Calculate the static average bit number of the current video frame according to the acceptable QP, where the static average bit number is an influencing factor of the rate control parameter;
[0008] Compare the static average bit number with a preset maximum average bit number;
[0009] Determine the target rate control parameter of the current video frame according to the comparison result, the preset frame type ratio, and the frame type corresponding to the current video frame;
[0010] Encode the current video frame according to the target rate control parameter.
[0011] In a second aspect, this application provides an encoding device, including:
[0012] A first determination module, configured to determine the acceptable quantization parameter QP of the current video frame;
[0013] A calculation module, configured to calculate the static average bit number of the current video frame according to the acceptable QP, where the static average bit number is an influencing factor of the rate control parameter;
[0014] A comparison module, configured to compare the static average bit number with a preset maximum average bit number;
[0015] A second determination module, configured to determine the target rate control parameter of the current video frame according to the comparison result, the preset frame type ratio, and the frame type corresponding to the current video frame;
[0016] An encoding module, configured to encode the current video frame according to the target rate control parameter.
[0017] In a third aspect, the present application provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the method in the first aspect are implemented.
[0018] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the method in the first aspect are implemented.
[0019] In a fifth aspect, the present application provides a computer program product, which includes a computer program. When the computer program is executed by one or more processors, the steps of the method in the first aspect are implemented.
[0020] The beneficial effects of the present application compared with the prior art are as follows: The electronic device no longer encodes each video frame of the video stream with fixed rate control parameters, but will adjust the rate control parameters in real time according to the specific encoding process and the own attributes of the current video frame. Specifically, first, the electronic device can determine the acceptable quantization parameter QP of the current video frame; then, the electronic device can calculate the static average bit number of the current video frame according to the acceptable QP, and compare the static average bit number with the preset maximum average bit number, where the static average bit number is an influencing factor of the rate control parameter; finally, the electronic device can determine the target rate control parameter of the current video frame according to the comparison result, the preset frame type ratio, and the frame type corresponding to the current video frame, and encode the current video frame according to the target rate control parameter. Through the above process, the dynamic and intelligent adjustment of the rate control parameter is realized, and the storage space of the encoded video stream is saved.
[0021] It can be understood that the beneficial effects of the above second aspect to fifth aspect can refer to the relevant descriptions in the first aspect above, and will not be repeated here. Description of the Drawings
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0023] Figure 1 It is a schematic flowchart of the implementation process of the encoding method provided by an embodiment of the present application;
[0024] Figure 2 It is a structural block diagram of the encoding device provided by an embodiment of the present application;
[0025] Figure 3 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0026] In the following description, specific details such as specific system structures and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0027] The encoding method provided by the embodiments of the present application is applied to an electronic device. By way of example only, the electronic device may be a device with a video shooting function such as a smart phone, a tablet computer, or an IP camera (IPC), etc., which is not limited herein. Hereinafter, taking the IPC as an example, the encoding method will be described.
[0028] Please refer to Figure 1 , and the implementation process of the encoding method is described in detail as follows:
[0029] Step 101, determine the acceptable quantization parameter QP of the current video frame.
[0030] The IPC can encode each video frame in the video stream to be encoded according to the timing. The current video frame that the IPC is about to encode is the current video frame. In order to obtain the rate control parameters required for encoding the current video frame, the IPC can first determine the acceptable QP of the current video frame, where the acceptable QP refers to: for the encoded frame obtained after encoding the current video frame, the QP corresponding to the lowest image quality that the user can theoretically accept.
[0031] In some embodiments, in order to save the system resources of the IPC and enable the IPC with low computing power to also implement intelligent encoding, the IPC can determine the acceptable QP of the current video frame in a hardware-related manner, and its process specifically includes:
[0032] A1. Determine the real-time encoding complexity.
[0033] The real-time encoding complexity represents the actual complexity of encoding the most recent video frame. When the scene changes little, the determined real-time encoding complexity can be approximately regarded as the predicted value of the encoding complexity of the current video frame. Denote the current video frame as the n-th frame of the video stream, then the following two situations may occur:
[0034] In the first situation, the current video frame is the first frame of the video stream before encoding; that is, n = 1. At this time, the IPC has not performed any encoding operations on this video stream, so there is no most recent encoding of this video stream, and thus the actual complexity of the previous encoding operation cannot be known. To handle this situation, an initial encoding complexity is pre-stored in the IPC, and the IPC can determine this initial encoding complexity as the real-time encoding complexity; that is, assign the value of this initial encoding complexity to the real-time encoding complexity.
[0035] For ease of explanation, denote the initial encoding complexity as C0, and the real-time encoding complexity of the n-th video frame as C n , then when the n-th video frame is the first frame of the video stream, C n = C0. Only as an example, the average encoding complexity in each typical scenario can be pre-statistically obtained from the video encoding processes of various different application scenarios as the initial encoding complexity for the corresponding typical scenario. In this way, after each IPC is put into use, each IPC can also determine the corresponding initial encoding complexity according to the specific scenario it is in.
[0036] In the second situation, the current video frame is a non-first frame of the video stream before encoding; that is, n > 1 and n is an integer. At this time, the IPC has performed encoding operations on the video frames of this video stream according to the time sequence, so there must be a most recent encoding of this video stream, specifically the encoding of the (n - 1)-th video frame. Based on this, the IPC can obtain encoding parameters related to the encoding complexity, that is, the first encoding parameters, from the encoding process of the (n - 1)-th video frame, and calculate the corresponding encoding complexity according to these first encoding parameters, thereby realizing the update of the real-time encoding complexity.
[0037] Only as an example, the first encoding parameters include the macroblock hierarchical structure, prediction angle, and in-frame encoding bit count, etc. The embodiments of the present application do not limit the parameter types involved in the first encoding parameters.
[0038] For ease of explanation, denote the macroblock hierarchical structure obtained from the encoding process of the (n - 1)-th video frame as α1 n-1 , the prediction angle as α2 n-1 , and the in-frame encoding bit count as α3 n-1 , then when the n-th video frame is a non-first frame of the video stream, C n = f1(α1 n-1 ,α2n-1 , α3 n-1 …).
[0039] A2. Determine the acceptable QP of the current video frame as the QP corresponding to the real-time coding complexity according to the mapping relationship between the coding complexity and QP.
[0040] IPC can store the mapping relationship between the coding complexity and QP in the form of a mapping table. This mapping relationship can be constructed in advance through a sample data set containing multiple sample images. The construction process is briefly described as follows:
[0041] The coding complexity can be calculated by the following formula (1):
[0042] C = a * size * QP (1)
[0043] Among them, C represents the coding complexity of encoding the sample image to obtain the encoded image; a represents the adjustment coefficient; size represents the data size of the encoded image.
[0044] For each sample image in the sample data set, at least two QPs can be used for encoding respectively, so as to obtain at least two encoded images corresponding to each sample image, and the coding complexity of each encoded image obtained by encoding can be calculated by the above formula (1). For each encoded image, a subjective visual score is given to obtain the score of each encoded image.
[0045] For each sample image, select the image with a score not lower than the target score from at least two encoded images corresponding to the sample image as the candidate encoded image, and then select the image with the lowest score from the candidate encoded images as the target encoded image. Thus, in the case of X sample images in the sample data set, finally X corresponding target encoded images can be obtained, and the mapping relationship between the coding complexity and QP can be constructed according to the QP and coding complexity corresponding to each target encoded image.
[0046] For the sake of convenience of explanation, the acceptable QP can be denoted as QP c .
[0047] Step 102. Calculate the static average number of bits of the current video frame according to the acceptable QP.
[0048] Existing research shows that there is a mutual mapping relationship between QP and the number of coding bits, as shown in the following formula (2):
[0049] QP = t1·log2b + t2 (2)
[0050] Among them, b is the number of coding bits, which is used to represent the data size of the encoded frame (i.e., the video frame obtained after encoding), and it can be approximately understood as the concept of the occupied space of the encoded frame. t1 and t2 are relationship parameters, which are related not only to the scene but also to the frame type; that is, for different frame types, different relationship parameters are set, and when the scene changes (usually manifested as a change in the picture), these relationship parameters should also be updated accordingly.
[0051] Only as an example, for two video frames I1 and I2 obtained by shooting the same scene, if the frame type corresponding to I1 is an I-frame (i.e., I1 is encoded with an I-frame, and the encoded frame obtained after encoding is an I-frame), and the frame type corresponding to I2 is a P-frame (i.e., I2 is encoded with a P-frame, and the encoded frame obtained after encoding is a P-frame), then when preparing to encode I1, if the above formula (2) needs to be used, the relationship parameters t 1-I and t 2-I corresponding to the I-frame should be referred to for the required calculations; similarly, when preparing to encode I2, if the above formula (2) needs to be used, the relationship parameters t 1-P and t 2-P corresponding to the P-frame should be referred to for the required calculations. For the convenience of description, the frame type corresponding to the current video frame will be simply referred to as the frame type of the current video frame hereinafter.
[0052] Given the acceptable QP and relationship parameters, substituting the acceptable QP and the relationship parameters into the above formula (1), the static average bit number can be obtained. Since the relationship parameters change with the change of the scene and the frame type of the current video frame, the calculation process of the static average bit number specifically includes:
[0053] B1. Determine the real-time relationship parameters.
[0054] As described above, the relationship parameters are related to the frame type; taking the video stream after IPC encoding including I-frames and P-frames as an example, the I-frames and P-frames each have corresponding relationship parameters. Based on this, similar to the scene complexity, when determining the real-time relationship parameters, the following two situations may also occur:
[0055] The first situation is that the current video frame is the first frame of the video stream in this frame type before encoding. For example, the current video frame is a video frame whose first frame in the video stream corresponds to an I-frame, or the current video frame is a video frame whose first frame in the video stream corresponds to a P-frame. To cope with this situation, the embodiments of the present application can pre-statistically obtain the typical values of the relationship parameters corresponding to each frame type through a large number of different scenes, so as to obtain the initial relationship parameters corresponding to each frame type and store them in the IPC.
[0056] For the convenience of description, the initial relationship parameter of the I-frame can be expressed as (t 1-I0,t 2-I0 ), where t 1-I0 is the initial value of t1 in the I-frame, and t 2-I0 is the initial value of t2 in the I-frame. Similarly, the initial relationship parameters of the P-frame can be expressed as (t 1-P0 , t 2-P0 ), where t 1-P0 is the initial value of t1 in the P-frame, and t 2-P0 is the initial value of t2 in the P-frame.
[0057] As an example only, the IPC can set the initial relationship parameters of the I-frame to (-3, 26), that is, for the I-frame type, the initial value of t1 is -3 and the initial value of t2 is 26; similarly, the IPC can set the initial relationship parameters of the P-frame to (-2, 22), that is, for the P-frame type, the initial value of t1 is -2 and the initial value of t2 is 22.
[0058] In the second case, the current video frame is a non-first frame of the pre-encoded video stream in this frame type. In this case, the IPC can update the real-time relationship parameters according to the encoding result of the previous video frame of this frame type and the preset parameter adjustment step size, so that the formula (2) represented by the updated relationship parameters (that is, the obtained real-time relationship parameters) can approach the encoding result, where the encoding result includes: the actual QP and the actual number of bits. The updated relationship parameter is the real-time relationship parameter.
[0059] Taking the P-frame as an example, the current video frame is the m-th (m > 1 and m is an integer) video frame corresponding to the pre-encoded video stream in the P-frame type, denoted as I p m , then I p m-1 represents the (m - 1)-th video frame corresponding to the pre-encoded video stream in the P-frame type. Obviously, when the current video frame is already I p m , the IPC has completed the encoding of I p m-1 . Based on this, the IPC can obtain the encoding result of I p m-1 , including: the actual QP and the actual number of bits of the encoded frame obtained after encoding I p m-1 . It can be understood that when the IPC encodes I p m-1 , there must be corresponding relationship parameters, denoted as t 1-P m-1 and t 2-P m-1; Meanwhile, there must be corresponding target coding control parameters, including the target QP and the target number of bits. The target QP issued during I p m-1 encoding is denoted as QP t m-1 , and the target number of bits issued during I p m-1 encoding is denoted as b t m-1 . Then, t 1-P m-1 , t 2-P m-1 , QP t m-1 and b t m-1 must satisfy the above formula (2). However, since the shooting scene of the IPC usually cannot remain unchanged, the actual QP and the actual number of bits after encoding usually deviate from the target QP and the target number of bits issued before encoding to a certain extent. Denote the actual QP obtained after I p m-1 encoding as QP real m-1 , and the actual number of bits as b real m-1 . Then, according to this QP real m-1 , b real m-1 and the preset parameter adjustment step size, t 1-P m-1 and t 2-P m-1 can be updated to obtain real-time relationship parameters.
[0060] The update process of the above relationship parameters can be understood as follows: The relationship parameters in the same scene are fixed, that is, when the scene remains unchanged, (QP, b) should be points on a certain fixed function curve. The scheme of this application issues (QP, b) (that is, the target coding control parameters, including the target QP and the target number of bits) to the encoder for encoding. However, due to the dynamic change of the scene, it is found that the actual (QP, b) is different from the issued (QP, b) after encoding. At this time, if the actual (QP, b) is directly used to update the function curve so that the updated function curve can pass through the actual (QP, b), it may cause the oscillatory change of the function curve due to the dynamic change of the scene. Based on this, in the embodiment of this application, when updating, the relationship parameters will be updated according to the preset parameter adjustment step size, so that the updated function curve can gradually approach the actual (QP, b) to achieve smooth update of the data.
[0061] For the convenience of description, the real-time relationship parameters obtained for the current video frame can be denoted as t1n and t 2n 。
[0062] B2. Calculate the static average bit number according to the real-time relationship parameter and the acceptable QP.
[0063] Denote this static average bit number as b1. Then, it can be known from the above formula (2) that:
[0064] It can be understood that this static average bit number is an intermediate parameter, and its value will affect the subsequent rate control parameters. That is to say, this static average bit number can be understood as the influencing factor of the rate control parameters.
[0065] Step 103: Compare the static average bit number with the preset maximum average bit number.
[0066] The maximum average bit number can be set in the following way: According to the scene code rate statistics experience, the cache space of the IPC, and / or the transmission bandwidth, etc., the maximum code rate R supported by the IPC can be obtained max ; Divide this maximum code rate by the preset frame rate f of the IPC, and the obtained result is the maximum average bit number b2. That is to say,
[0067] Only as an example, a typical value of the preset frame rate of the IPC can be 25 frames per second (fps).
[0068] Step 104: Determine the target rate control parameters of the current video frame according to the comparison result, the preset frame type ratio, and the frame type corresponding to the current video frame.
[0069] As described above, the target rate control parameters include the target QP and the target bit number. These two target rate control parameters can be specifically obtained in the following way:
[0070] C1. Determine the target average bit number according to the comparison result.
[0071] Since the static average bit number is calculated according to the acceptable QP, and the maximum average bit number is set according to the maximum code rate, when the static average bit number is less than the maximum average bit number, it indicates that the current video frame can achieve the user-recognized image quality even without encoding at the maximum code rate. That is to say, in this case, the IPC can save the code rate. Based on this, according to the comparison result, the following two situations may occur:
[0072] The first situation: The comparison result indicates that the static average bit number is less than the maximum average bit number. At this time, the IPC can calculate the target ratio according to the real-time motion area, the static average bit number, and the maximum average bit number, and determine the product of the target ratio and the maximum average bit number as the target average bit number.
[0073] Among them, the IPC can first determine the area ratio according to the real-time motion area, and the calculation process of the area ratio can be expressed as the following formula (3):
[0074]
[0075] In the above formula, r represents the area ratio; M n represents the real-time motion area of the current video frame (i.e., the nth video frame of the video stream before encoding); W represents the width of the current video frame, and H represents the height of the current video frame, that is, W*H represents the total area of the current video frame.
[0076] Based on the area ratio, the static average bit number, and the maximum average bit number, the IPC can set the target ratio as and calculate the target average bit number based on the target ratio and the maximum average bit number. The calculation process of the target average bit number can be expressed as the following formula (4):
[0077]
[0078] Among them, b t represents the target average bit number; the other parameters have been described above and will not be elaborated here.
[0079] Based on the above formula (3), it can be obtained that the value range of the area ratio is [0, 1]. Then, based on the above formula (4), it can be obtained that when r is 0, that is, when the current video frame is stationary compared to the previous video frame, b t = b1; when r is 1, that is, when the degree of motion of the current video frame compared to the previous video frame reaches the maximum, b t = b2. Thus, the IPC can obtain the target average bit number adapted to the motion degree of the current video frame between the static average bit number and the maximum average bit number by means of proportional adjustment.
[0080] In the second case, the comparison result indicates that the static average bit number is greater than or equal to the maximum average bit number. At this time, the IPC can determine the maximum average bit number as the target average bit number. That is, in this case, b t = b2.
[0081] In some embodiments, similar to the real-time encoding complexity described above, in order to save the system resources of the IPC and enable the IPC with low computing power to also achieve intelligent encoding, the IPC can determine the real-time motion area in a hardware-related manner. In the case where the scene changes little, the determined real-time motion area can be approximately regarded as the predicted value of the motion area of the current video frame. Denote the current video frame as the nth frame of the video stream before encoding, then the following two situations may occur:
[0082] In the first case, the current video frame is the first frame of the video stream before encoding; that is, n = 1. For this case, an initial motion area can be pre-stored in the IPC, and the IPC can determine this initial motion area as the real-time motion area; that is, assign the value of the initial motion area to the real-time motion area.
[0083] For ease of explanation, denote the initial motion area as M0, and the real-time motion area of the nth video frame as M n , then when the nth video frame is the first frame of the video stream, M n = M0. Only as an example, the initial motion area can be the total area of the video frame, which can ensure that the starting encoding will not cause picture quality problems due to insufficient bit rate.
[0084] In the second case, the current video frame is a non-first frame of the video stream before encoding; that is, n > 1 and n is an integer. At this time, the IPC has performed encoding operations on the video frames of this video stream according to the time sequence, so there must be a most recent encoding of this video stream, specifically the encoding of the (n - 1)th video frame. Based on this, the IPC can obtain encoding parameters related to the motion area, that is, the second encoding parameters, from the encoding process of the (n - 1)th video frame, and calculate the corresponding motion area according to these second encoding parameters, thereby realizing the update of the real-time motion area. Only as an example, the second encoding parameters include motion vectors, motion compensation amounts, and inter-frame encoding bit counts, etc. The embodiments of the present application do not limit the parameter types involved in the second encoding parameters.
[0085] For ease of explanation, denote the motion vector obtained from the encoding process of the (n - 1)th video frame as β1 n-1 , the motion compensation amount as β2 n-1 , and the inter-frame encoding bit count β3 n-1 , then when the nth video frame is a non-first frame of the video stream, M n = f2(β1 n-1 , β2 n-1 , β3 n-1 , …).
[0086] C2. Determine the target bit count of the current video frame according to the target average bit count, frame type ratio, and frame type.
[0087] The video stream obtained by IPC encoding contains I-frames and P-frames. Among them, I-frames are key frames and usually have a larger data size; P-frames are differential frames and usually have a smaller data size. Based on this, after obtaining the target average bit rate, it is also necessary to adjust the target average bit rate according to the frame type ratio (that is, the pre-set frame structure of the image sequence) and the frame type corresponding to the current video frame, so as to obtain the target bit rate adapted to this frame type and this frame type ratio. It can be understood that the target bit rate is the data size of the encoded frame expected to be obtained after encoding the current video frame.
[0088] C3. Determine the QP corresponding to the target bit rate as the target QP of the current video frame.
[0089] Based on the above formula (2), IPC can solve for QP according to the real-time relationship parameters and the obtained target bit rate, and the result obtained is the target QP of the current video frame.
[0090] Step 105, encode the current video frame according to the target rate control parameters.
[0091] The target rate control parameters can be sent to the encoder of IPC, and the encoder encodes the current video frame according to the received target rate control parameters. It can be understood that from the determination process of the real-time encoding complexity, the determination process of the real-time relationship parameters, and the determination process of the real-time motion area described above: the first encoding parameter in this encoding process will affect the real-time encoding complexity of the next video frame to be encoded; the second encoding parameter in this encoding process will affect the real-time motion area of the next video frame to be encoded; the target rate control parameters sent this time (that is, the target QP and the target bit rate), the actual QP and the actual bit rate of this encoding result will affect the relationship parameters of the next video frame to be encoded of the same frame type, thereby realizing the feedback adjustment of the relationship parameters, encoding complexity, and motion area during encoding.
[0092] As can be seen from the above, through the embodiments of the present application, the following technical effects are achieved: First, this encoding method does not require additional models to participate in the calculation of rate control parameters, realizing low-cost, low-bitrate, and high-quality encoding. Second, using the encoding complexity that can better represent the encoding cost instead of traditional texture statistics can more effectively calculate the accurate number of bits required for encoding. Third, using the encoding complexity combined with the motion area to adjust the rate control parameters takes advantage of the entropy masking characteristic of the human subjective visual system, effectively ensuring the subjective perception of the image quality after encoding by humans. Fourth, different frame types have their own relationship parameters, making this encoding method flexible and adaptable to various different frame structures of image sequences.
[0093] Corresponding to the encoding method provided above, an embodiment of the present application further provides an encoding device. As Figure 2 shown, the encoding device 200 includes:
[0094] A first determination module 201, configured to determine an acceptable quantization parameter QP of the current video frame;
[0095] A calculation module 202, configured to calculate a static average bit number of the current video frame according to the acceptable QP, where the static average bit number is an influencing factor of the rate control parameter;
[0096] A comparison module 203, configured to compare the static average bit number with a preset maximum average bit number;
[0097] A second determination module 204, configured to determine a target rate control parameter of the current video frame according to the comparison result, a preset frame type ratio, and the frame type corresponding to the current video frame;
[0098] An encoding module 205, configured to encode the current video frame according to the target rate control parameter.
[0099] In some embodiments, the first determination module 201 includes:
[0100] An encoding complexity determination unit, configured to determine the real-time encoding complexity;
[0101] An acceptable QP determination unit, configured to determine, according to a mapping relationship between the encoding complexity and the QP, the QP corresponding to the real-time encoding complexity as the acceptable QP of the current video frame.
[0102] In some embodiments, the encoding complexity determination unit is specifically configured to, when the current video frame is the first frame of the video stream, determine a preset initial encoding complexity as the real-time encoding complexity; when the current video frame is a non-first frame of the video stream, update the real-time encoding complexity according to a first encoding parameter, where the first encoding parameter is obtained from the encoding process of the previous video frame, and the first encoding parameter is related to the encoding complexity.
[0103] In some embodiments, the calculation module 202 includes:
[0104] A relationship parameter determination unit, configured to determine a real-time relationship parameter, where the real-time relationship parameter is related to the scene and the frame type;
[0105] A static average bit number calculation unit, configured to calculate the static average bit number according to the real-time relationship parameter and the acceptable QP.
[0106] In some embodiments, the relationship parameter determination unit is specifically configured to, when the current video frame is the first frame of the video stream under the frame type, determine a preset relationship parameter as the real-time relationship parameter; when the current video frame is a non-first frame of the video stream under the frame type, update and obtain the real-time relationship parameter according to the encoding result of the previous video frame under the frame type and a preset parameter adjustment step size, where the encoding result includes: the actual QP and the actual number of bits.
[0107] In some embodiments, the target rate control parameter includes: the target QP and the target number of bits; the second determination module 204 includes:
[0108] The target average bit number determination unit is configured to determine the target average bit number according to the comparison result;
[0109] The target bit number determination unit is configured to determine the target bit number of the current video frame according to the target average bit number, the frame type ratio, and the frame type;
[0110] The target QP determination unit is configured to determine the QP corresponding to the target bit number as the target QP of the current video frame.
[0111] In some embodiments, the target average bit number determination unit is specifically configured to, when the comparison result indicates that the static average bit number is less than the maximum average bit number, calculate a target ratio according to the real-time motion area, the static average bit number, and the maximum average bit number, and determine the product of the target ratio and the maximum average bit number as the target average bit number; when the comparison result indicates that the static average bit number is greater than or equal to the maximum average bit number, determine the maximum average bit number as the target average bit number.
[0112] In some embodiments, the determination process of the real-time motion area includes: when the current video frame is the first frame of the video stream, determining a preset initial motion area as the real-time motion area; when the current video frame is a non-first frame of the video stream, updating and obtaining the real-time motion area according to the second encoding parameter, where the second encoding parameter is obtained from the encoding process of the previous video frame and is related to the motion area.
[0113] As can be seen above, through the embodiments of the present application, the following technical effects are achieved: On the first hand, the encoding method does not require additional models to participate in the calculation of rate control parameters, achieving low-cost, low-bitrate, and high-quality encoding. On the second hand, using the encoding complexity that can better represent the encoding overhead instead of the traditional texture statistics can more effectively calculate the accurate number of bits required for encoding. On the third hand, using the encoding complexity combined with the motion area to adjust the rate control parameters takes advantage of the entropy masking characteristic of the human subjective visual system, effectively ensuring the subjective perception of the encoded image quality by humans. On the fourth hand, different frame types have their own relationship parameters respectively, making the present encoding method flexible and capable of adapting to various different image sequence frame structures.
[0114] Corresponding to the encoding method provided above, an embodiment of the present application further provides an electronic device. By way of example only, the electronic device may be a device of types such as a smart phone, a tablet computer, or an IPC, which is not limited herein. Please refer to Figure 3 , the electronic device 3 in the embodiment of the present application includes: a memory 301, one or more processors 302 ( Figure 3 only one is shown herein) and a computer program stored on the memory 301 and executable on the processor. Among them: the memory 301 is used to store software programs and units, and the processor 302 executes various functional applications and data processing by running the software programs and units stored in the memory 301 to obtain the resources corresponding to the above preset events. Specifically, when the processor 302 runs the above computer program stored in the memory 301, the following steps are implemented:
[0115] Determine the acceptable quantization parameter QP of the current video frame;
[0116] Calculate the static average number of bits of the current video frame according to the acceptable QP, where the static average number of bits is an influencing factor of the rate control parameter;
[0117] Compare the static average number of bits with the preset maximum average number of bits;
[0118] Determine the target rate control parameter of the current video frame according to the comparison result, the preset frame type ratio, and the frame type corresponding to the current video frame;
[0119] Encode the current video frame according to the target rate control parameter.
[0120] Assuming the above is the first possible implementation manner, then in the second possible implementation manner provided based on the first possible implementation manner, determining the acceptable quantization parameter QP of the current video frame includes:
[0121] Determine the real-time encoding complexity;
[0122] According to the mapping relationship between the coding complexity and the QP, the QP corresponding to the real-time coding complexity is determined as the acceptable QP of the current video frame.
[0123] In the third possible implementation provided based on the above second possible implementation, determining the real-time coding complexity includes:
[0124] When the current video frame is the first frame of the video stream, the preset initial coding complexity is determined as the real-time coding complexity;
[0125] When the current video frame is not the first frame of the video stream, the real-time coding complexity is updated according to the first coding parameter, where the first coding parameter is obtained from the coding process of the previous video frame, and the first coding parameter is related to the coding complexity.
[0126] In the fourth possible implementation provided based on the above first possible implementation, calculating the static average number of bits of the current video frame according to the acceptable QP includes:
[0127] Determine the real-time relationship parameter, where the real-time relationship parameter is related to the scene and the frame type;
[0128] Calculate the static average number of bits according to the real-time relationship parameter and the acceptable QP.
[0129] In the fifth possible implementation provided based on the above fourth possible implementation, determining the real-time relationship parameter includes:
[0130] When the current video frame is the first frame of the video stream under the frame type, the preset relationship parameter is determined as the real-time relationship parameter;
[0131] When the current video frame is not the first frame of the video stream under the frame type, the real-time relationship parameter is updated according to the coding result of the previous video frame under the frame type and the preset parameter adjustment step, where the coding result includes: the actual QP and the actual number of bits.
[0132] In the sixth possible implementation provided based on the above first possible implementation, the target rate control parameter includes: the target QP and the target number of bits; according to the comparison result, the preset frame type ratio, and the frame type corresponding to the current video frame, determining the target rate control parameter of the current video frame includes:
[0133] Determine the target average number of bits according to the comparison result;
[0134] Determine the target number of bits of the current video frame according to the target average number of bits, the frame type ratio, and the frame type;
[0135] Determine the QP corresponding to the target bit number as the target QP of the current video frame.
[0136] In a seventh possible implementation provided based on the above six possible implementations, determining the target average bit number according to the comparison result includes:
[0137] When the comparison result indicates that the static average bit number is less than the maximum average bit number, calculate the target ratio according to the real-time motion area, the static average bit number, and the maximum average bit number, and determine the product of the target ratio and the maximum average bit number as the target average bit number;
[0138] When the comparison result indicates that the static average bit number is greater than or equal to the maximum average bit number, determine the maximum average bit number as the target average bit number.
[0139] In an eighth possible implementation provided based on the above seven possible implementations, the process of determining the real-time motion area includes:
[0140] When the current video frame is the first frame of the video stream, determine the preset initial motion area as the real-time motion area;
[0141] When the current video frame is not the first frame of the video stream, update the real-time motion area according to the second encoding parameter, where the second encoding parameter is obtained from the encoding process of the previous video frame, and the second encoding parameter is related to the motion area.
[0142] It should be understood that in the embodiments of the present application, the so-called processor 302 may be a central processing unit (Central Processing Unit, CPU), and this processor may also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application-specific integrated circuits (Application Specific Integrated Circuit, ASIC), field-programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or this processor may also be any conventional processor, etc.
[0143] The memory 301 may include a read-only memory and a random access memory, and provide instructions and data to the processor 302. A part or all of the memory 301 may also include a non-volatile random access memory. For example, the memory 301 may also store information about the device category.
[0144] As can be seen from the above, through the embodiments of the present application, the following technical effects are achieved: In the first aspect, the encoding method does not require additional models to participate in the calculation of rate control parameters, achieving low-cost, low-bitrate, and high-quality encoding. In the second aspect, using the encoding complexity that can better represent the encoding overhead instead of the traditional texture statistics can more effectively calculate the accurate number of bits required for encoding. In the third aspect, using the encoding complexity in combination with the motion area to adjust the rate control parameters takes advantage of the entropy masking characteristic of the human subjective visual system, effectively ensuring the subjective perception of the encoded image quality by humans. In the fourth aspect, different frame types have their own relationship parameters respectively, making the present encoding method flexible and capable of adapting to various different image sequence frame structures.
[0145] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the above-mentioned division of each functional unit and module is used as an example. In practical applications, the above-mentioned functions can be assigned to different functional units and modules according to needs, that is, the internal structure of the above-mentioned device can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiments can be integrated into a processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of each functional unit and module are only for the convenience of mutual distinction and do not limit the protection scope of the present application. The specific working processes of the units and modules in the above system can refer to the corresponding processes in the foregoing method embodiments and will not be repeated here.
[0146] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0147] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of external device software and electronic hardware. Whether these functions are executed in hardware or software depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.
[0148] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For example, the division of the above-mentioned modules or units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces. The indirect coupling or communication connection of the devices or units can be in electrical, mechanical or other forms.
[0149] The units described above as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0150] If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above method embodiments of this application, it can also be completed by a computer program instructing the related hardware. The above computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be implemented. Among them, the above computer program includes computer program code, and the above computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The above computer-readable storage medium can include: any entity or device capable of carrying the above computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer-readable memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content included in the above computer-readable storage medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable storage medium does not include electrical carrier signals and telecommunication signals.
[0151] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included within the protection scope of the present application.
Claims
1. A coding method, characterized in that, Including: Determine an acceptable quantization parameter QP for the current video frame; Calculate a static average bit number of the current video frame according to the acceptable QP, where the static average bit number is an influencing factor of a rate control parameter; Compare the static average bit number with a preset maximum average bit number; Determine a target rate control parameter for the current video frame according to a comparison result, a preset frame type ratio, and a frame type corresponding to the current video frame; Encode the current video frame according to the target rate control parameter; Wherein, determining the acceptable quantization parameter QP for the current video frame includes: When the current video frame is the first frame of a video stream, determine a preset initial encoding complexity as a real-time encoding complexity; When the current video frame is a non-first frame of the video stream, update the real-time encoding complexity according to a first encoding parameter, where the first encoding parameter is obtained from an encoding process of a previous video frame, and the first encoding parameter is related to the encoding complexity; According to a mapping relationship between the encoding complexity and QP, determine the QP corresponding to the real-time encoding complexity as the acceptable QP for the current video frame.
2. The encoding method according to claim 1, wherein Calculating the static average bit number of the current video frame according to the acceptable QP includes: Determine a real-time relationship parameter, where the real-time relationship parameter is related to a scene and the frame type; Calculate the static average bit number according to the real-time relationship parameter and the acceptable QP.
3. The encoding method according to claim 2, characterized in that, Determining the real-time relationship parameter includes: When the current video frame is the first frame of the video stream in the frame type, determine a preset initial relationship parameter as the real-time relationship parameter; When the current video frame is a non-first frame of the video stream in the frame type, update the real-time relationship parameter according to a previous encoding result of a video frame in the frame type and a preset parameter adjustment step, where the encoding result includes: an actual QP and an actual bit number.
4. The encoding method according to claim 1, wherein The target rate control parameter includes: a target QP and a target bit number; determining the target rate control parameter for the current video frame according to the comparison result, the preset frame type ratio, and the frame type corresponding to the current video frame includes: Determine a target average bit number according to the comparison result; Determine the target bit number of the current video frame according to the target average bit number, the frame type ratio, and the frame type; Determine the QP corresponding to the target bit number as the target QP for the current video frame.
5. The encoding method according to claim 4, wherein Determining the target average bit number according to the comparison result includes: When the comparison result indicates that the static average bit number is less than the maximum average bit number, calculate a target ratio according to a real-time motion area, the static average bit number, and the maximum average bit number, and determine a product of the target ratio and the maximum average bit number as the target average bit number; When the comparison result indicates that the static average bit number is greater than or equal to the maximum average bit number, determine the maximum average bit number as the target average bit number.
6. The encoding method according to claim 5, wherein The determination process of the real-time motion area includes: When the current video frame is the first frame of the video stream, the preset initial motion area is determined as the real-time motion area; When the current video frame is not the first frame of the video stream, the real-time motion area is updated according to the second coding parameter, where the second coding parameter is obtained from the coding process of the previous video frame, and the second coding parameter is related to the motion area.
7. An encoding device, characterized in that, It includes: The first determination module is used to determine the acceptable quantization parameter QP of the current video frame; The calculation module is used to calculate the static average bit number of the current video frame according to the acceptable QP, where the static average bit number is an influencing factor of the rate control parameter; The comparison module is used to compare the static average bit number with the preset maximum average bit number; The second determination module is used to determine the target rate control parameter of the current video frame according to the comparison result, the preset frame type ratio and the frame type corresponding to the current video frame; The encoding module is used to encode the current video frame according to the target rate control parameter; Among them, the first determination module includes: The encoding complexity determination unit is used to determine the preset initial encoding complexity as the real-time encoding complexity when the current video frame is the first frame of the video stream, and update the real-time encoding complexity according to the first coding parameter when the current video frame is not the first frame of the video stream, where the first coding parameter is obtained from the coding process of the previous video frame, and the first coding parameter is related to the encoding complexity; The acceptable QP determination unit is used to determine the QP corresponding to the real-time encoding complexity as the acceptable QP of the current video frame according to the mapping relationship between the encoding complexity and QP.
8. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the method described in any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, the method described in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Video encoding method, apparatus, and program
US20070071094A1