Encoder recovery method based on number of stills
Patent Information
- Application Number
- CN202510492152.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2026-10-23
AI Technical Summary
运动后背景块不在同一时间补残差,导致运动后的块恢复不统一,恢复较为明显,存在明显的主观质量问题
[0066]所述方法适用于视频编码器,能够减弱恢复慢的现象,并提升长期静止块的主观效果;包括:
Smart Images

Figure CN122970261A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of video processing technology, and specifically relates to an encoder recovery method based on the number of still images. Background Technology
[0002] In existing technologies, encoders often use the RDCost scheme for mode selection during the mode selection process, with the following formula:
[0003] RDCost = distortion + lambda * bits. Distortion represents image quality; generally, higher distortion indicates lower image quality. Bits represent the number of bits required to encode the current mode, affecting the bitstream size of the current frame. Lambda is a balancing factor between quality and bits; a larger lambda tends to favor modes with fewer bits, while a smaller lambda tends to favor modes with lower distortion. In the encoder's mode selection, the mode with the lowest RDCost is chosen as the optimal mode for the current block.
[0004] Motion recognition is often used in encoders to allocate bitstreams appropriately based on whether an image block is moving or stationary. The goal is to allocate as little bitstream as possible to stationary blocks and as much bitstream as possible to moving blocks, thus ensuring subjective quality.
[0005] The recovery scheme based on the number of stillnesses, when applied to the mode selection of a video encoder, can reduce the distortion of the encoder in the still area after motion and improve the subjective quality of the video.
[0006] The encoder uses motion detection combined with block-level lambda configuration to achieve reasonable bitstream allocation. When a moving block is detected, a smaller lambda is used, resulting in less distortion but a larger bitstream; when a stationary block is detected, a larger lambda is used, resulting in a smaller bitstream but greater distortion. This allows for less bitstream allocation to stationary blocks and more bitstream allocation to moving blocks.
[0007] Currently, encoders commonly use the RDcost scheme for mode selection. This involves calculating the RDcost of each mode, comparing the RDcosts of different modes, and selecting the mode with the lowest cost. The lambda in this RDcost is obtained by looking up a table based on the current block-level QP, as detailed below. Figure 2 As shown, the lambda_tbl table is one of them.
[0008] Motion detection is also commonly used in encoders to guide encoding strategies based on the motion features of the image.
[0009] However, the existing technology has the following drawbacks:
[0010] Increasing the lambda of static blocks can lead to blurring or blocky reappearance of static areas after movement. This is because the inner frame of a p-frame has weaker restoration capabilities due to deadzone issues compared to the inner frame of an I-frame. The inner frame of a p-frame restores the general outline, while internal details require the use of merge mode for restoration. Increasing the lambda prioritizes bits, thus using skip mode more often. This results in some blocks having residuals filled in, while others remain stationary without residuals, leading to both blurring and blocky reappearance.
[0011] In addition, the technical terms in this field include:
[0012] H.265 / HEVC: A high-efficiency video coding protocol, a general scheme for compressing redundant information in video in terms of space, time, and structure.
[0013] I-frame: A keyframe in a video sequence. The entire frame uses the intra prediction mode, which depends on surrounding blocks. P-frame: A frame type in a video sequence that references the previous frame. The entire frame can use both intra and inter prediction modes.
[0014] CTU: is an independent encoding unit in H.265 / HEVC, and its size can be 64x64, 32x32, or 16x16.
[0015] CU: A CTU contains multiple coding units (CUs), whose sizes can be 64x64, 32x32, 16x16, or 8x8.
[0016] QP: Quantization level. The range for H.265 / HEVC is [0,51]. The larger the QP, the higher the quantization level, the less image detail is preserved, but the higher the compression rate.
[0017] Raw pixels: refers to the unprocessed pixels input to the encoder, i.e., the input data.
[0018] Merge mode: A prediction mode of Inter that does not perform motion search, but performs prediction + transformation quantization.
[0019] merge-skip mode: A special mode of merge where the coeff is 0, based on the merge mode.
[0020] AMVP mode: An Inter prediction mode that performs prediction plus transform quantization, and performs motion search compared to merge.
[0021] Intra mode: A mode that predicts the current block based on the pixels of surrounding blocks.
[0022] RDCost: In H.265 / HEVC, the cost value is calculated. Typically, the mode or partition with the minimum RDCost is chosen as the decision. It consists of Distortion and BitRate, and its formula is RDCost = Distortion + lambda * BitRate. Distortion is usually represented by the difference between the original pixel value and the pixel value after encoding and decoding. BitRate is usually the number of bits required to encode the current block, and lambda is the Lagrange multiplier, used to weigh the weights of distortion and bits.
[0023] Slow recovery: During encoding, under high qp, the static background portion after motion continues to recover over several frames. The background blocks after motion are not compensated for simultaneously, resulting in inconsistent recovery of the moved blocks. This uneven recovery leads to noticeable subjective quality issues. For example... Figure 1 As shown, the arrows indicate blocks that fill in the gaps, which are not consistent with the surrounding skip blocks and are more blurred than the surrounding blocks. Summary of the Invention
[0024] To address the aforementioned issues, the purpose of this application is to: for static blocks, distinguish between long-term static blocks and static blocks that have been stationary after movement by counting the number of times they remain stationary. Then, based on the characteristics of long-term or stationary states, the lambda value can be increased or decreased to accelerate the recovery of blocks after movement without consuming excessive bitstream, thereby improving subjective quality.
[0025] Specifically, the present invention provides an encoder recovery method based on the number of static cycles, comprising the following steps:
[0026] S1, Input video source, determine if it is an I-frame. If it is, initialize the number of still frames to the maximum value in the I-frame. The number of still frames is calculated and detected in units of blk16. If not, proceed to step S2 motion determination.
[0027] S2, motion detection is performed in units of blk16. The motion state is determined by calculating the average pixel difference between the current frame and the reference frame. If it is a moving block, the number of stationary positions is reset to zero; otherwise, the number of stationary positions is incremented by 1 and limited to the maximum number of stationary positions.
[0028] S3, During the encoding stage, the number of pauses is determined according to the size of the encoding block. For cu32 blocks, the minimum number of pauses among the four internal blk16 blocks is taken. For cu16 and smaller blocks, the number of pauses corresponding to blk16 is used directly.
[0029] S4, determine the block category based on the relationship between the number of pauses and the double threshold, and assign corresponding lambda values to blocks of different categories; including:
[0030] Count the number of times each block is stationary, and determine whether the current block is a long-term stationary block, a stationary block after movement, or a moving block based on the number of stationary times;
[0031] The lambda is set according to the block type of the current coding block. Smaller lambda values are assigned to static blocks after movement, and larger lambda values are assigned to static blocks that have been static for a long time. The default lambda value is used for moving blocks.
[0032] S5 uses the allocated lambda value to calculate the rate-distortion cost of each mode and selects the mode with the minimum cost as the best encoding mode; for each mode, the set lambda is used to calculate the RDcost, and the mode with the minimum RDcost is selected as the best mode for the current block.
[0033] Step S1 further includes:
[0034] When inputting the source video, at each I-frame, initialize the still_times of all blk16 frames to the maximum value max_still_times, which is an empirical value and is preferably 5.
[0035] The number of still frames is dynamically updated based on motion detection results at P-frame.
[0036] In step S2, the specific steps of motion detection include:
[0037] S2.1, calculate the mean value of the sum of the absolute values of the pixel differences between the current blk16 block and the corresponding block in the reference frame, motion_avg;
[0038] That is, at each P-frame, the mean value of motion_avg is calculated as the sum of the absolute values of the differences between each pixel in the current blk16 block raw and the previous frame raw_prev at the same position.
[0039]
[0040] S2.2 If motion_avg is greater than the preset threshold motion_thrd, which is an empirical value, preferably 8, then the current block is determined to be a moving block and motion_flag is set to 1; otherwise, it is 0 and is a stationary block.
[0041]
[0042] S2.3, Update the number of stationary blocks based on the judgment result. The number of stationary blocks for moving blocks is reset to zero, and the number of stationary blocks for stationary blocks is incremented by 1 and limited to the maximum value.
[0043] If the current block's motion_flag is 0, then the current block is determined to be a still block, and the still_times corresponding to the current block is incremented by 1. If the still_times is greater than the max_still_times value, then the still_times value is set to the max_still_times value.
[0044] If the current block's motion_flag is 1, then the current block is determined to be a moving block, and the still_times corresponding to the current block is set to 0;
[0045]
[0046] In step S3, during the encoding stage, the number of pauses is determined according to the size of the encoding block. For the cu32 block, the minimum number of pauses among the four internal blk16 blocks is taken. For cu16 and smaller blocks, the number of pauses corresponding to the blk16 blocks is used directly.
[0047] During the encoding phase, if the encoding block is cu32, the minimum value of the still_times of the four blk16 blocks within the cu32 block is used as the still_times value of the current cu32; if the encoding block is cu16 or smaller, the still_times value of the current cu16 is used as the still_times value of the current encoding block, and the still_times of the current encoding block is denoted as blk_still_times.
[0048] In step S4, the dual thresholds include thr0 and thr1, and the correspondence between the number of pauses and the block category is as follows:
[0049] Number of rests ≤ thr0: moving block;
[0050] thr0 < number of times at rest ≤ thr1: block at rest after movement;
[0051] Number of times stationary > thr1: Long-term stationary block.
[0052] In step S4, the allocation of the lambda value is implemented through qp_offset, specifically including:
[0053] S4.1 Determine qp_offset based on the number of times the block remains stationary. The qp_offset of the moving block is offset0, the qp_offset of the block that remains stationary after moving is offset1, and the qp_offset of the block that remains stationary for a long time is offset2.
[0054] S4.2, combine the qp and qp_offset of the current block to look up the lambda table to get the final lambda value.
[0055] Step S4 further includes:
[0056] S4.1, Determine the variable qp_offset based on the blk_still_times value of the current coded block; including: S4.1.1, If blk_still_times is less than or equal to thr0, which is an empirical value, preferably 1, then qp_offset = offset0, which is an empirical value, preferably 0;
[0057] S4.1.2, if blk_still_times is greater than thr0 and less than or equal to thr1, it is an empirical value, preferably 3; then qp_offset = offset1, which is an empirical value, preferably -10;
[0058] S4.1.3 If blk_still_times is greater than thr1 and less than or equal to max_still_times, then qp_offset = offset2, which is an empirical value, preferably 3;
[0059]
[0060] S4.2, based on the qp of the current block, look up the corresponding lambda table to obtain the final lambda for participating mode selection;
[0061] lambda=lambda_tbl[max(min(51,qp+qp_offset),1)].
[0062] In step S5, for each mode, merge, merge_skip, amvp, and intra mode, the modified lambda is used for calculation, and the mode with the minimum RDcost is selected as the optimal mode for the current coding block.
[0063] RDCost=distortion+lambda*bits.
[0064] The method is applicable to video encoders.
[0065] Therefore, the advantage of this solution is:
[0066] The method is applicable to video encoders, can reduce the slow recovery phenomenon, and improve the subjective effect of long static blocks; including:
[0067] 1. The recovery scheme based on the number of static cycles is simple to operate and easy to implement in hardware;
[0068] 2. Not limited to motion detection between two frames, this scheme counts the number of times a block remains still in the sequence and uses this count to classify blocks;
[0069] 3. This recovery scheme uses block-level lambda configuration, employing different lambdas for different types of blocks;
[0070] 4. The subjective quality of the recovery plan has been significantly improved. Attached Figure Description
[0071] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.
[0072] Figure 1 This is a diagram illustrating the slow recovery during the encoding process in existing technologies.
[0073] Figure 2 This is a schematic diagram of the lambda_cfg table in this application.
[0074] Figure 3 This is a flowchart illustrating the method used in this application.
[0075] Figure 4 This is a flowchart illustrating a specific example of this application.
[0076] Figures 5(1) and 5(2) are schematic diagrams comparing the bitstream screenshots before and after using this method and after modification.
[0077] Figure 6 This is a pseudocode implementation diagram of the method used in this application. Detailed Implementation
[0078] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.
[0079] This invention provides an encoder recovery method based on the number of stillnesses. The main idea of the method is as follows:
[0080] 1. Count the number of times each block is stationary. Based on the number of stationary times, determine whether the current block is a long-term stationary block or a block that has become stationary after movement. Assign a smaller lambda value to blocks that have become stationary after movement to allow them to recover quickly. Assign a larger lambda value to long-term stationary blocks to make them more likely to remain stationary.
[0081] 2. The number of stills is calculated and detected in units of blk16. In I-frames, the number of stills for each blk16 block is initialized, and each stills count is assigned the maximum number of stills. In p-frames, the number of stills for each blk16 block is updated based on motion detection.
[0082] 3. Motion detection is calculated and detected in units of blk16, and the number of stillnesses for each block is updated. At p-frame, the motion of the current block is determined by the original pixel raw_prev of the reference frame and the original pixel raw of the current frame. If the current block is detected as moving, the number of stillnesses for that block is cleared to 0; otherwise, the number of stillnesses for that block is incremented by 1. If the number of stillnesses exceeds the maximum number of stillnesses, the number of stillnesses is set to the maximum number of stillnesses.
[0083] 4. During the encoding phase, the CTU of the encoding block is set to 32, so the maximum CU block size is 32x32. A different lambda value is assigned to each encoding block based on the number of pauses in each block. If the current encoding block is CU32, the minimum number of pauses among the four blk16 blocks within the current block is used as the number of pauses for the current CU32; if the current encoding block is CU16 or smaller, the number of pauses in the corresponding blk16 block position is used as the number of pauses for the current CU.
[0084] 5. Set two thresholds for the current encoder to determine its state. If the number of times the current block stops is between the two thresholds, the current block is determined to be a block that has stopped after moving; if it is less than the threshold, it is determined to be a moving block; if it is greater than the threshold, it is determined to be a long-term stationary block.
[0085] 6. Set lambda for the current coding block according to the block type of the current coding block. For example, set a larger lambda for long-term static blocks; set a smaller lambda for static blocks after movement; and set the default lambda for moving blocks.
[0086] 7. Each mode uses the set lambda to calculate RDcost, and the mode with the smallest RDcost is selected as the best mode for the current block.
[0087] The overall process of the method includes:
[0088] 1. Initialization
[0089] (1) At each I-frame, initialize the still_times of all blk16 to the maximum value max_still_times (5, which is an empirical value);
[0090] 2. Motion determination
[0091] (1) At each P-frame, calculate the mean value of motion_avg, which is the sum of the absolute values of the differences between each pixel in the current blk16 block raw and the previous frame raw_prev at the same position. If motion_avg is greater than the threshold motion_thrd (8, which is an empirical value), then the current block is determined to be in motion and motion_flag is set to 1; otherwise, it is 0.
[0092]
[0093] 3. If the current block's motion_flag is 0, then the current block is determined to be a still block, and the still_times corresponding to the current block is incremented by 1. If the still_times is greater than the max_still_times value, then the still_times value is set to the max_still_times value.
[0094] If the current block's motion_flag is 1, then the current block is determined to be a moving block, and the still_times corresponding to the current block is set to 0;
[0095]
[0096] 4. During the encoding stage, if the encoding block is cu32, the minimum value of the still_times of the four blk16 values within the cu32 block is taken as the still_times value of the current cu32; if the encoding block is cu16 or smaller, the still_times value of the current cu16 is used as the still_times value of the current encoding block, and the still_times of the current encoding block is denoted as blk_still_times.
[0097] 5. Determine the variable qp_offset based on the blk_still_times value of the current encoded block. If blk_still_times is less than or equal to thr0 (1, an empirical value), then qp_offset = offset0 (0, an empirical value); if blk_still_times is greater than thr0 and less than or equal to thr1 (3, an empirical value), then qp_offset = offset1 (-10, an empirical value); if blk_still_times is greater than thr1 and less than or equal to max_still_times, then qp_offset = offset2 (3, an empirical value).
[0098]
[0099] 6. Based on the qp of the current block, look up the corresponding lambda table to obtain the final lambda for participating mode selection;
[0100] lambda=lambda_tbl[max(min(51,qp+qp_offset),1)]
[0101] 7. For each mode, merge, merge_skip, amvp, and intra mode, the modified lambda is used for calculation, and the mode with the minimum RDcost is selected as the optimal mode for the current coding block.
[0102] RDCost=distortion+lambda*bits.
[0103] In summary, as Figure 3 As shown, this application provides an encoder recovery method based on the number of stillnesses, which includes the following steps:
[0104] S1, Input the video source and determine whether it is an I-frame. If it is, initialize the number of still times to the maximum value at the I-frame. The number of still times is calculated and detected in units of blk16. If not, proceed to step S2 for motion determination. At each I-frame, initialize the still_times of all blk16 still times to the maximum value max_still_times, which is an empirical value, preferably 5.
[0105] The number of still frames is dynamically updated based on motion detection results at P-frame.
[0106] S2, motion detection is performed in units of blk16. The motion state is determined by calculating the average pixel difference between the current frame and the reference frame. If it is a moving block, the number of stationary blocks is reset to zero; otherwise, the number of stationary blocks is incremented by 1 and limited to the maximum number of stationary blocks. The specific steps of motion detection in step S2 include: S2.1, calculating the average value of the sum of the absolute values of the pixel differences between the current blk16 blocks and the corresponding blocks in the reference frame, motion_avg.
[0107] That is, at each P-frame, the mean value of motion_avg is calculated as the sum of the absolute values of the differences between each pixel in the current blk16 block raw and the previous frame raw_prev at the same position.
[0108]
[0109] S2.2 If motion_avg is greater than the preset threshold motion_thrd, which is an empirical value, preferably 8, then the current block is determined to be a moving block and motion_flag is set to 1; otherwise, it is 0 and is a stationary block.
[0110]
[0111] S2.3, Update the number of stationary blocks based on the judgment result. The number of stationary blocks for moving blocks is reset to zero, and the number of stationary blocks for stationary blocks is incremented by 1 and limited to the maximum value.
[0112] If the current block's motion_flag is 0, then the current block is determined to be a still block, and the still_times corresponding to the current block is incremented by 1. If the still_times is greater than the max_still_times value, then the still_times value is set to the max_still_times value.
[0113] If the current block's motion_flag is 1, then the current block is determined to be a moving block, and the still_times corresponding to the current block is set to 0;
[0114]
[0115] S3, during the encoding stage, the number of pauses is determined according to the size of the encoding block. The cu32 block takes the minimum number of pauses among the four internal blk16 blocks, and the cu16 and smaller blocks directly use the corresponding number of pauses for blk16.
[0116] During the encoding phase, if the encoding block is cu32, the minimum value of the still_times of the four blk16 blocks within the cu32 block is used as the still_times value of the current cu32; if the encoding block is cu16 or smaller, the still_times value of the current cu16 is used as the still_times value of the current encoding block, and the still_times of the current encoding block is denoted as blk_still_times.
[0117] S4, determine the block category based on the relationship between the number of pauses and the double threshold, and assign corresponding lambda values to blocks of different categories; including:
[0118] Count the number of times each block is stationary, and determine whether the current block is a long-term stationary block, a stationary block after movement, or a moving block based on the number of stationary times;
[0119] The lambda is set according to the block type of the current coding block. Smaller lambda values are assigned to static blocks after movement, and larger lambda values are assigned to static blocks that have been static for a long time. The default lambda value is used for moving blocks.
[0120] In step S4
[0121] The dual thresholds include thr0 and thr1, and the correspondence between the number of pauses and the block category is as follows:
[0122] Number of rests ≤ thr0: moving block;
[0123] thr0 < number of times at rest ≤ thr1: block at rest after movement;
[0124] Number of times stationary > thr1: Long-term stationary block.
[0125] In step S4, the allocation of the lambda value is implemented through qp_offset, specifically including:
[0126] S4.1 Determine qp_offset based on the number of times the block remains stationary. The qp_offset of the moving block is offset0, the qp_offset of the block that remains stationary after moving is offset1, and the qp_offset of the block that remains stationary for a long time is offset2.
[0127] S4.2, combine the qp and qp_offset of the current block to look up the lambda table to get the final lambda value.
[0128] Step S4 further includes:
[0129] S4.1, Determine the variable qp_offset based on the blk_still_times value of the current coded block; including: S4.1.1, If blk_still_times is less than or equal to thr0, which is an empirical value, preferably 1, then qp_offset = offset0, which is an empirical value, preferably 0;
[0130] S4.1.2, if blk_still_times is greater than thr0 and less than or equal to thr1, it is an empirical value, preferably 3; then qp_offset = offset1, which is an empirical value, preferably -10;
[0131] S4.1.3 If blk_still_times is greater than thr1 and less than or equal to max_still_times, then qp_offset = offset2, which is an empirical value, preferably 3;
[0132]
[0133] S4.2, based on the qp of the current block, look up the corresponding lambda table to obtain the final lambda for participating mode selection;
[0134] lambda=lambda_tbl[max(min(51,qp+qp_offset),1)].
[0135] S5 calculates the rate-distortion cost (RDC) for each mode using the allocated lambda value, and selects the mode with the lowest cost as the optimal coding mode. For each mode, the modified lambda is used to calculate the RDC, and the mode with the lowest RDC is selected as the optimal mode for the current block. For each mode—merge, merge_skip, amvp, and intra—the modified lambda is used for calculation, and the mode with the lowest RDC is selected as the optimal mode for the current coding block.
[0136] RDCost=distortion+lambda*bits.
[0137] like Figure 4 As shown, a specific process example includes:
[0138] S1: Input video source, determine if it is an I-frame?
[0139] No: Perform blk16 motion determination; proceed to step S2;
[0140] Yes: Initialize still_time to max_still_times; iterate through the encoded blocks, determine the RDCost of each block, and select the mode with the minimum RDCost as the best mode.
[0141] S2: Determine if it is a moving block?
[0142] No: Increment still_times and Clip(still_times, max_still_times);
[0143] Yes: Set the still_times of this block to 0;
[0144] S3: Determine if the encoding is 32x32?
[0145] Yes: Calculate blk_still_times=min(still_times[blk_idx0]...still_times[blk_idx3]); No: Calculate blk_still_times=still_times[blk_idx0];
[0146] S4.1: Determine qp_offset based on blk_still_times;
[0147] S4.2: Determine lambda based on the current encoded block qp and qp_offset;
[0148] S5: Determine RDCost and select the mode with the lowest RDCost as the optimal mode; return to step S3.
[0149] Specific pseudocode such as Figure 6 As shown.
[0150] The comparison of the use of this technical solution is shown in Figures 5(1) and 5(2), which are screenshots of the bitstream before and after modification. In Figure 5(1), the arrows indicate that the blocks still have residuals after a period of time after the movement and are still recovering, while the same area in Figure 5(2) has no residuals and remains stationary. The circles in Figure 5(1) indicate the area shortly after the movement, but the recovered area is smaller and more blurred than the area in Figure 5(2).
[0151] In summary, the present invention can achieve the following:
[0152] 1. A hardware-friendly motion block recovery algorithm;
[0153] 2. Blocks are classified by determining the number of times they remain still throughout the entire video sequence;
[0154] 3. Use block-level lambda configuration to apply different lambdas to different types of blocks and participate in the encoder mode selection decision;
[0155] 4. Identify long-term static blocks and apply a lower lambda to them for better subjective results;
[0156] 5. Reduce the slow recovery phenomenon in video encoding.
[0157] This technical solution can be applied to the T33 chip and similar chips that Ingenic is about to begin manufacturing.
[0158] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An encoder recovery method based on the number of stillnesses, characterized in that, Includes the following steps: S1, Input video source, determine if it is an I-frame. If it is, initialize the number of still frames to the maximum value in the I-frame. The number of still frames is calculated and detected in units of blk16. If not, proceed to step S2 motion determination. S2, motion detection is performed in units of blk16. The motion state is determined by calculating the average pixel difference between the current frame and the reference frame. If it is a moving block, the number of stationary positions is reset to zero; otherwise, the number of stationary positions is incremented by 1 and limited to the maximum number of stationary positions. S3, During the encoding stage, the number of pauses is determined according to the size of the encoding block. For cu32 blocks, the minimum number of pauses among the four internal blk16 blocks is taken. For cu16 and smaller blocks, the number of pauses corresponding to blk16 is used directly. S4, determine the block category based on the relationship between the number of pauses and the double threshold, and assign corresponding lambda values to blocks of different categories; including: Count the number of times each block is stationary, and determine whether the current block is a long-term stationary block, a stationary block after movement, or a moving block based on the number of stationary times; The lambda is set according to the block type of the current coding block. Smaller lambda values are assigned to static blocks after movement, and larger lambda values are assigned to static blocks that have been static for a long time. The default lambda value is used for moving blocks. S5 uses the allocated lambda value to calculate the rate-distortion cost of each mode and selects the mode with the minimum cost as the best encoding mode; for each mode, the set lambda is used to calculate the RDcost, and the mode with the minimum RDcost is selected as the best mode for the current block.
2. The method according to claim 1, characterized in that, Step S1 further includes: inputting a video source, and when each I-frame arrives, initializing the still_times of all blk16 frames to the maximum value max_still_times, which is an empirical value, preferably 5; The number of still frames is dynamically updated based on motion detection results at P-frame.
3. The method according to claim 2, characterized in that, In step S2, the specific steps of motion detection include: S2.1, calculate the mean value of the sum of the absolute values of the pixel differences between the current blk16 block and the corresponding block in the reference frame, motion_avg; That is, at each P-frame, the mean value of motion_avg is calculated as the sum of the absolute values of the differences between each pixel in the current blk16 block raw and the previous frame raw_prev at the same position. S2.2 If motion_avg is greater than the preset threshold motion_thrd, which is an empirical value, preferably 8, then the current block is determined to be a moving block and motion_flag is set to 1; otherwise, it is 0 and is a stationary block. S2.3, Update the number of stationary blocks based on the judgment result. The number of stationary blocks for moving blocks is reset to zero, and the number of stationary blocks for stationary blocks is incremented by 1 and limited to the maximum value. If the current block's motion_flag is 0, then the current block is determined to be a still block, and the still_times corresponding to the current block is incremented by 1. If the still_times is greater than the max_still_times value, then the still_times value is set to the max_still_times value. If the current block's motion_flag is 1, then the current block is determined to be a moving block, and the still_times corresponding to the current block is set to 0; 4. The method according to claim 3, characterized in that, In step S3, during the encoding stage, the number of pauses is determined according to the size of the encoding block. For the cu32 block, the minimum number of pauses among the four internal blk16 blocks is taken. For cu16 and smaller blocks, the number of pauses corresponding to the blk16 blocks is used directly. During the encoding phase, if the encoding block is cu32, the minimum value of the still_times of the four blk16 blocks within the cu32 block is used as the still_times value of the current cu32; if the encoding block is cu16 or smaller, the still_times value of the current cu16 is used as the still_times value of the current encoding block, and the still_times of the current encoding block is denoted as blk_still_times.
5. The method according to claim 4, characterized in that, In step S4 The dual thresholds include thr0 and thr1, and the correspondence between the number of pauses and the block category is as follows: Number of rests ≤ thr0: moving block; thr0 < number of times at rest ≤ thr1: block at rest after movement; Number of times stationary > thr1: Long-term stationary block.
6. The method according to claim 5, characterized in that, In step S4, the allocation of the lambda value is implemented through qp_offset, specifically including: S4.1 Determine qp_offset based on the number of times the block remains stationary. The qp_offset of the moving block is offset0, the qp_offset of the block that remains stationary after moving is offset1, and the qp_offset of the block that remains stationary for a long time is offset2. S4.2, combine the qp and qp_offset of the current block to look up the lambda table to get the final lambda value.
7. The method according to claim 6, characterized in that, Step S4 further includes: S4.1, determining the variable qp_offset based on the blk_still_times value of the current coded block; including: S4.1.1, if blk_still_times is less than or equal to thr0, which is an empirical value, preferably 1, then qp_offset = offset0, which is an empirical value, preferably 0; S4.1.2, if blk_still_times is greater than thr0 and less than or equal to thr1, it is an empirical value, preferably 3; then qp_offset = offset1, which is an empirical value, preferably -10; S4.1.3 If blk_still_times is greater than thr1 and less than or equal to max_still_times, then qp_offset = offset2, which is an empirical value, preferably 3; S4.2, based on the qp of the current block, look up the corresponding lambda table to obtain the final lambda for participating mode selection; lambda=lambda_tbl[max(min(51,qp+qp_offset),1)].
8. The method according to claim 1, characterized in that, In step S5, for each mode, merge, merge_skip, amvp, and intra mode, the modified lambda is used for calculation, and the mode with the minimum RDcost is selected as the optimal mode for the current coding block. RDCost=distortion+lambda*bits.