Video encoding method and apparatus

By determining the target prediction coefficients and calculating the quantization parameter offset based on the video frame type, the problem of insufficient efficiency and accuracy in determining quantization parameters in existing technologies is solved, achieving a more efficient video coding effect.

CN116137658BActive Publication Date: 2026-05-29BEIJING YUANLI WEILAI SCI & TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING YUANLI WEILAI SCI & TECH CO LTD
Filing Date
2021-11-17
Publication Date
2026-05-29

Smart Images

  • Figure CN116137658B_ABST
    Figure CN116137658B_ABST
Patent Text Reader

Abstract

The present specification provides a video encoding method and device, wherein the video encoding method comprises: determining a corresponding target prediction coefficient based on a frame type of a first video frame; obtaining a first intra-frame prediction loss value, a first inter-frame prediction loss value and a first motion vector of a first macro block in the first video frame; determining a quantization parameter offset value of the first macro block based on the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value and the first motion vector; determining a target quantization parameter of the first macro block; and encoding the first macro block based on the target quantization parameter. In this way, the prediction coefficient corresponding to the frame type of the first video frame, the content change between frames and the texture features in the frame can be jointly used to calculate the quantization parameter offset value of the first macro block, so as to determine the final quantization parameter for encoding, finely control the quantization of the macro block and improve the video encoding effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of video processing technology, and in particular to a video encoding method. This specification also relates to a video encoding apparatus, a computing device, and a computer-readable storage medium. Background Technology

[0002] With the rapid development of computer, communication, and network technologies, a wide variety of videos are emerging, and watching videos has become an important form of leisure and entertainment. Because videos contain a large amount of data, video encoding technology is needed to compress them for easier transmission and storage. Video encoding is a lossy compression process; the decoded video is not identical to the original. Therefore, balancing video quality and compression loss is a key research focus in video encoding.

[0003] In existing technologies, the initial quantization parameters of the macroblock to be encoded in a video frame can be calculated first, then the exactly-perceptible distortion of the macroblock can be calculated, and the initial quantization parameters can be adjusted based on the calculated exactly-perceptible distortion to obtain the final quantization parameters. The macroblock is then encoded based on these quantization parameters. However, in the above encoding methods, the calculation of exactly-perceptible distortion is complex and cannot utilize the spatial and temporal features of the video frame, resulting in poor efficiency and accuracy in determining the quantization parameters. Consequently, the video encoding effect is poor, affecting the user experience. Summary of the Invention

[0004] In view of this, embodiments of this specification provide a video encoding method. This specification also relates to a video encoding apparatus, a computing device, and a computer-readable storage medium to address the technical deficiencies existing in the prior art.

[0005] According to a first aspect of the embodiments of this specification, a video encoding method is provided, comprising:

[0006] Determine the corresponding target prediction coefficients based on the frame type of the first video frame;

[0007] Obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame;

[0008] The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficient, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector.

[0009] Based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, the target quantization parameter of the first macroblock is determined, and the first macroblock is encoded according to the target quantization parameter.

[0010] Optionally, the quantization parameter offset value of the first macroblock is determined based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector, including:

[0011] Determine the sum of the absolute values ​​of each component of the first motion vector, and use the sum of absolute values ​​as the first intermediate result;

[0012] The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first intermediate result.

[0013] Optionally, the target prediction coefficients include intra-frame prediction loss coefficients, inter-frame prediction loss coefficients, motion vector coefficients, and offset coefficients.

[0014] Based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first intermediate result, the quantization parameter offset value of the first macroblock is determined, including:

[0015] The quantization parameter offset value of the first macroblock is determined based on the first intra-frame prediction loss value and intra-frame prediction loss coefficient, the first inter-frame prediction loss value and inter-frame prediction loss coefficient, the first motion vector and motion vector coefficient, and the offset coefficient.

[0016] Optionally, before determining the quantization parameter offset value of the first macroblock based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector, the method further includes:

[0017] Based on the intra-frame prediction loss threshold corresponding to the first intra-frame prediction loss value, the inter-frame prediction loss threshold corresponding to the first inter-frame prediction loss value, and the motion vector threshold corresponding to the first motion vector, outliers in the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector are filtered out.

[0018] Optionally, before determining the corresponding target prediction coefficients based on the frame type of the first video frame, the method further includes:

[0019] Obtain the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock in the second video frame, wherein the second video frame is any video frame of the target frame type in the test set, and the test set includes video frames of at least one frame type.

[0020] Obtain the reference quantization parameter offset value for the second macroblock;

[0021] Based on the intra-frame prediction loss value, the inter-frame prediction loss value, the second motion vector, and the reference quantization parameter offset value, construct the prediction coefficient fitting constraint for the target frame type.

[0022] Based on the fitting constraints of the prediction coefficients, the prediction coefficients corresponding to the target frame type are determined, and the prediction coefficients are stored in correspondence with the target frame type.

[0023] Optionally, the reference quantization parameter offset value of the second macroblock is obtained, including:

[0024] The reference quantization parameter offset value is calculated based on the preset intensity coefficient, the prediction loss value in the second frame, and the propagation loss value.

[0025] The propagation loss value is calculated based on the intra-frame prediction loss value, the inter-frame prediction loss value, and the cumulative propagation value.

[0026] Optionally, before obtaining the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock, the method further includes:

[0027] Obtain test video data;

[0028] Obtain at least one video frame from the test video data and determine the frame type of at least one video frame;

[0029] The acquired video frames are combined into a test set, and each video frame in the test set carries the corresponding frame type.

[0030] Optionally, before determining the target quantization parameters of the first macroblock based on the quantization parameter offset value and the acquired basic quantization parameter values ​​of the first video frame, the method further includes:

[0031] Obtain the base quantization coefficients and initial offset values ​​of the first video frame;

[0032] The basic quantization parameter values ​​for the first video frame are determined based on the basic quantization coefficients and the initial offset value.

[0033] Optionally, the underlying quantization coefficients of the first video frame are obtained, including:

[0034] Determine the target video frame preceding the first video frame;

[0035] The complexity of the target video frame is filtered to obtain the filtering result;

[0036] Obtain the deviation between the target bitrate and the actual bitrate of the first video frame;

[0037] Based on the filtering results and the deviation value, the basic quantization coefficients of the first video frame are determined.

[0038] According to a second aspect of the embodiments of this specification, a video encoding apparatus is provided, comprising:

[0039] The prediction coefficient determination module is configured to determine the corresponding target prediction coefficient based on the frame type of the first video frame;

[0040] The acquisition module is configured to acquire the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame.

[0041] The offset determination module is configured to determine the quantization parameter offset value of the first macroblock based on the target prediction coefficient, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector.

[0042] The quantization parameter determination module is configured to determine the target quantization parameter of the first macroblock based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, and to encode the first macroblock according to the target quantization parameter.

[0043] Optionally, the offset value determination module is further configured to:

[0044] Determine the sum of the absolute values ​​of each component of the first motion vector, and use the sum of absolute values ​​as the first intermediate result;

[0045] The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first intermediate result.

[0046] Optionally, the target prediction coefficients include intra-frame prediction loss coefficients, inter-frame prediction loss coefficients, motion vector coefficients, and offset coefficients.

[0047] The offset value determination module is further configured as follows:

[0048] The quantization parameter offset value of the first macroblock is determined based on the first intra-frame prediction loss value and intra-frame prediction loss coefficient, the first inter-frame prediction loss value and inter-frame prediction loss coefficient, the first motion vector and motion vector coefficient, and the offset coefficient.

[0049] Optionally, the device also includes a screening module configured to:

[0050] Based on the intra-frame prediction loss threshold corresponding to the first intra-frame prediction loss value, the inter-frame prediction loss threshold corresponding to the first inter-frame prediction loss value, and the motion vector threshold corresponding to the first motion vector, outliers in the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector are filtered out.

[0051] Optionally, the device further includes a storage module configured to:

[0052] Obtain the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock in the second video frame, wherein the second video frame is any video frame of the target frame type in the test set, and the test set includes video frames of at least one frame type.

[0053] Obtain the reference quantization parameter offset value for the second macroblock;

[0054] Based on the intra-frame prediction loss value, the inter-frame prediction loss value, the second motion vector, and the reference quantization parameter offset value, construct the prediction coefficient fitting constraint for the target frame type.

[0055] Based on the fitting constraints of the prediction coefficients, the prediction coefficients corresponding to the target frame type are determined, and the prediction coefficients are stored in correspondence with the target frame type.

[0056] Optionally, the storage module is further configured as follows:

[0057] The reference quantization parameter offset value is calculated based on the preset intensity coefficient, the prediction loss value in the second frame, and the propagation loss value.

[0058] The propagation loss value is calculated based on the intra-frame prediction loss value, the inter-frame prediction loss value, and the cumulative propagation value.

[0059] Optionally, the storage module is further configured as follows:

[0060] Obtain test video data;

[0061] Obtain at least one video frame from the test video data and determine the frame type of at least one video frame;

[0062] The acquired video frames are combined into a test set, and each video frame in the test set carries the corresponding frame type.

[0063] Optionally, the device further includes a basic quantization parameter value determination module, configured to:

[0064] Obtain the base quantization coefficients and initial offset values ​​of the first video frame;

[0065] The basic quantization parameter values ​​for the first video frame are determined based on the basic quantization coefficients and the initial offset value.

[0066] Optionally, the basic quantization parameter value determination module is further configured as follows:

[0067] Determine the target video frame preceding the first video frame;

[0068] The complexity of the target video frame is filtered to obtain the filtering result;

[0069] Obtain the deviation between the target bitrate and the actual bitrate of the first video frame;

[0070] Based on the filtering results and the deviation value, the basic quantization coefficients of the first video frame are determined.

[0071] According to a third aspect of the embodiments of this specification, a computing device is provided, comprising:

[0072] Memory and processor;

[0073] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the following methods:

[0074] Determine the corresponding target prediction coefficients based on the frame type of the first video frame;

[0075] Obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame;

[0076] The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficient, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector.

[0077] Based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, the target quantization parameter of the first macroblock is determined, and the first macroblock is encoded according to the target quantization parameter.

[0078] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores computer-executable instructions that, when executed by a processor, implement the steps of a video encoding method.

[0079] The video coding method provided in this specification can first determine the corresponding target prediction coefficients based on the frame type of the first video frame. Then, it can obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame. Subsequently, based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector, it can determine the quantization parameter offset value of the first macroblock, thereby determining the target quantization parameter of the first macroblock, and encoding the first macroblock based on the target quantization parameter. In this case, the quantization parameter offset value of the first macroblock can be determined based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector corresponding to the first video frame, so as to finally determine the corresponding target quantization parameter. This simplifies the process of determining quantization parameters without the need for complex algorithms, thereby improving the efficiency of determining quantization parameters. In addition, different frame types can correspond to different prediction coefficients, that is, different types of video frames can be encoded based on different prediction coefficients, fully considering the characteristics of different types of video frames. In this way, the prediction coefficients corresponding to the frame type of the first video frame, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the first video frame, can be used together to calculate the quantization parameter offset value of the first macroblock, so as to determine the final quantization parameters for encoding. By comprehensively considering the content changes between frames and the texture features within frames, the quantization of macroblocks can be finely controlled, thereby reducing the size of the encoded video without reducing the video encoding quality, facilitating video storage and transmission, and improving the video encoding effect. Attached Figure Description

[0080] Figure 1 This is a flowchart of a video encoding method provided in one embodiment of this specification;

[0081] Figure 2 This is a flowchart illustrating the fitting of prediction coefficients according to an embodiment of this specification;

[0082] Figure 3 This is a flowchart of another video encoding method provided in one embodiment of this specification;

[0083] Figure 4 This is a schematic diagram of the structure of a video encoding device provided in one embodiment of this specification;

[0084] Figure 5 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation

[0085] Many specific details are set forth in the following description to provide a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.

[0086] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this specification. The singular forms “a” and “the” as used in one or more embodiments of this specification and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.

[0087] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this specification, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."

[0088] First, the terms and concepts used in one or more embodiments of this specification will be explained.

[0089] Video encoding: During video transmission, if the video is not compressed, the existing bandwidth cannot meet the transmission requirements. Therefore, video compression is necessary, and this process is called video encoding. More specifically, encoding is the technology of converting information from one form (format) to another using a specified method. Video encoding refers to the use of data compression technology to remove redundant information from digital video signals, converting the original video format file into another video format file, thereby reducing the bitrate required to represent the original video and facilitating the transmission and storage of video data.

[0090] Bitrate: The amount of data a video file uses per unit of time, often simply called bitrate, is the most important part of video encoding for controlling picture quality. Generally speaking, at the same resolution, the higher the bitrate of a video, the lower the compression ratio and the degree of distortion, resulting in higher picture quality.

[0091] Bitrate control: Video encoding is a lossy encoding process. The goal of video encoding is to save bitrate as much as possible while ensuring the subjective quality of the video. Bitrate control is an important tool for balancing bitrate and subjective quality.

[0092] Quantization refers to the process of mapping continuous values ​​(or a large number of possible discrete values) of a signal to a finite number of discrete values, achieving a many-to-one mapping of signal values. In video / image coding, after the residual signal undergoes DCT, the transform coefficients often have a large dynamic range. Therefore, quantizing the transform coefficients can effectively reduce the signal value space and achieve better compression results.

[0093] Quantization parameter (QP): In the quantization process, the quantization parameter is a crucial parameter used to control the dispersion of variables and is a major factor affecting video bitrate and compression level. The quantization parameter is the threshold selected during quantization to discretize continuous values. It reflects the compression of spatial details; a small QP preserves most details, while a large QP results in some detail loss, lower bitrate, but increased image distortion and reduced quality. In other words, QP and bitrate are inversely proportional, and this inverse relationship becomes more pronounced as the complexity of the video source increases. The core of bitrate control is determining the QP of macroblocks.

[0094] Macroblock (MB): When selecting quantization parameters for a frame of image, a fixed-size sliding window is typically used as the unit. The pixel block enclosed by this sliding window is called a macroblock. A macroblock is the basic unit of coding processing, typically 16x16 pixels in size. A coded image must first be divided into multiple blocks (4x4 pixels) before processing; obviously, macroblocks should consist of an integer number of blocks. Macroblocks are divided into I, P, and B macroblocks: I macroblocks (intra-prediction macroblocks) can only use previously decoded pixels in the current frame as references for intra-prediction; P macroblocks (inter-prediction macroblocks) can use previously decoded images as reference images for intra-prediction; B macroblocks (inter-bidirectional prediction macroblocks) use both forward and backward reference images for intra-prediction.

[0095] Basic quantization parameters: Calculated based on the characteristics of the coded frame, serving as the initial values ​​for macroblock quantization.

[0096] Quantization parameter offset: Calculated based on the characteristics of the macroblock, used to correct the basic quantization parameters.

[0097] MBTree: A method for calculating the quantization parameter offset of a macroblock using information from future coded frames.

[0098] JND stands for Just Noticeable Distortion. JND represents the maximum image distortion that the human eye cannot perceive, or the image distortion value that is just noticeable, reflecting the human eye's tolerance for image changes.

[0099] Intra-frame prediction loss: The coding distortion value when intra-frame prediction is used in coding.

[0100] Inter-frame prediction loss: The coding distortion value when inter-frame prediction techniques are used in coding.

[0101] Encoded frame types: Encoded frames are generally divided into three types as follows:

[0102] An I-frame (Intra Frame), also known as a keyframe, is an independent frame containing all its own information. It can be decoded independently without referencing other video frames. It uses intra-frame prediction encoding and does not refer to other frames, typically resulting in higher encoding quality but lower compression efficiency. The first video frame in a video sequence is always an I-frame. If the transmitted bitstream is corrupted, an I-frame is used as the starting point or resynchronization point for a new viewer. I-frames can be used to implement fast forward, rewind, and other random access functions. If a new client will participate in viewing the bitstream, the encoder will automatically insert I-frames at the same time intervals or as required. The disadvantage of I-frames is that they occupy more data bits, but on the other hand, I-frames do not produce perceptible blurring.

[0103] P-frames (Predicted Frames) are encoded by combining intra-frame and inter-frame prediction with reference to preceding I-frames or other preceding P-frames. They have higher compression efficiency than I-frames and typically occupy fewer data bits. However, because P-frames have complex dependencies on preceding P-frames and I-frames, they are very sensitive to transmission errors.

[0104] B-frames (Bi-predictive frames) can be used to predict and encode frames by referencing both the preceding and following frames, resulting in the highest compression efficiency.

[0105] SSIM: Structural Similarity is a method for calculating the structural similarity between two images. In video coding, it is mainly used to evaluate the quality of each image after compression.

[0106] PSNR: Peak Signal to Noise Ratio is the ratio of the energy of the peak signal to the average energy of the noise. It is a commonly used objective metric in video coding to evaluate the coding quality of each image.

[0107] It should be noted that with the rapid development of computer, communication, and network technologies, all kinds of videos are emerging, and watching videos has become an important way for people to relax and enjoy themselves. Because videos contain a very large amount of data, video encoding technology is needed to compress them for easier transmission and storage. Video encoding is a lossy compression process; the decoded video is not identical to the original. Therefore, balancing video quality and compression loss is a key research focus in video encoding, and bitrate control is an important technique that fully considers bandwidth, latency, and video quality.

[0108] Rate control is a technique for rationally allocating and fully utilizing bits. During video encoding, the encoder allocates a certain number of bits based on the characteristics of the frame to be encoded. Then, the basic quantization parameters of the encoded frame are calculated according to the rate control model. The encoder then divides the encoded frame into macroblocks of a specific size. The rate control algorithm then calculates the quantization parameter offset value based on the characteristics of the macroblock and adds it to the basic quantization parameters as the final quantization parameters for the macroblock.

[0109] In existing technologies, texture and motion features within video frames can be calculated, and quantization parameters can be adjusted using k-medoids clustering. However, this method is computationally intensive, and the mapping from classification to quantization parameters is not smooth, resulting in poor efficiency and accuracy in calculating quantization parameters. Alternatively, the initial quantization parameters of a macroblock can be calculated first, followed by the Just-Perceived Distortion (JND) of that macroblock. The initial quantization parameters are then adjusted based on the calculated JND to obtain the final quantization parameters, which are then used to encode the macroblock. However, the JND calculation in this method is complex, and it cannot effectively utilize spatial and temporal features, resulting in poor efficiency and accuracy in calculating quantization parameters, and consequently, poor video encoding performance.

[0110] This specification provides a novel method for calculating quantization parameter offset values ​​during bitrate control. This method combines the prediction coefficients corresponding to the video frame type, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the video frame to calculate the quantization parameter offset value of the macroblock. It fully considers the content changes between video frames and the texture features within the frame, and features simple calculation and content adaptability. Furthermore, it can reduce the bitrate while maintaining the same quality. The video quality can be represented by SSIM and PSNR.

[0111] This specification provides a video encoding method, and also relates to a video encoding apparatus, a computing device, and a computer-readable storage medium, which will be described in detail in the following embodiments.

[0112] Figure 1A flowchart of a video encoding method according to an embodiment of this specification is shown, which specifically includes the following steps:

[0113] Step 102: Determine the corresponding target prediction coefficients based on the frame type of the first video frame.

[0114] Specifically, the first video frame is the current video frame to be encoded, and the target prediction coefficient is the prediction coefficient corresponding to the frame type of the first video frame. The target prediction coefficient can be used to calculate the subsequent quantization parameter offset value. The target prediction coefficient can include the coefficients corresponding to the various calculation factors involved in the subsequent calculation of the quantization parameter offset value.

[0115] It should be noted that video frame types can include I-frames, P-frames, and B-frames. Different types of video frames have different characteristics and different encoding requirements. For example, I-frames usually require high encoding quality but low compression efficiency; P-frames require a combination of intra-frame and inter-frame prediction encoding, which has higher compression efficiency than I-frames; and B-frames require predictive encoding based on the preceding and following frames, resulting in the highest compression efficiency.

[0116] In practical applications, different prediction coefficients can be pre-fitted for different types of video frames. Then, the corresponding prediction coefficients for each frame type are stored. Subsequently, based on the frame type of the video frame to be encoded, the corresponding target prediction coefficients can be retrieved from the pre-stored correspondence for calculating the quantization parameter offset. In this way, macroblocks in different types of video frames can calculate quantization parameter offsets with different coefficients. By calculating quantization parameter offsets based on the type of video frame in which the macroblock resides, the characteristics of different types of video frames are fully considered.

[0117] In an optional implementation of this embodiment, prediction coefficients corresponding to different frame types can be pre-fitted using video frames of various types in the test set, and the frame types of the video frames and the fitted prediction coefficients can be stored accordingly. That is, before determining the corresponding target prediction coefficient based on the frame type of the first video frame, the following may also be included:

[0118] Obtain the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock in the second video frame, wherein the second video frame is any video frame of the target frame type in the test set, and the test set includes video frames of at least one frame type.

[0119] Obtain the reference quantization parameter offset value for the second macroblock;

[0120] Based on the intra-frame prediction loss value, the inter-frame prediction loss value, the second motion vector, and the reference quantization parameter offset value, construct the prediction coefficient fitting constraint for the target frame type.

[0121] Based on the fitting constraints of the prediction coefficients, the prediction coefficients corresponding to the target frame type are determined, and the prediction coefficients are stored in correspondence with the target frame type.

[0122] Specifically, the second video frame can be any video frame of the target frame type in the test set, and the second macroblock is any macroblock within the second video frame. The test set can be a collection of a large number of pre-collected video frames; by using video frames of various frame types in the test set, corresponding prediction coefficients can be fitted and obtained.

[0123] In addition, the second intra-frame prediction loss value refers to the intra-frame prediction loss of the second video frame in which the second macroblock is located; the second inter-frame prediction loss value refers to the inter-frame prediction loss between the second video frame in which the second macroblock is located and other video frames. This inter-frame prediction loss may include the inter-frame prediction loss with the preceding video frame, or it may include the inter-frame prediction loss with both the preceding and following video frames.

[0124] It should be noted that during inter-frame prediction in video coding, there is a motion estimation. For the second macroblock in the second video frame, the predicted macroblock that is closest to the second macroblock in the previous video frame can be estimated. This predicted macroblock is taken as the position of the second macroblock in the previous video frame. The motion from the predicted macroblock to the second macroblock is the motion vector of the second macroblock. In other words, the motion vector can refer to the motion of the second macroblock from its position in the previous video frame to its position in the second video frame. For example, in two dimensions, the motion vector can include horizontal motion components and vertical motion components. In three dimensions, the motion vector can include horizontal motion components, vertical motion components, and depth motion components.

[0125] In practical applications, the encoder can perform an actual encoding of the video stream. During the encoding process, the encoder can output the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector. That is, the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector can be intermediate output values ​​of the MBTree algorithm. These values ​​can be obtained from the intermediate output values ​​of the MBTree algorithm. Parameters that cannot be obtained can be set to 0.

[0126] It's important to understand that the MBTree algorithm works by adjusting the quantization parameters of a macroblock based on the information it contributes to future frames (frames following the current frame in the coding order) during inter-frame prediction—that is, the information it is referenced. In short, the more information a macroblock contributes to subsequent frames, the higher its importance, and the coding quality of that region should be improved by reducing its quantization parameters; conversely, the less information it contributes, the more important it is, and ...

[0127] In practical implementation, to determine the contribution of the first macroblock to future video frames, it's necessary to infer from future video frames how much information originates from the current first macroblock. Since future video frames haven't been encoded yet, forward prediction is used. Forward prediction estimates the encoding cost of a certain number of uncoded frames by performing fast motion estimation. Forward prediction yields estimated values ​​for the following parameters of the uncoded frames: frame type, type and motion vector of each macroblock, and the SATD (Sum of Absolute Transformed Difference) values ​​for intra-frame and inter-frame coding. These SATD values ​​represent the intra-frame prediction loss and inter-frame prediction loss, respectively.

[0128] Furthermore, after obtaining the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector, outliers in the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector can be further filtered out based on the intra-frame prediction loss threshold, the inter-frame prediction loss threshold, and the motion vector threshold to ensure the accuracy of subsequent determination of quantization parameter offset values.

[0129] The intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold can be pre-set values ​​based on experiments or experience. It should be noted that these thresholds can be set to the same levels used to remove outliers from the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector.

[0130] In other words, the intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold can be preset. The intra-frame prediction loss threshold is used to determine whether the obtained first intra-frame prediction loss value or second intra-frame prediction loss value is normal. The inter-frame prediction loss threshold is used to determine whether the obtained first inter-frame prediction loss value or second inter-frame prediction loss value is normal. The motion vector threshold is used to determine whether the obtained first motion vector or second motion vector is abnormal.

[0131] In one possible implementation, the reference quantization parameter offset value of the second macroblock is obtained, and the specific implementation process can be as follows:

[0132] The reference quantization parameter offset value is calculated based on the preset intensity coefficient, the prediction loss value in the second frame, and the propagation loss value.

[0133] The propagation loss value is calculated based on the intra-frame prediction loss value, the inter-frame prediction loss value, and the cumulative propagation value.

[0134] It should be noted that the preset intensity coefficient can refer to a pre-set numerical value, usually a constant. In practical applications, the reference quantization parameter offset value can be calculated using the following formulas (1) and (2):

[0135] QP_offset_mbtree=-strength*log2((intra_cost+propagate_cost) / intra_cost) (1)

[0136] propagate_cost=∑(weight*(intra_cost+propagate_in)*(intra_cost-min(intra_cost,inter_cost)) / intra_cost) (2)

[0137] Where QP_offset_mbtree is the reference quantization parameter offset value, strength is the preset intensity coefficient, intra_cost is the intra-prediction loss value of the second frame, propagate_cost is the cumulative propagation loss value of the second macroblock, which can be obtained through cumulative calculation. weight is the weight coefficient calculated based on the proportion of reference pixels, inter_cost is the inter-prediction loss value of the second frame, and propagate_in is the propagate_cost of the macroblock referencing the second macroblock.

[0138] It should be noted that the above calculation process of the reference quantization parameter offset value is based on the offset value obtained by backpropagation of the MBTree algorithm. Of course, in practical applications, the reference quantization parameter offset value can also be obtained without using the MBTree algorithm, but by using a large number of coding experiments to obtain the ideal reference quantization parameter offset value.

[0139] In one possible implementation, the MBTree algorithm can be used to obtain the intra-frame prediction loss value, the inter-frame prediction loss value, the second motion vector, and the reference quantization parameter offset value. After obtaining the above parameters, the prediction coefficient fitting constraints for the target frame type can be constructed using the following formulas (3) and (4):

[0140] α t ×intra_cost tki2 +β t ×inter_cost tki2 +γ t ×mv_total tki2 +θ t =QP_offset_mbtree tki2 (3)

[0141] mv_total tki2 =|mvx tki2 |+|mvy tki2 | (4)

[0142] Where t is the target frame type, α t β t γ t θ t Let α be the prediction coefficient corresponding to the target frame type to be fitted. t β represents the intra-frame prediction loss coefficient. t γ represents the inter-frame prediction loss coefficient. t Represents the motion vector coefficients, θ t Intra_cost represents the offset coefficient. tki2 The inter_cost is the intra-frame prediction loss value. tki2 The inter-frame prediction loss value, mv_total tki2 The second intermediate result is calculated based on the second motion vector, mvx tki2 mvy is the lateral motion component of the second motion vector. tki2 QP_offset_mbtree represents the longitudinal motion component of the second motion vector. tki This is the offset value for the reference quantization parameter.

[0143] In practical applications, the linear fitting coefficients (α) in the above-mentioned prediction coefficient fitting constraints can be calculated using the least squares method. t ,β t γ t θ t Of course, in actual implementation, other parameter estimation and fitting algorithms can also be used, such as the maximum likelihood algorithm; in addition to linear fitting, exponential, power functions, etc. can be added for nonlinear fitting to obtain nonlinear prediction coefficients. The embodiments in this specification do not limit this.

[0144] It should be noted that the test set includes video frames of different frame types. A target frame type video frame is arbitrarily selected from the test set as the second video frame. Through fitting operations, the prediction coefficients corresponding to the target frame type are determined and stored in association with the target frame type. Subsequently, video frames of other frame types in the test set can be selected as the second video frames, and the corresponding prediction coefficients can be obtained through fitting. This process continues until prediction coefficients for all frame types in the test set have been obtained. When encoding subsequent video frames, the target prediction coefficients corresponding to the frame type to be encoded can be directly obtained to calculate the quantization parameter offset.

[0145] For example, the correspondence between frame type and prediction coefficients can be shown in Table 1 below. Assuming the frame type of the first video frame is type I, the corresponding target prediction coefficient can be determined as (α). t ,β t γ t θ t ).

[0146] Table 1. Correspondence between frame type and prediction coefficients

[0147] Frame type Predictive coefficient Type I <![CDATA[(α t ,b t ,c t ,the t )]]> P type <![CDATA[(α z ,b z ,c z ,the z )]]> Type B <![CDATA[(α w ,b w ,c w ,the w )]]>

[0148] In the embodiments of this specification, the corresponding prediction coefficients can be pre-fitted linearly using the least squares method based on the video frames of various frame types included in the test set. The fitting process is simple and easy to implement, so that different types of video frames can correspond to different prediction coefficients. This allows subsequent different types of video frames to determine the corresponding quantization parameters for encoding based on different prediction coefficients, fully taking into account the characteristics of different types of video frames.

[0149] In an optional implementation of this embodiment, before fitting the corresponding prediction coefficients based on the video frames of each frame type included in the test set, a test set may be constructed first. That is, before obtaining the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock, the following may be included:

[0150] Obtain test video data;

[0151] Obtain at least one video frame from the test video data and determine the frame type of at least one video frame;

[0152] The acquired video frames are combined into a test set, and each video frame in the test set carries the corresponding frame type.

[0153] In practical applications, test video data can be obtained in advance based on the network. The test video data may include multiple video streams. Video frames are extracted from each video stream and combined into a test set. When extracting video frames from each video stream, there is no restriction on the frame type and number of video frames extracted from each video stream; they can all be extracted randomly.

[0154] It should be noted that, generally speaking, the frame types defined by the standard usually include I-frames, P-frames, and B-frames. However, in specific business scenarios, each video stream does not necessarily use these three types of video frames. For example, in low-latency live streaming services, B-frames are often not used to reduce latency.

[0155] In the embodiments of this specification, since it is necessary to fit the prediction coefficients corresponding to different frame types of video frames based on different frame types in the test set, that is, the operation on the video frames in the test set needs to refer to the frame type of the video frame, each video frame included in the test set can carry the corresponding frame type for fitting the prediction coefficients of the corresponding frame type.

[0156] Step 104: Obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame.

[0157] Specifically, based on the frame type of the first video frame and the corresponding target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame can be obtained. Here, the first macroblock can refer to the macroblock currently to be encoded in the first video frame.

[0158] Furthermore, the first intra-frame prediction loss value refers to the intra-frame prediction loss of the first video frame in which the first macroblock is located; the first inter-frame prediction loss value refers to the inter-frame prediction loss between the first video frame in which the first macroblock is located and other video frames. This inter-frame prediction loss may include the inter-frame prediction loss with the preceding video frame, or it may include the inter-frame prediction loss with both the preceding and following video frames.

[0159] In practical applications, the encoder can also first perform actual encoding on the first video frame. During the encoding process, the encoder can output the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector. That is to say, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector can also be intermediate output values ​​of the MBTree algorithm. Through the intermediate output values ​​of the MBTree algorithm, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector can be obtained. For parameters that cannot be obtained, they can be set to 0.

[0160] In the embodiments of this specification, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame can be obtained. Subsequently, the prediction coefficients corresponding to the frame type of the first video frame, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the first video frame, can be used together to calculate the quantization parameter offset value of the first macroblock, so as to determine the final quantization parameters for encoding. By comprehensively considering the content changes between frames and the texture features within frames, the quantization of the macroblock can be finely controlled, thereby reducing the size of the encoded video without reducing the video encoding quality, facilitating video storage and transmission, and improving the video encoding effect.

[0161] Step 106: Determine the quantization parameter offset value of the first macroblock based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector.

[0162] Specifically, based on obtaining the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame, the quantization parameter offset value of the first macroblock can be further determined according to the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector.

[0163] In one optional implementation of this embodiment, the first motion vector may include multiple components. Therefore, based on the first motion vector, the components can be merged to obtain a first intermediate result. Then, based on the first intermediate result, the quantization parameter offset value of the first macroblock can be calculated. That is, the quantization parameter offset value of the first macroblock is determined according to the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector. The specific implementation process can be as follows:

[0164] Determine the sum of the absolute values ​​of each component of the first motion vector, and use the sum of absolute values ​​as the first intermediate result;

[0165] The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first intermediate result.

[0166] In practical applications, the first intermediate result can be determined using the following formula (5):

[0167] mv_total tki1 =|mvx tki1 |+|mvy tki1 | (5)

[0168] Among them, mv_total tki1 Indicates the first intermediate result, mvx tki1 Mvy represents the lateral motion component of the first motion vector. tki1 This represents the longitudinal motion component of the first motion vector.

[0169] It should be noted that the first motion vector may include multiple components. When calculating the quantization parameter offset value of the first macroblock based on the first motion vector, the components of the first motion vector can be merged first to obtain a first intermediate result. Subsequently, the quantization parameter offset value of the first macroblock can be calculated directly based on the first intermediate result.

[0170] In an optional implementation of this embodiment, the target prediction coefficients may include coefficients corresponding to various calculation factors involved in calculating the quantization parameter offset value. That is, the target prediction coefficients include intra-frame prediction loss coefficients, inter-frame prediction loss coefficients, motion vector coefficients, and offset coefficients. In this case, the quantization parameter offset value of the first macroblock is determined based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first intermediate result. The specific implementation process can be as follows:

[0171] The quantization parameter offset value of the first macroblock is determined based on the first intra-frame prediction loss value and intra-frame prediction loss coefficient, the first inter-frame prediction loss value and inter-frame prediction loss coefficient, the first intermediate result and motion vector coefficient, and the offset coefficient.

[0172] In practical applications, the quantization parameter offset value of the first macroblock can be determined by the following formula (6):

[0173] QP_offset_model tki

[0174] =α t ×intra_cost tki1 +β t ×inter_cost tki1 +γ t ×mv_total tki1 +θ t (6)

[0175] Among them, QP_offset_model tki Intra_cost represents the quantization parameter offset of the first macroblock. tki1 Indicates the prediction loss value within the first frame, inter_cost tki1 This represents the prediction loss value between the first frame, mv_total tki1 α represents the first intermediate result calculated based on the first motion vector. t β t γ t and θ t Let be the target prediction coefficient corresponding to the frame type of the first video frame, where α t β represents the intra-frame prediction loss coefficient. t γ represents the inter-frame prediction loss coefficient. t Represents the motion vector coefficients, θ t This represents the offset coefficient.

[0176] In the embodiments of this specification, the prediction coefficients corresponding to the frame type of the first video frame, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the first video frame, can be used together to calculate the quantization parameter offset value of the first macroblock, so as to determine the final quantization parameters for encoding. By comprehensively considering the content changes between frames and the texture features within frames, the quantization of macroblocks can be finely controlled, thereby reducing the size of the encoded video without reducing the video encoding quality, facilitating video storage and transmission, and improving the video encoding effect.

[0177] In an optional implementation of this embodiment, outliers in the obtained first intra-frame prediction loss value, first inter-frame prediction loss value, and first motion vector may be removed first, and then the quantization parameter offset value of the first macroblock may be determined. That is, before determining the quantization parameter offset value of the first macroblock based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector, the following may be included:

[0178] Based on the intra-frame prediction loss threshold corresponding to the first intra-frame prediction loss value, the inter-frame prediction loss threshold corresponding to the first inter-frame prediction loss value, and the motion vector threshold corresponding to the first motion vector, outliers in the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector are filtered out.

[0179] It should be noted that the intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold can be values ​​set in advance based on experiments or experience. The intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold here can be set to the same thresholds as those set above for removing outliers in the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector.

[0180] In practical applications, for the obtained intra-frame prediction loss value, we can determine whether it is greater than the intra-frame prediction loss threshold. If it is, the obtained intra-frame prediction loss value is abnormal; remove the value, re-acquire, or set it to 0. If it is not greater, the obtained intra-frame prediction loss value is normal and can be used for subsequent quantization parameter offset calculations. Similarly, for the obtained inter-frame prediction loss value, we can determine whether it is greater than the inter-frame prediction loss threshold. If it is, the obtained inter-frame prediction loss value is abnormal; remove the value, re-acquire, or set it to 0. If it is not greater, the obtained inter-frame prediction loss value is normal and can be used for subsequent quantization parameter offset calculations. Finally, for the obtained first motion vector, we can determine whether it is greater than the motion vector threshold. If it is, the obtained first motion vector is abnormal; remove the value, re-acquire, or set it to 0. If it is not greater, the obtained first motion vector is normal and can be used for subsequent quantization parameter offset calculations.

[0181] In the embodiments of this specification, after obtaining the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector, outliers in the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector can be further filtered out based on the intra-frame prediction loss threshold, the inter-frame prediction loss threshold, and the motion vector threshold. This ensures that the values ​​used to calculate the quantization parameter offset value are all normal values, thereby ensuring the accuracy of the determination of the subsequent quantization parameter offset value.

[0182] Step 108: Based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, determine the target quantization parameter of the first macroblock, and encode the first macroblock according to the target quantization parameter.

[0183] Specifically, based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector, the quantization parameter offset value of the first macroblock is determined. Furthermore, based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, the target quantization parameter of the first macroblock is determined, and the first macroblock is encoded according to the target quantization parameter.

[0184] It should be noted that after determining the quantization parameter offset value of the first macroblock, the basic quantization parameter value of the first video frame can be obtained. Then, the determined quantization parameter offset value is superimposed on the basic quantization parameter value of the first video frame to obtain the final target quantization parameter of the first macroblock, and the first macroblock is encoded based on the target quantization parameter.

[0185] In practical applications, the target quantization parameters of the first macroblock can be determined using the following formula (7):

[0186] QP tki =QP_base tki +QP_offset_model tki (7)

[0187] Among them, QP tki QP_base represents the target quantization parameter for the first macroblock. tki This represents the base quantization parameter value of the first video frame, QP_offset_model. tki This represents the quantization parameter offset value of the first macroblock.

[0188] In the embodiments of this specification, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame can be obtained. This allows for the combined use of the prediction coefficients corresponding to the frame type of the first video frame, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the first video frame, to calculate the quantization parameter offset value of the first macroblock. The final quantization parameters are then determined for encoding. By comprehensively considering inter-frame content changes and intra-frame texture features, the quantization of the macroblock is precisely controlled. This allows for reducing the size of the encoded video without compromising video encoding quality, facilitating video storage and transmission, and improving video encoding performance.

[0189] In an optional implementation of this embodiment, since the target quantization parameters of the first macroblock need to be determined in conjunction with the basic quantization parameter values ​​of the first video frame, the basic quantization parameter values ​​of the first video frame can also be obtained in advance. That is, before determining the target quantization parameters of the first macroblock based on the quantization parameter offset value and the obtained basic quantization parameter values ​​of the first video frame, the following steps may be included:

[0190] Obtain the base quantization coefficients and initial offset values ​​of the first video frame;

[0191] The basic quantization parameter values ​​for the first video frame are determined based on the basic quantization coefficients and the initial offset value.

[0192] It should be noted that the basic quantization parameter value of the first video frame consists of two parts: one is the basic quantization coefficient, which can be calculated by the bitrate control algorithm before the encoding of each video frame begins; the other is the initial offset value, which is the initial quantization parameter offset value of each macroblock. Initially, it can be calculated using the traditional adaptive quantization algorithm (AQ), or it can be set to 0.

[0193] In practical applications, the basic quantization parameter value of the first video frame can be determined by the following formula (8):

[0194] QP_base tki =QP k +QP_offset (8)

[0195] Among them, QP_base tki The QP value represents the fundamental quantization parameter value of the first video frame. k QP_offset represents the base quantization coefficient, and QP_offset represents the initial offset value.

[0196] In one optional implementation of this embodiment, the basic quantization coefficients of the first video frame are obtained. The specific implementation process can be as follows:

[0197] Determine the target video frame preceding the first video frame;

[0198] The complexity of the target video frame is filtered to obtain the filtering result;

[0199] Obtain the deviation between the target bitrate and the actual bitrate of the first video frame;

[0200] Based on the filtering results and the deviation value, the basic quantization coefficients of the first video frame are determined.

[0201] In practical applications, the basic quantization coefficients of the first video frame can be determined using the following formula (9):

[0202] QP k =pow(blurred_complexity,1-qcompress) / rate_factor (9)

[0203] Among them, QP k This represents the base quantization coefficient of the first video frame, pow represents the exponentiation operation, blurred_complexity represents the filtering result of the complexity of the target video frames before the first video frame, qcompress represents the preset coefficient, and rate_factor represents the deviation between the target bitrate and the actual bitrate of the first video frame.

[0204] The video coding method provided in this specification can first determine the corresponding target prediction coefficients based on the frame type of the first video frame. Then, it can obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame. Subsequently, based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector, it can determine the quantization parameter offset value of the first macroblock, thereby determining the target quantization parameter of the first macroblock, and encoding the first macroblock based on the target quantization parameter. In this case, the quantization parameter offset value of the first macroblock can be determined based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector corresponding to the first video frame, so as to finally determine the corresponding target quantization parameter. This simplifies the process of determining quantization parameters without the need for complex algorithms, thereby improving the efficiency of determining quantization parameters. In addition, different frame types can correspond to different prediction coefficients, that is, different types of video frames can be encoded based on different prediction coefficients, fully considering the characteristics of different types of video frames. In this way, the prediction coefficients corresponding to the frame type of the first video frame, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the first video frame, can be used together to calculate the quantization parameter offset value of the first macroblock, so as to determine the final quantization parameters for encoding. By comprehensively considering the content changes between frames and the texture features within frames, the quantization of macroblocks can be finely controlled, thereby reducing the size of the encoded video without reducing the video encoding quality, facilitating video storage and transmission, and improving the video encoding effect.

[0205] Figure 2 This specification illustrates a flowchart of a prediction coefficient fitting process according to an embodiment, which specifically includes the following steps:

[0206] Step 202: Obtain test video data, extract at least one video frame from the test video data, determine the frame type of at least one video frame, and combine the obtained video frames into a test set.

[0207] Each video frame in the test set carries its corresponding frame type.

[0208] Step 204: Set the intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold.

[0209] Step 206: Obtain the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock in the second video frame.

[0210] The second video frame is any video frame of the target frame type in the test set, and the test set includes video frames of at least one frame type.

[0211] Step 208: Obtain the reference quantization parameter offset value of the second macroblock.

[0212] Step 210: Based on the intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold, filter out outliers in the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector.

[0213] It should be noted that step 204 only needs to be executed before step 210, and the order of execution between it and other steps is not limited.

[0214] Step 212: Determine the sum of the absolute values ​​of each component of the second motion vector, and use this sum of absolute values ​​as the second intermediate result.

[0215] Step 214: Construct the prediction coefficient fitting constraints for the target frame type based on the intra-frame prediction loss value, the inter-frame prediction loss value, the second intermediate result, and the reference quantization parameter offset value.

[0216] Step 216: Using the least squares method, determine the prediction coefficients corresponding to the target frame type based on the prediction coefficient fitting constraints.

[0217] Step 218: Store the prediction coefficients and their corresponding target frame types.

[0218] In the embodiments of this specification, the corresponding prediction coefficients can be pre-fitted linearly using the least squares method based on the video frames of various frame types included in the test set. The fitting process is simple and easy to implement, so that different types of video frames can correspond to different prediction coefficients. This allows subsequent different types of video frames to determine the corresponding quantization parameters for encoding based on different prediction coefficients, fully taking into account the characteristics of different types of video frames.

[0219] Figure 3 A flowchart of another video encoding method provided in one embodiment of this specification is shown, which specifically includes the following steps:

[0220] Step 302: Obtain the basic quantization parameter value of the first video frame containing the first macroblock.

[0221] Step 304: Determine the corresponding target prediction coefficients based on the frame type of the first video frame.

[0222] Step 306: Set the intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold.

[0223] Step 308: Obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock.

[0224] Step 310: Based on the intra-frame prediction loss threshold, inter-frame prediction loss threshold, and motion vector threshold, filter out outliers in the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector.

[0225] It should be noted that step 306 only needs to be executed before step 310, and the order of execution with other steps is not limited.

[0226] Step 312: Determine the sum of the absolute values ​​of each component of the first motion vector, and use the sum of absolute values ​​as the first intermediate result.

[0227] Step 314: Determine the quantization parameter offset value of the first macroblock based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first intermediate result.

[0228] Step 316: Based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, determine the target quantization parameter of the first macroblock, and encode the first macroblock according to the target quantization parameter.

[0229] The video coding method provided in this specification can first determine the corresponding target prediction coefficients based on the frame type of the first video frame. Then, it can obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame. Subsequently, based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector, it can determine the quantization parameter offset value of the first macroblock, thereby determining the target quantization parameter of the first macroblock, and encoding the first macroblock based on the target quantization parameter. In this case, the quantization parameter offset value of the first macroblock can be determined based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector corresponding to the first video frame, so as to finally determine the corresponding target quantization parameter. This simplifies the process of determining quantization parameters without the need for complex algorithms, thereby improving the efficiency of determining quantization parameters. In addition, different frame types can correspond to different prediction coefficients, that is, different types of video frames can be encoded based on different prediction coefficients, fully considering the characteristics of different types of video frames. In this way, the prediction coefficients corresponding to the frame type of the first video frame, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the first video frame, can be used together to calculate the quantization parameter offset value of the first macroblock, so as to determine the final quantization parameters for encoding. By comprehensively considering the content changes between frames and the texture features within frames, the quantization of macroblocks can be finely controlled, thereby reducing the size of the encoded video without reducing the video encoding quality, facilitating video storage and transmission, and improving the video encoding effect.

[0230] Corresponding to the above method embodiments, this specification also provides embodiments of video encoding apparatus. Figure 4 A schematic diagram of a video encoding apparatus according to an embodiment of this specification is shown. Figure 4 As shown, the device includes:

[0231] The prediction coefficient determination module 402 is configured to determine the corresponding target prediction coefficient based on the frame type of the first video frame;

[0232] The acquisition module 404 is configured to acquire the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame.

[0233] The offset determination module 406 is configured to determine the quantization parameter offset value of the first macroblock based on the target prediction coefficient, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector.

[0234] The quantization parameter determination module 408 is configured to determine the target quantization parameter of the first macroblock based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, and to encode the first macroblock according to the target quantization parameter.

[0235] Optionally, the offset value determination module 406 is further configured to:

[0236] Determine the sum of the absolute values ​​of each component of the first motion vector, and use the sum of absolute values ​​as the first intermediate result;

[0237] The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficients, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first intermediate result.

[0238] Optionally, the target prediction coefficients include intra-frame prediction loss coefficients, inter-frame prediction loss coefficients, motion vector coefficients, and offset coefficients.

[0239] Offset value determination module 406 is further configured as follows:

[0240] The quantization parameter offset value of the first macroblock is determined based on the first intra-frame prediction loss value and intra-frame prediction loss coefficient, the first inter-frame prediction loss value and inter-frame prediction loss coefficient, the first motion vector and motion vector coefficient, and the offset coefficient.

[0241] Optionally, the device also includes a screening module configured to:

[0242] Based on the intra-frame prediction loss threshold corresponding to the first intra-frame prediction loss value, the inter-frame prediction loss threshold corresponding to the first inter-frame prediction loss value, and the motion vector threshold corresponding to the first motion vector, outliers in the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector are filtered out.

[0243] Optionally, the device further includes a storage module configured to:

[0244] Obtain the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock in the second video frame, wherein the second video frame is any video frame of the target frame type in the test set, and the test set includes video frames of at least one frame type.

[0245] Obtain the reference quantization parameter offset value for the second macroblock;

[0246] Based on the intra-frame prediction loss value, the inter-frame prediction loss value, the second motion vector, and the reference quantization parameter offset value, construct the prediction coefficient fitting constraint for the target frame type.

[0247] Based on the fitting constraints of the prediction coefficients, the prediction coefficients corresponding to the target frame type are determined, and the prediction coefficients are stored in correspondence with the target frame type.

[0248] Optionally, the storage module is further configured as follows:

[0249] The reference quantization parameter offset value is calculated based on the preset intensity coefficient, the prediction loss value in the second frame, and the propagation loss value.

[0250] The propagation loss value is calculated based on the intra-frame prediction loss value, the inter-frame prediction loss value, and the cumulative propagation value.

[0251] Optionally, the storage module is further configured as follows:

[0252] Obtain test video data;

[0253] Obtain at least one video frame from the test video data and determine the frame type of at least one video frame;

[0254] The acquired video frames are combined into a test set, and each video frame in the test set carries the corresponding frame type.

[0255] Optionally, the device further includes a basic quantization parameter value determination module, configured to:

[0256] Obtain the base quantization coefficients and initial offset values ​​of the first video frame;

[0257] The basic quantization parameter values ​​for the first video frame are determined based on the basic quantization coefficients and the initial offset value.

[0258] Optionally, the basic quantization parameter value determination module is further configured as follows:

[0259] Determine the target video frame preceding the first video frame;

[0260] The complexity of the target video frame is filtered to obtain the filtering result;

[0261] Obtain the deviation between the target bitrate and the actual bitrate of the first video frame;

[0262] Based on the filtering results and the deviation value, the basic quantization coefficients of the first video frame are determined.

[0263] The video encoding apparatus provided in this specification can first determine the corresponding target prediction coefficients based on the frame type of the first video frame. Then, it can obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame. Subsequently, based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector, it can determine the quantization parameter offset value of the first macroblock, thereby determining the target quantization parameter of the first macroblock, and encoding the first macroblock based on the target quantization parameter. In this case, the quantization parameter offset value of the first macroblock can be determined based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector corresponding to the first video frame, so as to finally determine the corresponding target quantization parameter. This simplifies the process of determining quantization parameters without the need for complex algorithms, thereby improving the efficiency of determining quantization parameters. In addition, different frame types can correspond to different prediction coefficients, that is, different types of video frames can be encoded based on different prediction coefficients, fully considering the characteristics of different types of video frames. In this way, the prediction coefficients corresponding to the frame type of the first video frame, as well as the intra-frame prediction loss, inter-frame prediction loss, and motion vector of the first video frame, can be used together to calculate the quantization parameter offset value of the first macroblock, so as to determine the final quantization parameters for encoding. By comprehensively considering the content changes between frames and the texture features within frames, the quantization of macroblocks can be finely controlled, thereby reducing the size of the encoded video without reducing the video encoding quality, facilitating video storage and transmission, and improving the video encoding effect.

[0264] The above is an illustrative scheme of a video encoding device according to this embodiment. It should be noted that the technical solution of this video encoding device and the technical solution of the video encoding method described above belong to the same concept. For details not described in detail in the technical solution of the video encoding device, please refer to the description of the technical solution of the video encoding method described above.

[0265] Figure 5A structural block diagram of a computing device 500 according to an embodiment of this specification is shown. The components of the computing device 500 include, but are not limited to, a memory 510 and a processor 520. The processor 520 is connected to the memory 510 via a bus 530, and a database 550 is used to store data.

[0266] The computing device 500 also includes an access device 540, which enables the computing device 500 to communicate via one or more networks 560. Examples of these networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of wired or wireless network interface (e.g., a Network Interface Card (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) interface, a Wi-MAX interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, and so on.

[0267] In one embodiment of this specification, the above-described components of the computing device 500 and Figure 5 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 5 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.

[0268] The computing device 500 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs. The computing device 500 can also be a mobile or stationary server.

[0269] The processor 520 is configured to execute the following computer-executable instructions to implement the following method:

[0270] Determine the corresponding target prediction coefficients based on the frame type of the first video frame;

[0271] Obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame;

[0272] The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficient, the intra-frame prediction loss value, the inter-frame prediction loss value, and the first motion vector.

[0273] Based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, the target quantization parameter of the first macroblock is determined, and the first macroblock is encoded according to the target quantization parameter.

[0274] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the video encoding method described above belong to the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the video encoding method described above.

[0275] An embodiment of this specification also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, are used to implement the steps of a video encoding method.

[0276] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solution of the video encoding method described above. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the video encoding method described above.

[0277] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0278] Computer instructions include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. Computer-readable media can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.

[0279] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this specification is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this specification. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this specification.

[0280] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0281] The preferred embodiments disclosed above are merely illustrative of this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the content of this specification. These embodiments have been selected and specifically described in this specification to better explain the principles and practical applications of this specification, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.

Claims

1. A video encoding method, characterized in that, The method includes: Based on the frame type of the first video frame, the corresponding target prediction coefficient is determined. The target prediction coefficient includes the coefficients of each calculation factor involved in the subsequent calculation of the quantization parameter offset value. The target prediction coefficient includes the intra-frame prediction loss coefficient, the inter-frame prediction loss coefficient, the motion vector coefficient, and the offset coefficient. Obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame; The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector. Based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, the target quantization parameter of the first macroblock is determined, and the first macroblock is encoded according to the target quantization parameter.

2. The video encoding method according to claim 1, characterized in that, The step of determining the quantization parameter offset value of the first macroblock based on the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector includes: Determine the sum of the absolute values ​​of each component of the first motion vector, and use the sum of the absolute values ​​as the first intermediate result; The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first intermediate result.

3. The video encoding method according to claim 2, characterized in that, The step of determining the quantization parameter offset value of the first macroblock based on the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first intermediate result includes: The quantization parameter offset value of the first macroblock is determined based on the first intra-frame prediction loss value and the intra-frame prediction loss coefficient, the first inter-frame prediction loss value and the inter-frame prediction loss coefficient, the first intermediate result and the motion vector coefficient, and the offset coefficient.

4. The video encoding method according to any one of claims 1-3, characterized in that, Before determining the quantization parameter offset value of the first macroblock based on the target prediction coefficients, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector, the method further includes: Based on the intra-frame prediction loss threshold corresponding to the first intra-frame prediction loss value, the inter-frame prediction loss threshold corresponding to the first inter-frame prediction loss value, and the motion vector threshold corresponding to the first motion vector, outliers in the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector are filtered out.

5. The video encoding method according to any one of claims 1-3, characterized in that, Before determining the corresponding target prediction coefficient based on the frame type of the first video frame, the method further includes: Obtain the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock in the second video frame, wherein the second video frame is any video frame of the target frame type in the test set, and the test set includes video frames of at least one frame type; Obtain the reference quantization parameter offset value of the second macroblock; Based on the second intra-frame prediction loss value, the second inter-frame prediction loss value, the second motion vector, and the reference quantization parameter offset value, construct the prediction coefficient fitting constraint for the target frame type; Based on the prediction coefficient fitting constraints, the prediction coefficients corresponding to the target frame type are determined, and the prediction coefficients are stored in correspondence with the target frame type.

6. The video encoding method according to claim 5, characterized in that, The step of obtaining the reference quantization parameter offset value of the second macroblock includes: The reference quantization parameter offset value is calculated based on the preset intensity coefficient, the second intra-frame prediction loss value, and the propagation loss value. The propagation loss value is calculated based on the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the propagation cumulative value.

7. The video encoding method according to claim 5, characterized in that, Before obtaining the second intra-frame prediction loss value, the second inter-frame prediction loss value, and the second motion vector of the second macroblock, the method further includes: Obtain test video data; Obtain at least one video frame from the test video data and determine the frame type of the at least one video frame; The acquired video frames are combined into the test set, and each video frame in the test set carries a corresponding frame type.

8. The video encoding method according to any one of claims 1-3, characterized in that, Before determining the target quantization parameter of the first macroblock based on the quantization parameter offset value and the obtained basic quantization parameter value of the first video frame, the method further includes: Obtain the basic quantization coefficients and initial offset values ​​of the first video frame; The basic quantization parameter values ​​of the first video frame are determined based on the basic quantization coefficients and the initial offset value.

9. The video encoding method according to claim 8, characterized in that, The acquisition of the basic quantization coefficients of the first video frame includes: Determine the target video frame preceding the first video frame; The complexity of the target video frame is filtered to obtain the filtering result; Obtain the deviation between the target bitrate and the actual bitrate of the first video frame; Based on the filtering result and the deviation value, the basic quantization coefficient of the first video frame is determined.

10. A video encoding device, characterized in that, The device includes: The prediction coefficient determination module is configured to determine the corresponding target prediction coefficient based on the frame type of the first video frame. The target prediction coefficient includes the coefficients of each calculation factor involved in the subsequent calculation of the quantization parameter offset value. The target prediction coefficient includes the intra-frame prediction loss coefficient, the inter-frame prediction loss coefficient, the motion vector coefficient, and the offset coefficient. The acquisition module is configured to acquire the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame; The offset value determination module is configured to determine the quantization parameter offset value of the first macroblock based on the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector. The quantization parameter determination module is configured to determine the target quantization parameter of the first macroblock based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, and to encode the first macroblock according to the target quantization parameter.

11. A computing device, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the following method: Based on the frame type of the first video frame, the corresponding target prediction coefficient is determined. The target prediction coefficient includes the coefficients of each calculation factor involved in the subsequent calculation of the quantization parameter offset value. The target prediction coefficient includes the intra-frame prediction loss coefficient, the inter-frame prediction loss coefficient, the motion vector coefficient, and the offset coefficient. Obtain the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector of the first macroblock in the first video frame; The quantization parameter offset value of the first macroblock is determined based on the target prediction coefficient, the first intra-frame prediction loss value, the first inter-frame prediction loss value, and the first motion vector. Based on the quantization parameter offset value and the basic quantization parameter value of the first video frame, the target quantization parameter of the first macroblock is determined, and the first macroblock is encoded according to the target quantization parameter.

12. A computer-readable storage medium storing computer instructions that, when executed by a processor, implement the steps of the video encoding method according to any one of claims 1 to 9.