Video coding quantization parameter updating method and device, electronic equipment and storage medium

CN122802677APending Publication Date: 2026-09-22GUANGDONG JIANGXINCHUANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611309553.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-09-22

AI Technical Summary

Technical Problem

这种事后调整导致整个GOP内的P帧必须经历从低QP到高QP的缓慢爬升过程

Benefits of technology

[0016]本申请的附加方面和优点将在下面的描述中部分给出,部分将从下面的描述中变得明显,或通过本申请的实践了解到。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122802677A_ABST
    Figure CN122802677A_ABST
Patent Text Reader

Abstract

The application discloses a video coding quantization parameter updating method and device, electronic equipment and a storage medium, and belongs to the technical field of video coding. The video coding quantization parameter updating method comprises the following steps: acquiring a target code rate and calculating a target quantization parameter frame by frame based on a reference quantization parameter, and obtaining an actual coding bit number after inputting hardware coding. If it is an intra-coded frame, the consumption ratio of the actual code rate to the target code rate is calculated. If the consumption ratio exceeds a first threshold value and the reference quantization parameter is less than the first threshold value, the reference quantization parameter is added by a first adjustment amount to generate a new reference quantization parameter. If the consumption ratio is lower than a second threshold value and the reference quantization parameter is greater than the second threshold value, the reference quantization parameter is subtracted by a preset second adjustment amount to generate a new reference quantization parameter. After the encoding of the intra-coded frame is completed, the reference quantization parameter is immediately readjusted based on the consumption ratio, so that the quality drift phenomenon of the subsequent predicted coding frame is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of video coding technology, and in particular to a method, apparatus, electronic device, and storage medium for updating video coding quantization parameters. Background Technology

[0002] In a Group of Pictures (GOP) coding structure, where an I-frame (Intra-coded Frame) is a keyframe, it typically consumes several times more bits than a P-frame. When the actual bit consumption of an I-frame far exceeds expectations (e.g., scene complexity causing the number of bits after encoding the I-frame to reach more than 30% of the GOP budget), the available bit budget for the remaining frames within the GOP is severely compressed.

[0003] Traditional methods perform statistical feedback only after the Group of Pictures (GOP) ends. They adjust the baseline QP of the current GOP by calculating the average QP (Quantization Parameter, ranging from 0-51, with higher values ​​indicating lower encoding quality and fewer actual bits output) of the previous GOP. This post-hoc adjustment forces P-frames within the entire GOP to undergo a slow climb from low to high QP. Because QP changes between adjacent frames are constrained by inter-frame smoothing constraints, this climb can last 10-20 frames, resulting in a visible gradual decrease in image quality, known as quality drift. Summary of the Invention

[0004] This application aims to address at least one of the technical problems existing in the prior art. To this end, this application proposes a video coding quantization parameter update method, apparatus, electronic device, and storage medium, which can immediately readjust the reference quantization parameters based on the consumption ratio after the intra-frame coded frame is encoded, thereby avoiding quality drift in subsequent predictive coded frames.

[0005] The video coding quantization parameter update method according to the first aspect of this application includes: Obtain the baseline quantization parameters; For each frame of the image group to be encoded, the target bitrate is obtained, and the target quantization parameters corresponding to the current frame are calculated based on the reference quantization parameters, wherein the image group to be encoded includes intra-coded frames; The target quantization parameters are input into the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits. If the current frame is an intra-coded frame, the consumption ratio is calculated based on the target bitrate and the actual number of encoded bits. When the consumption ratio is greater than a preset first ratio threshold and the benchmark quantization parameter is less than the first threshold, a first adjustment amount is determined based on the difference between the consumption ratio and the first ratio threshold, and the benchmark quantization parameter is added to the first adjustment amount to generate a new benchmark quantization parameter. When the consumption ratio is less than a preset second ratio threshold and the benchmark quantization parameter is greater than the second threshold, the benchmark quantization parameter is subtracted from the preset second adjustment amount to generate a new benchmark quantization parameter.

[0006] The video coding quantization parameter update method according to the embodiments of this application has at least the following beneficial effects: by obtaining the reference quantization parameter, a unified reference anchor point is provided for the calculation of the target quantization parameter of each frame in the image group to be encoded, thereby calculating the target quantization parameter corresponding to each frame in the image group to be encoded, and then inputting the target quantization parameter to the video coding hardware module for hardware coding, and feeding back the actual number of encoded bits required for the coding process; by using the actual number of encoded bits and the target bit rate, the consumption ratio of the intra-frame coded frame is calculated, and when the consumption ratio is greater than the first ratio threshold and the reference quantization parameter is less than the first threshold, the reference quantization parameter is added to the first adjustment amount to generate a new reference quantization parameter, that is, the reference quantization parameter is increased to reduce the actual number of encoded bits of the subsequent predicted coded frames, so as to avoid the phenomenon of image quality drift, that is, the image quality gradually decreases; and when the consumption ratio is less than the second ratio threshold and the reference quantization parameter is greater than the second threshold, the reference quantization parameter is subtracted from the second adjustment amount to generate a new reference quantization parameter, that is, the reference quantization parameter is decreased to increase the actual number of encoded bits of the subsequent predicted coded frames, so as to avoid the phenomenon of image quality drift, that is, the image quality gradually improves.

[0007] According to some embodiments of this application, the image group to be encoded further includes a predicted coded frame, and the acquisition of the reference quantization parameters includes: The number of bits per pixel is calculated based on the preset raw bit rate, the frame rate and resolution of the image group to be encoded; The initial quantization parameters are determined based on the number of bits per pixel, the resolution of the image group to be encoded, and the preset quantization parameter range. Based on the initial quantization parameters and the average value of the target quantization parameters of each predicted coding frame in the previous adjacent group of images to be encoded, the baseline quantization parameters are calculated.

[0008] According to some embodiments of this application, for each frame of the image group to be encoded, a target bitrate is obtained, and a target quantization parameter corresponding to the current frame is calculated based on the reference quantization parameter, wherein the image group to be encoded includes intra-coded frames, including: For each frame of the image group to be encoded, the target bit rate is obtained, and the target number of encoded bits is calculated based on the target bit rate; If the current frame is the intra-coded frame, the target quantization parameter is calculated based on the reference quantization parameter, the preset intra-frame offset, and the historical statistical feedback value. If the current frame is the first predicted coding frame in the group of images to be encoded, the target quantization parameter is calculated based on the baseline quantization parameter and the preset buffer fullness. If the current frame is one of a first number of consecutive predicted coding frames following the first predicted coding frame in the image group to be encoded, the target quantization parameter is calculated based on the ratio of the actual number of coding bits to the target number of coding bits corresponding to the previous adjacent frame of the current frame, and a preset asymmetric segmentation mapping table, wherein the asymmetric segmentation mapping table is characterized as the mapping relationship between the ratio and the adjustment amount of the target quantization parameter; If the current frame is a predicted coding frame in the image group to be encoded, excluding the first predicted coding frame and the first number of consecutive predicted coding frames after the first predicted coding frame, the target quantization parameter is calculated based on the target number of coding bits, the preset quadratic rate-distortion model, and the linear mean absolute difference prediction model.

[0009] According to some embodiments of this application, after inputting the target quantization parameters into the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits, the method further includes: The nominal number of encoded bits is calculated based on the original bit rate and the frame rate of the image group to be encoded. Obtain the actual quantization parameters corresponding to the current frame from the video encoding hardware module; When the actual quantization parameters corresponding to a second consecutive number of predicted coding frames are greater than a third preset threshold, and the actual number of coded bits is greater than the product of the nominal number of coded bits and a first preset coefficient, the target bit rate is multiplied by a second preset coefficient to obtain a new target bit rate. When the actual quantization parameters corresponding to a third consecutive number of predicted coding frames are less than a preset fourth threshold, and the actual number of coded bits is less than the product of the nominal number of coded bits and a preset third coefficient, the target bitrate is multiplied by the preset fourth coefficient to obtain a new target bitrate.

[0010] According to some embodiments of this application, after inputting the target quantization parameters into the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits, the method further includes: The difference between the actual number of encoded bits and the nominal number of encoded bits is used to obtain the buffer offset. The buffer fullness is added to the buffer deviation to obtain the new buffer fullness.

[0011] According to some embodiments of this application, after adding the buffer fullness to the buffer deviation to obtain a new buffer fullness, the method further includes: When the current frame is a predictive coded frame, if the buffer fullness is greater than the product of the target bit rate and the preset fifth coefficient, and the actual quantization parameter is greater than the sum of the reference quantization parameter and the preset third offset, then the reference quantization parameter is added to the preset third adjustment amount to generate a new reference quantization parameter.

[0012] According to some embodiments of this application, the target quantization parameters corresponding to the first predicted coding frame in the image group to be encoded, and the consecutive preset first number of predicted coding frames after the first predicted coding frame, are restricted to a first range defined by a preset first upper limit value and a preset first lower limit value. The target quantization parameters corresponding to the predicted coding frames other than the first predicted coding frame and the consecutive preset first number of predicted coding frames after the first predicted coding frame are restricted to a second range defined by a preset second upper limit value and a preset second lower limit value, wherein the first upper limit value is greater than the second upper limit value, and the first lower limit value is less than the second lower limit value.

[0013] According to a second aspect of this application, a video coding quantization parameter update apparatus includes: A frame preprocessing module is configured to acquire a reference quantization parameter; for each frame of the image group to be encoded, acquire the target bitrate, and calculate the target quantization parameter corresponding to the current frame based on the reference quantization parameter, wherein the image group to be encoded includes intra-coded frames; A hardware encoding module is configured to input the target quantization parameters into a video encoding hardware module for hardware encoding to obtain the actual number of encoded bits. A post-frame processing module is configured to: if the current frame is an intra-coded frame, calculate the consumption ratio based on the target bitrate and the actual number of encoded bits; when the consumption ratio is greater than a preset first ratio threshold and the reference quantization parameter is less than the first threshold, determine a first adjustment amount based on the difference between the consumption ratio and the first ratio threshold, and add the reference quantization parameter to the first adjustment amount to generate a new reference quantization parameter; when the consumption ratio is less than a preset second ratio threshold and the reference quantization parameter is greater than the second threshold, subtract the reference quantization parameter from the preset second adjustment amount to generate a new reference quantization parameter.

[0014] An electronic device according to a third aspect of this application includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the video coding quantization parameter update method described in the first aspect of this application.

[0015] According to a fourth aspect embodiment of the present application, a computer-readable storage medium stores a computer program that, when executed by a processor, implements the video coding quantization parameter update method described in the first aspect embodiment of the present application.

[0016] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0017] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating the steps of the video encoding quantization parameter update method according to an embodiment of this application. Figure 2 This is a schematic flowchart of step S101 in an embodiment of this application; Figure 3 This is a schematic flowchart of step S102 in an embodiment of this application; Figure 4 This is a flowchart of steps S401 to S404 in an embodiment of this application. Figure 5 This is a flowchart of steps S501 to S502 in an embodiment of this application. Figure 6 This is a flowchart of step S601 in an embodiment of this application; Figure 7 This is a schematic diagram of the video encoding quantization parameter update device according to an embodiment of this application; Figure 8 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation

[0018] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0019] In the description of this application, it should be understood that the orientation descriptions, such as up, down, front, back, left, right, etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this application.

[0020] In the description of this application, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0021] In the description of this application, unless otherwise expressly defined, terms such as "setup," "installation," and "connection" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this application in conjunction with the specific content of the technical solution.

[0022] Currently, in the GOP (Group of Pictures, a collection of consecutive coded frames, typically starting with an I-frame followed by several P-frames) coding structure, the I-frame (Intra-coded Frame), as a keyframe, usually consumes several times the number of bits as the P-frame (Predictive-coded Frame). When the actual bit consumption of the I-frame far exceeds expectations (for example, scene complexity causing the number of bits after I-frame encoding to reach more than 30% of the GOP budget), the available bit budget for the remaining frames within the GOP is severely compressed.

[0023] Traditional methods perform statistical feedback only after the Group of Pictures (GOP) ends. They adjust the baseline QP of the current GOP by calculating the average QP (Quantization Parameter, ranging from 0-51, with higher values ​​indicating lower encoding quality and fewer actual bits output) of the previous GOP. This post-hoc adjustment forces P-frames within the entire GOP to undergo a slow climb from low to high QP. Because QP changes between adjacent frames are constrained by inter-frame smoothing constraints, this climb can last 10-20 frames, resulting in a visible gradual decrease in image quality, known as quality drift.

[0024] Based on this, this application proposes a video coding quantization parameter update method, apparatus, electronic device and storage medium, which aims to avoid quality drift in subsequent predictive coding frames by immediately readjusting the baseline quantization parameters based on the consumption ratio after the intra-coded frame is completed.

[0025] Base Quantization Parameter (Base QP): The base quantization parameter is a reference value set for the quantization parameter of the current image group to be encoded, serving as the anchor point for calculating the target quantization parameter of all frames within that image group. It is not a value ultimately written into the video encoding hardware module, but rather an intermediate variable at the software level, causing the target quantization parameter of all frames within the image group to fluctuate within a constrained range around the base quantization parameter. For example, the target quantization parameter of each frame cannot exceed the range of [base quantization parameter - preset offset, base quantization parameter + preset offset].

[0026] Target quantization parameter: The target quantization parameter refers to the quantization parameter value that, after calculation, is finally determined and prepared to be written into the configuration register of the video encoding hardware module for the current frame to be encoded. This value is the core control parameter used by the video encoding hardware module when actually performing compression operations, directly determining the quantization step size and compression intensity of the current frame, thus affecting the output bitrate and picture quality.

[0027] Video Engine (VE): A video engine is a dedicated hardware acceleration unit integrated into a System-on-Chip (SoC) used to perform real-time compression encoding of video images. This module receives encoding control parameters (including target quantization parameters) and raw image pixel data from the CPU via a bus interface. Based on the control parameters, it performs physical operations such as intra / inter-frame prediction, transform, quantization, and entropy coding, outputting the compressed video bitstream. It also feeds back the actual number of encoded bits and the actual quantization parameters used for the current frame to the CPU through registers. Raw bitrate: The raw bitrate refers to the user-defined expected output bitrate (in bps), which remains constant throughout the encoding process.

[0028] Target bitrate: This is the target bitrate (in bps) actually used by the bitrate control algorithm. It reflects the actual achievable capability of the video encoding hardware module under the current conditions. The initial value of the target bitrate is the same as the original bitrate.

[0029] The first aspect of this application proposes a method for updating video coding quantization parameters. (Refer to...) Figure 1 , Figure 1 This is a flowchart illustrating the steps of a video encoding quantization parameter update method according to an embodiment of this application. Figure 1 The illustrated process steps include, but are not limited to, steps S101 to S106.

[0030] Step S101: Obtain the baseline quantization parameters.

[0031] Step S102: For each frame of the image group to be encoded, obtain the target bit rate and calculate the target quantization parameters corresponding to the current frame based on the baseline quantization parameters. The image group to be encoded includes intra-coded frames.

[0032] Step S103: Input the target quantization parameters into the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits.

[0033] Step S104: If the current frame is an intra-coded frame, the consumption ratio is calculated based on the target bit rate and the actual number of encoded bits.

[0034] Step S105: When the consumption ratio is greater than the preset first ratio threshold and the benchmark quantization parameter is less than the first threshold, a first adjustment amount is determined based on the difference between the consumption ratio and the first ratio threshold, and the benchmark quantization parameter is added to the first adjustment amount to generate a new benchmark quantization parameter.

[0035] Step S106: When the consumption ratio is less than the preset second ratio threshold and the benchmark quantization parameter is greater than the second threshold, the benchmark quantization parameter is subtracted from the preset second adjustment amount to generate a new benchmark quantization parameter.

[0036] The video coding quantization parameter update method according to the embodiments of this application has at least the following beneficial effects: by obtaining the reference quantization parameter, a unified reference anchor point is provided for the calculation of the target quantization parameter of each frame in the image group to be encoded, thereby calculating the target quantization parameter corresponding to each frame in the image group to be encoded, and then inputting the target quantization parameter to the video coding hardware module for hardware coding, and feeding back the actual number of encoded bits required for the coding process; by using the actual number of encoded bits and the target bit rate, the consumption ratio of the intra-frame coded frame is calculated, and when the consumption ratio is greater than the first ratio threshold and the reference quantization parameter is less than the first threshold, the reference quantization parameter is added to the first adjustment amount to generate a new reference quantization parameter, that is, the reference quantization parameter is increased to reduce the actual number of encoded bits of the subsequent predicted coded frames, so as to avoid the phenomenon of image quality drift, that is, the image quality gradually decreases; and when the consumption ratio is less than the second ratio threshold and the reference quantization parameter is greater than the second threshold, the reference quantization parameter is subtracted from the second adjustment amount to generate a new reference quantization parameter, that is, the reference quantization parameter is decreased to increase the actual number of encoded bits of the subsequent predicted coded frames, so as to avoid the phenomenon of image quality drift, that is, the image quality gradually improves.

[0037] It should be noted that the target quantization parameters all fluctuate within the constraints around the baseline quantization parameters.

[0038] In some embodiments, the group of images to be encoded further includes a predicted coded frame, referenced Figure 2 Step S101 may include, but is not limited to, steps S201 to S203.

[0039] Step S201: Calculate the number of bits per pixel based on the preset original bitrate, frame rate, and resolution of the image group to be encoded.

[0040] Step S202: Determine the initial quantization parameters based on the number of bits per pixel, the resolution of the image group to be encoded, and the preset quantization parameter range.

[0041] Step S203: Based on the initial quantization parameters and the average value of the target quantization parameters of each predicted coding frame in the previous adjacent image group to be encoded, the baseline quantization parameters are calculated.

[0042] In step S201 of some embodiments, the original bitrate is a user-preset bitrate, and the formula for calculating bits per pixel is: bpp = target_bps / (frame_rate) width The expression is defined as follows: height), where bpp represents the number of bits per pixel, target_bps represents the original bitrate, frame_rate represents the frame rate of the image group to be encoded, represents the resolution of the image group to be encoded, width represents the width of each frame in the image group to be encoded, and height represents the height of each frame in the image group to be encoded.

[0043] In step S202 of some embodiments, a basic quantization parameter is determined based on a preset piecewise linear mapping table and the number of bits per pixel. The piecewise linear mapping table represents the correspondence between the number of bits per pixel and the basic quantization parameter; that is, for each number of bits per pixel, there is a corresponding basic quantization parameter in the piecewise linear mapping table. Based on human experience, each resolution corresponds to a resolution coefficient. The principle is as follows: for example, compared to 1080p, 4K video is less likely to be blurry to the human eye at the same viewing distance. Therefore, a resolution coefficient of +1 to +3 is often applied to 4K, that is, the QP is increased to save bitrate. The summation value obtained by adding the basic quantization parameters and the resolution coefficient is compared with the preset quantization parameter range. The quantization parameter range refers to the physical reach of the video encoding hardware module at the current resolution and frame rate of the image group to be encoded. If the summation value is within the quantization parameter range, it is used as the initial quantization parameter. If the summation value is outside the range, the boundary value of the range is used as the initial quantization parameter. For example, if the quantization parameter range is 6 to 47 and the summation value is 8, the initial quantization parameter is 8; if the summation value is 5, the initial quantization parameter is 6; and if the summation value is 48, the initial quantization parameter is 47. When the target bitrate is detected to be too low, below the preset threshold, the quantization parameter range will be appropriately widened, and the degree of widening can be set as needed.

[0044] In step S203 of some embodiments, the formula for calculating the reference quantization parameter is as follows: base_qp=(calculated_qp A+avg_p_qp B) / (A+B) In this formula, base_qp represents the baseline quantization parameter, calculated_qp represents the initial quantization parameter, avg_p_qp represents the average value of the target quantization parameters of each predicted coding frame in the previous adjacent image group to be encoded, that is, the average value of the target quantization parameters of all P frames in the previous GOP, and A and B are weight coefficients, wherein A is preferably 3 and B is preferably 2.

[0045] It should be noted that the baseline quantization parameters for the first group of images to be encoded are directly taken from the initial quantization parameters.

[0046] In the embodiments of this application, steps S201 to S203 update the benchmark quantization parameters by integrating two information sources: theoretical calculation and historical statistics, providing a more accurate reference benchmark for the subsequent calculation of target quantization parameters.

[0047] In some embodiments, reference Figure 3 Step S102 may include, but is not limited to, steps S301 to S305.

[0048] Step S301: For each frame of the image group to be encoded, obtain the target bit rate, and calculate the target number of encoded bits based on the target bit rate.

[0049] Step S302: If the current frame is an intra-coded frame, the target quantization parameters are calculated based on the reference quantization parameters, the preset intra-frame offset, and the historical statistical feedback values.

[0050] Step S303: If the current frame is the first predicted coding frame in the image group to be encoded, the target quantization parameters are calculated based on the baseline quantization parameters and the preset buffer fullness.

[0051] Step S304: If the current frame is one of the first number of consecutive predicted coding frames in the image group to be encoded, based on the ratio of the actual number of coding bits to the target number of coding bits corresponding to the previous adjacent frame of the current frame, and the preset asymmetric segmentation mapping table, the target quantization parameter is calculated, wherein the asymmetric segmentation mapping table is characterized as the mapping relationship between the ratio and the target quantization parameter adjustment amount.

[0052] Step S305: If the current frame is a predicted coding frame in the image group to be encoded, excluding the first predicted coding frame and the first number of consecutive predicted coding frames after the first predicted coding frame, the target quantization parameters are calculated based on the target number of coding bits, the preset quadratic rate-distortion model and the linear mean absolute difference prediction model.

[0053] In step S301 of some embodiments, the initial value of the target bitrate is equal to the value of the original bitrate. The product of the target bitrate and the duration of the image group to be encoded is the total bit count budget for the image group to be encoded. Typically, the duration of the image group to be encoded is 1 second. For intra-coded frames, i.e., I-frames, the target bit count = total bit count budget for the image group to be encoded / frame rate of the image group to be encoded. The bit weight is typically greater than 1 because intra-coded frames are key frames and therefore require more bits. For predictive coded frames (P-frames), a progressive allocation strategy is used. This involves first calculating the average available bits for the remaining frames, and then adjusting the average available bits based on buffer fullness and coding progress to obtain the target number of coded bits for the predictive coded frame. The specific calculation formula is as follows: TargetBuffer=BufferSize×(α+gop_frame_count / gop_size×(β α)); delta = (current_buffer) TargetBuffer / buffer_size; buffer_factor=1.0 K×delta; In this formula, TargetBuffer is represented as a linear function of the encoding progress of the image group to be encoded; gop_frame_count is the number of frames already encoded in the image group; gop_size is the total number of frames in the image group to be encoded; gop_frame_count / gop_size represents the encoding progress; α is the target level of the buffer when the encoding progress is 0% (usually 0.1 to 0.2); β is the target level of the buffer when the encoding progress is 100% (usually 0.6 to 0.8); delta is the buffer bias; current_buffer is the buffer fullness; buffer_size is the buffer capacity (the maximum number of bits it can hold); buffer_factor is the compensation factor; and K is the adjustment strength coefficient (usually 0.5 to 1). The compensation factor is generally limited to the range [0.75, 1.25] to ensure stability. The target bitrate is used to calculate the target bitrate, while the original bitrate is used to update the buffer. The initial fullness of the buffer is a preset value (usually 0). The nominal bitrate is obtained by dividing the original bitrate by the frame rate of the image group to be encoded. After each encoding is completed, the difference between the actual bitrate and the nominal bitrate is calculated, and the difference is added to the current fullness of the buffer to obtain the new fullness of the buffer, thus completing the buffer update. The buffer update uses the original bitrate, which can more realistically record the overshoot of the video encoding hardware module relative to the user's expectations.

[0054] Therefore, the target number of coded bits for the predicted coded frame = the average available bits for the remaining frames. The compensation factor is calculated as follows: Average available bits for remaining frames = Total remaining bit budget / Number of uncoded frames in the image group to be encoded. The target bit count constraint range for the latter half of the encoding progress (which can be 51% to 100% of the encoding progress) is within the target bit count constraint range for the first half of the encoding progress (which can be 0% to 50% of the encoding progress) to ensure a stable bit rate at the end of encoding.

[0055] It should be noted that the above-mentioned target bit count can also be calculated using other existing reference encoders. The scope limitations in this application are as follows: when the value is within the range, the target value is the specified value; when the value is outside the range, the boundary value of the range is used as the target value.

[0056] In step S302 of some embodiments, the difference between the reference quantization parameter and a preset intra-frame offset is calculated, and then a weighted sum is performed with the average value of the target quantization parameters corresponding to the intra-frame coded frames of the historical image group to be encoded. Specifically, this can be: I_frame_QP=ɡ×(base_qp-i_qp_offset)+(1-ɡ)×historical_avg_I_QP; In this formula, I_frame_QP represents the target quantization parameter of the intra-coded frame, g represents the weighting coefficient, base_qp represents the baseline quantization parameter, i_qp_offset represents the preset intra-frame offset, and historical_avg_I_QP represents the average value of the target quantization parameters corresponding to the intra-coded frames of the historical image groups to be encoded, i.e., the historical statistical feedback value. The historical image groups to be encoded can be one or more adjacent to the current image group to be encoded. In step S303 of some embodiments, for the first predicted coded frame in the image group to be encoded, if the buffer fullness is less than the product of the target bit rate and a preset ratio, the reference quantization parameter and a preset first offset are added together to obtain the target quantization parameter; if the buffer fullness is greater than the product of the target bit rate and the preset ratio, the reference quantization parameter and a preset second offset are added together to obtain the target quantization parameter, wherein the first offset is greater than the second offset, the first offset can be 1, the second offset can be 2, and the preset ratio can be 30%.

[0057] It should be noted that, according to traditional technology, when the intra-coded frame consumption ratio is too large, the target quantization parameter calculated by the subsequent predictive coded frame will be too large. However, there are constraints on the target quantization parameter of adjacent frames. This leads to a problem. Suppose the target quantization parameter calculated by the first predictive coded frame based on the reference quantization parameter is 28. Because the intra-coded frame consumption ratio is too large, the optimal target quantization parameter of the subsequent predictive coded frame should be 40. However, since the upper limit of the target quantization parameter constraint of adjacent frames is 2, it takes 6 frames to increase from 28 to 40. However, in this application, the reference quantization parameter is updated immediately after the intra-coded frame is encoded, so that the target quantization parameter calculated by the first predictive coded frame based on the reference quantization parameter can be 34, so it only takes 3 frames to increase from 34 to 40.

[0058] In step S304 of some embodiments, for a first number of predicted coding frames after the first predicted coding frame in the image group to be coded (the first number can be 4), an adjustment amount is determined based on the ratio and an asymmetric segmentation mapping table. This adjustment amount is added to the target quantization parameter of the previous adjacent frame to serve as the target quantization parameter for the current frame. Specifically, the asymmetric segmentation mapping table can be: when the ratio is greater than 2.5, the adjustment amount is +4; when the ratio is greater than 2 and less than or equal to 2.5, the adjustment amount is +3; when the ratio is greater than 1... When the ratio is 0.5 and less than or equal to 2, the adjustment is +2; when the ratio is greater than 1.2 and less than or equal to 1.5, the adjustment is +1; when the ratio is greater than or equal to 0.9 and less than or equal to 1.2, the adjustment is 0; when the ratio is greater than or equal to 0.7 and less than 0.9, the adjustment is -1; when the ratio is greater than or equal to 0.55 and less than 0.7, the adjustment is -2; when the ratio is greater than or equal to 0.4 and less than 0.55, the adjustment is -3; when the ratio is less than 0.4, the adjustment is -4.

[0059] In step S305 of some embodiments, the quadratic rate-distortion model is: R=MAD (X1 / Qstep+X2 / Qstep²); In this formula, R represents the target number of encoded bits, MAD represents the mean absolute difference of the current frame prediction, X1 and X2 represent the model parameters estimated from historical encoded data points using the least squares method, and Qstep represents the quantization step size. A pre-defined mapping table exists between the quantization step size and the target quantization parameters. Based on the calculated quantization step size, the corresponding target quantization parameters can be found in the mapping table to serve as the target quantization parameters for the current frame.

[0060] It should be noted that X2 is initialized to 0, and the initial estimated value of X1 is calculated using the quantization step size corresponding to the initial quantization parameters and the estimated MAD value. If the current frame is a predictive coded frame, then the (actual quantization parameters, actual number of coded bits) of the current frame are stored as data points in the historical coded data points.

[0061] The linear mean absolute difference prediction model is as follows: MAD=C1 MAD_prev+C2; MAD represents the mean absolute difference of the current frame prediction, C1 and C2 represent the linear prediction coefficients, and MAD_prev represents the actual mean absolute difference after encoding the previous adjacent frame.

[0062] In steps S301 to S305 of the embodiments of this application, during the coding initiation phase, i.e., the beginning of each GOP, the quadratic rate-distortion model has not yet accumulated enough historical coding data points. At this time, the number of historical coding data points used for model estimation may be 0 or very small, and the estimated values ​​of model parameters X1 and X2 are inaccurate or even unusable. Traditional schemes still use inaccurate quadratic rate-distortion models to calculate target quantization parameters during the initiation phase, resulting in a large deviation between the target quantization parameters and the optimal value in the first few frames, leading to a significant error between the actual bitrate and the target bitrate. Traditional schemes typically require 1-2 complete GOPs (30-60 frames) to converge. Therefore, in the initiation phase of this application, i.e., for the first number of predicted coding frames after the first predicted coding frame in the image group to be coded, the target quantization parameters are determined by the ratio of the actual number of coded bits to the target number of coded bits corresponding to the previous adjacent frame of the current frame, and an asymmetric segmented mapping table, in order to achieve fast closed convergence. Meanwhile, even if scene switching or the boundary of the image group to be encoded occurs during the encoding process, assuming the first number is 4, each image group to be encoded can quickly converge to the target bit rate within the first 5 predicted encoding frames, without being affected by the model state of the previous image group to be encoded, that is, no historical encoding data points are needed for convergence.

[0063] It should be noted that the target quantization parameter is usually constrained by the reference quantization parameter. For example, the range of the target quantization parameter is [reference quantization parameter - 20, reference quantization parameter + 20]. This 20 is a preset offset that can be set manually so that the target quantization parameter does not deviate too much from the reference quantization parameter.

[0064] In step S103 of some embodiments, the original image corresponding to the current frame and the target quantization parameters are input to the video encoding hardware module for hardware encoding, and the actual number of encoded bits is fed back. Hardware encoding refers to the video encoding hardware module performing prediction, transformation, quantization, and entropy encoding operations sequentially on the original image data of the current frame according to the received target quantization parameters, in order to convert the original image data into a compressed video stream.

[0065] In step S104 of some embodiments, the total bit budget of the image group to be encoded is calculated by multiplying the target bit rate by the duration of the image group to be encoded, and the actual number of encoded bits corresponding to the intra-coded frame is divided by the total bit budget to obtain the consumption ratio.

[0066] In step S105 of some embodiments, after the intra-frame coding is completed, the consumption ratio is immediately compared with a first ratio threshold and a second ratio threshold. If the consumption ratio is greater than the first ratio threshold (usually 0.25), and the reference quantization parameter has not reached the preset maximum value of the quantization parameter, i.e., there is still room for improvement, then a first adjustment amount is determined based on the difference between the consumption ratio and the first ratio threshold. The formula for determining the first adjustment amount is: boost=CLIP3(min,max,(int)((i_ratio-θ) &)); In this formula, boost represents the first adjustment amount, CLIP3(min,max,(int)((i_ratio-θ)). &)) represents (int)((i_ratio-θ) &) is limited to the range [min, max], where min represents the lower limit of the first adjustment (usually 2), max represents the upper limit of the first adjustment (usually 12), i_ratio represents the consumption ratio, θ represents the first threshold, and & represents the preset coefficient (usually 15); (int)((i_ratio-θ) &) represents (i_ratio-θ) The result of & is rounded down to the nearest integer.

[0067] Then, the baseline quantization parameter and the first adjustment amount are added together to form a new baseline quantization parameter, and its range is restricted. The specific formula is as follows: base_qp=MIN(qp_max-2,base_qp+boost); In this formula, base_qp represents the baseline quantization parameter, qp_max represents the preset maximum value of the quantization parameter, and boost represents the first adjustment amount.

[0068] In step S106 of some embodiments, if the consumption ratio is less than the second ratio threshold (usually 0.08), and the baseline quantization parameter has not reached the preset minimum value of the quantization parameter, i.e., there is still room for reduction, then the baseline quantization parameter is subtracted from the preset second adjustment amount (usually 1) to generate a new baseline quantization parameter. The reason why the second adjustment amount is usually set to 1 is that reducing the baseline quantization parameter will increase the number of encoded bits in subsequent frames. If it is reduced too much, it may cause bitrate overshoot when the subsequent picture becomes more complex. Therefore, a conservative strategy is adopted, and the baseline quantization parameter is only gradually and tentatively reduced in small increments to utilize the remaining budget. After the intra-frame coded frame is encoded, the baseline quantization parameter is adjusted immediately before the next predictive coded frame is encoded, so that the picture quality of the entire image to be encoded remains stable from the first predictive coded frame, and there will be no visible quality drift. This eliminates the phenomenon in traditional schemes where the target quantization parameter of the predictive coded frame slowly increases because the adjustment is only performed after the entire group of images to be encoded is encoded.

[0069] It should be noted that the difference in target quantization parameters between adjacent frames will not exceed the preset inter-frame constraint threshold to ensure smooth inter-frame constraints. The inter-frame constraint threshold is 8 for intra-coded frames, 2 for predictive-coded frames, and 4 when the buffer is overfilled.

[0070] In some embodiments, refer to Figure 4 After step S103, there may be steps S401 to S404, including but not limited to.

[0071] Step S401: Calculate the nominal number of encoded bits based on the original bit rate and the frame rate of the image group to be encoded.

[0072] Step S402: Obtain the actual quantization parameters corresponding to the current frame from the video encoding hardware module.

[0073] Step S403: When the actual quantization parameters corresponding to a second consecutive number of predicted coding frames are greater than a third preset threshold, and the actual number of coded bits is greater than the product of the nominal number of coded bits and the first preset coefficient, the target bit rate is multiplied by the second preset coefficient to obtain the new target bit rate.

[0074] Step S404: When the actual quantization parameters corresponding to a third consecutive number of predicted coding frames are less than a preset fourth threshold, and the actual number of coded bits is less than the product of the nominal number of coded bits and the preset third coefficient, the target bit rate is multiplied by the preset fourth coefficient to obtain the new target bit rate.

[0075] In step S401 of some embodiments, after each frame of predictive coding is encoded, the original bit rate is divided by the frame rate of the image group to be encoded to obtain the nominal number of encoded bits.

[0076] In step S402 of some embodiments, after encoding, the actual quantization parameters of the current frame are fed back from the video encoding hardware module.

[0077] In step S403 of some embodiments, when the actual quantization parameters corresponding to a second preset number (e.g., 3) of predicted encoded frames are greater than a preset third threshold, for example: the third threshold = the preset maximum value of the quantization parameters - 1, it indicates that the video encoding hardware module has pushed the quantization loss to the maximum and cannot further compress the bitrate; and when the actual number of encoded bits is greater than the product of the nominal number of encoded bits and the preset first coefficient, for example: the first coefficient is 1.5, it indicates that even if the actual quantization parameters are at their maximum value, the bitrate output by the video encoding hardware module is still much higher than the target value. The target bitrate is multiplied by the preset second coefficient, for example: 1.08. The reason for taking 1.08 is that if the target bitrate is too low, it means that the bitrate expected by the user cannot be physically achieved. It is necessary to gradually relax the target bitrate to maintain the encoding quality, but the increase should not be too large each time to avoid a sudden change in the bitrate. The upper limit of the second coefficient is 3, which is used as the new target bitrate.

[0078] In step S404 of some embodiments, if the current frame is a predicted coding frame in the image group to be encoded, excluding the first predicted coding frame and the first preset number of predicted coding frames after the first predicted coding frame, the fourth threshold has two values ​​based on the preset minimum value of the quantization parameter and the reference quantization parameter. The first value is the preset minimum value of the quantization parameter minus 1, and the second value is the reference quantization parameter minus 2. The actual quantization parameter only needs to satisfy a value less than either of the fourth threshold values. If the current frame is the first predicted coding frame in the image group to be encoded and the first preset number of predicted coding frames after the first predicted coding frame, the fourth threshold has only one value based on the preset minimum value of the quantization parameter, which is equal to the preset minimum value of the quantization parameter minus 1. The third quantity can be 5, the third coefficient can be 0.5, and the fourth coefficient can be 0.85. The fourth coefficient has a greater fluctuation than the second coefficient; that is, the fourth coefficient differs from 1 by 0.15, while the second coefficient differs from 1 by 0.08. This is because when the target bitrate is too high, the video encoding hardware module generates a large number of padding bits (invalid data), requiring a faster tightening of the target bitrate to reduce bandwidth waste. The asymmetric design makes downward adjustments more decisive. The lower limit of the adjusted target bitrate is 30% of the original bitrate to retain the minimum bit budget to maintain basic image quality and prevent the image from becoming completely unacceptable due to an excessively low bitrate.

[0079] In steps S401 to S404 of the embodiments of this application, the quantization parameter QP in the H.264 hardware encoder ranges from 0 to 51 (as defined by the H.264 standard). When the user-set target bitrate exceeds the physical achievable range of the video encoding hardware module at the current resolution and frame rate—that is, the target bitrate is too low, lower than the minimum bitrate the hardware can generate, or too high, higher than the maximum bitrate the hardware can generate—the quantization parameter will be continuously pushed to extreme values, but the actual bitrate still cannot reach the target value. At this time, the traditional bitrate control scheme will exhibit the following divergent behavior: When the target bitrate is too low: QP remains at its maximum value, but the actual bitrate still far exceeds the target bitrate. The buffer continuously accumulates positive deviations, causing QP calculation to be forced to remain at its maximum value even if the content of subsequent frames is simple and could have used a lower QP, due to the excessive buffer deviation. When the target bitrate is too high: QP remains at its minimum value, but the actual bitrate still cannot fill the target. The buffer continuously accumulates negative deviations, QP cannot be further reduced, and the encoding quality cannot be improved. The fundamental reason lies in the fact that traditional schemes have only one target bitrate, failing to distinguish between the target bitrate and the original bitrate as in this application. Bit allocation and buffer feedback share the same target bitrate, exacerbating the deviation when the target is physically unreachable. The allocation of encoded bits is based on the unreachable target, resulting in an unreasonable number of bits, and the buffer accumulates deviation based on the same unreachable target, creating a vicious cycle. In contrast, this application adjusts the target bitrate accordingly when it detects that it is consistently too low or too high, i.e., increasing or decreasing it. At the same time, the buffer update in this application uses the original bitrate, which remains unchanged. This differentiated usage strategy ensures that: when the target bitrate is too low, the video encoding hardware module will not abandon the bitrate constraint because the QP has reached its limit, and the buffer still honestly records overshoot; at the same time, the allocation of the target encoded bitrate will not result in unreasonable QP calculations due to the low bitrate. When the target bitrate is too high, the video encoding hardware module will not continuously waste bits because the QP has reached its lower limit, and the buffer still records insufficient bits, while the allocation of the target encoded bitrate remains reasonable and achievable.

[0080] In some embodiments, refer to Figure 5 After step S103, steps S501 to S502 may also be included, but are not limited to.

[0081] Step S501: Subtract the actual number of encoded bits from the nominal number of encoded bits to obtain the buffer offset.

[0082] Step S502: Add the buffer fullness to the buffer deviation to obtain the new buffer fullness.

[0083] In step S501 of some embodiments, for the current frame, the buffer offset is equal to the difference between the actual number of encoded bits and the nominal number of encoded bits fed back after encoding the current frame.

[0084] In step S502 of some embodiments, the buffer fullness is added to the buffer offset to obtain a new buffer fullness, thereby updating the buffer.

[0085] In steps S501 to S502 of this embodiment, the buffer is updated using the original bitrate, which remains constant. This ensures that even if the target bitrate is too low or too high, the buffer can still honestly record overshoot or undershoot. In contrast, the prior art uses a variable target bitrate for buffer updates. When the target bitrate is too high or too low, the buffer is still updated using the target bitrate, resulting in the calculated absolute value of the buffer offset being smaller than the actual absolute value of the buffer offset.

[0086] In some embodiments, refer to Figure 6 Step S502 may be followed by steps including but not limited to step S601.

[0087] Step S601: When the current frame is a predictive coding frame, if the buffer fullness is greater than the product of the target bit rate and the preset fifth coefficient, and the actual quantization parameter is greater than the sum of the reference quantization parameter and the preset third offset, then the reference quantization parameter is added to the preset third adjustment amount to generate a new reference quantization parameter.

[0088] In step S601 of some embodiments, the fifth coefficient is set to 0.3, the third offset is set to 3, and the third adjustment is set to 2, when the buffer fullness is greater than the target bit rate. When the actual quantization parameter of the current frame is greater than the baseline quantization parameter + 3, the new baseline quantization parameter = MIN(base_qp+2, qp_max-5), where qp_max represents the preset maximum value of the quantization parameter.

[0089] Step S601 shown in this embodiment ensures that the baseline quantization parameter can be dynamically adjusted according to the actual coding state, rather than being rigidly fixed in the entire GOP. The third adjustment amount is 2, with an upper limit of qp_max-5, leaving more adjustment space for subsequent frames.

[0090] It is understood that the target quantization parameters corresponding to the first predicted coding frame in the image group to be encoded, and the consecutive preset first number of predicted coding frames after the first predicted coding frame, are restricted to a first range defined by a preset first upper limit value and a preset first lower limit value. The target quantization parameters corresponding to the predicted coding frames other than the first predicted coding frame and the consecutive preset first number of predicted coding frames after the first predicted coding frame are restricted to a second range defined by a preset second upper limit value and a preset second lower limit value, wherein the first upper limit value is greater than the second upper limit value and the first lower limit value is less than the second lower limit value.

[0091] For example, in this embodiment, the first range includes the second range, such as: the first range is [base_qp-10, base_qp+10]; the second range is [base_qp-4, base_qp+4]; where base_qp-10 is the first lower limit value, base_qp+10 is the first upper limit value, base_qp-4 is the second lower limit value, base_qp+4 is the second upper limit value, and base_qp is the baseline quantization parameter. This provides greater adjustment space for fast convergence.

[0092] Reference Figure 7 , Figure 7 This is a schematic diagram of a video coding quantization parameter update apparatus according to a second aspect embodiment of this application. The video coding quantization parameter update apparatus includes: The frame preprocessing module 701 is configured to acquire reference quantization parameters; for each frame of the image group to be encoded, acquire the target bit rate, and calculate the target quantization parameters corresponding to the current frame based on the reference quantization parameters, wherein the image group to be encoded includes intra-coded frames. Hardware encoding module 702 is configured to input the target quantization parameters to the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits. The frame post-processing module 703 is configured to: if the current frame is an intra-coded frame, calculate the consumption ratio based on the target bit rate and the actual number of encoded bits; when the consumption ratio is greater than a preset first ratio threshold and the reference quantization parameter is less than the first threshold, determine a first adjustment amount based on the difference between the consumption ratio and the first ratio threshold, and add the reference quantization parameter to the first adjustment amount to generate a new reference quantization parameter; when the consumption ratio is less than a preset second ratio threshold and the reference quantization parameter is greater than the second threshold, subtract the reference quantization parameter from the preset second adjustment amount to generate a new reference quantization parameter.

[0093] In this embodiment, the frame preprocessing module 701 obtains the reference quantization parameters, providing a unified reference anchor point for calculating the target quantization parameters of each frame within the image group to be encoded. This allows for the calculation of the target quantization parameters corresponding to each frame within the image group. The target quantization parameters are then input to the video encoding hardware module via the hardware encoding module 702 for hardware encoding, and the actual number of encoded bits required for the encoding process is fed back. Using the actual number of encoded bits and the target bitrate, the frame postprocessing module 703 calculates the consumption ratio of the intra-frame encoded frames. Furthermore, when the consumption ratio exceeds a first ratio threshold, and the reference quantization parameter is not specified, the quantization parameters are determined. When the quantization parameter is less than the first threshold, the baseline quantization parameter is added to the first adjustment amount to generate a new baseline quantization parameter, which increases the baseline quantization parameter to reduce the actual number of encoded bits in subsequent predictive coded frames, thus avoiding image quality drift, i.e., a gradual decrease in image quality. When the consumption ratio is less than the second ratio threshold and the baseline quantization parameter is greater than the second threshold, the baseline quantization parameter is subtracted from the second adjustment amount to generate a new baseline quantization parameter, i.e., decreases the baseline quantization parameter to increase the actual number of encoded bits in subsequent predictive coded frames, thus avoiding image quality drift, i.e., a gradual increase in image quality.

[0094] An embodiment of the third aspect of this application also provides an electronic device, which includes a memory 802 and a processor 801. The memory 802 stores a computer program, and the processor 801 executes the computer program to implement the video coding quantization parameter update method of the first aspect embodiment described above. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0095] Reference Figure 8 , Figure 8 This is a schematic diagram of the structure of an electronic device according to one embodiment. The electronic device includes: The processor 801 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 802 can be implemented as a read-only memory, static storage device, dynamic storage device, or random access memory (RAM). The memory 802 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 802 and is called and executed by the processor 801 using the television bezel laser etching method of the embodiments of this application. The 803 input / output interface is used to implement information input and output. The communication interface 804 is used to enable communication and interaction between this device and other devices. Communication can be achieved via wired or wireless means. Bus 805 transmits information between various components of the device; The processor 801, memory 802, input / output interface 803, and communication interface 804 are connected to each other within the device via bus 805.

[0096] A fourth aspect of this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the video coding quantization parameter update method of the first aspect embodiment described above.

[0097] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0098] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0099] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.

[0100] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0101] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.

[0102] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0103] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.

[0104] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0105] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0106] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0107] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0108] Furthermore, it should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent will be obtained first. Moreover, the collection, use, and processing of this data will comply with relevant laws, regulations, and standards. Additionally, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user will be obtained through pop-ups or redirects to confirmation pages. Only after obtaining the user's separate permission or consent will the necessary user-related data for the proper functioning of these embodiments be acquired.

[0109] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.

Claims

1. A method for updating video coding quantization parameters, characterized in that, The method includes: Obtain the baseline quantization parameters; For each frame of the image group to be encoded, the target bitrate is obtained, and the target quantization parameters corresponding to the current frame are calculated based on the reference quantization parameters, wherein the image group to be encoded includes intra-coded frames; The target quantization parameters are input into the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits. If the current frame is an intra-coded frame, the consumption ratio is calculated based on the target bitrate and the actual number of encoded bits. When the consumption ratio is greater than a preset first ratio threshold and the benchmark quantization parameter is less than the first threshold, a first adjustment amount is determined based on the difference between the consumption ratio and the first ratio threshold, and the benchmark quantization parameter is added to the first adjustment amount to generate a new benchmark quantization parameter. When the consumption ratio is less than a preset second ratio threshold and the benchmark quantization parameter is greater than the second threshold, the benchmark quantization parameter is subtracted from the preset second adjustment amount to generate a new benchmark quantization parameter.

2. The video coding quantization parameter update method according to claim 1, characterized in that, The group of images to be encoded further includes a predicted coded frame, and the acquisition of the baseline quantization parameters includes: The number of bits per pixel is calculated based on the preset raw bit rate, the frame rate and resolution of the image group to be encoded; The initial quantization parameters are determined based on the number of bits per pixel, the resolution of the image group to be encoded, and the preset quantization parameter range. Based on the initial quantization parameters and the average value of the target quantization parameters of each predicted coding frame in the previous adjacent group of images to be encoded, the baseline quantization parameters are calculated.

3. The video coding quantization parameter update method according to claim 2, characterized in that, For each frame of the image group to be encoded, the target bitrate is obtained, and the target quantization parameters corresponding to the current frame are calculated based on the baseline quantization parameters. The image group to be encoded includes intra-coded frames, including: For each frame of the image group to be encoded, the target bit rate is obtained, and the target number of encoded bits is calculated based on the target bit rate; If the current frame is the intra-coded frame, the target quantization parameter is calculated based on the reference quantization parameter, the preset intra-frame offset, and the historical statistical feedback value. If the current frame is the first predicted coding frame in the group of images to be encoded, the target quantization parameter is calculated based on the baseline quantization parameter and the preset buffer fullness. If the current frame is one of a first number of consecutive predicted coding frames following the first predicted coding frame in the image group to be encoded, the target quantization parameter is calculated based on the ratio of the actual number of coding bits to the target number of coding bits corresponding to the previous adjacent frame of the current frame, and a preset asymmetric segmentation mapping table, wherein the asymmetric segmentation mapping table is characterized as the mapping relationship between the ratio and the adjustment amount of the target quantization parameter; If the current frame is a predicted coding frame in the image group to be encoded, excluding the first predicted coding frame and the first number of consecutive predicted coding frames after the first predicted coding frame, the target quantization parameter is calculated based on the target number of coding bits, the preset quadratic rate-distortion model, and the linear mean absolute difference prediction model.

4. The video coding quantization parameter update method according to claim 3, characterized in that, After inputting the target quantization parameters into the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits, the method further includes: The nominal number of encoded bits is calculated based on the original bit rate and the frame rate of the image group to be encoded. Obtain the actual quantization parameters corresponding to the current frame from the video encoding hardware module; When the actual quantization parameters corresponding to a second consecutive number of predicted coding frames are greater than a third preset threshold, and the actual number of coded bits is greater than the product of the nominal number of coded bits and a first preset coefficient, the target bit rate is multiplied by a second preset coefficient to obtain a new target bit rate. When the actual quantization parameters corresponding to a third consecutive number of predicted coding frames are less than a preset fourth threshold, and the actual number of coded bits is less than the product of the nominal number of coded bits and a preset third coefficient, the target bitrate is multiplied by the preset fourth coefficient to obtain a new target bitrate.

5. The video coding quantization parameter update method according to claim 4, characterized in that, After inputting the target quantization parameters into the video encoding hardware module for hardware encoding to obtain the actual number of encoded bits, the method further includes: The difference between the actual number of encoded bits and the nominal number of encoded bits is used to obtain the buffer offset. The buffer fullness is added to the buffer deviation to obtain the new buffer fullness.

6. The video coding quantization parameter update method according to claim 5, characterized in that, After adding the buffer fullness to the buffer deviation to obtain the new buffer fullness, the method further includes: When the current frame is a predictive coded frame, if the buffer fullness is greater than the product of the target bit rate and the preset fifth coefficient, and the actual quantization parameter is greater than the sum of the reference quantization parameter and the preset third offset, then the reference quantization parameter is added to the preset third adjustment amount to generate a new reference quantization parameter.

7. The video coding quantization parameter update method according to claim 3, characterized in that, The target quantization parameters corresponding to the first predicted coding frame in the image group to be encoded, and the consecutive predetermined first number of predicted coding frames after the first predicted coding frame, are restricted to a first range defined by a predetermined first upper limit and a predetermined first lower limit. The target quantization parameters corresponding to the predicted coding frames other than the first predicted coding frame and the consecutive predetermined first number of predicted coding frames after the first predicted coding frame are restricted to a second range defined by a predetermined second upper limit and a predetermined second lower limit, wherein the first upper limit is greater than the second upper limit and the first lower limit is less than the second lower limit.

8. A video coding quantization parameter update device, characterized in that, The device includes: A frame preprocessing module is configured to acquire a reference quantization parameter; for each frame of the image group to be encoded, acquire the target bitrate, and calculate the target quantization parameter corresponding to the current frame based on the reference quantization parameter, wherein the image group to be encoded includes intra-coded frames; A hardware encoding module is configured to input the target quantization parameters into a video encoding hardware module for hardware encoding to obtain the actual number of encoded bits. A post-frame processing module is configured to: if the current frame is an intra-coded frame, calculate the consumption ratio based on the target bitrate and the actual number of encoded bits; when the consumption ratio is greater than a preset first ratio threshold and the reference quantization parameter is less than the first threshold, determine a first adjustment amount based on the difference between the consumption ratio and the first ratio threshold, and add the reference quantization parameter to the first adjustment amount to generate a new reference quantization parameter; when the consumption ratio is less than a preset second ratio threshold and the reference quantization parameter is greater than the second threshold, subtract the reference quantization parameter from the preset second adjustment amount to generate a new reference quantization parameter.

9. An electronic device, characterized in that, The electronic device includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the video coding quantization parameter update method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the video coding quantization parameter update method according to any one of claims 1 to 7.