Method, apparatus and device for encoding video data
Patent Information
- Application Number
- CN202211711937.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2042-12-29
AI Technical Summary
[0004]按照CBR的方式进行编码码率的控制时,码率固定,对复杂场景进行编码时质量较低,对简单场景进行编码时浪费码率
[0015]由以上技术方案可见,本申请实施例中,可以基于参考调节周期对应的实际码率确定当前调节周期对应的目标码率,进而控制每个调节周期对应的目标码率,能够基于编码过程中的目标码率调整量化参数,这样,即可以按照实际场景的复杂程度来控制编码码率,不会出现复杂场景编码后的质量过低,或者简单场景编码后浪费过多码率的情况,提高了码率的控制能力。又可以控制编码过程中的目标码率,使得码率控制较稳定,避免码率不可预期等问题。针对复杂场景给与更高的码率,针对简单场景给与较低的码率,使得码率利用率更加高效,图像质量更稳定,综合图像质量更好,在宽时间尺度上码率可预期。
Smart Images

Figure CN116016924B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of coding technology, and in particular to a method, apparatus and device for coding video data. Background Technology
[0002] Video data encoding refers to the process of encoding video data using specific compression techniques to obtain a bitstream, also known as recorded data. Since recorded data is significantly smaller than video data, storing recorded data can improve storage space utilization.
[0003] In related technologies, when encoding video data, the encoding bitrate can be controlled using either CBR (Constant Bit Rate) or VBR (Variable Bit Rate). When using CBR, the encoded bitrate is fixed. Conversely, when using VBR, the encoded bitrate is lower than the target bitrate and fluctuates within a certain range of the target bitrate; the target bitrate is the maximum bitrate that can be controlled using VBR.
[0004] When controlling the encoding bitrate using the CBR (Constant Bitrate Buffer) method, the bitrate is fixed, resulting in lower quality encoding complex scenes and wasted bitrate when encoding simple scenes. When controlling the encoding bitrate using the VBR (Variable Bitrate Buffer) method, the bitrate is uncontrollable for a certain period. In complex images, the bitrate is limited by the maximum bitrate, leading to degraded image quality. As the image becomes more complex, the maximum bitrate control fails, and the bitrate becomes uncontrollable. Summary of the Invention
[0005] This application provides a video data encoding method, wherein the video data encoding process is divided into multiple long cycles, each long cycle is divided into K adjustment cycles, where K is greater than 1, and the method includes:
[0006] During the encoding of video data, if the current long period is not the first long period in the encoding process of the video data, a reference adjustment period is selected from the previous long period. The position of the reference adjustment period in the previous long period is the same as the position of the current adjustment period in the current long period.
[0007] The target bitrate for the current adjustment period is determined based on the actual bitrate corresponding to the reference adjustment period; wherein, the target bitrate represents the expected average bitrate within the current adjustment period;
[0008] The target quantization parameters for the current adjustment period are determined based on the target bitrate.
[0009] During the current adjustment period, video data is encoded based on the target quantization parameters.
[0010] This application provides a video data encoding apparatus. The video data encoding process is divided into multiple long cycles, and each long cycle is divided into K adjustment cycles, where K is greater than 1. The apparatus includes:
[0011] The processing module is configured to, during the video data encoding process, for the current adjustment period within the current long period, if the current long period is not the first long period in the video data encoding process, select a reference adjustment period from the previous long period, wherein the position of the reference adjustment period in the previous long period is the same as the position of the current adjustment period in the current long period; and determine the target bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period; wherein the target bitrate represents the expected average bitrate within the current adjustment period;
[0012] The determination module is used to determine the target quantization parameters of the current adjustment period based on the target bit rate;
[0013] The encoding module is used to encode video data based on the target quantization parameters within the current adjustment cycle.
[0014] This application provides an electronic device, including: a processor and a machine-readable storage medium, the machine-readable storage medium storing machine-executable instructions that can be executed by the processor; the processor is configured to execute the machine-executable instructions to implement the video data encoding method of the example above.
[0015] As can be seen from the above technical solutions, in this embodiment, the target bitrate corresponding to the current adjustment period can be determined based on the actual bitrate corresponding to the reference adjustment period, thereby controlling the target bitrate for each adjustment period. This allows for adjustment of quantization parameters based on the target bitrate during the encoding process. Thus, the encoding bitrate can be controlled according to the complexity of the actual scene, avoiding situations where the quality is too low after encoding complex scenes or too much bitrate is wasted after encoding simple scenes, improving bitrate control capability. Furthermore, controlling the target bitrate during the encoding process ensures more stable bitrate control and avoids problems such as unpredictable bitrate. Applying higher bitrates to complex scenes and lower bitrates to simple scenes results in more efficient bitrate utilization, more stable image quality, better overall image quality, and predictable bitrate over a wide time scale. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments of this application or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings of the embodiments of this application.
[0017] Figure 1 This is a flowchart illustrating a video data encoding method according to one embodiment of this application;
[0018] Figure 2 This is a schematic diagram of the long period, short period, and adjustment period in one embodiment of this application;
[0019] Figures 3A-3C This is a schematic diagram illustrating the measured effect in one embodiment of this application;
[0020] Figure 4 This is a schematic diagram of the motion level in one embodiment of this application;
[0021] Figure 5 This is a schematic diagram of the structure of a video data encoding device according to one embodiment of this application;
[0022] Figure 6 This is a hardware structure diagram of an electronic device according to one embodiment of this application. Detailed Implementation
[0023] The terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the application. The singular forms “a,” “the,” and “the” as used in this application and claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to any and all possible combinations comprising one or more of the associated listed items.
[0024] It should be understood that although the terms first, second, third, etc., may be used to describe various information in embodiments of this application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" may also be interpreted as "when," "when," or "in response to a determination."
[0025] This application proposes a video data encoding method. The video data encoding process is divided into multiple long periods, and each long period is further divided into K adjustment periods, where K can be a positive integer greater than 1. See [link to relevant documentation]. Figure 1 The diagram shown illustrates a flowchart of a video data encoding method, which may include:
[0026] Step 101: During the encoding of video data, for the current adjustment period within the current long period, if the current long period is not the first long period in the encoding process of video data, a reference adjustment period is selected from the previous long period. The position of the reference adjustment period in the previous long period is the same as the position of the current adjustment period in the current long period.
[0027] For example, "same position" can mean that if the current adjustment cycle is the 5th adjustment cycle within the current long cycle, then the reference adjustment cycle is the 5th adjustment cycle within the previous long cycle.
[0028] Step 102: Determine the target bitrate for the current adjustment period based on the actual bitrate corresponding to the reference adjustment period; wherein, the target bitrate is used to represent the expected average bitrate within the current adjustment period.
[0029] In one possible implementation, to determine the target bitrate for the current adjustment period, the actual bitrate for each adjustment period within the previous long period can be normalized to obtain a normalized bitrate for each adjustment period. A scaling factor is determined based on the normalized bitrate corresponding to the actual bitrate of a reference adjustment period and the sum of the normalized bitrates for all adjustment periods within the previous long period. The target bitrate for the current adjustment period is then determined based on the long-period bitrate, the long-period duration, and this scaling factor; where the long-period bitrate represents the expected average bitrate within the long period, the long-period bitrate for all long periods is a fixed value, and the long-period duration represents the total duration of the long period.
[0030] For example, normalizing the actual bitrate for each adjustment period within the previous long period to obtain the normalized bitrate for each adjustment period may include, but is not limited to: for each adjustment period within the previous long period, determining a first quantization parameter for that adjustment period based on the size of each encoded image and the actual quantization parameters within that adjustment period, and the total encoding length of that adjustment period. The first quantization parameter represents the average quantization parameter of that adjustment period when frame size is used as the weight. Determining the normalized adjustment coefficient for that adjustment period based on the first quantization parameter, a configured baseline quantization parameter value (pre-configured based on experience), and the bitrate change caused by each quantization parameter change (pre-configured based on experience). Normalizing the actual bitrate for that adjustment period based on the normalized adjustment coefficient to obtain the normalized bitrate for that adjustment period.
[0031] For example, determining the target bitrate for the current adjustment period based on the actual bitrate corresponding to the reference adjustment period may include, but is not limited to: determining the initial bitrate for the current adjustment period based on the actual bitrate corresponding to the reference adjustment period, and directly setting the initial bitrate as the target bitrate for the current adjustment period. Alternatively, determining the initial bitrate for the current adjustment period based on the actual bitrate corresponding to the reference adjustment period; if the current long period is the second long period in the video data encoding process, then the initial bitrate can be set as the target bitrate for the current adjustment period; otherwise, if the current long period is not the second long period in the video data encoding process, then the quotient of the target bitrate corresponding to the reference adjustment period and the actual bitrate corresponding to the reference adjustment period can be determined as the bitrate coefficient, and the product of the initial bitrate and the bitrate coefficient can be determined as the target bitrate for the current adjustment period.
[0032] In one possible implementation, if the current long period is the first long period in the video data encoding process, the target bitrate corresponding to the current adjustment period can be determined based on the configured long period bitrate. For example, if the current adjustment period is the first adjustment period within the current long period, the long period bitrate can be determined as the target bitrate corresponding to the current adjustment period; and / or, if the current adjustment period is not the first adjustment period within the current long period, the target bitrate corresponding to the current adjustment period can be determined based on the long period bitrate, the long period duration, the actual total number of encoded bits before the current adjustment period, and the remaining duration of the current long period. For instance, the target bitrate corresponding to the current adjustment period can be determined based on the following formula: Target bitrate = [Long period bitrate * Long period duration - Actual total number of encoded bits] / Remaining duration of the long period.
[0033] Step 103: Determine the target quantization parameters for the current adjustment cycle based on the target bit rate.
[0034] For example, the variable adjustment bitrate for the current adjustment period can be determined based on the target bitrate and the scene motion level of the current adjustment period; wherein the variable adjustment bitrate is less than or equal to the target bitrate; the higher the scene motion level, the higher the variable adjustment bitrate can be. For instance, a configured scaling factor corresponding to the scene motion level can be determined, which can be greater than 0 and less than or equal to 1; the higher the scene motion level, the higher the scaling factor corresponding to that scene motion level; the product of this scaling factor and the target bitrate is determined as the variable adjustment bitrate.
[0035] If the actual bitrate corresponding to the quantization parameter of the current adjustment period is greater than the variable adjustment bitrate, the quantization parameter of the current adjustment period can be increased to obtain the target quantization parameter of the current adjustment period. Alternatively, if the actual bitrate corresponding to the quantization parameter of the current adjustment period is less than the variable adjustment bitrate, the quantization parameter of the current adjustment period can be decreased to obtain the target quantization parameter of the current adjustment period.
[0036] Step 104: Encode the video data based on the target quantization parameters within the current adjustment period.
[0037] In one possible implementation, after encoding the video data based on the target quantization parameters within the current adjustment period, a reference adjustment period can be selected from each of the previous M long periods of the current long period, where M can be a positive integer. The average normalized length of the M reference adjustment periods is determined. If the percentage change between the normalized length of the current adjustment period and this average length is greater than a first threshold, the scene change score is increased. If the scene change score is greater than a second threshold, the next long period of the current long period can be updated to the first long period, i.e., the above process is repeated starting from the first long period.
[0038] The method for determining the normalized length of the reference adjustment period or the current adjustment period may include, but is not limited to: determining a second quantization parameter corresponding to the adjustment period based on the size and actual quantization parameters of each encoded image within the adjustment period (i.e., any reference adjustment period or the current adjustment period), and the total coding length of the adjustment period, wherein the second quantization parameter represents the average quantization parameter of the adjustment period with frame size as the weight; determining a normalized adjustment coefficient corresponding to the adjustment period based on the second quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change; and performing a normalization operation on the total coding length of the adjustment period based on the normalized adjustment coefficient to obtain the normalized length of the adjustment period.
[0039] As can be seen from the above technical solutions, in this embodiment, the target bitrate corresponding to the current adjustment period can be determined based on the actual bitrate corresponding to the reference adjustment period, thereby controlling the target bitrate for each adjustment period. This allows for adjustment of quantization parameters based on the target bitrate during the encoding process. Thus, the encoding bitrate can be controlled according to the complexity of the actual scene, avoiding situations where the quality is too low after encoding complex scenes or too much bitrate is wasted after encoding simple scenes, improving bitrate control capability. Furthermore, controlling the target bitrate during the encoding process ensures more stable bitrate control and avoids problems such as unpredictable bitrate. Applying higher bitrates to complex scenes and lower bitrates to simple scenes results in more efficient bitrate utilization, more stable image quality, better overall image quality, and predictable bitrate over a wide time scale.
[0040] The technical solutions described above in the embodiments of this application will be explained below in conjunction with specific application scenarios.
[0041] In related technologies, when encoding video data, the CBR (Conditional Bitrate) method can be used to control the encoding bitrate. This results in a fixed bitrate, leading to low quality encoding complex scenes and wasted bitrate on simple scenes. Alternatively, the VBR (Variable Bitrate) method can be used to control the encoding bitrate. However, this results in a variable bitrate, which is uncontrollable for a certain period. When the image is complex, the bitrate is limited by a maximum bitrate, leading to degraded image quality. Furthermore, as the image becomes more complex, the maximum bitrate control fails, and the bitrate becomes uncontrollable.
[0042] In response to the above findings, this application proposes a video data encoding method that divides the video data encoding process into multiple long cycles. Each long cycle may include multiple short cycles, and each long cycle may also include multiple adjustment cycles (also referred to as adjustment periods). See also Figure 2 The diagram illustrates long cycles, short cycles, and adjustment cycles. In other words, the bitrate control time can be divided into long cycles, short cycles, and adjustment cycles. At the long cycle scale, the bitrate consumption is fixed, while within each adjustment cycle within the long cycle, variable bitrate encoding is used. Alternatively, the video data encoding process can be divided into multiple long cycles, each of which can include multiple adjustment cycles, but without short cycles.
[0043] For example, multiple cameras can communicate with a hard disk video recorder (HDD). The cameras can capture images of the actual scene within their shooting range, obtain video data, and send the video data to the HDD. The HDD can encode the video data sent by the cameras according to the video data encoding method provided in this application embodiment to obtain recorded data, which is then stored. Alternatively, the cameras can capture images of the actual scene within their shooting range, obtain video data, and encode the video data according to the video data encoding method provided in this application embodiment to obtain recorded data. Then, the cameras send the recorded data to the HDD, which receives and stores the recorded data. The HDD can be an HVR (High Definition & Hybrid Digital Video Recorder), a DVR (Digital Video Recorder), an NVR (Network Video Recorder), etc.
[0044] For example, given multiple long periods, all long periods can correspond to the same bitrate. The bitrate corresponding to all long periods is called the long period bitrate. The long period bitrate is a fixed value, meaning that the long period bitrate corresponding to each long period is fixed and will not change. Since the long period bitrate corresponding to all long periods is a fixed value, a fixed long period bitrate consumption is used on the long period scale. The long period bitrate represents the expected average bitrate within the long period, that is, the expected average bitrate within the long period is the long period bitrate. In the actual encoding process, the average bitrate within the long period may be greater than or less than the long period bitrate; the control objective for the long period is to make the average bitrate within the long period as close to the long period bitrate as possible.
[0045] For example, for each long period, the long period can include multiple short periods, that is, the long period can be longer than the short period. For example, the long period can be set to several hours and the short period can be set to several minutes, or the long period can be set to several days and the short period can be set to several hours.
[0046] For example, for each long period, the long period can include multiple adjustment periods, meaning the long period can be longer than the adjustment period. Furthermore, for each short period within the long period, the short period can include multiple adjustment periods, meaning the short period can be longer than the adjustment period. For instance, the long period can be set to several days, the short period to several hours, and the adjustment period to several minutes. For example, the long period can be 24 hours, the short period can be 4 hours, and the adjustment period can be 10 minutes. For example, the long period can include short period 1, short period 2, short period 3, and short period 4; short period 1 can include adjustment period 11, adjustment period 12, adjustment period 13, and adjustment period 14; short period 2 can include adjustment period 21, adjustment period 22, adjustment period 23, and adjustment period 24, and so on. That is, the long period includes 4 short periods, each short period includes 4 adjustment periods, and the long period includes 16 adjustment periods.
[0047] For example, the bitrate corresponding to the adjustment period can be called the target bitrate. The target bitrate for different adjustment periods can be the same or different, that is, the target bitrate for different adjustment periods is a variable value that can change dynamically. For the target bitrate corresponding to the same adjustment period, the target bitrate is a fixed value, that is, the target bitrate for that adjustment period is fixed and will not change. Here, the target bitrate represents the expected average bitrate within the adjustment period, that is, the expected average bitrate within the adjustment period is the target bitrate. In the actual encoding process, the average bitrate within the adjustment period may be greater than or less than the target bitrate, but the control objective of the adjustment period is to make the average bitrate within the adjustment period as close to the target bitrate as possible.
[0048] For example, variable bitrate encoding can be used for short periods and adjustment periods within a long period. Different bitrate adjustments can be made for the long, short, and adjustment periods. For instance, only the long-period bitrate can be set, and this bitrate is a fixed value. In each long period, the long-period bitrate is restored to this fixed value. The long-period bitrate can be configured empirically, such as 400Kbps, meaning it is restored to 400Kbps in each long period. Within each short period within the long period, the quantization parameter range can be dynamically adjusted. For example, the quantization parameter range can be increased or decreased to compensate for bitrate in complex and simple scenarios during the short period. Within each adjustment period within the long period, the target bitrate can be determined. Then, based on the target bitrate and the quantization parameter range, the quantization parameters are determined, and the video data is encoded based on these parameters. The quantization parameter can be QP (Quantizer Parameter), etc. The quantization parameter reflects the spatial detail compression; the smaller the value of the quantization parameter, the finer the quantization, the higher the image quality, and the longer the generated bitstream.
[0049] In the above application scenarios, the video data encoding method proposed in this application embodiment may include:
[0050] First, determine the target bitrate for each adjustment cycle.
[0051] Scenario 1: For each adjustment period within the first long period, the target bitrate for each adjustment period can be determined as follows: For the current adjustment period within the first long period, the target bitrate for the current adjustment period can be determined based on the configured long period bitrate. For example, if the current adjustment period is the first adjustment period within the long period, the long period bitrate can be determined as the target bitrate for the current adjustment period; if the current adjustment period is not the first adjustment period within the long period, the target bitrate for the current adjustment period can be determined based on the long period bitrate, the long period duration (i.e., the total duration corresponding to the long period), the actual total number of encoded bits before the current adjustment period within the long period, and the remaining duration of the long period. For instance, the target bitrate for the current adjustment period can be determined based on the following formula: Target bitrate = [Long period bitrate * Long period duration - Actual total number of encoded bits] / Remaining duration of the long period.
[0052] For example, assuming a long-period bitrate of 400Kbps, and the long period includes adjustment periods 1-16 (i.e., there are 16 adjustment periods), then for adjustment period 1, the long-period bitrate of 400Kbps is determined as the target bitrate corresponding to adjustment period 1. For adjustment period 2, the target bitrate corresponding to adjustment period 2 is determined using the following formula: Target bitrate = [400Kbps * Long period duration - Total encoded bits over time (Kb)] / Remaining time. 400Kbps represents the long-period bitrate, the long period duration represents the total duration corresponding to the long period (i.e., the total duration of the 16 adjustment periods), the total encoded bits over time represents the total actual encoded bits before adjustment period 2 (i.e., the total actual encoded bits of adjustment period 1), and the remaining time represents the remaining duration of the long period (i.e., the total duration of adjustment periods 2-16). Obviously, if the average bit rate corresponding to adjustment period 1 is greater than 400Kbps, then the target bit rate corresponding to adjustment period 2 is less than 400Kbps. If the average bit rate corresponding to adjustment period 1 is less than 400Kbps, then the target bit rate corresponding to adjustment period 2 is greater than 400Kbps. In other words, when the average bit rate used in the adjustment period that has been encoded is high (i.e., the total amount of actual encoded bits is large), the target bit rate corresponding to the remaining adjustment period is lowered. When the average bit rate used in the adjustment period that has been encoded is low (i.e., the total amount of actual encoded bits is small), the target bit rate corresponding to the remaining adjustment period is raised.
[0053] By analogy, the target bitrate corresponding to each adjustment cycle within a long period can be obtained.
[0054] Scenario 2: For each adjustment period other than the first long period (i.e., the second long period and subsequent long periods), the target bitrate for each adjustment period can be determined using the following steps:
[0055] Step S11: For each adjustment period in the previous long period of the current long period, based on the size of each encoded image in the adjustment period, the actual quantization parameters, and the total encoding length of the adjustment period, determine the first quantization parameter corresponding to the adjustment period. The first quantization parameter is used to represent the average quantization parameter of the adjustment period when the frame size is used as the weight, that is, the average quantization parameter when the frame size is used as the weight.
[0056] For example, suppose the multiple long cycles that have been divided include long cycle 1, long cycle 2, long cycle 3, long cycle 4, ..., then when the current long cycle is long cycle 2, the previous long cycle is long cycle 1; when the current long cycle is long cycle 3, the previous long cycle is long cycle 2, and so on.
[0057] Taking the current long cycle as long cycle 3 and the previous long cycle as long cycle 2 as an example, assuming that the current long cycle can include four adjustment cycles in sequence, namely adjustment cycle 3-1, adjustment cycle 3-2, adjustment cycle 3-3 and adjustment cycle 3-4 (i.e., K adjustment cycles), then the previous long cycle can include four adjustment cycles in sequence, namely adjustment cycle 2-1, adjustment cycle 2-2, adjustment cycle 2-3 and adjustment cycle 2-4.
[0058] Based on this, the first quantization parameter corresponding to adjustment period 2-1 can be determined based on the size of each encoded image within adjustment period 2-1, the actual quantization parameter, and the total encoding length of adjustment period 2-1. Similarly, the first quantization parameter corresponding to adjustment period 2-2, the first quantization parameter corresponding to adjustment period 2-3, and the first quantization parameter corresponding to adjustment period 2-4 can be obtained.
[0059] In one possible implementation, the first quantization parameter corresponding to the adjustment period can be determined using the following formula (1). Of course, formula (1) is just an example and is not a limitation.
[0060]
[0061] In formula (1), A1 / QP represents the first quantization parameter corresponding to adjustment period 2-1. QP1 represents the actual quantization parameter of the first encoded image frame within adjustment period 2-1, FRM1 represents the size of the first encoded image frame within adjustment period 2-1, and so on. QPm represents the actual quantization parameter of the m-th encoded image frame within adjustment period 2-1, FRMm represents the size of the m-th encoded image frame within adjustment period 2-1, and m represents the total number of encoded images within adjustment period 2-1. X represents the total encoding length of adjustment period 2-1. In summary, the first quantization parameter A1 / QP corresponding to adjustment period 2-1 can be determined based on the size and actual quantization parameter of each encoded image within adjustment period 2-1, and the total encoding length of adjustment period 2-1. Similarly, the first quantization parameter A2 / QP corresponding to adjustment period 2-2 can be obtained, and so on.
[0062] Step S12: Based on the first quantization parameter corresponding to the adjustment period, the configured baseline quantization parameter value, and the bit rate change value caused by each quantization parameter change, determine the normalized adjustment coefficient corresponding to the adjustment period.
[0063] For example, the normalized adjustment coefficient R1 corresponding to adjustment period 2-1 can be determined based on the first quantization parameter A1 / QP corresponding to adjustment period 2-1, the reference quantization parameter value, and the bitrate change value caused by each quantization parameter change. Similarly, the normalized adjustment coefficient R2 corresponding to adjustment period 2-2 can be determined based on the first quantization parameter A2 / QP corresponding to adjustment period 2-2, the reference quantization parameter value, and the bitrate change value caused by each quantization parameter change, and so on. In one possible implementation, the normalized adjustment coefficient corresponding to the adjustment period can be determined using the following formula (2). Of course, formula (2) is just an example and is not intended to limit the implementation.
[0064] R1 = p (A1 / QP-33) Formula (2)
[0065] In formula (2), R1 represents the normalized adjustment coefficient corresponding to the adjustment period 2-1, p represents the bit rate change value caused by each change in quantization parameter, which can be an empirical value, such as 1 / 6, 1 / 8, 1.1225, etc., without restriction, and 33 represents the configured baseline quantization parameter value, which is configured according to experience, without restriction.
[0066] Step S13: Normalize the actual bitrate corresponding to the adjustment period based on the normalized adjustment coefficient corresponding to the adjustment period to obtain the normalized bitrate corresponding to the adjustment period.
[0067] For example, since the encoding process of adjustment period 2-1 has been completed, the actual bitrate (also called the actual coding bitrate) corresponding to adjustment period 2-1 can be calculated. This actual bitrate is used to represent the coding bitrate corresponding to the actual bitstream length of adjustment period 2-1. That is, the actual bitrate corresponding to adjustment period 2-1 is determined based on the actual bitstream length and the duration of adjustment period 2-1. There are no restrictions on this. The actual bitrate corresponding to adjustment period 2-1 is recorded as bps1. Based on this, the actual bitrate bps1 corresponding to adjustment period 2-1 can be normalized based on the normalization adjustment coefficient R1 corresponding to adjustment period 2-1 to obtain the normalized bitrate bpsA corresponding to adjustment period 2-1. In one possible implementation, the normalized bitrate bpsA can be determined using the following formula (3). Of course, formula (3) is just an example and is not restricted.
[0068] bpsA=bps1*R1 formula (3)
[0069] Similarly, the actual bit rate bps2 corresponding to adjustment period 2-2 can be normalized based on the normalized adjustment coefficient R2 corresponding to adjustment period 2-2 to obtain the normalized bit rate bpsB corresponding to adjustment period 2-2. By analogy, the normalized bit rate corresponding to each adjustment period in the previous long period can be obtained.
[0070] In summary, assuming that each long period includes K adjustment periods, the normalized bitrate corresponding to the K adjustment periods in the previous long period can be obtained. The normalized bitrate is used to adjust the actual bitrate corresponding to all adjustment periods in the previous long period to the same bitrate benchmark (i.e., benchmark quantization parameter value).
[0071] Step S14: For the current adjustment period within the current long period, select a reference adjustment period corresponding to the current adjustment period from the previous long period. For example, the position of the reference adjustment period in the previous long period can be the same as the position of the current adjustment period in the current long period.
[0072] For example, if the current adjustment cycle is adjustment cycle 3-1 within the current long cycle, then the reference adjustment cycle is adjustment cycle 2-1 within the previous long cycle. If the current adjustment cycle is adjustment cycle 3-2 within the current long cycle, then the reference adjustment cycle is adjustment cycle 2-2 within the previous long cycle, and so on.
[0073] Step S15: Determine the scaling factor for the current adjustment period based on the normalized bitrate corresponding to the actual bitrate of the reference adjustment period and the sum of the normalized bitrates corresponding to all adjustment periods within the previous long period. For example, determine the scaling factor for adjustment period 3-1 based on the normalized bitrate corresponding to the actual bitrate of adjustment period 2-1 and the sum of the normalized bitrates corresponding to all adjustment periods within long period 2; determine the scaling factor for adjustment period 3-2 based on the normalized bitrate corresponding to the actual bitrate of adjustment period 2-2 and the sum of the normalized bitrates corresponding to all adjustment periods within long period 2, and so on.
[0074] In one possible implementation, the proportional coefficient C1 corresponding to the adjustment period 3-1 can be determined by the following formula (4), and the proportional coefficient C2 corresponding to the adjustment period 3-2 can be determined by the following formula (5), and so on. Of course, formula (4) and formula (5) are just examples and are not limited thereto.
[0075]
[0076]
[0077] As can be seen from formulas (4) and (5), the scaling factor C1 corresponding to adjustment period 3-1 is determined based on the normalized code rate bpsA corresponding to adjustment period 2-1 and the sum of the normalized code rates corresponding to all adjustment periods (bpsA+bpsB+…+bpsZ), and the scaling factor C2 corresponding to adjustment period 3-2 is determined based on the normalized code rate bpsB corresponding to adjustment period 2-2 and the sum of the normalized code rates corresponding to all adjustment periods.
[0078] Step S16: Based on the long-cycle bitrate, long-cycle duration, and the proportional coefficient corresponding to the current adjustment cycle, determine the target bitrate corresponding to the current adjustment cycle; the long-cycle bitrate represents the expected average bitrate within the long cycle, the long-cycle bitrate corresponding to the long cycle is a fixed value, and the long-cycle duration represents the total duration of the long cycle.
[0079] For example, if the current adjustment period is adjustment period 3-1, then the target bitrate bpsa corresponding to adjustment period 3-1 is determined based on the long period bitrate, the long period duration, and the proportional coefficient C1 corresponding to adjustment period 3-1. If the current adjustment period is adjustment period 3-2, then the target bitrate bpsb corresponding to adjustment period 3-2 is determined based on the long period bitrate, the long period duration, and the proportional coefficient C2 corresponding to adjustment period 3-2, and so on.
[0080] In one possible implementation, the target bit rate bpsa corresponding to the adjustment period 3-1 can be determined by the following formula (6). Of course, formula (6) is just an example and is not a limitation.
[0081]
[0082] In formula (6), 400Kbps represents the long period bitrate, which can be configured based on experience or obtained by using a certain algorithm without any restrictions. T represents the long period duration, that is, the total duration of the long period.
[0083] In summary, for each adjustment period within the current long period, when that adjustment period is used as the current adjustment period, the above steps can be used to obtain the target bitrate corresponding to that adjustment period.
[0084] See Figure 3A The diagram shown illustrates the actual test results, assuming a long cycle duration of 3 hours, a short cycle duration of 20 minutes, and an adjustment cycle duration of 4 minutes. Figure 3A The diagram illustrates the bitrate performance of two long-cycle periods. The horizontal axis represents time, totaling 6 hours, and the vertical axis represents bitrate. The long-cycle bitrate is 400Kbps. Figure 3A The diagram shows the actual bitrate and the target bitrate corresponding to the adjustment period. From... Figure 3AAs can be seen, in the first long cycle, due to the lack of corresponding reference data, the target bitrate for each adjustment cycle was determined based on a long cycle bitrate of 400Kbps. This resulted in not allocating more bitrate for complex images and not allocating lower bitrates for simple images. In the second long cycle, because there is corresponding reference data (such as the actual bitrate for each adjustment cycle within the first long cycle), the target bitrate for each adjustment cycle within the second long cycle can be determined according to steps S11-S15. This means that the target bitrate for each adjustment cycle within the second long cycle is adjusted, allowing for more bitrates for complex images and lower bitrates for simple images, thus making bitrate utilization more efficient.
[0085] See Figure 3B The diagram shown is a comparison between the scene learning code control algorithm (i.e., the code rate control algorithm of this application) and the CBR algorithm. Figure 3B It can be seen that, compared with the CBR algorithm, the scene learning code control algorithm has more stable image quality, better overall image quality, and predictable bitrate over a wide time scale.
[0086] See Figure 3C The diagram shown is a comparison between the scene learning rate control algorithm (i.e., the rate control algorithm of this application) and the VBR algorithm. Figure 3C It can be seen that, compared with the VBR algorithm, the scene learning code control algorithm has a higher bitrate utilization rate, more stable image quality, and predictable bitrate over a wide time scale.
[0087] Second, determine the target bitrate for each adjustment cycle.
[0088] from Figure 3A , Figure 3B and Figure 3C It can be seen that the target bitrate increases at the end of both long cycles. For the tail adjustment period of the first long cycle, when the remaining duration of the long cycle is short and the bitrate is not fully utilized, the target bitrate corresponding to the adjustment period will rapidly increase. For the tail adjustment period of the second long cycle (and subsequent long cycles), since each adjustment period uses a variable adjustment bitrate for control, and the variable adjustment bitrate is determined based on the motion level, the variable adjustment bitrate corresponding to the maximum motion level is the target bitrate. When the motion level is low, the variable adjustment bitrate will be lower than the target bitrate, meaning the motion level directly affects the target bitrate. Therefore, the adjustment periods of the second long cycle will not always be controlled according to the maximum target bitrate, resulting in a target bitrate increase at the tail adjustment period.
[0089] For example, the phenomenon of increased target bitrate corresponding to the tail of a long period can be called the tail effect. In order to deal with the tail effect and avoid the phenomenon of increased target bitrate, the following method can be adopted in this embodiment:
[0090] For each adjustment period within the first long period, in order to determine the target bit rate corresponding to each adjustment period, we can use Case 1 of the first point. This determination method will not be repeated here.
[0091] For each adjustment period within the second long cycle, to determine the target bitrate for each adjustment period, we can use Case 2 from point 1, and this determination method will not be repeated here. For example, based on the actual bitrate corresponding to the reference adjustment period, we determine the initial bitrate corresponding to the current adjustment period (such as each adjustment period within the second long cycle), and directly set this initial bitrate as the target bitrate corresponding to the current adjustment period.
[0092] To determine the target bitrate for each adjustment period within the third long period and subsequent long periods, the following steps can be taken:
[0093] Step S21: For each adjustment period in the previous long period of the current long period, based on the size of each encoded image in the adjustment period, the actual quantization parameters, and the total encoding length of the adjustment period, determine the first quantization parameter corresponding to the adjustment period. The first quantization parameter is used to represent the average quantization parameter of the adjustment period when the frame size is used as the weight, that is, the average quantization parameter when the frame size is used as the weight.
[0094] Step S22: Based on the first quantization parameter corresponding to the adjustment period, the configured baseline quantization parameter value, and the bit rate change value caused by each quantization parameter change, determine the normalized adjustment coefficient corresponding to the adjustment period.
[0095] Step S23: Based on the normalized adjustment coefficient corresponding to the adjustment period, normalize the actual bitrate corresponding to the adjustment period to obtain the normalized bitrate corresponding to the adjustment period.
[0096] Step S24: For the current adjustment period within the current long period, select a reference adjustment period corresponding to the current adjustment period from the previous long period. For example, the position of the reference adjustment period in the previous long period can be the same as the position of the current adjustment period in the current long period.
[0097] Step S25: Based on the normalized code rate corresponding to the reference adjustment period and the sum of the normalized code rates corresponding to all adjustment periods in the previous long period, determine the proportional coefficient corresponding to the current adjustment period.
[0098] Step S26: Based on the long-cycle bitrate (i.e., the expected average bitrate within the long cycle), the long-cycle duration (i.e., the total duration of the long cycle), and the proportional coefficient corresponding to the current adjustment cycle, determine the initial bitrate corresponding to the current adjustment cycle. The determination method is the same as the method for determining the target bitrate in step S16, and will not be repeated here.
[0099] In summary, based on steps S21-S26, the initial bitrate corresponding to the current adjustment period can be determined based on the actual bitrate corresponding to the reference adjustment period. The implementation method is described in steps S11-S16.
[0100] Step S27: Determine the bitrate coefficient based on the target bitrate and the actual bitrate corresponding to the reference adjustment period, and determine the target bitrate for the current adjustment period based on the initial bitrate and the bitrate coefficient. For example, the product of the initial bitrate and the bitrate coefficient for the current adjustment period is determined as the target bitrate for the current adjustment period.
[0101] For example, if the current adjustment period is adjustment period 3-1 and the reference adjustment period is adjustment period 2-1, then the bitrate coefficient D1 is determined based on the target bitrate and the actual bitrate corresponding to adjustment period 2-1, and the target bitrate corresponding to adjustment period 3-1 is determined based on the initial bitrate and the bitrate coefficient D1. If the current adjustment period is adjustment period 3-2 and the reference adjustment period is adjustment period 2-2, then the bitrate coefficient D2 is determined based on the target bitrate and the actual bitrate corresponding to adjustment period 2-2, and the target bitrate corresponding to adjustment period 3-2 is determined based on the initial bitrate and the bitrate coefficient D2, and so on.
[0102] In one possible implementation, if the current adjustment period is adjustment period 3-1, the bit rate coefficient D1 can be determined by the following formula (7), and the target bit rate corresponding to adjustment period 3-1 can be determined by the following formula (8). Of course, formula (7) and formula (8) are just examples and are not limited thereto.
[0103]
[0104]
[0105] In formulas (7) and (8), bpsa represents the target bitrate corresponding to the reference adjustment period 2-1, bps1 represents the actual bitrate corresponding to the reference adjustment period 2-1, D1 represents the bitrate coefficient, bpsa′ represents the initial bitrate corresponding to the current adjustment period 3-1, and bpsa″ represents the target bitrate corresponding to the current adjustment period 3-1. Thus, the target bitrate corresponding to the current adjustment period 3-1 is obtained. Using the same method, the target bitrate corresponding to each adjustment period can be obtained, and the tail effect of the target bitrate has been improved.
[0106] Third, control the video data encoding process based on the target bitrate.
[0107] For example, the encoding process of video data can be controlled using the following steps:
[0108] Step S31: Determine the variable adjustment bitrate corresponding to the current adjustment period based on the target bitrate and the scene motion level of the current adjustment period. The variable adjustment bitrate is less than or equal to the target bitrate; when the scene motion level is higher, the motion of the current scene is greater, and the variable adjustment bitrate is higher. When the scene motion level is lower, the motion of the current scene is smaller, and the variable adjustment bitrate is also smaller.
[0109] For example, within the current adjustment cycle, the variable adjustment bitrate can be dynamically adjusted according to the actual motion conditions of the scene. During the adjustment process, different variable adjustment bitrates can be set according to the degree of motion. For instance, when the actual motion conditions of the scene are complex, the variable adjustment bitrate increases, and when the actual motion conditions of the scene are simple, the variable adjustment bitrate decreases. Because the variable adjustment bitrate is a dynamically adjusted value, the actual average bitrate within each adjustment cycle can be controlled, thereby controlling the encoding bitrate according to the different levels of complexity of the actual scene. This avoids situations where the encoding quality is too low after encoding complex scenes or too much bitrate is wasted after encoding simple scenes.
[0110] For example, after determining the variable adjustment bitrate based on the target bitrate and the scene motion level corresponding to the current adjustment period, when the scene motion level corresponding to the current adjustment period changes, the variable adjustment bitrate corresponding to the current adjustment period can be re-determined based on the target bitrate and the changed scene motion level.
[0111] For example, determining the variable adjustment bitrate corresponding to the current adjustment period based on the target bitrate and the scene motion level may include: determining the configured scaling factor corresponding to the scene motion level; the scaling factor may be greater than 0 and less than or equal to 1, and the scaling factor corresponding to the scene motion level is larger when the scene motion level is larger; the variable adjustment bitrate may be determined based on the product of the scaling factor and the target bitrate.
[0112] For example, we can pre-define K scene motion levels, where K is a positive integer greater than 1, such as 3 scene motion levels, 5 scene motion levels, 7 scene motion levels, etc. For ease of description, let's take 7 scene motion levels as an example, denoted as Scene Motion Level 1 to Scene Motion Level 7. Among these 7 scene motion levels, Scene Motion Level 1 corresponds to the lowest motion intensity, and Scene Motion Level 7 corresponds to the highest motion intensity. We can pre-configure the mapping relationship between scene motion levels and scaling factors. The scaling factor can be a value between 0 and 1, i.e., greater than 0 and less than or equal to 1. The lower the motion intensity corresponding to a scene motion level, the smaller the scaling factor for that scene motion level; conversely, the higher the motion intensity corresponding to a scene motion level, the larger the scaling factor for that scene motion level.
[0113] For example, the scaling factor corresponding to scene motion level 1 is less than that corresponding to scene motion level 2, the scaling factor corresponding to scene motion level 2 is less than that corresponding to scene motion level 3, and so on, with the scaling factor corresponding to scene motion level 6 being less than that corresponding to scene motion level 7. See Table 1 for an example of the mapping relationship between scene motion levels and scaling factors. Of course, this is just an example of the mapping relationship, and no restrictions are imposed on it.
[0114] Table 1
[0115] Scene motion level 7 1 Scene motion level 6 0.875 Scene motion level 5 0.75 Scene motion level 4 0.625 Scene motion level 3 0.5 Scene motion level 2 0.375 Scene motion level 1 0.25
[0116] In Table 1, the scaling factor for scene motion level 7 is 1, indicating that the variable bitrate corresponding to the highest scene motion level is the target bitrate. The scaling factor for scene motion level 1 is 0.25, indicating that the variable bitrate corresponding to the lowest scene motion level is the target bitrate * 0.25.
[0117] For the current adjustment period, it can be divided into multiple sampling periods. In each sampling period, the scene motion level can be determined. This scene motion level reflects the actual motion situation in the current sampling period, i.e., the degree of motion in the current scene. For example, the scene motion level of the current sampling period can be obtained based on image analysis. This process is not limited, as long as the scene motion level can be obtained. After obtaining the scene motion level of the current sampling period, the mapping relationship shown in Table 1 can be consulted to obtain the scaling factor corresponding to the scene motion level. Based on the product of this scaling factor and the target bitrate corresponding to the current adjustment period, the variable adjustment bitrate of the next sampling period is determined.
[0118] For example, the adjustment period can be divided into sampling period 1, sampling period 2, sampling period 3, and so on. In sampling period 1, the scene motion level is determined, such as scene motion level 7, with a scaling factor of 1. Assuming the target bitrate for the current adjustment period is 400Kbps, then the variable adjustment bitrate for sampling period 2 is 400Kbps. In sampling period 2, the scene motion level is determined, such as scene motion level 6, with a scaling factor of 0.875, then the variable adjustment bitrate for sampling period 3 is 350Kbps (400 * 0.875). In sampling period 3, the scene motion level is determined, such as scene motion level 6, with a scaling factor of 0.875, then the variable adjustment bitrate for sampling period 4 is 350Kbps, and so on.
[0119] In summary, for each sampling period of the current adjustment period, the variable adjustment bit rate for that sampling period can be obtained. Clearly, the variable adjustment bit rate corresponding to the current adjustment period is a variable value that can change dynamically. That is, the variable adjustment bit rate can be dynamically adjusted according to the actual motion conditions of the scene. The variable adjustment bit rate for different sampling periods can be the same or different. For example, when the actual motion conditions of the scene are more complex, the variable adjustment bit rate increases; when the actual motion conditions of the scene are simpler, the variable adjustment bit rate decreases.
[0120] In one possible implementation, see Figure 4 As shown, the system can determine the motion of the current scene over a period of time and divide the scene into multiple motion levels. It then calculates the variable bitrate corresponding to each motion level based on the target bitrate. Specifically, to determine the motion of the current scene, the percentage of image difference is obtained by comparing images. The motion level of the current scene is determined based on this percentage difference, thus achieving the division into multiple motion levels. The motion detection time is approximately ten seconds.
[0121] Step S32: Determine the target quantization parameter range corresponding to the current adjustment cycle.
[0122] In one possible implementation, the quantization parameter range can be pre-configured based on experience. This quantization parameter range can be used as the target quantization parameter range, without any restrictions on it. For example, the quantization parameter range can be [a, b], where a represents the minimum value of the quantization parameter (minQP) and b represents the maximum value of the quantization parameter (maxQP). The maximum value of the quantization parameter b is usually greater than the minimum value of the quantization parameter a.
[0123] In one possible implementation, the quantization parameter range of the previous adjustment cycle can be adjusted, and the adjusted quantization parameter range can be used as the target quantization parameter range.
[0124] In one possible implementation, the range of quantization parameters can also be adjusted in each short period, and the adjusted range of quantization parameters can be used as the target range of quantization parameters for the current adjustment period.
[0125] Of course, the above are just a few examples, and there is no limitation on the range of quantization parameters for this target.
[0126] Step S33: Determine the actual bit rate corresponding to the initial quantization parameters within the target quantization parameter range.
[0127] For example, after obtaining the target quantization parameter range corresponding to the current adjustment period, a quantization parameter can be selected from the target quantization parameter range as the initial quantization parameter. There are no restrictions on this initial quantization parameter, as long as it is greater than or equal to the minimum quantization parameter and less than or equal to the maximum quantization parameter. After obtaining the initial quantization parameter, video data can be encoded based on it, and the actual bitrate during the encoding process can be obtained. When encoding video data using the initial quantization parameter, if the actual motion of the scene is complex, the actual bitrate during the encoding process will be higher; conversely, if the actual motion of the scene is simple, the actual bitrate during the encoding process will be lower. Clearly, during the encoding process of video data, the actual bitrate corresponding to the initial quantization parameter can be statistically analyzed, and then the initial quantization parameter can be adjusted based on the actual bitrate.
[0128] Step S34: If the actual bitrate corresponding to the quantization parameter (i.e., the initial quantization parameter) of the current adjustment period is greater than the variable adjustment bitrate corresponding to the current adjustment period, the quantization parameter of the current adjustment period can be increased to obtain the target quantization parameter of the current adjustment period. Alternatively, if the actual bitrate corresponding to the quantization parameter of the current adjustment period is less than the variable adjustment bitrate corresponding to the current adjustment period, the quantization parameter of the current adjustment period can be decreased to obtain the target quantization parameter of the current adjustment period.
[0129] For example, if the actual bitrate is greater than the variable scalable bitrate, the initial quantization parameter is increased; if the increased quantization parameter is within the target quantization parameter range, it is used as the target quantization parameter; if the increased quantization parameter is not within the target quantization parameter range (i.e., the increased quantization parameter is greater than the maximum quantization parameter value within the target quantization parameter range), the maximum quantization parameter value within the target quantization parameter range is used as the target quantization parameter. If the actual bitrate is less than the variable scalable bitrate, the initial quantization parameter is decreased; if the decreased quantization parameter is within the target quantization parameter range, it is used as the target quantization parameter; if the decreased quantization parameter is not within the target quantization parameter range (i.e., the decreased quantization parameter is less than the minimum quantization parameter value within the target quantization parameter range), the minimum quantization parameter value within the target quantization parameter range is used as the target quantization parameter.
[0130] For example, during the encoding of video data using initial quantization parameters, the actual bitrate can be compared with the variable quantization bitrate (since the variable quantization bitrate changes dynamically, the actual bitrate is compared with the variable quantization bitrate at the current moment). If the actual bitrate is greater than the variable quantization bitrate, the initial quantization parameter is increased, and the increased quantization parameter is used as the target quantization parameter. If the actual bitrate is less than the variable quantization bitrate, the initial quantization parameter is decreased, and the decreased quantization parameter is used as the target quantization parameter.
[0131] During the adjustment of the initial quantization parameter, if the adjusted quantization parameter is greater than the maximum value of the quantization parameter, then the maximum value of the quantization parameter is used as the target quantization parameter. If the adjusted quantization parameter is less than the minimum value of the quantization parameter, then the minimum value of the quantization parameter is used as the target quantization parameter. In other words, the initial quantization parameter needs to be adjusted within the target quantization parameter range [minQP, maxQP]. When the initial quantization parameter is adjusted to minQP or maxQP, the initial quantization parameter will no longer be adjusted, regardless of the relationship between the actual bitrate and the variable adjustable bitrate.
[0132] After obtaining the target quantization parameters, video data can be encoded based on these parameters to obtain the actual bitrate during encoding. The target quantization parameters can then be adjusted based on this actual bitrate. For example, if the actual bitrate is greater than the variable bitrate, the target quantization parameters are increased; if the increased quantization parameters are within the target quantization parameter range, the target quantization parameters are determined based on the increased quantization parameters; if the increased quantization parameters are not within the target quantization parameter range, the target quantization parameters are determined based on the maximum value of the quantization parameters within the target quantization parameter range. Conversely, if the actual bitrate is less than the variable bitrate, the target quantization parameters are decreased; if the decreased quantization parameters are within the target quantization parameter range, the target quantization parameters are determined based on the decreased quantization parameters; if the decreased quantization parameters are not within the target quantization parameter range, the target quantization parameters are determined based on the minimum value of the quantization parameters within the target quantization parameter range.
[0133] By analogy, the target quantization parameters can be continuously adjusted, and the video data can be encoded based on the adjusted target quantization parameters, so that the actual bitrate approaches the variable adjustable bitrate. That is, the quantization parameters are adjusted between minQP and maxQP to make the actual bitrate close to the variable adjustable bitrate corresponding to the current scene motion level.
[0134] Step S35: Encode the video data based on the target quantization parameters within the current adjustment period.
[0135] During the encoding process of video data, the target quantization parameters can be adjusted continuously based on the actual bitrate during the encoding process and the variable adjustment bitrate corresponding to the current adjustment cycle, and the above process can be repeated continuously.
[0136] When the actual bitrate is higher than the variable bitrate, the quantization parameter is adjusted upwards until it approaches the variable bitrate. Once the quantization parameter is adjusted to its maximum value (maxQP), it is clamped and no further adjustment is made. When the actual bitrate is lower than the variable bitrate, the quantization parameter is adjusted downwards until it approaches the variable bitrate. Once the quantization parameter is adjusted to its minimum value (minQP), it is clamped and no further adjustment is made.
[0137] Fourth, scenario change compatibility. For example, assuming the environment changes cyclically over long periods, when the scenario changes compared to previous long periods, it will affect the new long-term encoding. In this case, triggering a scenario change allows the new long period to be used as the first long period, and the above encoding process can be repeated. For instance, after 10 long periods, if a scenario change is triggered, the 11th long period can be used as the first long period, the 12th long period as the second long period, and so on, repeating the above encoding process.
[0138] In one possible implementation, the following steps can be used to determine whether the scenario has changed:
[0139] Step S41: Within the current adjustment period, after encoding the video data based on the target quantization parameters, determine the second quantization parameter corresponding to the current adjustment period based on the size of each encoded image within the current adjustment period, the actual quantization parameters, and the total encoding length of the current adjustment period. The second quantization parameter represents the average quantization parameter of the current adjustment period when the frame size is used as the weight. The method for determining the second quantization parameter is similar to that for determining the first quantization parameter, see step S11, and will not be repeated here.
[0140] Step S42: Based on the second quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change, determine the normalized adjustment coefficient corresponding to the current adjustment period.
[0141] For example, step S42 can be referred to step S12, and will not be repeated here.
[0142] Step S43: Normalize the total length of the code for the current adjustment period based on the normalized adjustment coefficient corresponding to the current adjustment period to obtain the normalized length of the current adjustment period.
[0143] In one possible implementation, the normalized length of the current adjustment period can be determined using the following formula (9). Of course, the following formula (9) is just an example and is not a limitation.
[0144] X = A * (1 + 0.1225) (QPa-33) Formula (9)
[0145] In formula (9), (1+0.1225) (QPa-33) The normalized adjustment coefficient corresponding to the current adjustment period is represented by QPa, the second quantization parameter corresponding to the current adjustment period is represented by 33, the configured baseline quantization parameter value is represented by 1.1225, the bit rate change value caused by each change in quantization parameter is represented by A, the total coding length of the current adjustment period is represented by X, and the normalized length of the current adjustment period is represented by X.
[0146] Step S44: Select one reference adjustment period from each of the previous M long periods of the current long period to obtain the M reference adjustment periods corresponding to the current adjustment period. M can be a positive integer.
[0147] For example, taking M as 3, the reference adjustment period corresponding to the current adjustment period is selected from the first long period before the current long period, the reference adjustment period corresponding to the current adjustment period is selected from the second long period before the current long period, and the reference adjustment period corresponding to the current adjustment period is selected from the third long period before the current long period. The selection method can be found in step S14, and will not be repeated here.
[0148] Step S45: Determine the average length of the normalized length of the M reference adjustment cycles.
[0149] For example, for each reference adjustment period, the normalized length of that reference adjustment period can be determined. The determination method is described in steps S41-S43 and will not be repeated here. After obtaining the normalized length of each reference adjustment period, the average length of these normalized lengths can be determined. For example, the average length of the normalized lengths of M reference adjustment periods can be determined using the following formula.
[0150] Where, L*(1+0.1225) (QPl-33) Q*(1+0.1225) (QPq-33) And N*(1+0.1225) (QPn-33) Let M represent the normalized length of the M reference adjustment periods, and Y represent the average length of the normalized length.
[0151] Step S46: If the percentage change between the normalized length (e.g., normalized length X) and the average length (e.g., average length Y) of the current adjustment period is greater than the first threshold, then increase the scenario change score. The percentage change may be an increase in X and Y, or it may be a decrease in X and Y.
[0152] In one possible implementation, the first threshold can be a single value. When the percentage change is greater than the first threshold, the scene change score is incremented by 1; when the percentage change is not greater than the first threshold, the scene change score remains unchanged. Alternatively, the first threshold can be multiple values. These multiple values control the scene change score to increase as the percentage change increases, such as two or three values. Taking values 1 and 2 as an example, if value 1 is less than value 2, the scene change score remains unchanged when the percentage change is not greater than value 1; when the percentage change is greater than value 1 but not greater than value 2, the scene change score is incremented by 1; and when the percentage change is greater than value 2, the scene change score is incremented by 2.
[0153] For example, the initial value of the scene change score is 0. Starting from the 4th long cycle (i.e., starting from the M+1th long cycle), for each adjustment cycle, when the adjustment cycle is the current adjustment cycle, the scene change score can be updated through steps S41-S46. The scene change score may remain unchanged or may increase, such as by adding 1 to the scene change score.
[0154] Step S47: After each increase in the scene change score, if the scene change score is greater than the second threshold, a scene change will be triggered, updating the next long cycle of the current long cycle to the first long cycle, and repeating the above process starting from the first long cycle. If the scene change score is not greater than the second threshold, the next long cycle of the current long cycle will not be updated to the first long cycle.
[0155] Based on the same concept as the methods described above, this application proposes a video data encoding apparatus, see [link to relevant documentation]. Figure 5 The diagram shows the structure of the device. The video data encoding process is divided into multiple long cycles, and each long cycle is further divided into K adjustment cycles, where K is greater than 1. The device includes:
[0156] Processing module 51 is used, during the encoding process of video data, for the current adjustment period within the current long period, if the current long period is not the first long period in the encoding process of video data, to select a reference adjustment period from the previous long period, wherein the position of the reference adjustment period in the previous long period is the same as the position of the current adjustment period in the current long period; and to determine the target bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period; wherein the target bitrate represents the expected average bitrate within the current adjustment period; determining module 52 is used to determine the target quantization parameter of the current adjustment period based on the target bitrate; and encoding module 53 is used to encode the video data within the current adjustment period based on the target quantization parameter.
[0157] For example, when the processing module 51 determines the target bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period, it specifically performs the following operations: normalizes the actual bitrate corresponding to each adjustment period within the previous long period to obtain the normalized bitrate corresponding to each adjustment period; determines a scaling factor based on the normalized bitrate corresponding to the actual bitrate corresponding to the reference adjustment period and the sum of the normalized bitrates corresponding to all adjustment periods within the previous long period; and determines the target bitrate corresponding to the current adjustment period based on the long period bitrate, the long period duration, and the scaling factor; wherein, the long period bitrate represents the expected average bitrate within the long period, the long period bitrate corresponding to all long periods is a fixed value, and the long period duration represents the total duration of the long period.
[0158] For example, when the processing module 51 normalizes the actual bitrate corresponding to each adjustment period within the previous long period to obtain the normalized bitrate corresponding to each adjustment period, it specifically performs the following steps: For each adjustment period within the previous long period, based on the size of each encoded image and the actual quantization parameter within the adjustment period, as well as the total encoding length of the adjustment period, it determines a first quantization parameter corresponding to the adjustment period, where the first quantization parameter represents the average quantization parameter of the adjustment period with frame size as the weight; based on the first quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change, it determines a normalized adjustment coefficient corresponding to the adjustment period; based on the normalized adjustment coefficient corresponding to the adjustment period, it performs a normalization operation on the actual bitrate corresponding to the adjustment period to obtain the normalized bitrate corresponding to the adjustment period.
[0159] For example, when the processing module 51 determines the first quantization parameter corresponding to the adjustment period based on the size of each encoded image within the adjustment period, the actual quantization parameters, and the total encoding length of the adjustment period, it specifically uses the following formula to determine the first quantization parameter corresponding to the adjustment period:
[0160]
[0161] Where A / QP represents the first quantization parameter corresponding to the adjustment period, QP1 represents the actual quantization parameter of the first frame encoded image within the adjustment period, FRM1 represents the size of the first frame encoded image within the adjustment period, QPm represents the actual quantization parameter of the m-th frame encoded image within the adjustment period, FRMm represents the size of the m-th frame encoded image within the adjustment period, and X represents the total encoding length of the adjustment period.
[0162] For example, when the processing module 51 determines the normalized adjustment coefficient corresponding to the adjustment period based on the first quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change, it specifically uses the following formula to determine the normalized adjustment coefficient corresponding to the adjustment period:
[0163] R = p (A / QP-s)
[0164] Where R represents the normalized adjustment coefficient corresponding to the adjustment period, p represents the bitrate change caused by each change in quantization parameter (a pre-configured value), A / QP represents the first quantization parameter corresponding to the adjustment period, and s represents the configured baseline quantization parameter value (a pre-configured value).
[0165] For example, when the processing module 51 normalizes the actual bitrate corresponding to the adjustment period based on the normalized adjustment coefficient corresponding to the adjustment period, the normalized bitrate corresponding to the adjustment period is specifically determined by: using the following formula to determine the normalized bitrate corresponding to the adjustment period:
[0166] bpaA=bps1*R
[0167] Where R represents the normalized adjustment coefficient corresponding to the adjustment period, bps1 represents the actual bit rate corresponding to the adjustment period, and bpsA represents the normalized bit rate corresponding to the adjustment period.
[0168] For example, when determining the scaling factor based on the normalized bitrate corresponding to the actual bitrate of the reference adjustment period and the sum of the normalized bitrates corresponding to all adjustment periods within the previous long period, the processing module 51 specifically uses the following formula to determine the scaling factor corresponding to the adjustment period:
[0169]
[0170] Where C represents the proportional coefficient corresponding to the adjustment period, bpsA represents the normalized bit rate corresponding to the actual bit rate of the reference adjustment period, and bpsA+bpsB+…+bpsZ represents the sum of the normalized bit rates corresponding to all adjustment periods within the previous long period.
[0171] For example, when the processing module 51 determines the target bitrate corresponding to the current adjustment period based on the long period bitrate, the long period duration and the proportional coefficient, it is specifically used to: determine the target bitrate corresponding to the current adjustment period using the following formula: bpsa=Y*T*C;
[0172] Where Y represents the long-cycle bitrate, which is a pre-configured value or a value obtained by an algorithm, T represents the long-cycle duration, C represents the proportional coefficient, and bpsa represents the target bitrate corresponding to the current adjustment cycle.
[0173] For example, when the processing module 51 determines the target bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period, it is specifically used to: determine the initial bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period; determine the initial bitrate as the target bitrate corresponding to the current adjustment period; or, if the current long period is the second long period of the video data encoding process, then determine the initial bitrate as the target bitrate corresponding to the current adjustment period; if the current long period is not the second long period of the video data encoding process, then determine the quotient of the target bitrate corresponding to the reference adjustment period and the actual bitrate corresponding to the reference adjustment period as the bitrate coefficient, and determine the product of the initial bitrate and the bitrate coefficient as the target bitrate corresponding to the current adjustment period.
[0174] For example, before determining the target quantization parameter of the current adjustment period based on the target bitrate, the processing module 51 is further configured to: if the current long period is the first long period in the encoding process of video data, determine the target bitrate corresponding to the current adjustment period based on the configured long period bitrate; wherein, if the current adjustment period is the first adjustment period within the current long period, determine the long period bitrate as the target bitrate corresponding to the current adjustment period; and / or, if the current adjustment period is not the first adjustment period within the current long period, determine the target bitrate corresponding to the current adjustment period based on the long period bitrate, the long period duration, the total amount of actual encoded bits before the current adjustment period, and the remaining duration of the current long period.
[0175] For example, when the processing module 51 determines the target bit rate corresponding to the current adjustment period based on the long period bit rate, the long period duration, the actual total number of encoded bits before the current adjustment period, and the remaining duration of the current long period, it is specifically used to: determine the target bit rate corresponding to the current adjustment period based on the following formula: target bit rate = [long period bit rate * long period duration - actual total number of encoded bits] / remaining duration of the long period.
[0176] For example, the processing module 51 is further configured to: select one reference adjustment period from each of the previous M long periods of the current long period; determine the average length of the normalized length of the M reference adjustment periods; if the percentage change between the normalized length of the current adjustment period and the average length is greater than a first threshold, then increase the scene change score; if the scene change score is greater than a second threshold, then update the next long period of the current long period to the first long period; when determining the normalized length of the reference adjustment period or the current adjustment period, the processing module 51 is specifically configured to: determine the second quantization parameter corresponding to the adjustment period based on the size of each encoded image and the actual quantization parameter within the adjustment period, and the total encoding length of the adjustment period, wherein the second quantization parameter represents the average quantization parameter of the adjustment period with frame size as the weight; determine the normalized adjustment coefficient corresponding to the adjustment period based on the second quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by the change of each quantization parameter; and perform a normalization operation on the total encoding length of the adjustment period based on the normalized adjustment coefficient to obtain the normalized length of the adjustment period.
[0177] For example, when determining the target quantization parameter of the current adjustment period based on the target bitrate, the determining module 52 is specifically used to: determine the variable adjustment bitrate corresponding to the current adjustment period based on the target bitrate corresponding to the current adjustment period and the scene motion level of the current adjustment period; wherein, the variable adjustment bitrate is less than or equal to the target bitrate; when the scene motion level is higher, the variable adjustment bitrate is higher; if the actual bitrate corresponding to the quantization parameter of the current adjustment period is greater than the variable adjustment bitrate, then the quantization parameter of the current adjustment period is increased to obtain the target quantization parameter of the current adjustment period; if the actual bitrate corresponding to the quantization parameter of the current adjustment period is less than the variable adjustment bitrate, then the quantization parameter of the current adjustment period is decreased to obtain the target quantization parameter of the current adjustment period.
[0178] For example, when the determining module 52 determines the variable adjustment bitrate corresponding to the current adjustment period based on the target bitrate corresponding to the current adjustment period and the scene motion level of the current adjustment period, it is specifically used to: determine the configured scaling factor corresponding to the scene motion level, wherein the scaling factor is greater than 0 and less than or equal to 1, and the scaling factor is larger when the scene motion level is larger; and determine the variable adjustment bitrate by multiplying the scaling factor and the target bitrate.
[0179] Based on the same concept as the above method, this application proposes an electronic device, see [link to previous application]. Figure 6As shown, the electronic device includes a processor 61 and a machine-readable storage medium 62, the machine-readable storage medium 62 storing machine-executable instructions that can be executed by the processor 61; the processor 61 is used to execute the machine-executable instructions to implement the video data encoding method disclosed in the above example of this application.
[0180] Based on the same concept as the above method, this application also provides a machine-readable storage medium storing a plurality of computer instructions, which, when executed by a processor, can implement the video data encoding method disclosed in the above examples of this application.
[0181] The aforementioned machine-readable storage medium can be any electronic, magnetic, optical, or other physical storage device that can contain or store information, such as executable instructions, data, etc. For example, machine-readable storage media can be: RAM (Random Access Memory), volatile memory, non-volatile memory, flash memory, storage drives (such as hard disk drives), solid-state drives, any type of storage disk (such as optical discs, DVDs, etc.), or similar storage media, or combinations thereof.
[0182] The systems, devices, modules, or units described in the above embodiments can be implemented by a computer entity or by a product with a certain function. A typical implementation device is a computer, which can be a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email sending and receiving device, game console, tablet computer, wearable device, or any combination of these devices.
[0183] For ease of description, the above devices are described separately by function as various units. Of course, in implementing this application, the functions of each unit can be implemented in one or more software and / or hardware.
[0184] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0185] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0186] Furthermore, these computer program instructions can also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in the process. Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0187] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0188] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for encoding video data, characterized in that, The video data encoding process is divided into multiple long periods, each long period is further divided into K adjustment periods, where K is greater than 1. Fixed bitrate encoding is used at the long period scale, and variable bitrate encoding is used within each adjustment period of the long period. The method includes: During the encoding of video data, if the current long period is not the first long period in the encoding process of the video data, a reference adjustment period is selected from the previous long period. The position of the reference adjustment period in the previous long period is the same as the position of the current adjustment period in the current long period. The target bitrate for the current adjustment period is determined based on the actual bitrate corresponding to the reference adjustment period; wherein the target bitrate represents the expected average bitrate within the current adjustment period; wherein, the actual bitrate corresponding to each adjustment period within the previous long period is normalized to obtain the normalized bitrate for each adjustment period; a scaling factor is determined based on the normalized bitrate corresponding to the actual bitrate of the reference adjustment period and the sum of the normalized bitrates corresponding to all adjustment periods within the previous long period; the target bitrate for the current adjustment period is determined based on the long-period bitrate, the long-period duration, and the scaling factor; wherein, the long-period bitrate represents the expected average bitrate within the long period, the long-period bitrate for all long periods is a fixed value, and the long-period duration represents the total duration of the long period; The target quantization parameters for the current adjustment period are determined based on the target bitrate. During the current adjustment period, video data is encoded based on the target quantization parameters.
2. The method according to claim 1, characterized in that, The step of normalizing the actual bitrate corresponding to each adjustment cycle within the preceding long period to obtain the normalized bitrate for each adjustment cycle includes: for each adjustment cycle within the preceding long period... Based on the size of each encoded image and the actual quantization parameters within the adjustment period, as well as the total encoding length of the adjustment period, a first quantization parameter corresponding to the adjustment period is determined. The first quantization parameter is used to represent the average quantization parameter of the adjustment period when the frame size is used as the weight. Based on the first quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change, the normalized adjustment coefficient corresponding to the adjustment period is determined. Based on the normalized adjustment coefficient corresponding to the adjustment period, the actual bitrate corresponding to the adjustment period is normalized to obtain the normalized bitrate corresponding to the adjustment period.
3. The method according to claim 2, characterized in that, The determination of the first quantization parameter corresponding to the adjustment period based on the size and actual quantization parameters of each encoded image within the adjustment period, and the total encoding length of the adjustment period, includes: The first quantization parameter corresponding to this adjustment period is determined using the following formula: Where A / QP represents the first quantization parameter corresponding to the adjustment period, QP1 represents the actual quantization parameter of the first frame encoded image within the adjustment period, FRM1 represents the size of the first frame encoded image within the adjustment period, QPm represents the actual quantization parameter of the m-th frame encoded image within the adjustment period, FRMm represents the size of the m-th frame encoded image within the adjustment period, and X represents the total encoding length of the adjustment period.
4. The method according to claim 2, characterized in that, The step of determining the normalized adjustment coefficient corresponding to the adjustment period based on the first quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change includes: The normalized adjustment coefficient corresponding to this adjustment period is determined using the following formula: Where R represents the normalized adjustment coefficient corresponding to the adjustment period, p represents the bitrate change caused by each change in quantization parameter (a pre-configured value), A / QP represents the first quantization parameter corresponding to the adjustment period, and s represents the configured baseline quantization parameter value (a pre-configured value).
5. The method according to claim 2, characterized in that, The step of normalizing the actual bitrate corresponding to the adjustment period based on the normalized adjustment coefficient to obtain the normalized bitrate corresponding to the adjustment period includes: The normalized bitrate corresponding to this adjustment period is determined using the following formula: Where R represents the normalized adjustment coefficient corresponding to the adjustment period. This indicates the actual bitrate corresponding to the adjustment period. This represents the normalized code rate corresponding to the adjustment period.
6. The method according to claim 1, characterized in that, The determination of the scaling factor based on the normalized bitrate corresponding to the actual bitrate of the reference adjustment period and the sum of the normalized bitrates corresponding to all adjustment periods within the previous long period includes: The proportional coefficient corresponding to the adjustment period is determined using the following formula: Where C represents the proportional coefficient corresponding to the adjustment period. This represents the normalized bitrate corresponding to the actual bitrate corresponding to the reference adjustment period. This represents the sum of the normalized code rates corresponding to all adjustment cycles within the preceding long cycle.
7. The method according to claim 1, characterized in that, The step of determining the target bitrate corresponding to the current adjustment period based on the long-period bitrate, the long-period duration, and the proportional coefficient includes: The target bitrate corresponding to the current adjustment period is determined using the following formula: in, The long-period bitrate represents a pre-configured value or a value obtained using an algorithm, where T represents the long-period duration and C represents the scaling factor. This indicates the target bitrate corresponding to the current adjustment period.
8. The method according to any one of claims 1-7, characterized in that, Determining the target bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period includes: The initial bitrate corresponding to the current adjustment period is determined based on the actual bitrate corresponding to the reference adjustment period. The initial bitrate is determined as the target bitrate corresponding to the current adjustment period; or, If the current long period is the second long period in the video data encoding process, then the initial bitrate is determined as the target bitrate corresponding to the current adjustment period; if the current long period is not the second long period in the video data encoding process, then the quotient of the target bitrate corresponding to the reference adjustment period and the actual bitrate corresponding to the reference adjustment period is determined as the bitrate coefficient, and the product of the initial bitrate and the bitrate coefficient is determined as the target bitrate corresponding to the current adjustment period.
9. The method according to any one of claims 1-7, characterized in that, Before determining the target quantization parameter of the current adjustment period based on the target bitrate, the method further includes: If the current long period is the first long period in the video data encoding process, then the target bitrate corresponding to the current adjustment period is determined based on the configured long period bitrate. Wherein, if the current adjustment period is the first adjustment period within the current long period, then the long period bitrate is determined as the target bitrate corresponding to the current adjustment period; and / or, If the current adjustment period is not the first adjustment period within the current long period, then the target bit rate corresponding to the current adjustment period is determined based on the long period bit rate, the long period duration, the total amount of actual encoded bits before the current adjustment period, and the remaining duration of the current long period.
10. The method according to claim 9, characterized in that, The step of determining the target bitrate corresponding to the current adjustment period based on the long-period bitrate, the long-period duration, the actual total number of encoded bits before the current adjustment period, and the remaining duration of the current long period includes: The target bitrate corresponding to the current adjustment period is determined based on the following formula: Target bitrate = [Long period bitrate × Long period duration - Total actual encoded bits] / Remaining duration of the long period.
11. The method according to any one of claims 1-7, characterized in that, After encoding the video data based on the target quantization parameters within the current adjustment period, the method further includes: Select one reference adjustment period from each of the M previous long periods of the current long period; determine the average length of the normalized length of the M reference adjustment periods; if the percentage change between the normalized length of the current adjustment period and the average length is greater than a first threshold, then increase the scene change score; if the scene change score is greater than a second threshold, then update the next long period of the current long period to the first long period. The methods for determining the normalized length of the reference adjustment period or the current adjustment period include: Based on the size of each encoded image and the actual quantization parameters within the adjustment period, as well as the total encoding length of the adjustment period, a second quantization parameter corresponding to the adjustment period is determined. The second quantization parameter represents the average quantization parameter of the adjustment period when the frame size is used as the weight. Based on the second quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change, a normalized adjustment coefficient corresponding to the adjustment period is determined. Based on the normalized adjustment coefficient, the total encoding length of the adjustment period is normalized to obtain the normalized length of the adjustment period.
12. The method according to any one of claims 1-7, characterized in that, Determining the target quantization parameter for the current adjustment period based on the target bitrate includes: The variable adjustment bitrate corresponding to the current adjustment period is determined based on the target bitrate and the scene motion level of the current adjustment period; wherein, the variable adjustment bitrate is less than or equal to the target bitrate; and the higher the scene motion level, the higher the variable adjustment bitrate. If the actual bit rate corresponding to the quantization parameter of the current adjustment period is greater than the variable adjustment bit rate, then the quantization parameter of the current adjustment period is increased to obtain the target quantization parameter of the current adjustment period. If the actual bitrate corresponding to the quantization parameter of the current adjustment period is less than the variable adjustment bitrate, then the quantization parameter of the current adjustment period is reduced to obtain the target quantization parameter of the current adjustment period.
13. The method according to claim 12, characterized in that, The step of determining the variable adjustment bitrate corresponding to the current adjustment period based on the target bitrate and the scene motion level of the current adjustment period includes: Determine the configured scaling factor corresponding to the scene motion level. The scaling factor is greater than 0 and less than or equal to 1. The larger the scene motion level, the larger the scaling factor. The product of the scaling factor and the target bit rate is determined as the variable adjustment bit rate.
14. A video data encoding apparatus, characterized in that, The video data encoding process is divided into multiple long periods, each long period is further divided into K adjustment periods, where K is greater than 1. Fixed bitrate encoding is used at the long period scale, and variable bitrate encoding is used within each adjustment period of the long period. The device includes: The processing module is configured to, during the video data encoding process, for the current adjustment period within the current long period, if the current long period is not the first long period in the video data encoding process, select a reference adjustment period from the previous long period, wherein the position of the reference adjustment period in the previous long period is the same as the position of the current adjustment period in the current long period; and determine the target bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period; wherein the target bitrate represents the expected average bitrate within the current adjustment period; The determination module is used to determine the target quantization parameters of the current adjustment period based on the target bit rate; The encoding module is used to encode video data based on the target quantization parameters within the current adjustment cycle; Specifically, when the processing module determines the target bitrate for the current adjustment period based on the actual bitrate corresponding to the reference adjustment period, it performs the following steps: normalizes the actual bitrate for each adjustment period within the previous long period to obtain a normalized bitrate for each adjustment period; determines a scaling factor based on the normalized bitrate corresponding to the actual bitrate of the reference adjustment period and the sum of the normalized bitrates for all adjustment periods within the previous long period; and determines the target bitrate for the current adjustment period based on the long-period bitrate, the long-period duration, and the scaling factor. The long-period bitrate represents the expected average bitrate within the long period, all long-period bitrates are fixed values, and the long-period duration represents the total duration of the long period.
15. The apparatus according to claim 14, Its features are, Specifically, when the processing module normalizes the actual bitrate corresponding to each adjustment period within the preceding long period to obtain the normalized bitrate for each adjustment period, it performs the following steps: For each adjustment period within the preceding long period, based on the size of each encoded image within that adjustment period, the actual quantization parameters, and the total encoding length of that adjustment period, it determines a first quantization parameter corresponding to that adjustment period. The first quantization parameter represents the average quantization parameter of that adjustment period when frame size is used as the weight. Based on the first quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change, it determines a normalized adjustment coefficient corresponding to that adjustment period. Based on the normalized adjustment coefficient corresponding to that adjustment period, it performs a normalization operation on the actual bitrate corresponding to that adjustment period to obtain the normalized bitrate for that adjustment period. Specifically, when the processing module determines the first quantization parameter corresponding to the adjustment period based on the size of each encoded image within the adjustment period, the actual quantization parameters, and the total encoding length of the adjustment period, it uses the following formula to determine the first quantization parameter corresponding to the adjustment period: Where A / QP represents the first quantization parameter corresponding to the adjustment period, QP1 represents the actual quantization parameter of the first frame encoded image within the adjustment period, FRM1 represents the size of the first frame encoded image within the adjustment period, QPm represents the actual quantization parameter of the m-th frame encoded image within the adjustment period, FRMm represents the size of the m-th frame encoded image within the adjustment period, and X represents the total encoding length of the adjustment period. Specifically, when the processing module determines the normalized adjustment coefficient corresponding to the adjustment period based on the first quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change, it uses the following formula to determine the normalized adjustment coefficient corresponding to the adjustment period: Where R represents the normalized adjustment coefficient corresponding to the adjustment period, p represents the bit rate change caused by each change in quantization parameter, which is a pre-configured value, A / QP represents the first quantization parameter corresponding to the adjustment period, and s represents the configured baseline quantization parameter value, which is a pre-configured value. Specifically, the processing module normalizes the actual bitrate corresponding to the adjustment period based on the normalized adjustment coefficient to obtain the normalized bitrate corresponding to the adjustment period. This is achieved by using the following formula to determine the normalized bitrate corresponding to the adjustment period: Where R represents the normalized adjustment coefficient corresponding to the adjustment period. This indicates the actual bitrate corresponding to the adjustment period. This represents the normalized code rate corresponding to the adjustment period; Specifically, when determining the scaling factor based on the normalized bitrate corresponding to the actual bitrate of the reference adjustment period and the sum of the normalized bitrates of all adjustment periods within the previous long period, the processing module uses the following formula to determine the scaling factor corresponding to the adjustment period: Where C represents the proportional coefficient corresponding to the adjustment period. This represents the normalized bitrate corresponding to the actual bitrate corresponding to the reference adjustment period. This represents the sum of the normalized code rates corresponding to all adjustment cycles within the preceding long cycle; Specifically, when the processing module determines the target bitrate corresponding to the current adjustment period based on the long-period bitrate, the long-period duration, and the proportional coefficient, it uses the following formula to determine the target bitrate corresponding to the current adjustment period: in, The long-period bitrate represents a pre-configured value or a value obtained using an algorithm, where T represents the long-period duration and C represents the scaling factor. This indicates the target bitrate corresponding to the current adjustment period; Specifically, when the processing module determines the target bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period, it is used to: determine the initial bitrate corresponding to the current adjustment period based on the actual bitrate corresponding to the reference adjustment period; determine the initial bitrate as the target bitrate corresponding to the current adjustment period; or, if the current long period is the second long period of the video data encoding process, then determine the initial bitrate as the target bitrate corresponding to the current adjustment period; if the current long period is not the second long period of the video data encoding process, then determine the quotient of the target bitrate corresponding to the reference adjustment period and the actual bitrate corresponding to the reference adjustment period as the bitrate coefficient, and determine the product of the initial bitrate and the bitrate coefficient as the target bitrate corresponding to the current adjustment period. Before determining the target quantization parameter of the current adjustment period based on the target bitrate, the processing module further performs the following steps: if the current long period is the first long period in the video data encoding process, then determine the target bitrate corresponding to the current adjustment period based on the configured long period bitrate; if the current adjustment period is the first adjustment period within the current long period, then determine the long period bitrate as the target bitrate corresponding to the current adjustment period; and / or, if the current adjustment period is not the first adjustment period within the current long period, then determine the target bitrate corresponding to the current adjustment period based on the long period bitrate, the long period duration, the total actual encoded bits before the current adjustment period, and the remaining duration of the current long period. Specifically, when the processing module determines the target bitrate corresponding to the current adjustment period based on the long-period bitrate, the long-period duration, the actual total number of encoded bits before the current adjustment period, and the remaining duration of the current long period, it is used to: determine the target bitrate corresponding to the current adjustment period based on the following formula: target bitrate = [long-period bitrate × long-period duration - actual total number of encoded bits] / remaining duration of the long period; The processing module is further configured to: select one reference adjustment period from each of the previous M long periods of the current long period; determine the average length of the normalized length of the M reference adjustment periods; if the percentage change between the normalized length of the current adjustment period and the average length is greater than a first threshold, then increase the scene change score; if the scene change score is greater than a second threshold, then update the next long period of the current long period to the first long period; specifically, when determining the normalized length of the reference adjustment period or the current adjustment period, the processing module is configured to: determine the second quantization parameter corresponding to the adjustment period based on the size of each encoded image and the actual quantization parameter within the adjustment period, and the total encoding length of the adjustment period, wherein the second quantization parameter represents the average quantization parameter of the adjustment period with frame size as the weight; determine the normalized adjustment coefficient corresponding to the adjustment period based on the second quantization parameter, the configured baseline quantization parameter value, and the bitrate change value caused by each quantization parameter change; and perform a normalization operation on the total encoding length of the adjustment period based on the normalized adjustment coefficient to obtain the normalized length of the adjustment period. Specifically, when the determining module determines the target quantization parameter of the current adjustment period based on the target bitrate, it is used to: determine the variable adjustment bitrate corresponding to the current adjustment period based on the target bitrate and the scene motion level of the current adjustment period; wherein, the variable adjustment bitrate is less than or equal to the target bitrate; the higher the scene motion level, the higher the variable adjustment bitrate; if the actual bitrate corresponding to the quantization parameter of the current adjustment period is greater than the variable adjustment bitrate, then the quantization parameter of the current adjustment period is increased to obtain the target quantization parameter of the current adjustment period; if the actual bitrate corresponding to the quantization parameter of the current adjustment period is less than the variable adjustment bitrate, then the quantization parameter of the current adjustment period is decreased to obtain the target quantization parameter of the current adjustment period. Specifically, when the determining module determines the variable adjustment bitrate corresponding to the current adjustment period based on the target bitrate and the scene motion level of the current adjustment period, it is used to: determine the configured scaling factor corresponding to the scene motion level, wherein the scaling factor is greater than 0 and less than or equal to 1, and the scaling factor is larger when the scene motion level is larger; and determine the variable adjustment bitrate by multiplying the scaling factor and the target bitrate.
16. An electronic device, characterized in that, include: A processor and a machine-readable storage medium, the machine-readable storage medium storing machine-executable instructions that can be executed by the processor; The processor is configured to execute machine-executable instructions to implement the method according to any one of claims 1-13.
Citation Information
Patent Citations
Video data coding method, device and equipment
CN115379210A
Video data compression
US20010014120A1