Video coding method and device based on quantization parameter adaptive adjustment
By calculating the motion area ratio of the encoding unit in the video frame and adaptively adjusting the quantization parameters, the problem of breathing effect in video encoding is solved, the encoding efficiency is improved and applicable to multiple encoding standards.
Patent Information
- Application Number
- CN202411994329.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-06
AI Technical Summary
In the existing video encoding technology, the breathing effect causes periodic distortions in the background or edges of static scenes in the video, affecting visual quality, and the existing suppression methods are inefficient or non-common.
By calculating the proportion of the motion area of each encoding unit in the current frame, the quantization parameter value is adaptively adjusted to suppress the respiration effect, and the quantization parameter adjustment can be achieved without modifying the standard in different encoding standards.
It effectively suppresses the breathing effect during video encoding, improves video encoding efficiency, and is suitable for different encoding standards without secondary encoding.
Smart Images

Figure CN119946265A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of video image encoding, and in particular to a video encoding method and device based on adaptive adjustment of quantization parameters. Background Art
[0002] In video encoding, in order to save bit rate during the compression process, the video encoding algorithm compresses some parts of the video frame more, while other parts retain more details, resulting in obvious quality differences in different areas and a visual distortion phenomenon, namely the "breathing effect". When the encoded video is played, the background or edges of the static scene in the video will periodically show slight distortion or changes, giving the viewer a feeling of instability and discontinuity. This is more obvious when switching between I frames (Intra-coded Frames) and P frames (Predicted Frames).
[0003] In order to solve the visual quality problem caused by the breathing effect, the existing methods for suppressing the breathing effect include:
[0004] 1. Use two-time encoding to introduce time-domain distortion information into the I frame, thereby reducing the visual distortion problem caused by the breathing effect. However, the two-time encoding method requires multiple encodings, consumes a lot of computing resources, and is difficult to meet real-time requirements, resulting in low video encoding efficiency.
[0005] 2. Visual distortion calculation is introduced into the module that calculates the rate-distortion cost in the encoder core, thereby affecting the selection of the prediction mode. However, since different video coding standards use different prediction modes, this method has poor versatility and is difficult to apply to other coding platforms with different coding standards. When used on different coding platforms, the coding standard of the coding platform needs to be modified, resulting in low video coding efficiency.
[0006] Therefore, how to effectively suppress the breathing effect and improve video coding efficiency has become an urgent problem to be solved. Summary of the invention
[0007] The present application provides a video encoding method and device based on adaptive adjustment of quantization parameters to suppress the breathing effect and improve video encoding efficiency.
[0008] In a first aspect, the present application provides a video encoding method based on adaptive adjustment of quantization parameters, the method comprising:
[0009] Calculating a motion region ratio of each coding unit of a preset pixel size in the current frame based on motion state information of the current frame;
[0010] Based on the motion region ratio of each coding unit, an initial quantization parameter value of each coding unit is adjusted to obtain a target quantization parameter value;
[0011] The current frame is encoded based on the target quantization parameter values of each encoding unit until all frame images of the video to be encoded are encoded to obtain an encoded video.
[0012] In a second aspect, the present application further provides a video encoding device based on adaptive adjustment of quantization parameters, the device comprising:
[0013] A ratio obtaining module, configured to calculate a motion region ratio of each coding unit of a preset pixel size in the current frame based on motion state information of the current frame;
[0014] A parameter value adjustment module, configured to adjust an initial quantization parameter value of each coding unit based on a motion region ratio of each coding unit to obtain a target quantization parameter value;
[0015] The video encoding module is used to encode the current frame based on the target quantization parameter value of each encoding unit until all frame images of the video to be encoded are encoded to obtain an encoded video.
[0016] In a third aspect, the present application also provides a computer device, comprising a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program and implement the video encoding method based on adaptive adjustment of quantization parameters as described above when executing the computer program.
[0017] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the video encoding method based on adaptive adjustment of quantization parameters as described above.
[0018] The present application discloses a video encoding method and device based on adaptive adjustment of quantization parameters. Based on the motion state information of the current frame, the motion area ratio of each encoding unit of a preset pixel size in the current frame is calculated; based on the motion area ratio of each encoding unit, the initial quantization parameter value of each encoding unit is adjusted to obtain a target quantization parameter value; based on the target quantization parameter value of each encoding unit, the current frame is encoded until all frames of the video to be encoded are encoded to obtain the encoded video. The present application can adaptively adjust the quantization parameter value corresponding to the encoding unit according to the motion area ratio of each encoding unit, and obtain the target quantization parameter value that meets each encoding unit, so as to suppress the breathing effect in the video encoding process. Moreover, the quantization parameter can be modified in different encoding standards without modifying the encoding standard or performing secondary encoding on the video to be encoded, thereby improving the encoding efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 is a schematic flow chart of a video encoding method based on adaptive adjustment of quantization parameters provided by the first embodiment of the present application;
[0021] Figure 2 is a schematic flow chart of a video encoding method based on adaptive adjustment of quantization parameters provided by the second embodiment of the present application;
[0022] Figure 3 A schematic block diagram of a video encoding device based on adaptive adjustment of quantization parameters provided in an embodiment of the present application;
[0023] Figure 4 A schematic block diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0025] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0026] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0027] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0028] The embodiment of the present application provides a video encoding method and device based on adaptive adjustment of quantization parameters. Among them, the video encoding method based on adaptive adjustment of quantization parameters can be applied to a server, and the quantization parameter value corresponding to the coding unit can be adaptively adjusted according to the motion area ratio of each coding unit to obtain the target quantization parameter value that meets each coding unit, so as to suppress the breathing effect in the video encoding process. Moreover, the quantization parameters can be modified in different coding standards without modifying the coding standards or performing secondary encoding on the encoded video, thereby improving the coding efficiency. Among them, the server can be an independent server or a server cluster.
[0029] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0030] See also Figure 1 , Figure 1 This is a schematic flow chart of a video encoding method based on adaptive adjustment of quantization parameters provided by an embodiment of the present application. The video encoding method based on adaptive adjustment of quantization parameters can be applied to a server, and is used to adaptively adjust the quantization parameter value corresponding to the encoding unit according to the motion area ratio of each encoding unit, and obtain the target quantization parameter value that meets each encoding unit, so as to suppress the breathing effect in the video encoding process. In addition, the quantization parameters can be modified in different encoding standards without modifying the encoding standard or performing secondary encoding on the encoded video, thereby improving the encoding efficiency.
[0031] like Figure 1 As shown, the video encoding method based on adaptive adjustment of quantization parameters specifically includes steps S101 to S103.
[0032] S101, calculating a motion area ratio of each coding unit of a preset pixel size in the current frame based on motion state information of the current frame;
[0033] In one embodiment, the motion state information includes the motion state value corresponding to each pixel of each frame image. The motion state value indicates the static state and the motion state of the pixel. For example, the motion state value is 0 and 1, representing the static state and the motion state, respectively.
[0034] In one embodiment, the preset pixel size can be freely set by the user according to actual needs, such as 16×16.
[0035] In a specific embodiment, the ratio of motion pixels to total pixels in each CU (Coding Unit) of a preset size is calculated. Specifically, for each CU of a preset pixel size, the number of pixels in a motion state (for example, a motion state value of 1) is counted. The ratio of the number of motion pixels to the total number of pixels in the CU is calculated, that is, the motion area ratio = (the number of motion pixels) / (the total number of pixels in the CU).
[0036] Furthermore, before step S101, it also includes: when receiving the video to be encoded, performing motion estimation on the video to be encoded to obtain a motion vector of each pixel; based on the motion vector, determining the motion state of each pixel, and updating the motion state value of each pixel based on the motion state; after the motion state values of all pixels in the video to be encoded are updated, obtaining the motion state information of each frame image in the video to be encoded.
[0037] In one embodiment, the motion state of each pixel in each frame of the video relative to a reference frame (e.g., the previous frame) is determined. A motion estimation algorithm, such as a block matching algorithm (e.g., full search, three-step search, diamond search, etc.) can be used. An optical flow algorithm can also be used to estimate pixel-level motion. A deep learning method, such as a pre-trained convolutional neural network, can also be used to predict motion vectors.
[0038] In one embodiment, the pixel is classified as static or moving according to the magnitude of the motion vector. Specifically, a threshold is set, and when the magnitude of the motion vector is less than the threshold, the pixel is considered to be static. If the magnitude of the motion vector is greater than or equal to the threshold, the pixel is considered to be moving.
[0039] In one embodiment, the motion state value of the pixel in the stationary state is updated to a first preset value (eg, 0), and the motion state value of the pixel in the moving state is updated to a second preset value (eg, 1).
[0040] In one embodiment, after processing the entire video to be encoded, the motion state values of all pixels in each frame are collected to form the motion state information of each frame. Specifically, a two-dimensional array or image with the same resolution as the video frame can be created to store the motion state value of each pixel. Each pixel in each frame is traversed and the two-dimensional array or image is updated according to its motion state value. After processing all pixels, a two-dimensional array or image corresponding to each frame is obtained, which represents the motion state information of each pixel in each frame.
[0041] Further, the step S101 includes: based on the motion state information, obtaining the motion state value corresponding to each pixel in the coding unit; based on the motion state value, obtaining the number of pixels in the coding unit that are in a motion state; based on the number of pixels in the motion state and the total number of pixels in the coding unit, obtaining the motion area ratio.
[0042] In one embodiment, a motion state value corresponding to each pixel in the coding unit is obtained from the motion state information of the current frame, and the motion state value indicates whether the pixel is in a stationary state or a moving state.
[0043] In one embodiment, how many pixels are marked as being in motion within a coding unit of a preset pixel size is calculated. Specifically, all pixels within the coding unit are traversed, and pixels in motion (eg, pixels with a value of 1) are counted.
[0044] In one embodiment, after obtaining the number of pixels in motion, the ratio of the number of pixels in motion to the total number of pixels in the coding unit is calculated. Specifically, the total number of pixels in the coding unit is determined, for example, for a CU of 16x16 pixels, the total number of pixels is 256. The number of pixels in motion is divided by the total number of pixels in the coding unit to obtain the motion area ratio. The formula is: motion area ratio = (number of pixels in motion) / (total number of pixels in the coding unit).
[0045] Furthermore, before step S101, it also includes: when receiving a video encoding task, decomposing the video encoding task to obtain motion ratio calculation subtasks of the encoding units in each frame image, and storing at least one of the motion ratio calculation subtasks in a preset task queue; obtaining the load status of at least one ratio calculation node, and allocating a ratio calculation node to each motion ratio calculation subtask in the task queue, so as to parallelly calculate the motion area ratio of each encoding unit in the current frame based on at least one of the ratio calculation nodes and the motion state information.
[0046] In one embodiment, after receiving a video encoding task, a video frame sequence of the video to be encoded is analyzed to determine the number and position of coding units (CUs) in each frame, and a motion ratio calculation subtask is created for each CU in each frame.
[0047] In one embodiment, the decomposed proportional calculation subtasks and their corresponding detailed information (such as frame number, CU position, etc.) are stored in one or more pre-created task queues.
[0048] In one embodiment, the load of each proportional computing node is monitored in real time, including CPU usage, memory usage, the number of tasks currently being processed, etc.
[0049] According to the load and processing capacity of the node, one or more proportional calculation nodes are dynamically selected to process the motion proportional calculation subtask in the task queue. Specifically, a load balancing algorithm (such as polling, least connection, weighted allocation, etc.) can be used to allocate the subtasks.
[0050] Specifically, when processing the current frame, at least one ratio calculation node takes out the motion ratio calculation subtask corresponding to the current frame number assigned to it from the task queue, and calculates the motion area ratio of each CU in the current frame based on the motion state information of the current frame, so as to realize parallel processing of multiple motion ratio calculation subtasks.
[0051] In one embodiment, when each ratio calculation node obtains a calculation result, the calculation result is stored in a message queue until all ratio calculation subtasks corresponding to the current frame have obtained calculation results for use in subsequent parameter adjustment.
[0052] In the above embodiment, the distributed processing flow based on the task queue and the proportional computing node realizes parallel processing, which effectively improves the processing speed and efficiency of the video encoding task.
[0053] S102, adjusting the initial quantization parameter value of each coding unit based on the motion region ratio of each coding unit to obtain a target quantization parameter value;
[0054] In one embodiment, the initial quantization parameter value of each coding unit may be a fixed value preset based on a coding scenario, or a value dynamically determined according to a coding strategy.
[0055] In one embodiment, the initial quantization parameter of each coding unit is adjusted according to the motion region ratio of each coding unit to obtain a target quantization parameter value that meets each coding unit, so as to optimize the video encoding quality.
[0056] In one embodiment, after the target quantization parameter values of all coding units of the current frame are obtained, the target quantization parameter value of each coding unit of the current frame is stored in the form of a QP Map.
[0057] Among them, QP Map (Quantization Parameter Map) is a technology used to optimize coding efficiency and video quality in video coding, allowing the encoder to use a specific QP for each CU in a video frame instead of using a single QP value for the entire frame.
[0058] Furthermore, before step S102, it also includes: when each of the proportional calculation nodes obtains a proportional calculation result, storing the proportional calculation result in a preset message queue; when it is detected that the proportional calculation results of all the coding units of the current frame exist in the message queue, generating a parameter adjustment subtask of the current frame, and storing the parameter adjustment subtask in the task queue; obtaining the load condition of at least one parameter adjustment node, and based on the load condition, allocating a parameter adjustment node to each quantization parameter adjustment subtask in the task queue, so as to adjust the initial quantization parameter value of each coding unit in parallel based on at least one parameter adjustment node to obtain the target quantization parameter value.
[0059] In one embodiment, after completing the calculation, each ratio calculation node sends the result to a preset message queue. The result may include information such as the frame number, CU number, and the calculated motion area ratio.
[0060] Monitor the message queue to detect whether the ratio calculation results of all CUs of the current frame have been collected. Specifically, a counter, a flag, or a specific data structure can be used to track the result collection status of the current frame.
[0061] When it is detected that the motion ratio calculation results of all CUs in the current frame already exist, a parameter adjustment subtask is generated based on these results. The subtask contains the CU information for which the quantization parameter needs to be adjusted and the corresponding motion area ratio.
[0062] In one embodiment, the generated parameter adjustment subtask is added to a task queue, waiting to be processed by the parameter adjustment node.
[0063] Monitor the load and processing capacity of each parameter adjustment node in real time, such as CPU usage, memory usage, number of tasks currently being processed, etc. Based on the load and processing capacity of the node, dynamically select one or more parameter adjustment nodes to process the parameter adjustment subtasks of the task queue.
[0064] In one embodiment, each parameter adjustment node takes out the subtask assigned to it from the task queue and calculates the target quantization parameter value based on the motion area ratio and the quantization parameter adjustment strategy, thereby achieving parallel adjustment of quantization parameters of multiple coding units and improving processing efficiency.
[0065] In one embodiment, when each parameter adjustment node obtains a calculation result, the result is stored in a message queue until the quantization parameters of all coding units of the current frame have been adjusted, and the target quantization parameters of all coding units of the current frame are extracted from the message queue, and the target quantization parameters of all coding units of the current frame are stored in the form of a QP Map.
[0066] S103 , encoding the current frame based on the target quantization parameter values of the encoding units until all frames of the video to be encoded are encoded to obtain an encoded video.
[0067] In one embodiment, the target quantization parameter value in the form of QP Map is input into the encoder, and the current frame is encoded according to the target quantization parameter value of each coding unit in a rate control manner.
[0068] In one embodiment, the above steps are repeated until all frames of the video to be encoded are encoded, and then the encoding is terminated to obtain the encoded video.
[0069] The above embodiment provides a video encoding method and device based on adaptive adjustment of quantization parameters. Based on the motion state information of the current frame, the motion area ratio of each coding unit of a preset pixel size in the current frame is calculated; based on the motion area ratio of each coding unit, the initial quantization parameter value of each coding unit is adjusted to obtain a target quantization parameter value; based on the target quantization parameter value of each coding unit, the current frame is encoded until all frames of the video to be encoded are encoded, and the encoded video is obtained. The present application can adaptively adjust the quantization parameter value corresponding to the coding unit according to the motion area ratio of each coding unit, and obtain the target quantization parameter value that meets each coding unit, so as to suppress the breathing effect in the video encoding process. At the same time, the quantization parameter adjustment is easy to implement in the existing encoding system, without modifying the encoding standard, and the video to be encoded can be directly encoded according to the obtained target quantization parameter value, without the need to perform secondary encoding on the video to be encoded, thereby improving the encoding efficiency.
[0070] See also Figure 2 , Figure 2The present invention is a schematic flow chart of a video encoding method based on adaptive adjustment of quantization parameters provided by an embodiment of the present application. The video encoding method based on adaptive adjustment of quantization parameters can be applied to a server, and is used to obtain a quantization parameter offset value of each coding unit according to the motion area ratio of each coding unit, and adjust the quantization parameter of each coding unit by the quantization parameter offset value, so as to reduce visual distortion when switching video frames and suppress the generation of breathing effect.
[0071] like Figure 2 As shown, the video encoding method based on adaptive adjustment of quantization parameters specifically includes steps S201 to S204.
[0072] S201, obtaining a quantization parameter difference between a target frame and the current frame, and calculating a quantization parameter offset value of each coding unit based on the motion area ratio and the quantization parameter difference, wherein the target frame is the first key frame in the key frame interval corresponding to the current frame;
[0073] S202: Taking the sum of the initial quantization parameter value of each coding unit and the quantization parameter offset value as the target quantization parameter value of each coding unit.
[0074] Further, the calculating the quantization parameter offset value of each coding unit based on the motion area ratio and the quantization parameter difference value includes: obtaining a preset offset value calculation formula; calculating the quantization parameter offset value based on the motion area ratio, the quantization parameter difference value and the offset value calculation formula;
[0075] Among them, the offset value calculation formula is:
[0076] ΔQP j =P j Motion ·QP diff -(1-P j Motion )·QP diff
[0077] ΔQP j is the quantization parameter offset value of the jth coding unit, P j Motion is the motion area ratio of the jth coding unit, the quantization parameter difference QP diff =QP P -QP I , QP P is the quantization parameter value of the current frame, QP I is the quantization parameter value of the target frame.
[0078] In one embodiment, a quantization parameter difference between a target frame and a current frame is determined. The target frame is the first I frame in an I frame (Intra-coded Frame, key frame) interval corresponding to the current frame. The I frame interval refers to the frame number interval between two consecutive I frames in video coding.
[0079] Specifically, the QP value of the target frame and the QP value of the current frame are determined. Calculate the difference: QP diff =QP P -QP I , QP P is the quantization parameter value of the current frame, QP I is the quantization parameter value of the target frame.
[0080] In one embodiment, for each CU, the quantization parameter offset value is determined according to the offset value calculation formula and its motion area ratio. The offset value calculation formula is ΔQP j =P j Motion ·QP diff -(1-P j Motion )·QP diff .P j Motion ·QP diff Indicates the contribution of the motion area to the QP offset value, (1-P j Motion )·QP diff Indicates the contribution of the static area to the QP offset value. The total QP offset value is calculated by combining the contributions of the moving area and the static area, so that the QP value is dynamically adjusted according to the ratio of moving and static pixels in the CU.
[0081] In one embodiment, for each CU, its initial QP value is added to the calculated offset value to obtain the target quantization parameter value. When the encoded video is played, the breathing effect is manifested as the background or edge of the static scene in the video periodically showing slight distortion or change, which gives the viewer a sense of instability and discontinuity. Therefore, in the above embodiment, when the motion area ratio of the coding unit is smaller and the static area ratio is larger, the quantization parameter offset value is smaller, and then the target quantization parameter value of the coding unit is smaller, thereby maintaining more image details and reducing the breathing effect.
[0082] In the above embodiment, the quantization parameter offset value of each coding unit is obtained according to the motion area ratio of each coding unit, and the quantization parameter of each coding unit is adjusted by the quantization parameter offset value to reduce the visual distortion when the video frame is switched and suppress the breathing effect.
[0083] See also Figure 3 , Figure 3 The embodiment of the present application provides a schematic block diagram of a video encoding device based on adaptive adjustment of quantization parameters, and the video encoding device based on adaptive adjustment of quantization parameters is used to execute the aforementioned video encoding method based on adaptive adjustment of quantization parameters. The video encoding device based on adaptive adjustment of quantization parameters can be configured on a server.
[0084] like Figure 3 As shown, the video encoding device 300 based on adaptive adjustment of quantization parameters includes:
[0085] A ratio obtaining module 301 is used to calculate the motion area ratio of each coding unit of a preset pixel size in the current frame based on the motion state information of the current frame;
[0086] A parameter value adjustment module 302, configured to adjust an initial quantization parameter value of each coding unit based on a motion region ratio of each coding unit to obtain a target quantization parameter value;
[0087] The video encoding module 303 is used to encode the current frame based on the target quantization parameter value of each encoding unit until all frames of the video to be encoded are encoded to obtain an encoded video.
[0088] Furthermore, the parameter value adjustment module includes:
[0089] an offset value calculation unit, configured to obtain a quantization parameter difference between a target frame and the current frame, and calculate a quantization parameter offset value of each encoding unit based on the motion region ratio and the quantization parameter difference, wherein the target frame is the first key frame in a key frame interval corresponding to the current frame;
[0090] The target value obtaining unit is used to take the sum of the initial quantization parameter value of each coding unit and the quantization parameter offset value as the target quantization parameter value of each coding unit.
[0091] Furthermore, the offset value calculation unit includes:
[0092] A formula acquisition subunit is used to acquire a preset offset value calculation formula;
[0093] an offset value calculation subunit, configured to calculate the quantization parameter offset value based on the motion region ratio, the quantization parameter difference value, and the offset value calculation formula;
[0094] Among them, the offset value calculation formula is:
[0095] ΔQP j =P j Motion ·QP diff-(1-P j Motion )·QP diff
[0096] ΔQP j is the quantization parameter offset value of the jth coding unit, P j Motion is the motion area ratio of the jth coding unit, the quantization parameter difference QP diff =QP P -QP I , QP P is the quantization parameter value of the current frame, QP I is the quantization parameter value of the target frame.
[0097] Furthermore, the ratio obtaining module includes:
[0098] A state value acquisition unit, configured to acquire a motion state value corresponding to each pixel in the coding unit based on the motion state information;
[0099] A pixel number obtaining unit, used for obtaining the number of pixels in the coding unit that are in a motion state based on the motion state value;
[0100] The ratio obtaining unit is used to obtain the motion area ratio based on the number of pixels in the motion state and the total number of pixels in the coding unit.
[0101] Furthermore, the video encoding device based on adaptive adjustment of quantization parameters further includes a proportional calculation node allocation module, and the proportional calculation node allocation module includes:
[0102] A task decomposition unit is used to decompose the video encoding task upon receiving the video encoding task, obtain motion ratio calculation subtasks of the encoding unit in each frame image, and store at least one of the motion ratio calculation subtasks into a preset task queue;
[0103] A proportional calculation node allocation unit is used to obtain the load status of at least one proportional calculation node, allocate a proportional calculation node to each motion proportional calculation subtask in the task queue, and parallelly calculate the motion area ratio of each coding unit in the current frame based on at least one of the proportional calculation nodes and the motion state information.
[0104] Furthermore, the video encoding device based on adaptive adjustment of quantization parameters further includes a parameter adjustment node allocation module, and the parameter adjustment node allocation module includes:
[0105] A result storage unit, used for storing the proportion calculation result in a preset message queue when each proportion calculation node obtains the proportion calculation result;
[0106] A parameter adjustment subtask generating unit, configured to generate a parameter adjustment subtask for the current frame when detecting that the proportion calculation results of all coding units of the current frame exist in the message queue, and store the parameter adjustment subtask in the task queue;
[0107] A parameter adjustment node allocation unit is used to obtain the load condition of at least one parameter adjustment node, and based on the load condition, allocate a parameter adjustment node to each quantization parameter adjustment subtask in the task queue, so as to adjust the initial quantization parameter value of each encoding unit in parallel based on at least one parameter adjustment node to obtain a target quantization parameter value.
[0108] Furthermore, the video encoding device based on adaptive adjustment of quantization parameters further includes a motion state information acquisition module, and the motion state acquisition module includes:
[0109] A motion vector obtaining unit, configured to perform motion estimation on the video to be encoded when receiving the video to be encoded, and obtain a motion vector of each pixel;
[0110] a motion state value updating unit, configured to determine the motion state of each pixel based on the motion vector, and update the motion state value of each pixel based on the motion state;
[0111] The motion state information obtaining unit is used to obtain the motion state information of each frame image in the video to be encoded after the motion state values of all pixels in the video to be encoded are updated.
[0112] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described device and each module can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0113] The above-mentioned device can be implemented in the form of a computer program. Figure 4 Runs on the computer device shown.
[0114] See also Figure 4 , Figure 4 1 is a schematic block diagram of a computer device provided in an embodiment of the present application. The computer device may be a server.
[0115] See also Figure 4 The computer device includes a processor, a memory and a network interface connected through a system bus, wherein the memory may include a non-volatile storage medium and an internal memory.
[0116] The non-volatile storage medium can store an operating system and a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor can execute any video encoding method based on adaptive adjustment of quantization parameters.
[0117] The processor is used to provide computing and control capabilities and support the operation of the entire computer equipment.
[0118] The internal memory provides an environment for the operation of the computer program in the non-volatile storage medium. When the computer program is executed by the processor, the processor can execute any video encoding method based on adaptive adjustment of quantization parameters.
[0119] The network interface is used for network communication, such as sending assigned tasks, etc. Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0120] It should be understood that the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0121] In one embodiment, the processor is used to run a computer program stored in the memory to implement the following steps:
[0122] Calculating a motion region ratio of each coding unit of a preset pixel size in the current frame based on motion state information of the current frame;
[0123] Based on the motion region ratio of each coding unit, an initial quantization parameter value of each coding unit is adjusted to obtain a target quantization parameter value;
[0124] The current frame is encoded based on the target quantization parameter values of each encoding unit until all frame images of the video to be encoded are encoded to obtain an encoded video.
[0125] In one embodiment, when the processor adjusts the initial quantization parameter value of each coding unit based on the motion region ratio of each coding unit to obtain the target quantization parameter value, it is used to implement:
[0126] Obtaining a quantization parameter difference between a target frame and the current frame, and calculating a quantization parameter offset value of each coding unit based on the motion region ratio and the quantization parameter difference, wherein the target frame is the first key frame in a key frame interval corresponding to the current frame;
[0127] The sum of the initial quantization parameter value of each coding unit and the quantization parameter offset value is used as the target quantization parameter value of each coding unit.
[0128] In one embodiment, when the processor calculates the quantization parameter offset value of each coding unit based on the motion area ratio and the quantization parameter difference, the processor is used to implement:
[0129] Get the preset offset value calculation formula;
[0130] Calculating the quantization parameter offset value based on the motion area ratio, the quantization parameter difference value, and the offset value calculation formula;
[0131] Among them, the offset value calculation formula is:
[0132] ΔQP j =P j Motion ·QP diff -(1-P j Motion )·QP diff
[0133] ΔQP j is the quantization parameter offset value of the jth coding unit, P j Motion is the motion area ratio of the jth coding unit, the quantization parameter difference QP diff =QP P -QP I , QP P is the quantization parameter value of the current frame, QP I is the quantization parameter value of the target frame.
[0134] In one embodiment, when the processor calculates the motion area ratio of each coding unit of a preset pixel size in the current frame based on the motion state information of the current frame, it is used to implement:
[0135] Based on the motion state information, obtaining a motion state value corresponding to each pixel in the coding unit;
[0136] Based on the motion state value, obtaining the number of pixels in the coding unit that are in a motion state;
[0137] The motion area ratio is obtained based on the number of pixels in the motion state and the total number of pixels in the coding unit.
[0138] In one embodiment, before calculating the motion area ratio of each coding unit of a preset pixel size in the current frame based on the motion state information of the current frame, the processor is further configured to implement:
[0139] When receiving a video encoding task, decomposing the video encoding task to obtain motion ratio calculation subtasks of encoding units in each frame image, and storing at least one motion ratio calculation subtask into a preset task queue;
[0140] Obtain the load condition of at least one proportional calculation node, and assign a proportional calculation node to each motion proportional calculation subtask in the task queue, so as to parallelly calculate the motion area ratio of each coding unit in the current frame based on at least one of the proportional calculation nodes and the motion state information.
[0141] In one embodiment, before the processor adjusts the initial quantization parameter value of each coding unit based on the motion region ratio of each coding unit to obtain the target quantization parameter value, it is further used to implement:
[0142] When each of the proportion calculation nodes obtains a proportion calculation result, the proportion calculation result is stored in a preset message queue;
[0143] When it is detected that the proportion calculation results of all coding units of the current frame exist in the message queue, a parameter adjustment subtask of the current frame is generated, and the parameter adjustment subtask is stored in the task queue;
[0144] Obtain the load condition of at least one parameter adjustment node, and based on the load condition, assign a parameter adjustment node to each quantization parameter adjustment subtask in the task queue, so as to adjust the initial quantization parameter value of each encoding unit in parallel based on at least one parameter adjustment node to obtain a target quantization parameter value.
[0145] In one embodiment, before calculating the motion area ratio of each coding unit of a preset pixel size in the current frame based on the motion state information of the current frame, the processor is further configured to implement:
[0146] When receiving a video to be encoded, performing motion estimation on the video to be encoded to obtain a motion vector of each pixel;
[0147] Based on the motion vector, determining the motion state of each pixel, and updating the motion state value of each pixel based on the motion state;
[0148] After the motion state values of all pixels of the video to be encoded are updated, the motion state information of each frame image in the video to be encoded is obtained.
[0149] A computer-readable storage medium is also provided in an embodiment of the present application, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and the processor executes the program instructions to implement any one of the video encoding methods based on adaptive adjustment of quantization parameters provided in the embodiments of the present application.
[0150] The computer-readable storage medium may be an internal storage unit of the computer device described in the foregoing embodiment, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (Smart Medi a Card, SMC), a secure digital (Secure Digital, SD) card, a flash memory card (Flash Card), etc., equipped on the computer device.
[0151] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A video encoding method based on adaptive adjustment of quantization parameters, characterized in that: include: Calculating a motion region ratio of each coding unit of a preset pixel size in the current frame based on motion state information of the current frame; Based on the motion region ratio of each coding unit, an initial quantization parameter value of each coding unit is adjusted to obtain a target quantization parameter value; The current frame is encoded based on the target quantization parameter values of each encoding unit until all frame images of the video to be encoded are encoded to obtain an encoded video.
2. The video encoding method based on adaptive adjustment of quantization parameters according to claim 1, characterized in that: The adjusting the initial quantization parameter value of each coding unit based on the motion region ratio of each coding unit to obtain the target quantization parameter value includes: Obtaining a quantization parameter difference between a target frame and the current frame, and calculating a quantization parameter offset value of each coding unit based on the motion region ratio and the quantization parameter difference, wherein the target frame is the first key frame in a key frame interval corresponding to the current frame; The sum of the initial quantization parameter value of each coding unit and the quantization parameter offset value is used as the target quantization parameter value of each coding unit.
3. The video encoding method based on adaptive adjustment of quantization parameters according to claim 2, characterized in that: The calculating the quantization parameter offset value of each coding unit based on the motion area ratio and the quantization parameter difference value includes: Get the preset offset value calculation formula; Calculating the quantization parameter offset value based on the motion area ratio, the quantization parameter difference value, and the offset value calculation formula; Among them, the offset value calculation formula is: ΔQP j =P j Motion ·QP diff -(1-P j Motion )·QP diff ΔQP j is the quantization parameter offset value of the jth coding unit, P j Motion is the motion area ratio of the jth coding unit, the quantization parameter difference QP diff =QP P -QP I , QP P is the quantization parameter value of the current frame, QP I is the quantization parameter value of the target frame.
4. The video encoding method based on adaptive adjustment of quantization parameters according to claim 1, characterized in that: The calculating, based on the motion state information of the current frame, the motion area ratio of each coding unit of a preset pixel size in the current frame includes: Based on the motion state information, obtaining a motion state value corresponding to each pixel in the coding unit; Based on the motion state value, obtaining the number of pixels in the coding unit that are in a motion state; The motion area ratio is obtained based on the number of pixels in the motion state and the total number of pixels in the coding unit.
5. The video encoding method based on adaptive adjustment of quantization parameters according to claim 1, characterized in that: Before calculating the motion area ratio of each coding unit of a preset pixel size in the current frame based on the motion state information of the current frame, the method further includes: When receiving a video encoding task, decomposing the video encoding task to obtain motion ratio calculation subtasks of encoding units in each frame image, and storing at least one motion ratio calculation subtask into a preset task queue; Obtain the load condition of at least one proportional calculation node, and assign a proportional calculation node to each motion proportional calculation subtask in the task queue, so as to parallelly calculate the motion area ratio of each coding unit in the current frame based on at least one of the proportional calculation nodes and the motion state information.
6. The video encoding method based on adaptive adjustment of quantization parameters according to claim 5, characterized in that: Before the initial quantization parameter value of each coding unit is adjusted based on the motion region ratio of each coding unit to obtain the target quantization parameter value, the method further includes: When each of the proportion calculation nodes obtains a proportion calculation result, the proportion calculation result is stored in a preset message queue; When it is detected that the proportion calculation results of all coding units of the current frame exist in the message queue, a parameter adjustment subtask of the current frame is generated, and the parameter adjustment subtask is stored in the task queue; Obtain the load condition of at least one parameter adjustment node, and based on the load condition, assign a parameter adjustment node to each quantization parameter adjustment subtask in the task queue, so as to adjust the initial quantization parameter value of each encoding unit in parallel based on at least one parameter adjustment node to obtain a target quantization parameter value.
7. The video encoding method based on adaptive adjustment of quantization parameters according to any one of claims 1 to 6, characterized in that: Before calculating the motion area ratio of each coding unit of a preset pixel size in the current frame based on the motion state information of the current frame, the method further includes: When receiving a video to be encoded, performing motion estimation on the video to be encoded to obtain a motion vector of each pixel; Based on the motion vector, determining the motion state of each pixel, and updating the motion state value of each pixel based on the motion state; After the motion state values of all pixels of the video to be encoded are updated, the motion state information of each frame image in the video to be encoded is obtained.
8. A video encoding device based on adaptive adjustment of quantization parameters, characterized in that: include: A ratio obtaining module, configured to calculate a motion region ratio of each coding unit of a preset pixel size in the current frame based on motion state information of the current frame; A parameter value adjustment module, configured to adjust an initial quantization parameter value of each coding unit based on a motion region ratio of each coding unit to obtain a target quantization parameter value; The video encoding module is used to encode the current frame based on the target quantization parameter value of each encoding unit until all frame images of the video to be encoded are encoded to obtain an encoded video.
9. A computer device, characterized in that: The computer device includes a memory and a processor; The memory is used to store computer programs; The processor is configured to execute the computer program and implement the video encoding method based on adaptive adjustment of quantization parameters according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the video encoding method based on adaptive adjustment of quantization parameters according to any one of claims 1 to 7.