Coding parameter determination method and device, equipment, storage medium and program product
By adjusting the constant rate factor according to the complexity of the target image, the bandwidth waste problem caused by the fixed rate factor in image encoding is solved, and a more efficient encoding effect is achieved.
Patent Information
- Application Number
- CN202411319166.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-21
- Publication Date
- 2024-12-27
AI Technical Summary
In the prior art, the constant rate factor setting in image encoding is fixed, resulting in the problem of bandwidth waste.
By acquiring the complexity of the target image, the constant rate factor adjustment model is used to predict the target constant rate factor, and the encoding parameters are adjusted according to the image complexity to ensure that the slope of the encoded image in the rate distortion curve is appropriate, thereby reducing the encoding code rate.
It effectively reduces the image encoding rate, reduces the impact on image quality, and improves the encoding efficiency.
Smart Images

Figure CN119211605A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer application technology, and in particular to a method, device, equipment, storage medium and program product for determining coding parameters. Background Art
[0002] In recent years, with the rapid development of the Internet, the application demand for images on the Internet has increased, and the amount of image data is very large. If images are to be transmitted on the Internet with limited bandwidth, the first problem that must be solved is the image compression coding problem. In the image coding process, due to the limitation of factors such as bandwidth, the coding bit rate needs to be controlled to meet the bandwidth requirements. The way to control the coding bit rate can be to use a constant rate factor (CRF). Generally, a fixed CRF value is set in advance, and all images are subsequently encoded with the fixed CRF value. However, this method of encoding all images with a fixed CRF value does not adjust the CRF value for different images, which will lead to the problem of wasting bandwidth. Based on this, how to reduce the image coding bit rate is a technical problem that needs to be solved urgently. Summary of the invention
[0003] The technical problem to be solved by the embodiments of the present application is to provide a method, device, equipment, storage medium and program product for determining coding parameters, which can reduce the image coding bit rate.
[0004] In a first aspect, an embodiment of the present application provides a method for determining a coding parameter, the method comprising:
[0005] Get the complexity of the target image;
[0006] Inputting the complexity of the target image into a constant rate factor adjustment model to obtain a target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict a target slope of the target image in a rate-distortion curve according to the complexity of the target image, and obtain a target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to a preset complexity, the target constant rate factor is greater than an initial constant rate factor;
[0007] The target image is encoded according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor.
[0008] In a second aspect, an embodiment of the present application provides a device for determining a coding parameter, the device comprising:
[0009] An acquisition unit, used for acquiring the complexity of a target image;
[0010] A determination unit, configured to input the complexity of the target image into a constant rate factor adjustment model to obtain a target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is configured to predict a target slope of the target image in a rate-distortion curve according to the complexity of the target image, and obtain a target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to a preset complexity, the target constant rate factor is greater than an initial constant rate factor;
[0011] The encoding unit is used to encode the target image according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor.
[0012] In one embodiment, the acquisition unit is further configured to include:
[0013] Obtaining the complexity of a training image, at least two preset constant rate factors sampled from a constant rate factor interval, and a reference slope;
[0014] Based on each of the at least two preset constant rate factors, encoding the training image, and determining a coding slope of the encoded training image corresponding to each of the preset constant rate factors in a rate-distortion curve;
[0015] Determining a training slope according to the determined at least two encoding slopes and the reference slope;
[0016] The slope determination model is trained based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model; the constant rate factor adjustment model is used to predict the slope of the image to be encoded in the rate-distortion curve according to the complexity of the image to be encoded, and obtain the constant rate factor to be encoded corresponding to the image to be encoded according to the slope to be encoded, and the image to be encoded includes any image.
[0017] In one implementation, the determining unit determines the training slope according to the determined at least two encoding slopes and the reference slope, including:
[0018] determining a training slope from the at least two encoding slopes;
[0019] The absolute value of the difference between the training slope and the reference slope is smaller than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0020] In one implementation, the determining unit determines the training slope according to the determined at least two encoding slopes and the reference slope, including:
[0021] Determining a training curvature of the rate-distortion curve corresponding to the training image according to a quality score and a coding bit rate of the encoded training image in the rate-distortion curve corresponding to the at least two preset constant rate factors;
[0022] The training slope is determined according to the at least two encoding slopes, the training curvature and the reference slope.
[0023] In one implementation, the determining unit determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0024] If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes;
[0025] Among them, the training slope is smaller than the reference slope, and the difference between the reference slope and the training slope is smaller than the absolute value of the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two coding slopes that is smaller than the reference slope.
[0026] In one implementation, the determining unit determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0027] If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes;
[0028] The training slope is greater than or equal to the reference slope, and a difference between the training slope and the reference slope is less than a difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0029] In one implementation, the determining unit determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0030] If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes;
[0031] Among them, the training slope is greater than the reference slope, and the difference between the training slope and the reference slope is less than the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two encoding slopes that is greater than the reference slope.
[0032] In one implementation, the determining unit determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0033] If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes;
[0034] The training slope is less than or equal to the reference slope, and the difference between the reference slope and the training slope is less than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0035] In one embodiment, the determining unit trains the slope determination model based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model, including:
[0036] Inputting the complexity of the training image into the slope determination model to obtain a predicted slope corresponding to the training image;
[0037] The slope determination model is trained with the goal of reducing the difference between the predicted slope and the training slope to obtain a trained slope determination model, and the constant rate factor adjustment model is constructed based on the trained slope determination model.
[0038] In one embodiment, the acquisition unit is further configured to include:
[0039] Acquire a first encoding bit rate required for encoding the target image using the target constant rate factor, and a second encoding bit rate required for encoding the target image using the initial constant rate factor;
[0040] Determining a coding rate difference between the first coding rate and the second coding rate;
[0041] Determining a constant rate factor deviation value according to the encoding bit rate difference;
[0042] adjusting the target constant rate factor based on the constant rate factor deviation value to determine an adjusted target constant rate factor;
[0043] The encoding unit encodes the target image according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor, including:
[0044] The target image is encoded according to the adjusted target constant rate factor to obtain an encoded target image corresponding to the adjusted target constant rate factor.
[0045] In a third aspect, an embodiment of the present application provides a computer device, which includes a memory, a communication interface, and a processor, wherein the memory, the communication interface, and the processor are interconnected; the memory stores a computer program, and the processor calls the computer program stored in the memory to implement the method for determining the coding parameters of the first aspect above.
[0046] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, it implements the method for determining the encoding parameters of the first aspect mentioned above.
[0047] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program stored in a computer storage medium; a processor of a computer device reads the computer program from the computer storage medium, and the processor executes the computer program, so that the computer device executes the method for determining the encoding parameters of the first aspect above.
[0048] In an embodiment of the present application, the complexity of the target image is obtained; the complexity of the target image is input into a constant rate factor adjustment model to obtain a target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict the target slope of the target image in the rate-distortion curve according to the complexity of the target image, and obtain the target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to the preset complexity, the target constant rate factor is greater than the initial constant rate factor; the target image is encoded according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor. Since the slope of the rate-distortion curve of an image with lower complexity after encoding is smaller, reducing the encoding bit rate for an image with lower complexity has less impact on the quality of the encoded image, so the present application increases the constant rate factor of a target image with a complexity less than the preset complexity, that is, an image with lower complexity, to reduce the image encoding bit rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the background technology, the drawings required for use in the embodiments of the present application or the background technology will be described below.
[0050] Figure 1 is a schematic diagram of a rate-distortion curve provided in an embodiment of the present application;
[0051] Figure 2 It is a schematic diagram of the architecture of a slope determination model provided in an embodiment of the present application;
[0052] Figure 3It is a flowchart of a training method for a slope determination model provided in an embodiment of the present application;
[0053] Figure 4 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application;
[0054] Figure 5 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application;
[0055] Figure 6 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application;
[0056] Figure 7 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application;
[0057] Figure 8 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application;
[0058] Fig. 9 It is a flowchart of a method for determining a coding parameter provided in an embodiment of the present application;
[0059] Fig.10 It is a flowchart of another method for determining coding parameters provided in an embodiment of the present application;
[0060] Fig.11 It is a structural diagram of a device for determining a coding parameter provided in an embodiment of the present application;
[0061] Fig.12 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0062] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0063] At the same time, in the description of the embodiments of the present application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more features. In the description of the embodiments of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0064] In the specific implementation of this application, user-related data, such as user images, video information, etc., is involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with local laws, regulations and standards.
[0065] In video or image encoding, the quality indicated by the CRF value set in the encoder is encoded. Different videos or images have different complexities, so the quality score and encoding bit rate point of the encoded image or video in the rate-distortion curve (RD-Curve) are also different, that is, the slope of the RD-Curve is also different. Figure 1 As shown, Figure 1 It is a schematic diagram of a rate-distortion curve provided in an embodiment of the present application, which can characterize that after encoding images or videos of different complexities according to the CRF value, the quality scores and the slopes of the coding bitrate points in the rate-distortion curve are different, wherein the horizontal coordinate of the rate-distortion curve is the coding bitrate (bitrates), and the vertical coordinate is the quality score (Vmaf). When the rate-distortion curve is in a smooth (small slope) area, the quality score and coding bitrate point, such as the quality score and coding bitrate point with a slope of Lambda1, can ensure that the quality of the video or image will not be reduced a lot under the premise of reducing the coding bitrate; at the same time, for the quality score and coding bitrate point in the steep (large slope) area of the rate-distortion curve, such as the quality score and coding bitrate point with a slope of Lambda2, the quality score of the video or image can be greatly improved under the premise of increasing a smaller bitrate.
[0066] Based on the above description, an embodiment of the present application provides a slope determination model, which can predict the slope to be encoded of the image to be encoded or the video to be encoded in the rate-distortion curve according to the complexity of the input image to be encoded or the video to be encoded. Furthermore, a constant rate factor adjustment model can be constructed by the slope determination model, and the constant rate factor adjustment model can determine the constant rate factor to be encoded corresponding to the image to be encoded or the video to be encoded according to the complexity of the input image to be encoded or the video to be encoded. Among them, each predicted slope to be encoded corresponds to a constant rate factor to be encoded. Optionally, a mapping model of slope and constant rate factor can be used, and the model determines the constant rate factor to be encoded according to the predicted slope to be encoded. Optionally, a constant rate factor adjustment model can be constructed by the slope determination model and the mapping model of slope and constant rate factor. Please refer to Figure 2 , Figure 2Schematic diagram of a slope determination model provided in an embodiment of the present application, wherein the slope determination model uses four fully connected layers to predict the slope of the image or video to be encoded in the rate-distortion curve.
[0067] The features received by the input layer may include a total of 1x8 features, for example, complexity features such as sad (Sum of Absolute Differences), satd (Sum of Absolute Transformed Differences), mrsad (Mean Res idua l Sum of Absolute Differences), sad_min, etc., and are passed to the first hidden layer.
[0068] The hidden layer contains three layers, of which the first layer is 8x32 network parameters, i.e. 8 input neurons and 32 output neurons. Optionally, the first layer of the hidden layer can use the ReLU (Rectified Linear Un it) activation function, the dimension of the weight matrix is 8x32, and the dimension of the bias term is 32. The second layer is 32x32 network parameters, i.e. 32 input neurons and 32 output neurons. Optionally, the second layer of the hidden layer can use the ReLU activation function, the dimension of the weight matrix is 32x32, and the dimension of the bias term is 32. The second layer is 32x5 network parameters, i.e. 32 input neurons and 5 output neurons. Optionally, the third layer of the hidden layer can use the ReLU activation function, the dimension of the weight matrix is 32x5, and the dimension of the bias term is 5.
[0069] The output layer has 5 input neurons (corresponding to the output of the third hidden layer), and finally outputs the probability distribution of n categories. Optionally, the output layer can use a softmax activation function to convert the output into a category probability. Among them, the slope with the largest probability is the slope to be encoded in the rate-distortion curve of the image or video to be encoded.
[0070] Based on the above description, see Figure 3 , Figure 3 is a flow chart of a training method for a slope determination model provided in an embodiment of the present application, such as Figure 3 The training method of the slope determination model shown includes but is not limited to steps S301-S304, wherein:
[0071] S301, obtaining the complexity of a training image, at least two preset constant rate factors sampled from a constant rate factor interval, and a reference slope.
[0072] In this embodiment, the training image can be a single image or any frame image in a training video frame sequence. The complexity of the training image can indicate the complexity characteristics of the training image, and the complexity of the training image can include at least one of the following: the texture complexity of the training image and the motion complexity of the training image. The constant rate factor (CRF) is a parameter for video or image encoding quality control, which is mainly used to control the balance between the compression quality and file size of the video or image. The value range of CRF is from 0 to 51, where 0 represents lossless encoding and 51 represents the lowest quality. The reference slope is used to characterize the quality score of the encoded video obtained by encoding any video with a constant rate factor corresponding to the reference slope, and the ratio between the encoding bit rate required for encoding any video with a constant rate factor corresponding to the reference slope. Among them, the quality score is used to characterize the quality of the encoded training image, and the quality score may include VMAF (Video Multi-method Assessment Fusion). Optionally, the quality score may also include PSNR (Peak Signal-to-Noise Ratio) or SSIM (Structural Similarity Index).
[0073] Among them, the texture complexity of the training image is used to characterize the details and texture information of the training image, such as SATD, which measures the differences between image blocks in the transform domain (such as DCT domain) and can reflect the complexity of texture and details. The motion complexity of the training image is used for motion estimation and prediction residual analysis, such as SAD, MRSAD, etc. SAD is mainly used to measure the absolute pixel difference between image blocks, and MRSAD is an extension of SAD and is used to evaluate the average residual of multiple image blocks.
[0074] Alternatively, the texture complexity of the training image can be characterized by the sum of absolute transform differences (SATD cost).
[0075] In an optional embodiment, the absolute transformation difference and cost (SATD cost) may be determined by: calculating the pixel difference between the training image and the reference image, and performing frequency domain transformation on the pixel difference to obtain a difference coefficient; performing an absolute value transformation on the difference coefficient, and summing the absolute value transformed difference coefficients to obtain the absolute transformation difference of the training image; and obtaining the absolute transformation difference and cost of the training image based on the absolute transformation difference of the training image and the absolute transformation difference of images adjacent to the training image. Specifically, the training image is compared with its reference image (which may include an image before the training image or a predicted image), and the pixel difference between the images is calculated, wherein the training image may be any frame image in the video, and the image before the training image may be one or more frames of images before the training image. The pixel difference is processed by transformation (for example, discrete cosine transform DCT or Hadamard transform) to obtain difference coefficients, the absolute values of the transformed difference coefficients are calculated, and then these absolute values are summed up. The sum obtained is the absolute transformation difference SATD of the training image. The absolute transformation difference SATD of the training image and the absolute transformation difference SATD of the image adjacent to the training image are linearly weighted summed to obtain the absolute transformation difference and cost SATD cost of the training image.
[0076] Optionally, the SATD value of the training image is the sum of the residual STAD of the half-pixel accuracy of the image, which is calculated in the preprocessing module before the bit rate control module; SATD requires a predictive coding process, and the I frame (intra-frame prediction) needs to decide its best prediction direction based on the image block of the training image, and the P frame (inter-frame prediction) needs to decide its best motion vector MV based on the image block division of the training image, that is, motion estimation is required to obtain the SATD sum of all blocks of the training image. Among them, for the I frame (intra-frame prediction), the encoder needs to decide which prediction mode (such as horizontal, vertical, DC prediction, etc.) to use for each image block of the training image. Each prediction mode will generate a prediction value. For each image block, the encoder will calculate the residual between its original pixel and the prediction value generated by each prediction mode, transform these residuals (such as DCT), and then calculate the sum of the absolute values of the transformed residuals, that is, SATD. This SATD value is used to measure the encoding effect of each image block using different prediction modes. For P frames (inter-frame prediction), the encoder needs to perform motion estimation on each block of the training image to find the best motion vector (MV), which represents the position in the reference image that best matches the current block. For each image block, its residual is obtained through motion estimation. These residuals are also transformed (such as DCT), and then the sum of the absolute values of the transformed residuals (ie, SATD) is calculated as the SATD of the block.
[0077] Optionally, sampling from the constant rate factor interval to obtain at least two preset constant rate factors may be performed in the following manner: sampling in the preset constant rate factor interval according to a preset step length to obtain at least two preset constant rate factors. Specifically, the preset constant rate factor interval may be [22, 25], and the preset step length may be step=0.5, i.e., sampling in the preset constant rate factor interval [22, 25] according to a preset step length of 0.5 to obtain at least two preset constant rate factors.
[0078] S302: Encode a training image based on each of at least two preset constant rate factors, and determine a coding slope of the encoded training image corresponding to each preset constant rate factor in a rate-distortion curve.
[0079] In this embodiment, after sampling from the constant rate factor interval to obtain at least two preset constant rate factors, the training image is encoded based on each of the at least two preset constant rate factors, and the quality score and encoding bit rate of the encoded training image corresponding to each preset constant rate factor in the rate-distortion curve are determined, and a curve of the quality score and encoding bit rate of different encoding bit rate points of the training image, i.e., the rate-distortion curve, can be plotted. For details, see Figure 4 , Figure 4 It is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application. The quality score of the training image is characterized by Vmaf, which includes multiple groups of rate quality points: {bitrate1, Vmaf1}, {bitrate2, Vmaf2}, {bitrate3, Vmaf3}, {bitrate4, Vmaf4}, and the difference between the encoding rate and the quality score of adjacent quality score points can be calculated, that is, the encoding slope, wherein each encoding slope is used to characterize: the ratio between the quality score of the encoded training image obtained by encoding the training image by each preset constant rate factor and the encoding rate used by encoding the training image by each preset constant rate factor. Wherein, the calculation formula of the encoding rate is shown in formula (1):
[0080]
[0081] Where lambda_i represents the coding slope of the i-th preset constant rate factor crf point, Vmaf i Vmaf represents the mass fraction of the i-th preset constant rate factor crf point. i+1 Indicates the quality score of the i+1th preset constant rate factor crf point, bitrate i Indicates the encoding bitrate of the i-th preset constant rate factor crf point, bitrate i+1Indicates the encoding bit rate of the i+1th preset constant rate factor crf point.
[0082] S303: Determine a training slope according to the determined at least two encoding slopes and a reference slope.
[0083] In this embodiment, the training slope may be determined from at least two encoding slopes based on a reference slope; or the training slope may be determined by weighted averaging at least two encoding slopes and according to the reference slope.
[0084] In an optional implementation, the training slope is determined based on the at least two determined coding slopes and the reference slope, which can be determined in the following manner: the training slope is determined from the at least two coding slopes; wherein the absolute value of the difference between the training slope and the reference slope is smaller than the absolute value of the difference between the reference slope and the other slopes other than the training slope in the at least two coding slopes. Specifically, the value closest to the reference slope lambda_target is determined in the at least two coding slopes as the training slope of the training image, and the training slope is the true label value (Groundtruth label).
[0085] In an optional embodiment, the training slope is determined based on at least two determined coding slopes and a reference slope, and the following methods can be used: according to the quality score and coding bit rate of the encoded training image in the rate-distortion curve corresponding to the at least two preset constant rate factors, the training curvature of the rate-distortion curve corresponding to the training image is determined; according to the at least two coding slopes, the training curvature and the reference slope, the training slope is determined. Specifically, the rate-distortion curve is fitted based on the quality score and coding bit rate of the encoded training image in the rate-distortion curve corresponding to at least two preset constant rate factors and a target fitting method, and the target fitting method may include at least one of the following: logarithmic fitting or quadratic fitting. According to the obtained rate-distortion curve, the training curvature is determined, and then the training slope is determined from at least two coding slopes based on the training curvature and the reference slope.
[0086] In an optional embodiment, the training slope is determined based on at least two encoding slopes, a training curvature and a reference slope in the following manner: if the training curvature is greater than a preset curvature, the training slope is determined from at least two encoding slopes; wherein the training slope is less than the reference slope, and the difference between the reference slope and the training slope is less than the absolute value of the difference between the reference slope and other slopes in the slope interval except the training slope; the slope interval includes: a slope of at least two encoding slopes that is less than the reference slope.
[0087] In this embodiment, the preset curvature is used to characterize the steepness or flatness of the rate-distortion curve. The greater the complexity of the training image, the steeper the rate-distortion curve of the encoded training image; the smaller the complexity of the training image, the flatter the rate-distortion curve of the encoded training image. If the training curvature is greater than the preset curvature, the training slope closest to the reference slope is determined from the slope interval, and the slope interval includes: the slope of at least two encoding slopes that is smaller than the reference slope. For details, please refer to Figure 5 , Figure 5 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application, wherein the rate-distortion curve includes 4 quality scores and coding rate points, and the reference slope, namely Lambda_target, is greater than the minimum slope of at least two coding slopes and less than the maximum slope of at least two coding slopes. Figure 5 The quality score of the rate-distortion curve and the coding bit rate point can be used to obtain the preset curvature of the rate-distortion curve. At this time, the training curvature is greater than the preset curvature, which is a steep curve. For the steep curve, increasing the coding bit rate by a small amount can obtain a larger quality score improvement, and it is necessary to try to meet the quality score and coding bit rate requirements indicated by the reference slope. Therefore, the training slope is Figure 5 For the steep curve scenario, increasing the encoding bit rate and trying to meet the quality score and encoding bit rate indicated by the reference slope (Lambda_target) can achieve a greater improvement in quality score while increasing the bit rate slightly.
[0088] In an optional embodiment, the training slope is determined based on at least two encoding slopes, a training curvature and a reference slope in the following manner: if the training curvature is greater than a preset curvature, the training slope is determined from at least two encoding slopes; wherein the training slope is greater than or equal to the reference slope, and the difference between the training slope and the reference slope is less than the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0089] In this embodiment, if the training curvature is greater than the preset curvature, a training slope closest to the reference slope is determined from at least two encoding slopes. Figure 6 , Figure 6 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application, wherein the rate-distortion curve includes 4 quality scores and coding bit rate points, and the reference slope, namely Lambda_target, is less than the minimum slope of at least two coding slopes. Figure 6The quality score of the rate-distortion curve and the coding bit rate point can be used to obtain the preset curvature of the rate-distortion curve. At this time, the training curvature is greater than the preset curvature, which is a steep curve. For the steep curve, increasing the coding bit rate by a small amount can obtain a larger quality score improvement, and it is necessary to try to meet the quality score and coding bit rate requirements indicated by the reference slope. Therefore, the training slope is Figure 6 For the steep curve scenario, increasing the encoding bit rate and trying to meet the quality score and encoding bit rate indicated by the reference slope (Lambda_target) can achieve a greater improvement in quality score while increasing the bit rate slightly.
[0090] In an optional embodiment, the training slope is determined based on at least two encoding slopes, a training curvature and a reference slope in the following manner: if the training curvature is less than or equal to a preset curvature, the training slope is determined from at least two encoding slopes; wherein the training slope is greater than the reference slope, and the difference between the training slope and the reference slope is less than the difference between the reference slope and other slopes in the slope interval except the training slope; the slope interval includes: a slope greater than the reference slope among at least two encoding slopes.
[0091] In this embodiment, if the training curvature is less than or equal to the preset curvature, a training slope closest to the reference slope is determined from the slope interval, and the slope interval includes: a slope greater than the reference slope among at least two encoding slopes. For details, please refer to Figure 7 , Figure 7 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application, wherein the rate-distortion curve includes 4 quality scores and coding rate points, and the reference slope, namely Lambda_target, is greater than the minimum slope of at least two coding slopes and less than the maximum slope of at least two coding slopes. Figure 7 The quality score of the rate-distortion curve and the coding bit rate point can be used to obtain the preset curvature of the rate-distortion curve. At this time, the training curvature is less than the preset curvature, which is a gentle curve. For the gentle curve, reducing the coding bit rate has little effect on the quality score, and it is necessary to try to meet the quality score and coding bit rate requirements indicated by the reference slope. Therefore, the training slope is Figure 7 For the flat curve scenario, reducing the encoding bit rate and trying to meet the quality score and encoding bit rate indicated by the reference slope (Lambda_target) can reduce the encoding bit rate with little impact on the quality score.
[0092] In an optional embodiment, the training slope is determined based on at least two encoding slopes, a training curvature and a reference slope in the following manner: if the training curvature is less than or equal to a preset curvature, the training slope is determined from at least two encoding slopes; wherein the training slope is less than or equal to the reference slope, and the difference between the reference slope and the training slope is less than the absolute value of the difference between the reference slope and the other slopes of the at least two encoding slopes except the training slope.
[0093] In this embodiment, if the training curvature is less than or equal to the preset curvature, a training slope closest to the reference slope is determined from at least two encoding slopes. Figure 8 , Figure 8 is a schematic diagram of another rate-distortion curve provided in an embodiment of the present application, wherein the rate-distortion curve includes 4 quality scores and encoding bit rate points, and the reference slope, namely Lambda_target, is greater than the maximum slope of at least two encoding slopes. Figure 8 The quality score of the rate-distortion curve and the coding bit rate point can be used to obtain the preset curvature of the rate-distortion curve. At this time, the training curvature is less than the preset curvature, which is a gentle curve. For the gentle curve, reducing the coding bit rate has little effect on the quality score, and it is necessary to try to meet the quality score and coding bit rate requirements indicated by the reference slope. Therefore, the training slope is Figure 8 For the flat curve scenario, reducing the encoding bit rate and trying to meet the quality score and encoding bit rate indicated by the reference slope (Lambda_target) can reduce the encoding bit rate with little impact on the quality score.
[0094] S304: training the slope determination model based on the complexity of the training image and the training slope to obtain a constant rate factor adjustment model.
[0095] In this embodiment, after the slope determination model is trained to obtain the slope determination model, a constant rate factor adjustment model can be constructed through the slope determination model. The constant rate factor adjustment model can predict the slope to be encoded of the image to be encoded in the rate-distortion curve according to the complexity of the input image to be encoded, and obtain the constant rate factor to be encoded corresponding to the image to be encoded according to the slope to be encoded. The image to be encoded can be any image. Among them, each predicted slope to be encoded corresponds to a constant rate factor to be encoded. Optionally, a mapping model of slope and constant rate factor can be used, and the model determines the constant rate factor to be encoded according to the predicted slope to be encoded. Optionally, a constant rate factor adjustment model can be constructed through the slope determination model and the mapping model of slope and constant rate factor. Optionally, the slope determination model can use four fully connected layers to predict the slope to be encoded in the rate-distortion curve of the image to be encoded.
[0096] In an optional embodiment, the slope determination model is trained based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model. This can be done in the following way: the complexity of the training image is input into the slope determination model to obtain the predicted slope corresponding to the training image; the slope determination model is trained with the goal of reducing the difference between the predicted slope and the training slope to obtain the trained slope determination model; and the constant rate factor adjustment model is constructed based on the trained slope determination model.
[0097] In this embodiment, the complexity feature of the training image is input into the slope determination model to predict the predicted slope corresponding to the training image, the difference between the predicted slope and the training slope is used as the loss function, the slope determination model is optimized, the difference between the predicted slope and the training slope is reduced, and the slope determination model is trained through iterative optimization so that it can accurately predict the slope. A constant rate factor adjustment model is constructed based on the trained slope determination model. For example, a constant rate factor adjustment model can be constructed through a slope determination model, a mapping model of slope and constant rate factor (the model determines the constant rate factor to be encoded based on the predicted slope to be encoded). Optionally, the loss of the predicted slope and the training slope can be estimated by cross entropy.
[0098] Based on the above description, the specific method of the embodiment of the present application for training the slope determination model according to the complexity of the training image and the training slope can also be applied to training the slope determination model according to the complexity of the training video and the training slope to obtain a constant rate factor adjustment model. The obtained constant rate factor adjustment model is used to predict the slope of the video to be encoded in the rate-distortion curve according to the complexity of the video to be encoded, and obtain the constant rate factor to be encoded corresponding to the video to be encoded according to the slope to be encoded. The video to be encoded includes any video.
[0099] In an embodiment of the present application, the complexity of the training image is obtained, at least two preset constant rate factors sampled from the constant rate factor interval, and a reference slope are obtained; based on each of the at least two preset constant rate factors, the training image is encoded, and the encoding slope of the encoded training image corresponding to each preset constant rate factor in the rate-distortion curve is determined; based on the determined at least two encoding slopes and the reference slope, the training slope is determined; based on the complexity of the training image and the training slope, the slope determination model is trained to obtain a constant rate factor adjustment model. The trained slope determination model can determine the training slope corresponding to the training image according to the complexity of the training image, so that the training slope meets the reference slope as much as possible, and the constructed constant rate factor adjustment model can determine the constant rate factor corresponding to the training image according to the complexity of the training image.
[0100] Based on the above description, the embodiments of the present application can be applied to image or video encoding. Fig. 9 , Fig. 9 is a flow chart of a method for determining a coding parameter provided in an embodiment of the present application, such as Fig. 9 The method for determining the encoding parameters shown includes but is not limited to steps S901-S903, wherein:
[0101] S901, obtaining the complexity of the target image.
[0102] In this embodiment, the target image may be a single image or any frame image in a target video frame sequence. The complexity of the target image may indicate a complexity feature of the target image, and the complexity of the target image may include at least one of the following: texture complexity of the target image and motion complexity of the target image.
[0103] Among them, the texture complexity of the target image is used to characterize the details and texture information of the target image, such as SATD, which measures the differences between image blocks in the transform domain (such as DCT domain) and can reflect the complexity of texture and details. The motion complexity of the target image is used for motion estimation and prediction residual analysis, such as SAD, MRSAD, etc. SAD is mainly used to measure the absolute pixel difference between image blocks, and MRSAD is an extension of SAD and is used to evaluate the average residual of multiple image blocks.
[0104] Optionally, the texture complexity of the target image can be characterized by the sum of absolute transform differences (SATD cost).
[0105] In an optional implementation, the absolute transformation difference and cost (SATD cost) may be determined by: calculating the pixel difference between the target image and the reference image, and performing frequency domain transformation on the pixel difference to obtain a difference coefficient; performing an absolute value transformation on the difference coefficient, and summing the absolute value transformed difference coefficients to obtain the absolute transformation difference of the target image; and obtaining the absolute transformation difference and cost of the target image based on the absolute transformation difference of the target image and the absolute transformation difference of images adjacent to the target image. Specifically, the target image is compared with its reference image (which may include an image before the target image or a predicted image), and the pixel difference between the images is calculated, wherein the target image may be any frame image in the video, and the image before the target image may be one or more frames of images before the target image. The pixel difference is processed by transformation (for example, discrete cosine transform DCT or Hadamard transform) to obtain difference coefficients, the absolute values of the transformed difference coefficients are calculated, and then these absolute values are summed up. The sum obtained is the absolute transformation difference SATD of the target image. The absolute transformation difference SATD of the target image and the absolute transformation difference SATD of the adjacent images of the target image are linearly weighted summed to obtain the absolute transformation difference and cost SATD cost of the target image.
[0106] Optionally, the SATD value of the target image is the sum of the residual STAD of the half-pixel accuracy of the image, which is calculated in the preprocessing module before the bit rate control module; SATD requires a predictive coding process, and the I frame (intra-frame prediction) needs to determine its best prediction direction based on the image block of the target image, and the P frame (inter-frame prediction) needs to determine its best motion vector MV based on the image block division of the target image, that is, motion estimation is required to obtain the SATD sum of all blocks of the target image. Among them, for the I frame (intra-frame prediction), the encoder needs to decide which prediction mode (such as horizontal, vertical, DC prediction, etc.) to use for each image block of the target image. Each prediction mode will generate a prediction value. For each image block, the encoder will calculate the residual between its original pixel and the prediction value generated by each prediction mode, transform these residuals (such as DCT), and then calculate the sum of the absolute values of the transformed residuals, that is, SATD. This SATD value is used to measure the encoding effect of each image block using different prediction modes. For P frames (inter-frame prediction), the encoder needs to perform motion estimation on each block of the target image to find the best motion vector (MV), which represents the position in the reference image that best matches the current block. For each image block, its residual is obtained through motion estimation. These residuals are also transformed (such as DCT), and then the sum of the absolute values of the transformed residuals (ie, SATD) is calculated as the SATD of the block.
[0107] S902, input the complexity of the target image into the constant rate factor adjustment model to obtain the target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict the target slope of the target image in the rate-distortion curve according to the complexity of the target image, and obtain the target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to the preset complexity, the target constant rate factor is greater than the initial constant rate factor.
[0108] In this embodiment, the constant rate factor adjustment model predicts the target slope of the target image in the rate-distortion curve according to the complexity of the input target image, and obtains the target constant rate factor corresponding to the target image according to the target slope. Optionally, a mapping model or linear function of the slope and the constant rate factor can be used to obtain the target constant rate factor corresponding to the target image according to the target slope. For example, the target slope is one-half, and the mapped target constant rate factor is 23. If the complexity of the target image is less than or equal to the preset complexity, it can be predicted that the slope of the encoded target image in the rate-distortion curve is small, that is, the flat part, and the effect of reducing the encoding bit rate on the quality score is small, that is, the constant rate factor can be increased to reduce the encoding bit rate, wherein the increased constant rate factor is the target constant rate factor, and the initial constant rate factor can indicate the constant rate factor of the encoder by default or the constant rate factor set by the object for the encoder.
[0109] In an optional implementation, the following method can also be used: obtaining a first encoding rate required for encoding the target image using a target constant rate factor, and a second encoding rate required for encoding the target image using an initial constant rate factor; determining a coding rate difference between the first coding rate and the second coding rate; determining a constant rate factor deviation value according to the coding rate difference; adjusting the target constant rate factor based on the constant rate factor deviation value, and determining the adjusted target constant rate factor. Optionally, determining the constant rate factor deviation value according to the coding rate difference can be done in any of the following ways: determining the constant rate factor deviation value through a mapping table of coding rate and constant rate factor; or determining the constant rate factor deviation value through a functional relationship between coding rate and constant rate factor. For example, the coding rate difference is 3bps. That is, if the target image is encoded by the target constant rate factor, the bit rate required for encoding the target image by the initial constant rate factor is 3 bps less, then by querying the mapping table, the constant rate factor deviation value corresponding to the encoding bit rate difference of 3 bps is determined to be 0.5, wherein the target constant rate factor is 23, and the target constant rate factor can be adjusted based on the constant rate factor deviation value by subtraction to determine the adjusted target constant rate factor, that is, 23-0.5=22.5, and the obtained 22.5 is the adjusted target constant rate factor. By determining the bit rate saved by encoding based on the target constant rate factor, the saved bit rate is converted into a constant rate factor deviation value, and the target constant rate factor is adjusted by the constant rate factor deviation value to obtain the adjusted target constant rate factor, wherein the adjusted target constant rate factor is less than the target constant rate factor, and encoding the target image by the adjusted target constant rate factor can improve the quality score under the premise of the same bit rate as encoding the target image by the initial constant rate factor.
[0110] S903, encoding the target image according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor.
[0111] In this embodiment, the encoder encodes the target image according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor. By encoding the target image by the target constant rate factor, the encoding bit rate can be reduced compared to encoding by the initial constant rate factor.
[0112] In an optional implementation, encoding the target image according to the target constant rate factor to obtain the encoded target image corresponding to the target constant rate factor can be performed in the following manner: encoding the target image according to the adjusted target constant rate factor to obtain the encoded target image corresponding to the adjusted target constant rate factor. That is, the encoder encodes the target image according to the adjusted target constant rate factor to obtain the encoded target image corresponding to the adjusted target constant rate factor, and encoding the target image by the adjusted target constant rate factor can increase the quality score, that is, improve the subjective quality, compared with encoding by the initial constant rate factor.
[0113] In an optional implementation, a target quantization parameter (QP) is determined according to the target constant rate factor, and the target image is encoded according to the target quantization parameter to obtain an encoded target image corresponding to the target constant rate factor. Optionally, the target quantization parameter corresponding to the target constant rate factor can be determined through a mapping table, for example, the target constant rate factor can be converted into the target quantization parameter through an internal algorithm of the encoder, that is, a mapping relationship between the constant rate factor and the quantization parameter, and the encoder encodes the target image based on the target QP value.
[0114] Based on the above description, the specific method of determining the target constant rate factor corresponding to the target image according to the complexity of the target image in the embodiment of the present application can also be applied to determining the target constant rate factor corresponding to the target video according to the complexity of the target video, and encoding the target video according to the obtained constant rate factor. Optionally, the complexity of the target video can be obtained by the complexity of each frame of the target video, for example, the mean, maximum or minimum value of the complexity of each frame of the target video is used as the complexity of the target video.
[0115] In an embodiment of the present application, the complexity of the target image is obtained; the complexity of the target image is input into a constant rate factor adjustment model to obtain a target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict the target slope of the target image in the rate-distortion curve according to the complexity of the target image, and obtain the target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to the preset complexity, the target constant rate factor is greater than the initial constant rate factor; the target image is encoded according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor. By increasing the constant rate factor of an image with a smaller complexity, the bit rate required for encoding can be reduced. At the same time, since the slope of an image with a smaller complexity in the rate-distortion curve is smaller, that is, it is relatively gentle, the bit rate can be reduced with less impact on subjective quality.
[0116] Based on the above description, the embodiments of the present application can be applied to the encoding of multiple videos (video groups) or multiple images (image groups), see Fig.10 , Fig.10 is a flow chart of another method for determining coding parameters provided in an embodiment of the present application, such as Fig.10 The method for determining the encoding parameters shown includes but is not limited to steps S1001-S1003, wherein:
[0117] S1001, obtaining the complexity of each video from multiple videos.
[0118] In this embodiment, the complexity of each video may indicate the complexity feature of each video, and the complexity of each video may include at least one of the following: texture complexity of each video and motion complexity of each video.
[0119] The texture complexity or motion complexity of any video can be obtained by the complexity of each image in the video, for example, the complexity of any video can be determined by the mean, maximum or minimum value of the complexity of each image in the video. The complexity of each image can include at least one of the following: the texture complexity of each image, the motion complexity of each image.
[0120] Among them, the texture complexity of any image is used to characterize the details and texture information of the image, such as SATD, which measures the differences between image blocks in the transform domain (such as DCT domain) and can reflect the complexity of texture and details. The motion complexity of any image is used for motion estimation and prediction residual analysis, such as SAD, MRSAD, etc. SAD is mainly used to measure the absolute pixel difference between image blocks, and MRSAD is an extension of SAD and is used to evaluate the average residual of multiple image blocks.
[0121] Optionally, the texture complexity of any image in any video may be characterized by the sum of absolute transform differences (SATD cost).
[0122] In an optional implementation, the absolute transformation difference and cost (SATD cost) may be determined by: calculating the pixel difference between any image and a reference image, and performing frequency domain transformation on the pixel difference to obtain a difference coefficient; performing an absolute value transformation on the difference coefficient, and summing the absolute value transformed difference coefficients to obtain the absolute transformation difference of any image; and obtaining the absolute transformation difference and cost of any image based on the absolute transformation difference of any image and the absolute transformation difference of an image adjacent to any image. Specifically, any image is compared with its reference image (which may include an image before any image or a predicted image), and the pixel difference between the images is calculated, wherein any image may be any frame image in a video, and the image before any image may be one or more frames of images before any image. The pixel difference is processed by transformation (for example, discrete cosine transform DCT or Hadamard transform) to obtain difference coefficients, the absolute values of the transformed difference coefficients are calculated, and then these absolute values are summed up. The sum obtained is the absolute transformation difference SATD of any image. The absolute transformation difference SATD of any image and the absolute transformation difference SATD of any adjacent image are linearly weighted summed to obtain the absolute transformation difference and cost SATD cost of any image.
[0123] Optionally, the SATD value of any image is the sum of the residual STAD of the half-pixel accuracy of the image, which is calculated in the preprocessing module before the bit rate control module; SATD requires a predictive coding process, and the I frame (intra-frame prediction) needs to determine its best prediction direction based on the image block of any image, and the P frame (inter-frame prediction) needs to determine its best motion vector MV based on the image block division of any image, that is, motion estimation is required to obtain the SATD sum of all blocks of any image. Among them, for I frames (intra-frame prediction), the encoder needs to decide which prediction mode (such as horizontal, vertical, DC prediction, etc.) to use for each image block of any image. Each prediction mode will generate a prediction value. For each image block, the encoder will calculate the residual between its original pixel and the prediction value generated by each prediction mode, transform these residuals (such as DCT), and then calculate the sum of the absolute values of the transformed residuals, that is, SATD. This SATD value is used to measure the encoding effect of each image block using different prediction modes. For P frames (inter-frame prediction), the encoder needs to perform motion estimation on each block of any image to find the best motion vector (MV), which represents the position in the reference image that best matches the current block. For each image block, its residual is obtained through motion estimation. These residuals are also transformed (such as DCT), and then the sum of the absolute values of the transformed residuals (ie, SATD) is calculated as the SATD of the block.
[0124] S1002, input the complexity of each video into a constant rate factor adjustment model to obtain a target constant rate factor corresponding to each video.
[0125] In this embodiment, the constant rate factor adjustment model predicts the target slope of the currently input video in the rate-distortion curve according to the complexity of the currently input video, and obtains the target constant rate factor corresponding to the currently input video according to the target slope. Optionally, a mapping model or linear function of the slope and the constant rate factor can be used to obtain the target constant rate factor corresponding to the currently input video according to the target slope. For example, if the target slope is one-half, the mapped target constant rate factor is 23. If the complexity of the currently input video is less than or equal to the preset complexity, it can be predicted that the slope of the currently input video after encoding in the rate-distortion curve is smaller, that is, the flat part, and the effect of reducing the encoding bit rate on the quality score is smaller, that is, the constant rate factor can be increased to reduce the encoding bit rate, wherein the increased constant rate factor is the target constant rate factor. If the complexity of the currently input video is greater than the preset complexity, it can be predicted that the slope of the currently input video after encoding in the rate-distortion curve is larger, that is, the steep part, then increasing the encoding bit rate has a greater impact on the quality score, that is, the constant rate factor can be reduced to appropriately increase the encoding bit rate and significantly increase the quality score, wherein the reduced constant rate factor is the target constant rate factor. The initial constant rate factor can indicate the constant rate factor of the encoder by default or the constant rate factor set by the object for the encoder. By appropriately increasing the encoding bit rate of a video with a higher complexity, that is, a video with a larger slope in the rate-distortion curve after encoding, that is, reducing the constant rate factor, the quality score can be significantly improved; by appropriately reducing the encoding bit rate of a video with a lower complexity, that is, a video with a smaller slope in the rate-distortion curve after encoding, that is, increasing the constant rate factor, the quality score has a smaller impact, thereby reducing the video encoding bit rate while ensuring that the overall quality score (subjective quality) of multiple videos (video groups) is not reduced.
[0126] In an optional implementation, the following method can be used: obtaining the third encoding rate required for encoding each video using the target constant rate factor corresponding to each video, and the fourth encoding rate required for encoding each video using the initial constant rate factor; determining the encoding rate difference between the third encoding rate and the fourth encoding rate; determining the constant rate factor deviation value according to the encoding rate difference; adjusting the target constant rate factor corresponding to each video based on the constant rate factor deviation value, and determining the adjusted target constant rate factor corresponding to each video. Optionally, determining the constant rate factor deviation value according to the encoding rate difference can be done in any of the following ways: determining the constant rate factor deviation value through a mapping table of encoding rate and constant rate factor; or determining the constant rate factor deviation value through a functional relationship between encoding rate and constant rate factor. For example, the encoding rate difference is 3bps. That is, if the bit rate required for encoding each video by the target constant rate factor corresponding to each video is 3 bps less than that required for encoding each video by the initial constant rate factor, then by querying the mapping table, it is determined that the constant rate factor deviation value corresponding to the encoding bit rate difference of 3 bps is 0.5, wherein the target constant rate factor is 23, and the target constant rate factor can be adjusted by subtraction based on the constant rate factor deviation value to determine the adjusted target constant rate factor, that is, 23-0.5=22.5, and the obtained 22.5 is the adjusted target constant rate factor. By determining the bit rate saved by encoding based on the target constant rate factor corresponding to each video, the saved bit rate is converted into a constant rate factor deviation value, and the target constant rate factor corresponding to each video is adjusted by the constant rate factor deviation value to obtain the adjusted target constant rate factor corresponding to each video, wherein the adjusted target constant rate factor is less than the target constant rate factor, and encoding by the adjusted target constant rate factor corresponding to each video can improve the quality score (subjective quality) under the premise of encoding each video at the same bit rate as the initial constant rate factor.
[0127] S1003, encoding each video based on the target constant rate factor corresponding to each video to obtain an encoded video corresponding to each video.
[0128] In this embodiment, the encoder encodes each video according to the target constant rate factor corresponding to each video to obtain an encoded video corresponding to each video. By encoding each video according to the target constant rate factor corresponding to each video, the encoding bit rate can be reduced compared to encoding each video according to the initial constant rate factor.
[0129] In an optional implementation, encoding each video based on the target constant rate factor corresponding to each video to obtain the encoded video corresponding to each video can be performed in the following manner: encoding each video according to the adjusted target constant rate factor corresponding to each video to obtain the encoded video corresponding to the adjusted target constant rate factor corresponding to each video. That is, the encoder encodes each video according to the adjusted target constant rate factor corresponding to each video to obtain the encoded video corresponding to the adjusted target constant rate factor corresponding to each video, and encoding each video by the adjusted target constant rate factor corresponding to each video can increase the quality score, that is, improve the subjective quality, compared with encoding each video by the adjusted target constant rate factor corresponding to the initial constant rate factor.
[0130] Based on the above description, the specific method of the embodiment of the present application for determining the target constant rate factor corresponding to each video according to the complexity of each video in multiple videos can also be applied to determining the target constant rate factor corresponding to each image according to the complexity of each image in multiple images, and encoding each image according to the constant rate factor of each image.
[0131] In the embodiment of the present application, the complexity of each video is obtained from multiple videos; the complexity of each video is input into the constant rate factor adjustment model to obtain the target constant rate factor corresponding to each video; based on the target constant rate factor corresponding to each video, each video is encoded to obtain the encoded video corresponding to each video. By increasing the constant rate factor of the video with less complexity, the bit rate required for encoding can be reduced. At the same time, since the slope of the video with less complexity in the rate-distortion curve is smaller, that is, it is relatively gentle, the bit rate can be reduced under the condition of less impact on subjective quality; by reducing the constant rate factor of the video with greater complexity, the quality score can be increased. At the same time, since the slope of the video with greater complexity in the rate-distortion curve is larger, that is, it is steeper, the quality score (subjective quality) can be significantly improved under the condition of increasing the encoding bit rate appropriately. Therefore, this scheme can adjust the constant rate factor corresponding to each video according to the complexity of each video in multiple videos, and can reduce the encoding bit rate without reducing the quality score (subjective quality).
[0132] An embodiment of the present application further provides a computer storage medium, in which program instructions are stored. When the program instructions are executed, they are used to implement the corresponding methods described in the above embodiments.
[0133] An embodiment of the present application provides a computer program product, which includes a computer program stored in a computer storage medium; a processor of a computer device reads the computer program from the computer storage medium, and the processor executes the computer program, so that the computer device executes the corresponding method described in the above embodiment.
[0134] See also Fig.11 , Fig.11 It is a structural diagram of a device for determining coding parameters provided in an embodiment of the present application.
[0135] In one implementation of the device for determining a coding parameter in an embodiment of the present application, the device for determining a coding parameter includes the following structure:
[0136] An acquisition unit 1101 is used to acquire the complexity of a target image;
[0137] The determination unit 1102 is used to input the complexity of the target image into the constant rate factor adjustment model to obtain a target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict a target slope of the target image in a rate-distortion curve according to the complexity of the target image, and obtain a target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to a preset complexity, then the target constant rate factor is greater than an initial constant rate factor;
[0138] The encoding unit 1103 is configured to encode the target image according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor.
[0139] In one implementation, the acquiring unit 1101 is further configured to include:
[0140] Obtaining the complexity of a training image, at least two preset constant rate factors sampled from a constant rate factor interval, and a reference slope;
[0141] Based on each of the at least two preset constant rate factors, encoding the training image, and determining a coding slope of the encoded training image corresponding to each of the preset constant rate factors in a rate-distortion curve;
[0142] Determining a training slope according to the determined at least two encoding slopes and the reference slope;
[0143] The slope determination model is trained based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model; the constant rate factor adjustment model is used to predict the slope of the image to be encoded in the rate-distortion curve according to the complexity of the image to be encoded, and obtain the constant rate factor to be encoded corresponding to the image to be encoded according to the slope to be encoded, and the image to be encoded includes any image.
[0144] In one implementation, the determining unit 1102 determines the training slope according to the determined at least two encoding slopes and the reference slope, including:
[0145] determining a training slope from the at least two encoding slopes;
[0146] The absolute value of the difference between the training slope and the reference slope is smaller than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0147] In one implementation, the determining unit 1102 determines the training slope according to the determined at least two encoding slopes and the reference slope, including:
[0148] Determining a training curvature of the rate-distortion curve corresponding to the training image according to a quality score and a coding bit rate of the encoded training image in the rate-distortion curve corresponding to the at least two preset constant rate factors;
[0149] The training slope is determined according to the at least two encoding slopes, the training curvature and the reference slope.
[0150] In one implementation, the determining unit 1102 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0151] If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes;
[0152] Among them, the training slope is smaller than the reference slope, and the difference between the reference slope and the training slope is smaller than the absolute value of the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two coding slopes that is smaller than the reference slope.
[0153] In one implementation, the determining unit 1102 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0154] If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes;
[0155] The training slope is greater than or equal to the reference slope, and a difference between the training slope and the reference slope is less than a difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0156] In one implementation, the determining unit 1102 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0157] If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes;
[0158] Among them, the training slope is greater than the reference slope, and the difference between the training slope and the reference slope is less than the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two encoding slopes that is greater than the reference slope.
[0159] In one implementation, the determining unit 1102 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, including:
[0160] If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes;
[0161] The training slope is less than or equal to the reference slope, and the difference between the reference slope and the training slope is less than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0162] In one implementation, the determining unit 1102 trains the slope determination model based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model, including:
[0163] Inputting the complexity of the training image into the slope determination model to obtain a predicted slope corresponding to the training image;
[0164] The slope determination model is trained with the goal of reducing the difference between the predicted slope and the training slope to obtain a trained slope determination model, and the constant rate factor adjustment model is constructed based on the trained slope determination model.
[0165] In one implementation, the acquiring unit 1101 is further configured to include:
[0166] Acquire a first encoding bit rate required for encoding the target image using the target constant rate factor, and a second encoding bit rate required for encoding the target image using the initial constant rate factor;
[0167] Determining a coding rate difference between the first coding rate and the second coding rate;
[0168] Determining a constant rate factor deviation value according to the encoding bit rate difference;
[0169] adjusting the target constant rate factor based on the constant rate factor deviation value to determine an adjusted target constant rate factor;
[0170] The encoding unit 1103 encodes the target image according to the target constant rate factor to obtain the encoded target image corresponding to the target constant rate factor, including:
[0171] The target image is encoded according to the adjusted target constant rate factor to obtain an encoded target image corresponding to the adjusted target constant rate factor.
[0172] In the embodiment of the present application, the acquisition unit 1101 acquires the complexity of the target image; the determination unit 1102 inputs the complexity of the target image into the constant rate factor adjustment model to obtain the target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict the target slope of the target image in the rate-distortion curve according to the complexity of the target image, and obtain the target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to the preset complexity, the target constant rate factor is greater than the initial constant rate factor; the encoding unit 1103 encodes the target image according to the target constant rate factor to obtain the encoded target image corresponding to the target constant rate factor. Since the slope of the rate-distortion curve of the image with lower complexity after encoding is smaller, reducing the encoding bit rate for the image with lower complexity has less impact on the quality of the encoded image, so the present application increases the constant rate factor of the target image with a complexity less than the preset complexity, that is, the image with lower complexity, so as to reduce the image encoding bit rate.
[0173] See also Fig.12 , Fig.12 1 is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device in the embodiment of the present application includes a power supply module and other structures, and includes a processor 1201, a memory 1202, and a communication interface 1203. The processor 1201, the memory 1202, and the communication interface 1203 can exchange data, and the processor 1201 implements the corresponding coding parameter determination method.
[0174] The memory 1202 may include a volatile memory, such as a random-access memory (RAM); the memory 1202 may also include a non-volatile memory, such as a flash memory, a solid-state drive (SSD), etc.; the memory 1202 may also include a combination of the above-mentioned types of memory.
[0175] The processor 1201 may be a central processing unit (CPU). The processor 1201 may also be a combination of a CPU and a GPU. In a computer device, multiple CPUs and GPUs may be included as needed to determine corresponding encoding parameters. In one embodiment, the memory 1202 is used to store program instructions. The processor 1201 may call program instructions to implement various methods involved in the embodiments of the present application.
[0176] In a first possible implementation, the processor 1201 of the computer device calls the program instructions stored in the memory 1202 to obtain the complexity of the target image; inputs the complexity of the target image into the constant rate factor adjustment model to obtain the target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict the target slope of the target image in the rate-distortion curve according to the complexity of the target image, and obtain the target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to the preset complexity, the target constant rate factor is greater than the initial constant rate factor; the target image is encoded according to the target constant rate factor to obtain the encoded target image corresponding to the target constant rate factor.
[0177] In one implementation, the processor 1201 may further perform the following operations:
[0178] Obtaining the complexity of a training image, at least two preset constant rate factors sampled from a constant rate factor interval, and a reference slope;
[0179] Based on each of the at least two preset constant rate factors, encoding the training image, and determining a coding slope of the encoded training image corresponding to each of the preset constant rate factors in a rate-distortion curve;
[0180] Determining a training slope according to the determined at least two encoding slopes and the reference slope;
[0181] The slope determination model is trained based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model; the constant rate factor adjustment model is used to predict the slope of the image to be encoded in the rate-distortion curve according to the complexity of the image to be encoded, and obtain the constant rate factor to be encoded corresponding to the image to be encoded according to the slope to be encoded, and the image to be encoded includes any image.
[0182] In one implementation, the processor 1201 determines the training slope according to the determined at least two encoding slopes and the reference slope, and may perform the following operations:
[0183] determining a training slope from the at least two encoding slopes;
[0184] The absolute value of the difference between the training slope and the reference slope is smaller than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0185] In one implementation, the processor 1201 determines the training slope according to the determined at least two encoding slopes and the reference slope, and may perform the following operations:
[0186] Determining a training curvature of the rate-distortion curve corresponding to the training image according to a quality score and a coding bit rate of the encoded training image in the rate-distortion curve corresponding to the at least two preset constant rate factors;
[0187] The training slope is determined according to the at least two encoding slopes, the training curvature and the reference slope.
[0188] In one implementation, the processor 1201 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, and may perform the following operations:
[0189] If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes;
[0190] Among them, the training slope is smaller than the reference slope, and the difference between the reference slope and the training slope is smaller than the absolute value of the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two coding slopes that is smaller than the reference slope.
[0191] In one implementation, the processor 1201 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, and may perform the following operations:
[0192] If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes;
[0193] The training slope is greater than or equal to the reference slope, and a difference between the training slope and the reference slope is less than a difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0194] In one implementation, the processor 1201 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, and may perform the following operations:
[0195] If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes;
[0196] Among them, the training slope is greater than the reference slope, and the difference between the training slope and the reference slope is less than the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two encoding slopes that is greater than the reference slope.
[0197] In one implementation, the processor 1201 determines the training slope according to the at least two encoding slopes, the training curvature, and the reference slope, and may perform the following operations:
[0198] If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes;
[0199] The training slope is less than or equal to the reference slope, and the difference between the reference slope and the training slope is less than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
[0200] In one implementation, the processor 1201 trains the slope determination model based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model, and may perform the following operations:
[0201] Inputting the complexity of the training image into the slope determination model to obtain a predicted slope corresponding to the training image;
[0202] The slope determination model is trained with the goal of reducing the difference between the predicted slope and the training slope to obtain a trained slope determination model, and the constant rate factor adjustment model is constructed based on the trained slope determination model.
[0203] In one implementation, the processor 1201 may further perform the following operations:
[0204] Acquire a first encoding bit rate required for encoding the target image using the target constant rate factor, and a second encoding bit rate required for encoding the target image using the initial constant rate factor;
[0205] Determining a coding rate difference between the first coding rate and the second coding rate;
[0206] Determining a constant rate factor deviation value according to the encoding bit rate difference;
[0207] adjusting the target constant rate factor based on the constant rate factor deviation value to determine an adjusted target constant rate factor;
[0208] The processor 1201 encodes the target image according to the target constant rate factor to obtain the encoded target image corresponding to the target constant rate factor, and may perform the following operations:
[0209] The target image is encoded according to the adjusted target constant rate factor to obtain an encoded target image corresponding to the adjusted target constant rate factor.
[0210] In an embodiment of the present application, the processor 1201 obtains the complexity of the target image; inputs the complexity of the target image into the constant rate factor adjustment model to obtain the target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict the target slope of the target image in the rate-distortion curve according to the complexity of the target image, and obtain the target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to the preset complexity, the target constant rate factor is greater than the initial constant rate factor; the target image is encoded according to the target constant rate factor to obtain the encoded target image corresponding to the target constant rate factor. Since the slope of the rate-distortion curve of the image with lower complexity after encoding is smaller, reducing the encoding bit rate for the image with lower complexity has less impact on the quality of the encoded image, so the present application increases the constant rate factor of the target image with a complexity less than the preset complexity, that is, the image with lower complexity, so as to reduce the image encoding bit rate.
[0211] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.
[0212] The above disclosure is only part of the embodiments of the present application, which certainly cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiments and equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A method for determining a coding parameter, characterized in that: include: Get the complexity of the target image; Inputting the complexity of the target image into a constant rate factor adjustment model to obtain a target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is used to predict a target slope of the target image in a rate-distortion curve according to the complexity of the target image, and obtain a target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to a preset complexity, the target constant rate factor is greater than an initial constant rate factor; The target image is encoded according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor.
2. The method according to claim 1, characterized in that The method further comprises: Obtaining the complexity of a training image, at least two preset constant rate factors sampled from a constant rate factor interval, and a reference slope; Based on each of the at least two preset constant rate factors, encoding the training image, and determining a coding slope of the encoded training image corresponding to each of the preset constant rate factors in a rate-distortion curve; Determining a training slope according to the determined at least two encoding slopes and the reference slope; The slope determination model is trained based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model; the constant rate factor adjustment model is used to predict the slope of the image to be encoded in the rate-distortion curve according to the complexity of the image to be encoded, and obtain the constant rate factor to be encoded corresponding to the image to be encoded according to the slope to be encoded, and the image to be encoded includes any image.
3. The method according to claim 2, characterized in that The step of determining a training slope according to the determined at least two encoding slopes and the reference slope comprises: determining a training slope from the at least two encoding slopes; The absolute value of the difference between the training slope and the reference slope is smaller than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
4. The method according to claim 2, characterized in that The step of determining a training slope according to the determined at least two encoding slopes and the reference slope comprises: Determining a training curvature of the rate-distortion curve corresponding to the training image according to a quality score and a coding bit rate of the encoded training image in the rate-distortion curve corresponding to the at least two preset constant rate factors; The training slope is determined according to the at least two encoding slopes, the training curvature and the reference slope.
5. The method according to claim 4, characterized in that The determining the training slope according to the at least two encoding slopes, the training curvature and the reference slope comprises: If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes; Among them, the training slope is smaller than the reference slope, and the difference between the reference slope and the training slope is smaller than the absolute value of the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two coding slopes that is smaller than the reference slope.
6. The method according to claim 4, characterized in that The determining the training slope according to the at least two encoding slopes, the training curvature and the reference slope comprises: If the training curvature is greater than a preset curvature, determining a training slope from the at least two encoding slopes; The training slope is greater than or equal to the reference slope, and a difference between the training slope and the reference slope is less than a difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
7. The method according to claim 4, characterized in that The determining the training slope according to the at least two encoding slopes, the training curvature and the reference slope comprises: If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes; Among them, the training slope is greater than the reference slope, and the difference between the training slope and the reference slope is less than the difference between other slopes in the slope interval except the training slope and the reference slope; the slope interval includes: the slope of the at least two encoding slopes that is greater than the reference slope.
8. The method according to claim 4, characterized in that The determining the training slope according to the at least two encoding slopes, the training curvature and the reference slope comprises: If the training curvature is less than or equal to a preset curvature, determining a training slope from the at least two encoding slopes; The training slope is less than or equal to the reference slope, and the difference between the reference slope and the training slope is less than the absolute value of the difference between the reference slope and other slopes of the at least two encoding slopes except the training slope.
9. The method according to claim 2, characterized in that The step of training the slope determination model based on the complexity of the training image and the training slope to obtain the constant rate factor adjustment model comprises: Inputting the complexity of the training image into the slope determination model to obtain a predicted slope corresponding to the training image; The slope determination model is trained with the goal of reducing the difference between the predicted slope and the training slope to obtain a trained slope determination model, and the constant rate factor adjustment model is constructed based on the trained slope determination model.
10. The method according to claim 1, characterized in that The method further comprises: Acquire a first encoding bit rate required for encoding the target image using the target constant rate factor, and a second encoding bit rate required for encoding the target image using the initial constant rate factor; Determining a coding rate difference between the first coding rate and the second coding rate; Determining a constant rate factor deviation value according to the encoding bit rate difference; adjusting the target constant rate factor based on the constant rate factor deviation value to determine an adjusted target constant rate factor; The step of encoding the target image according to the target constant rate factor to obtain the encoded target image corresponding to the target constant rate factor includes: The target image is encoded according to the adjusted target constant rate factor to obtain an encoded target image corresponding to the adjusted target constant rate factor.
11. A device for determining a coding parameter, characterized in that: include: An acquisition unit, used for acquiring the complexity of a target image; A determination unit, configured to input the complexity of the target image into a constant rate factor adjustment model to obtain a target constant rate factor corresponding to the target image; wherein the constant rate factor adjustment model is configured to predict a target slope of the target image in a rate-distortion curve according to the complexity of the target image, and obtain a target constant rate factor corresponding to the target image according to the target slope; if the complexity of the target image is less than or equal to a preset complexity, the target constant rate factor is greater than an initial constant rate factor; The encoding unit is used to encode the target image according to the target constant rate factor to obtain an encoded target image corresponding to the target constant rate factor.
12. A computer device, characterized in that: The computer device includes a memory, a communication interface and a processor, wherein the memory, the communication interface and the processor are interconnected; the memory stores a computer program, and the processor calls the computer program stored in the memory to implement the method for determining the coding parameters described in any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for determining the encoding parameters according to any one of claims 1 to 10 is implemented.
14. A computer program product, characterized in that The computer program product includes a computer program, which is stored in a computer storage medium; a processor of a computer device reads the computer program from the computer storage medium, and the processor executes the computer program, so that the computer device executes the method for determining the encoding parameters as described in any one of claims 1 to 10.
Citation Information
Cited By
Low-delay video security exchange method suitable for video monitoring center
CN121056640A
