Video encoding method, device, and electronic device

By dividing the video into multiple frame sequences and encoding based on the target encoding parameters, the problem of low encoding efficiency in the prior art is solved, and a lower code rate and higher encoding efficiency are achieved.

CN113938682BActive Publication Date: 2025-06-03BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010616088.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-29
Publication Date
2025-06-03
Estimated Expiration
2040-06-29

AI Technical Summary

Technical Problem

In the existing video encoding technology, the global encoding method based on CRF results in low encoding efficiency and failing to fully utilize the perceived differences in video content.

Method used

The video to be encoded is divided into multiple frame sequences, and the target encoding parameters are determined based on the preset multiple initial encoding parameters and parameter determination principles for each frame sequence. The principle of parameter determination includes ensuring that the total quality parameters of the video to be encoded meet the preset quality parameter threshold and the total code rate is the lowest. The video to be encoded is encoded by the target encoding parameters of each frame sequence.

Benefits of technology

On the premise of ensuring video quality, the lower code rate is achieved through frame sequence analysis and the determination of target encoding parameters, and the encoding efficiency of video encoding is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113938682B_ABST
    Figure CN113938682B_ABST
Patent Text Reader

Abstract

The present invention provides a video encoding method, apparatus and electronic device, which divides the video to be encoded into multiple frame sequences; for each frame sequence, based on a plurality of preset initial encoding parameters and parameter determination principles, determines the target encoding parameter of the current frame sequence; wherein, the parameter determination principle includes: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; encodes the video to be encoded through the target encoding parameters of each frame sequence. In this way, taking the frame sequence as the analysis unit, for each frame sequence, on the condition that the total quality parameter of the video to be encoded meets the preset quality parameter threshold and the total bit rate of the video to be encoded is the lowest, determines the target encoding parameter of the current frame sequence, which can obtain a lower bit rate on the premise of ensuring the video quality and improves the encoding efficiency of video encoding.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of video coding, and in particular, to a video coding method, apparatus, and electronic device. Background Art

[0002] Video coding is to encode video signals through specific compression technologies to achieve video format conversion, thereby reducing the data volume and signal bandwidth of the video, which is beneficial to the storage and transmission of the video. Video coding can reduce the bit rate of the video, thereby affecting the quality of the video. Generally, the lower the bit rate of the video, the worse the quality of the video.

[0003] During the video coding process, the bit rate of the video can be controlled by CRF (Constant Rate Factor). CRF is a bit rate control method. Generally, according to the service to which the video belongs, the video quality to be achieved in video coding can be determined. Based on this video quality, the CRF value for video coding is determined, and then the video is globally encoded based on this CRF value. This method results in low coding efficiency of video coding. Summary of the Invention

[0004] In view of this, an object of the present invention is to provide a video coding method, apparatus, and electronic device to improve the coding efficiency of video coding.

[0005] In a first aspect, an embodiment of the present invention provides a video coding method, including: dividing a video to be encoded into multiple frame sequences; where each frame sequence includes at least one video frame in the video to be encoded; for each frame sequence, determining a target coding parameter of the current frame sequence based on a plurality of preset initial coding parameters and a parameter determination principle; where the parameter determination principle includes: the total quality parameter of the video to be encoded satisfies a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; encoding the video to be encoded through the target coding parameter of each frame sequence.

[0006] Further, the step of determining the target coding parameter of the current frame sequence based on a plurality of preset initial coding parameters and a parameter determination principle includes: determining a first correspondence between the coding parameter and the bit rate, and a second correspondence between the coding parameter and the quality parameter of the current frame sequence based on the plurality of initial coding parameters; determining the target coding parameter of the current frame sequence according to the first correspondence, the second correspondence, and the parameter determination principle.

[0007] Further, the step of determining the first correspondence between the encoding parameters and the bitrate, and the second correspondence between the encoding parameters and the quality parameters based on multiple initial encoding parameters includes: encoding the current frame sequence based on the multiple initial encoding parameters to obtain an encoding result corresponding to each initial encoding parameter; determining the bitrate and the first quality parameter of the encoding result corresponding to each initial encoding parameter; fitting the first correspondence between the encoding parameters and the bitrate of the current frame sequence through the multiple initial encoding parameters and the bitrate of the encoding result corresponding to each initial encoding parameter; and fitting the second correspondence between the encoding parameters and the quality parameters of the current frame sequence through the multiple initial encoding parameters and the first quality parameter of the encoding result corresponding to each initial encoding parameter.

[0008] Further, the first correspondence between the encoding parameters and the bitrate includes: the encoding parameters and the bitrate have a logarithmic function relationship; the second correspondence between the encoding parameters and the quality parameters includes: the encoding parameters and the quality parameters have an exponential function relationship.

[0009] Further, the step of determining the target encoding parameters of the current frame sequence according to the first correspondence, the second correspondence, and the parameter determination principle includes: setting the lowest total bitrate of the video to be encoded as the objective function; determining that the total quality parameter of the video to be encoded satisfies the quality parameter threshold as the constraint relationship; screening the target encoding parameters from the preset encoding parameter range through the objective function and the constraint relationship; wherein, the bitrate corresponding to the target encoding parameters is obtained through the first correspondence; the quality parameter corresponding to the target encoding parameters is obtained through the second correspondence; the total bitrate of the video to be encoded is obtained by weighting the bitrates corresponding to the target encoding parameters of each frame sequence; and the total quality parameter of the video to be encoded is obtained by weighting the quality parameters corresponding to the target encoding parameters of each frame sequence.

[0010] Further, the quality parameter threshold includes the minimum quality parameter; the minimum quality parameter is determined in the following manner: encoding the video to be encoded through the preset standard encoding parameters to obtain the encoding result of the video to be encoded; calculating the second quality parameter of the encoding result of the video to be encoded, and determining the second quality parameter as the minimum quality parameter.

[0011] Further, the step of encoding the video to be encoded through the target encoding parameters of each frame sequence includes: for each frame sequence, encoding the current frame sequence based on the target encoding parameters of the current frame sequence to obtain the encoding result of the current frame sequence; and arranging the encoding results of each frame sequence in the order of arrangement of each frame sequence in the video to be encoded to obtain the encoding result of the video to be encoded.

[0012] In a second aspect, an embodiment of the present invention provides a video encoding device, which includes: a partitioning module configured to partition a video to be encoded into a plurality of frame sequences; wherein each frame sequence includes at least one video frame in the video to be encoded; a determination module configured to determine, for each frame sequence, a target encoding parameter of the current frame sequence based on a plurality of preset initial encoding parameters and a parameter determination principle; wherein the parameter determination principle includes: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; an encoding module configured to encode the video to be encoded by using the target encoding parameter of each frame sequence.

[0013] In a third aspect, an embodiment of the present invention provides an electronic device, which includes a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the video encoding method according to any one of the first aspect.

[0014] In a fourth aspect, an embodiment of the present invention provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the video encoding method according to any one of the first aspect.

[0015] The embodiments of the present invention bring the following beneficial effects:

[0016] The embodiments of the present invention provide a video encoding method, device, and electronic device, which partition a video to be encoded into a plurality of frame sequences; for each frame sequence, determine a target encoding parameter of the current frame sequence based on a plurality of preset initial encoding parameters and a parameter determination principle; wherein the parameter determination principle includes: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; and encode the video to be encoded by using the target encoding parameter of each frame sequence. In this way, taking the frame sequence as an analysis unit, for each frame sequence, under the condition that the total quality parameter of the video to be encoded meets the preset quality parameter threshold and the total bit rate of the video to be encoded is the lowest, the target encoding parameter of the current frame sequence is determined, which can obtain a lower bit rate while ensuring the video quality and improve the encoding efficiency of video encoding.

[0017] Other features and advantages of the present invention will be described in the following specification, and, in part, will be obvious from the specification, or will be understood by implementing the present invention. The objectives and other advantages of the present invention are achieved and obtained by the structures specifically pointed out in the specification, claims, and drawings.

[0018] To make the above objectives, features, and advantages of the present invention more obvious and understandable, the following preferred embodiments are specifically described below in conjunction with the accompanying drawings. Description of the Drawings

[0019] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those skilled in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0020] Figure 1 It is a flowchart of a video encoding method provided by an embodiment of the present invention;

[0021] Figure 2 It is a flowchart of another video encoding method provided by an embodiment of the present invention;

[0022] Figure 3 It is a schematic structural diagram of a video encoding device provided by an embodiment of the present invention;

[0023] Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. Specific Embodiments

[0024] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions of the present invention with reference to the accompanying drawings. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative efforts fall within the protection scope of the present invention.

[0025] Currently, when encoding a video using the CRF mode, it often only supports a fixed CRF value, that is, the entire video is globally encoded using the same CRF value. However, the same video can often be divided into many segments. Some segments have low dynamics, that is, the plot is gentle and the picture changes relatively little; some segments have high dynamics, that is, the plot is intense, the picture changes quickly, and the content is rich. For the human eye, it is often more sensitive to the quality changes of relatively static pictures or simple pictures. On the contrary, it is less sensitive to the quality changes of moving pictures or complex pictures. Of course, the so-called less sensitive here is relative to static pictures.

[0026] Corresponding to video encoding technology, when increasing the CRF parameter for the entire video, usually only the quality changes of static pictures or simple pictures can be perceived, while it is relatively difficult to perceive the quality changes of dynamic pictures or complex pictures. Therefore, globally encoding a video based on a fixed CRF value usually ignores the perception characteristics of the human visual system and does not make full use of the perceptual differences between contents, resulting in low encoding efficiency of video encoding.

[0027] Based on this, an embodiment of the present invention provides a video encoding method, apparatus, and electronic device. This technology can be applied to devices with video playback or video recording capabilities, such as mobile phones, tablets, laptops, cameras, etc. For ease of understanding of this embodiment, a video encoding method disclosed in the embodiment of the present invention will be introduced in detail first.

[0028] First, an embodiment of the present invention provides a video encoding method, as Figure 1 shown, the method includes the following steps:

[0029] Step S102, divide the video to be encoded into multiple frame sequences; where each frame sequence includes at least one video frame in the video to be encoded;

[0030] Video encoding, also known as video compression encoding or video compression, is a way to convert a file in the original video format into another video format file. Simply put, it is to remove redundant information in the video data. In addition, a video encoder encodes a video signal according to a specific process to compress the signal bandwidth so that it is suitable for video storage, transmission, and distribution. Currently, commonly used video encoders include H.264, H.265, etc.

[0031] The above video to be encoded can include various video formats, such as local video images suitable for local playback or network streaming media video images suitable for playback on the network; dividing the video to be encoded into multiple frame sequences can be done according to a fixed length. For example, the video to be encoded can be divided according to length K, and the length of each frame sequence is K, that is, each frame sequence includes K video frames; it can also be divided without a fixed length. For example, the video to be encoded can be divided using the video slicing method; each of the above frame sequences can include one video frame in the video to be encoded or a continuous video frame of a preset length; the preset length can be set according to the actual video to be encoded; in addition, each frame sequence can be represented by GOP (Group Of Pictures), and a GOP can represent a group of continuous pictures; the number of the above frame sequences can be determined according to the length of each frame sequence.

[0032] Step S104, for each frame sequence, based on a plurality of preset initial encoding parameters and parameter determination principles, determine the target encoding parameters of the current frame sequence; where the parameter determination principles include: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest;

[0033] The number of the above-mentioned preset multiple initial coding parameters can be three, four, five, etc., and the number of the preset multiple initial coding parameters is usually not less than three; the values of the preset multiple initial coding parameters can be set according to the original coding parameters, and on the basis of the original coding parameters, multiple initial coding parameters are obtained; they can also be set according to the types and characteristics of the actual video to be coded, such as the type of business, etc.; the above-mentioned target coding parameters can be determined by the parameter determination principle, and the coding parameters that meet the parameter determination principle are determined as the target coding parameters, and the target coding parameters can be the preset multiple initial coding parameters or coding parameters other than the preset multiple initial coding parameters.

[0034] The total quality parameter of the above-mentioned video to be coded can be determined according to the quality parameters of each frame sequence; among them, the quality parameter of each frame sequence can be determined according to the target coding parameters. The above-mentioned preset quality parameter threshold can be determined according to the types and characteristics of the video to be coded, such as the type of business, etc., or can be determined according to the original coding parameters. For example, the video to be coded can be coded according to the original coding parameters to obtain the original coding result of the video to be coded, and the above-mentioned preset quality parameter threshold is determined according to the original coding result; the total bit rate of the above-mentioned video to be coded can be determined according to the bit rate of each frame sequence, and among them, the bit rate of each frame sequence can be determined according to the target coding parameters.

[0035] Specifically, for each frame sequence, according to the preset multiple initial coding parameters, a coding operation can be performed on the current frame sequence to obtain the coding result of the current frame sequence, and a model of the current frame sequence is established through the functional relationship between the initial coding parameters and the coding result, and the model can reflect the relationship between the coding parameters and the coding result; through the models of each frame sequence, the total quality parameter of the video to be coded and the total bit rate of the video to be coded can be calculated; then, multiple coding parameters can be randomly selected, and the total quality parameter of the video to be coded and the total bit rate of the video to be coded corresponding to each coding parameter are calculated, and the coding parameter corresponding to the total quality parameter of the video to be coded meeting the preset quality parameter threshold and the lowest total bit rate of the video to be coded is determined as the target coding parameter of the current frame sequence.

[0036] In addition, the above quality parameters can be used to analyze the quality of a video. Usually, video quality assessment methods are utilized, such as PSNR (Peak Signal to Noise Ratio), SSIM (Structural SIMilarity), VMAF (Visual Multimethod Assessment Fusion), etc., to evaluate the quality of the encoded video or frame sequence, and a certain functional relationship can be established with the encoding parameters. The bitrate of the above video is the number of data bits transmitted per unit time during data transmission, and the general unit is kbps, that is, thousands of bits per second. It can also be understood as the sampling rate. The larger the sampling rate per unit time, the higher the precision, and the better the quality of the encoded video. However, the size of the compressed file is proportional to the bitrate, so it is not the case that the larger the bitrate, the better the effect. Therefore, it is necessary to minimize the bitrate while ensuring the quality. Using this condition, the above parameter determination principle can be determined, that is, the total quality parameter of the video to be encoded meets the preset quality parameter threshold, and the total bitrate of the video to be encoded is the lowest.

[0037] The above initial encoding parameters can be set in the way of CRF (Constant Rate Factor, a bitrate control method). This method provides the maximum compression efficiency, enabling each video frame to obtain the number of bits it needs according to the required video quality. The quantization ratio range of crf is 0 - 51, where 0 is the lossless mode, 23 is the default value, and 51 is usually the worst. Generally, the higher the crf value of CRF, the lower the bitrate and the worse the quality; the lower the crf value, the higher the bitrate and the better the quality. Among them, multiple initial encoding parameters can be set according to the original encoding parameters. For example, the original encoding parameter can be crf 0 and multiple initial encoding parameters can be determined by means such as addition and subtraction based on this original encoding parameter.

[0038] Step S106: Encode the video to be encoded using the target encoding parameter of each frame sequence.

[0039] The target encoding parameters of each above frame sequence can be different or the same. Usually, for frame sequences with low dynamics, that is, gentle plots and relatively small changes in the picture, and frame sequences with high dynamics, that is, tense plots, relatively fast changes in the picture, and rich content, their corresponding target encoding parameters are different. Encode each corresponding frame sequence in the video to be encoded using the target encoding parameter of each frame sequence to obtain the encoding result of each frame sequence. The encoding results of each frame sequence are spliced and other methods to obtain the encoding result of the video to be encoded.

[0040] An embodiment of the present invention provides a video encoding method, which divides the video to be encoded into multiple frame sequences; for each frame sequence, based on a plurality of preset initial encoding parameters and a parameter determination principle, determines the target encoding parameters of the current frame sequence; wherein, the parameter determination principle includes: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; encodes the video to be encoded through the target encoding parameters of each frame sequence. In this way, taking the frame sequence as the analysis unit, for each frame sequence, on the condition that the total quality parameter of the video to be encoded meets the preset quality parameter threshold and the total bit rate of the video to be encoded is the lowest, determines the target encoding parameters of the current frame sequence, which can obtain a lower bit rate on the premise of ensuring the video quality and improve the encoding efficiency of video encoding.

[0041] An embodiment of the present invention provides another video encoding method, which is implemented on the basis of the above embodiment; this embodiment focuses on describing the implementation process of the step of determining the target encoding parameters of the current frame sequence based on a plurality of preset initial encoding parameters and a parameter determination principle (implemented through steps S204 - S206), and the implementation process of the step of encoding the video to be encoded through the target encoding parameters of each frame sequence (implemented through steps S208 - S210); as Figure 2 shown, the method includes the following steps:

[0042] Step S202, divides the video to be encoded into multiple frame sequences; wherein, each frame sequence includes at least one video frame in the video to be encoded;

[0043] Step S204, for each frame sequence, based on a plurality of initial encoding parameters, determines a first correspondence between the encoding parameters and the bit rate of the current frame sequence, and a second correspondence between the encoding parameters and the quality parameters;

[0044] The above correspondences can be correspondences in the form of a table, or correspondences in the form of a curve, or a specific formula model; wherein, each initial encoding parameter corresponds to a bit rate and a quality parameter. For example, for each frame sequence, according to a plurality of initial encoding parameters, through the video encoding method, the bit rate and quality parameters of the current frame sequence can be obtained; statistically analyze each initial encoding parameter and the corresponding bit rate to obtain the first correspondence; statistically analyze each initial encoding parameter and the corresponding quality parameter to obtain the second correspondence.

[0045] A preferred implementation manner includes the following steps:

[0046] Step A1, encodes the current frame sequence based on a plurality of initial encoding parameters to obtain the encoding results corresponding to each initial encoding parameter;

[0047] In this embodiment, there are five initial coding parameters, namely crf 0 -4, crf 0 -2, crf 0 , crf 0 +2, crf 0 +4 as an example for illustration. For the current frame sequence, using the five initial coding parameters, encode the current frame sequence GOP 1 to obtain the encoding results GOP 1 0, GOP 1 1, GOP 1 2, GOP 1 3, GOP 1 4 corresponding to each initial coding parameter respectively.

[0048] Step A2, determine the bitrate and the first quality parameter of the encoding result corresponding to each initial coding parameter;

[0049] The above-mentioned first quality parameter refers to the quality parameter of the encoding result corresponding to the initial coding parameter; specifically, the bitrate calculation formula can be used: bitrate (kbps) = file size (KB) * 8 / time (seconds) to calculate the bitrate of the encoding result corresponding to the initial coding parameter. For example, after encoding the current frame sequence based on the initial coding parameter crf 0 if the file size of the current frame sequence is 9000 KB and the time length of the current frame sequence is 1 minute (60 seconds), the calculated bitrate is 9000 * 8 / 60 = 1200 kbps; the video quality assessment method VMAF can also be used to evaluate the encoding result corresponding to the initial coding parameter to determine the first quality parameter of the encoding result corresponding to the initial coding parameter.

[0050] Step A3, through multiple initial coding parameters and the bitrate of the encoding result corresponding to each initial coding parameter, fit to obtain the first correspondence between the coding parameter and the bitrate of the current frame sequence;

[0051] Step A4, through multiple initial coding parameters and the first quality parameter of the encoding result corresponding to each initial coding parameter, fit to obtain the second correspondence between the coding parameter and the quality parameter of the current frame sequence.

[0052] For each frame sequence, five encoding results can be obtained, and the bitrate and the first quality parameter of each encoding result are determined; therefore, for each frame sequence, a set of sampling points can be obtained, each set includes five sampling points, and each sampling point contains three indicators: coding parameter, bitrate, and first quality parameter.

[0053] Specifically, by fitting, establish the relationship between the coding parameter and the bitrate, and the relationship between the coding parameter and the first quality parameter in each sampling point of the current frame sequence;

[0054] Among them, the first correspondence between the encoding parameter and the bitrate includes: the encoding parameter and the bitrate have a logarithmic function relationship; the second correspondence between the encoding parameter and the quality parameter includes: the encoding parameter and the quality parameter have an exponential function relationship. The specific model is as follows:

[0055] Bitrate i = a i log(crf + b i ) + c i

[0056] Vmaf i = x i exp(y i crf) + z i

[0057] Among them, Bitrate i represents the bitrate of the i-th frame sequence; crf represents the encoding parameter; Vmaf i represents the quality parameter of the i-th frame sequence; a i represents the first parameter of the i-th frame sequence in the first correspondence; b i represents the second parameter of the i-th frame sequence in the first correspondence; c i represents the third parameter of the i-th frame sequence in the first correspondence; log represents the logarithmic function; x i represents the fourth parameter of the i-th frame sequence in the second correspondence; y i represents the fifth parameter of the i-th frame sequence in the second correspondence; z i represents the sixth parameter of the i-th frame sequence in the second correspondence; exp represents the exponential function.

[0058] The least squares method can be used to calculate, based on the known encoding parameter crf of each group of sampling points in the i-th frame sequence 0 -4, crf 0 -2, crf 0 , crf 0 +2, crf 0+4, and the bitrate and the first quality parameter corresponding to the encoding parameter, calculate the parameters a, b, c, x, y, and z in the i-th frame sequence model; after obtaining the parameter values of the parameters a, b, c, x, y, and z, the corresponding relationship between the encoding parameter and the bitrate of the i-th frame sequence, and the corresponding relationship between the encoding parameter and the quality parameter can be determined. For example, the video to be encoded can be divided into 10 frame sequences. Through the parameter indicators of each group of sampling points, the crf-bitrate (encoding parameter and bitrate) fitting curve and the crf-vmaf (encoding parameter and quality parameter) fitting curve of each frame sequence can be obtained, and the fitting curves of each frame sequence are different.

[0059] The significance of this model is that given a crf value, the bitrate Bitrate and the quality parameter Vmaf after encoding the frame sequence using this crf value can be estimated using the model of the i-th frame sequence, without the need to perform encoding operations on the actual frame sequence using this encoding parameter crf value.

[0060] It should be noted that the above first and second corresponding relationships are only applicable to the encoding of the current video to be encoded. If the video to be encoded is changed, the model needs to be re-established; the above crf-bitrate (encoding parameter and bitrate) fitting curve and the crf-vmaf (encoding parameter and quality parameter) fitting curve can be expressed as an R-D (Rate and Distortion) curve, where Rate represents Bitrate, that is, the bitrate of the video. Distortion represents distortion, that is, the quality of the video. Generally speaking, R and D are in an inverse relationship, that is, when the bitrate increases, the distortion decreases and the video quality is higher; when the bitrate decreases, the distortion increases and the video quality is lower.

[0061] Step S206, determine the target encoding parameter of the current frame sequence according to the first corresponding relationship, the second corresponding relationship, and the parameter determination principle;

[0062] Specifically, different encoding parameters can be selected for each frame sequence. Through the first corresponding relationship and the second corresponding relationship of each frame sequence, the bitrate and the quality parameter of each frame sequence can be obtained; all the obtained bitrates and quality parameters can be calculated to obtain the total bitrate and the total quality parameter of the video to be encoded by means of weighted average or other statistical methods; through the parameter determination principle, that is, under the condition that the total quality parameter of the video to be encoded meets the preset quality parameter threshold and the total bitrate of the video to be encoded is the lowest, the target encoding parameter of the current frame sequence that meets the above parameter determination principle is obtained through the target optimization method.

[0063] It is also possible to establish models for the total quality parameter and the total bitrate of the video to be encoded through the first correspondence and the second correspondence; different encoding parameters are selected for each frame sequence, and through the way of objective optimization, the target encoding parameters of the current frame sequence that meet the above parameter determination principle are obtained.

[0064] A preferred implementation includes the following steps:

[0065] Step B1, set the lowest total bitrate of the video to be encoded as the objective function; determine that the total quality parameter of the video to be encoded meets the quality parameter threshold as the constraint relationship;

[0066] Through the above steps A1 - A4, the first correspondence and the second correspondence of all frame sequences of the video to be encoded can be obtained, that is, the above models.

[0067] In addition, the bitrate corresponding to the target encoding parameter is obtained through the first correspondence; the quality parameter corresponding to the target encoding parameter is obtained through the second correspondence; the total bitrate of the video to be encoded is obtained by weighting the bitrates corresponding to the target encoding parameters of each frame sequence; the total quality parameter of the video to be encoded is obtained by weighting the quality parameters corresponding to the target encoding parameters of each frame sequence.

[0068] Therefore, the total bitrate of the above video to be encoded can be expressed by the following formula:

[0069]

[0070] Among them, Bitrate represents the total bitrate of the video to be encoded; crf i represents the encoding parameter of the i-th frame sequence; Bitrate i represents the bitrate of the i-th frame sequence; N represents the number of frame sequences; L i represents the length of the i-th frame sequence; represents the sum of the lengths of all frame sequences; w i represents the weight of the i-th frame sequence in the video to be encoded; a i represents the first parameter of the i-th frame sequence in the first correspondence; b i represents the second parameter of the i-th frame sequence in the first correspondence; c i represents the third parameter of the i-th frame sequence in the first correspondence; log represents the logarithmic function; if the video to be encoded is divided into frame sequences with a fixed length, the above formula can be simplified to:

[0071]

[0072] Similarly, the total quality parameter of the above video to be encoded can be expressed by the following formula:

[0073]

[0074] Among them, Vmaf represents the total quality parameter of the video to be encoded; crf i represents the encoding parameter of the i-th frame sequence; Vmaf i represents the quality parameter of the i-th frame sequence; N represents the number of frame sequences; L i represents the length of the i-th frame sequence; represents the sum of the lengths of all frame sequences; w i represents the weight of the i-th frame sequence in the video to be encoded; x i represents the fourth parameter of the i-th frame sequence in the second correspondence; y i represents the fifth parameter of the i-th frame sequence in the second correspondence; z i represents the sixth parameter of the i-th frame sequence in the second correspondence; exp represents the exponential function; if the video to be encoded is divided into frame sequences with a fixed length, the above formula can be simplified as:

[0075]

[0076] After obtaining the calculation formulas for the total bitrate of the video to be encoded and the total quality parameter of the video to be encoded, set the lowest total bitrate of the video to be encoded as the objective function; determine that the total quality parameter of the video to be encoded meets the quality parameter threshold as the constraint relationship. It can be understood that, on the premise of ensuring the total quality of the video to be encoded, seeking a certain combination of crf parameters to minimize the total bitrate of the video to be encoded can be expressed as an optimization problem of extreme value solution under specific conditions. This problem can be expressed as:

[0077] min Bitrate

[0078] s.t. Vmaf >= Vmaf 0

[0079] Among them, min Bitrate represents the objective function; Bitrate represents the total bitrate of the video to be encoded; Vmaf >= Vmaf 0 represents the constraint relationship; Vmaf represents the total quality parameter of the video to be encoded; Vmaf 0 represents the quality parameter threshold.

[0080] Step B2, through the objective function and the constraint relationship, screen out the target encoding parameters from the preset encoding parameter range;

[0081] The above preset encoding parameter range can be set according to the type, service characteristics, etc. of the actual video to be encoded; for example, it can be set to [crf 0 -2, crf 0 +2], crf0 is a preset standard coding parameter; then the above objective function and constraint conditions can be expressed as:

[0082]

[0083] s.t. Vmaf >= Vmaf 0

[0084] where, represents the objective function; crf represents the coding parameter; Bitrate represents the total bitrate of the video to be encoded; Vmaf >= Vmaf 0 represents the constraint relationship; Vmaf represents the total quality parameter of the video to be encoded; Vmaf 0 represents the quality parameter threshold; C represents the parameter range of the allowable coding parameter crf, which can be specifically limited to each frame sequence within the interval [crf 0 - 2, crf 0 + 2] to find the optimal target coding parameter; the final target coding parameter combination can be obtained by the gradient descent method; the target coding parameter combination includes the target coding parameter corresponding to each frame sequence.

[0085] The above quality parameter threshold includes the minimum quality parameter; the minimum quality parameter is determined in the following way: by using the preset standard coding parameter, encoding the video to be encoded to obtain the encoding result of the video to be encoded; calculating the second quality parameter of the encoding result of the video to be encoded, and determining the second quality parameter as the minimum quality parameter.

[0086] The above preset standard coding parameter can be set according to empirical values or classical values. Usually, the preset standard coding parameter is related to the service to which the video belongs; for example, in x265 (an open-source free software and library for encoding videos that conform to the High Efficiency Video Coding standard), the default initial coding parameter is usually 28; in x264, the general initial coding parameter value is 18 - 28, and the default value is 23.

[0087] Specifically, by using the preset standard coding parameter crf 0 , encoding the video to be encoded to obtain the encoding result of the video to be encoded; during the encoding process of the entire video, the value of the standard coding parameter crf 0 remains unchanged; calculating the second quality parameter of the encoding result of the video to be encoded, and determining the second quality parameter as the minimum quality parameter, that is, the above quality parameter threshold Vmaf 0 .

[0088] Step S208, for each frame sequence, based on the target coding parameter of the current frame sequence, encoding the current frame sequence to obtain the encoding result of the current frame sequence;

[0089] Step S210: Arrange the encoding results of each frame sequence in the order of arrangement of each frame sequence in the video to be encoded, so as to obtain the encoding result of the video to be encoded.

[0090] Through the target encoding parameter corresponding to each frame sequence included in the final target encoding parameter combination, according to the playback order of the video to be encoded, for each frame sequence, based on the target encoding parameter corresponding to the current frame sequence, encode the current frame sequence to obtain the encoding result of the current frame sequence, that is, the encoded frame sequence file; arrange the encoding results of each frame sequence in the order of arrangement of each frame sequence in the video to be encoded, for example, according to the playback order of the video to be encoded, connect the encoding results of each frame sequence together to obtain the final complete encoding result of the video to be encoded.

[0091] In this method, taking the frame sequence as the analysis unit, according to the complexity characteristics of each frame sequence, based on a plurality of preset initial encoding parameters, determine the bit rate and the first quality parameter corresponding to each initial encoding parameter, and use the initial encoding parameter, bit rate and quality parameter in each frame sequence, through the fitting method, establish the corresponding relationship between the encoding parameter of each frame sequence and the bit rate and quality parameter; use this corresponding relationship to construct the optimization objective function and constraint conditions; through the objective function and the constraint relationship, screen out the target encoding parameters from the preset encoding parameter range; thus solve the optimal target encoding parameter combination; compared with the method of encoding the video with fixed encoding parameters, this method can make full use of the complexity characteristics of local frame sequences in the video for bit rate allocation, so as to obtain a lower bit rate on the premise of maintaining the picture quality, and improve the efficiency of video encoding.

[0092] In addition, compared with the method of encoding the video with fixed encoding parameters, the present invention collects a large-scale test data set, indicating that the present invention can save an average of 1.5% of the bit rate, while the vast majority of encoding tools can only save less than 0.5% of the bit rate, improving the efficiency of video encoding.

[0093] Corresponding to the above method embodiments, the embodiments of the present invention provide a video encoding device, as Figure 3 shown, the device includes:

[0094] A partitioning module 31, configured to partition the video to be encoded into a plurality of frame sequences; wherein each frame sequence includes at least one video frame in the video to be encoded;

[0095] A determining module 32, configured to determine the target encoding parameter of the current frame sequence for each frame sequence based on a plurality of preset initial encoding parameters and parameter determination principles; wherein the parameter determination principles include: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest;

[0096] The encoding module 33 encodes the video to be encoded by using the target encoding parameters of each frame sequence.

[0097] An embodiment of the present invention provides a video encoding device, which divides the video to be encoded into multiple frame sequences; for each frame sequence, based on a plurality of preset initial encoding parameters and a parameter determination principle, determines the target encoding parameters of the current frame sequence; wherein, the parameter determination principle includes: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; the video to be encoded is encoded by using the target encoding parameters of each frame sequence. In this way, taking the frame sequence as the analysis unit, for each frame sequence, under the condition that the total quality parameter of the video to be encoded meets the preset quality parameter threshold and the total bit rate of the video to be encoded is the lowest, the target encoding parameters of the current frame sequence are determined, so that a lower bit rate can be obtained on the premise of ensuring the video quality, and the encoding efficiency of video encoding is improved.

[0098] Further, the above-mentioned determination module is further configured to: based on a plurality of initial encoding parameters, determine a first correspondence between the encoding parameters and the bit rate of the current frame sequence, and a second correspondence between the encoding parameters and the quality parameter; according to the first correspondence, the second correspondence and the parameter determination principle, determine the target encoding parameters of the current frame sequence.

[0099] Further, the above-mentioned determination module is further configured to: based on a plurality of initial encoding parameters, encode the current frame sequence to obtain an encoding result corresponding to each initial encoding parameter; determine the bit rate and the first quality parameter of the encoding result corresponding to each initial encoding parameter; through a plurality of initial encoding parameters and the bit rate of the encoding result corresponding to each initial encoding parameter, fit to obtain a first correspondence between the encoding parameters and the bit rate of the current frame sequence; through a plurality of initial encoding parameters and the first quality parameter of the encoding result corresponding to each initial encoding parameter, fit to obtain a second correspondence between the encoding parameters and the quality parameter of the current frame sequence.

[0100] Further, the above-mentioned determination module is further configured to: the relationship between the encoding parameters and the bit rate is a logarithmic function relationship; the second correspondence between the encoding parameters and the quality parameter includes: the relationship between the encoding parameters and the quality parameter is an exponential function relationship.

[0101] Further, the above determination module is further configured to: set the lowest total bitrate of the video to be encoded as the objective function; determine that the total quality parameter of the video to be encoded meets the quality parameter threshold as the constraint relationship; screen out the target encoding parameters from the preset encoding parameter range through the objective function and the constraint relationship; wherein, the bitrate corresponding to the target encoding parameters is obtained through the first correspondence relationship; the quality parameter corresponding to the target encoding parameters is obtained through the second correspondence relationship; the total bitrate of the video to be encoded is obtained by weighting the bitrates corresponding to the target encoding parameters of each frame sequence; the total quality parameter of the video to be encoded is obtained by weighting the quality parameters corresponding to the target encoding parameters of each frame sequence.

[0102] Further, the above quality parameter threshold includes the minimum quality parameter; the device further includes a minimum quality parameter determination module, configured to encode the video to be encoded through the preset standard encoding parameters to obtain the encoding result of the video to be encoded; calculate the second quality parameter of the encoding result of the video to be encoded, and determine the second quality parameter as the minimum quality parameter.

[0103] Further, the above encoding module is further configured to: for each frame sequence, encode the current frame sequence based on the target encoding parameters of the current frame sequence to obtain the encoding result of the current frame sequence; arrange the encoding results of each frame sequence in the arrangement order of each frame sequence in the video to be encoded to obtain the encoding result of the video to be encoded.

[0104] The video encoding device provided by the embodiment of the present invention has the same technical features as the video encoding method provided by the above embodiment, so it can also solve the same technical problems and achieve the same technical effects.

[0105] The embodiment of the present invention further provides an electronic device. Refer to Figure 4 As shown, the electronic device includes a processor 90 and a memory 91. The memory 91 stores machine-executable instructions that can be executed by the processor 90. The processor 90 executes the machine-executable instructions to implement the above video encoding method.

[0106] Further, Figure 4 As shown, the electronic device further includes a bus 92 and a communication interface 93. The processor 90, the communication interface 93, and the memory 91 are connected through the bus 92.

[0107] Among them, the memory 91 may include high-speed random access memory (RAM), and may also include non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 93 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 92 can be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, Figure 4 only a bidirectional arrow is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0108] The processor 90 may be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the above method can be completed by the integrated logic circuit in the hardware of the processor 90 or the instructions in the form of software. The above-mentioned processor 90 can be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it can also be a digital signal processor (DSP for short), an application specific integrated circuit (ASIC for short), a field programmable gate array (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present invention can be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the art such as random access memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, register, etc. This storage medium is located in the memory 91, and the processor 90 reads the information in the memory 91 and combines its hardware to complete the steps of the method in the foregoing embodiments.

[0109] The embodiments of the present invention also provide a machine-readable storage medium. The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the above video encoding method. For the specific implementation, reference can be made to the method embodiments, which will not be elaborated here.

[0110] A computer program product of a video encoding method, apparatus, and electronic device provided by an embodiment of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the foregoing method embodiments. For specific implementation, reference can be made to the method embodiments, which will not be elaborated herein.

[0111] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems and apparatuses described above can refer to the corresponding processes in the foregoing method embodiments, which will not be elaborated herein.

[0112] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "coupled" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the communication inside two elements. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific situations.

[0113] If the above functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program code.

[0114] In the description of the present invention, it should be noted that the orientation or positional relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. is based on the orientation or positional relationship shown in the drawings. It is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus cannot be understood as a limitation to the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.

[0115] Finally, it should be noted that the above embodiments are only specific implementation manners of the present invention, used to illustrate the technical solutions of the present invention, rather than limiting it. The protection scope of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art within the technical scope disclosed by the present invention can still modify the technical solutions recorded in the foregoing embodiments, or can easily think of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A video encoding method, characterized in that, the method includes: dividing the video to be encoded into multiple frame sequences; wherein, each of the frame sequences includes at least one video frame in the video to be encoded; for each of the frame sequences, based on a plurality of preset initial encoding parameters and a parameter determination principle, determining the target encoding parameters of the current frame sequence; wherein, the parameter determination principle includes: the total quality parameter of the video to be encoded meets a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; encoding the video to be encoded with the target encoding parameters of each of the frame sequences; wherein, the step of determining the target encoding parameters of the current frame sequence based on a plurality of preset initial encoding parameters and a parameter determination principle includes: based on the plurality of initial encoding parameters, determining a first correspondence between the encoding parameters and the bit rate of the current frame sequence, and a second correspondence between the encoding parameters and the quality parameter; determining the target encoding parameters of the current frame sequence according to the first correspondence, the second correspondence and the parameter determination principle; the first correspondence between the encoding parameters and the bit rate includes: the encoding parameters and the bit rate are in a logarithmic function relationship; the second correspondence between the encoding parameters and the quality parameter includes: the encoding parameters and the quality parameter are in an exponential function relationship; the step of determining the target encoding parameters of the current frame sequence according to the first correspondence, the second correspondence and the parameter determination principle includes: setting the lowest total bit rate of the video to be encoded as the objective function; determining that the total quality parameter of the video to be encoded meets the quality parameter threshold as the constraint relationship; screening out the target encoding parameters from a preset encoding parameter range through the objective function and the constraint relationship; wherein, the bit rate corresponding to the target encoding parameters is obtained through the first correspondence; the quality parameter corresponding to the target encoding parameters is obtained through the second correspondence; the total bit rate of the video to be encoded is weighted by the bit rates corresponding to the target encoding parameters of each of the frame sequences; the total quality parameter of the video to be encoded is weighted by the quality parameters corresponding to the target encoding parameters of each of the frame sequences.

2. The method according to claim 1, characterized in that, the step of determining a first correspondence between the encoding parameters and the bit rate of the current frame sequence, and a second correspondence between the encoding parameters and the quality parameter based on the plurality of initial encoding parameters includes: encoding the current frame sequence based on the plurality of initial encoding parameters to obtain an encoding result corresponding to each of the initial encoding parameters; determining the bit rate and the first quality parameter of the encoding result corresponding to each of the initial encoding parameters; fitting a first correspondence between the encoding parameters and the bit rate of the current frame sequence through the plurality of initial encoding parameters and the bit rates of the encoding results corresponding to each of the initial encoding parameters; fitting a second correspondence between the encoding parameters and the quality parameter of the current frame sequence through the plurality of initial encoding parameters and the first quality parameters of the encoding results corresponding to each of the initial encoding parameters.

3. The method according to claim 1, wherein, the quality parameter threshold includes a minimum quality parameter; the minimum quality parameter is determined by the following method: encoding the video to be encoded through a preset standard encoding parameter to obtain an encoding result of the video to be encoded; calculating a second quality parameter of the encoding result of the video to be encoded, and determining the second quality parameter as the minimum quality parameter.

4. The method according to claim 1, wherein, the step of encoding the video to be encoded through the target encoding parameter of each frame sequence includes: for each frame sequence, encoding the current frame sequence based on the target encoding parameter of the current frame sequence to obtain an encoding result of the current frame sequence; arranging the encoding results of each frame sequence in the arrangement order of each frame sequence in the video to be encoded to obtain an encoding result of the video to be encoded.

5. A video encoding device, wherein, the device includes: a dividing module, configured to divide a video to be encoded into multiple frame sequences; wherein, each frame sequence includes at least one video frame in the video to be encoded; a determining module, configured to determine a target encoding parameter of the current frame sequence for each frame sequence based on a plurality of preset initial encoding parameters and a parameter determination principle; wherein, the parameter determination principle includes: the total quality parameter of the video to be encoded satisfies a preset quality parameter threshold, and the total bit rate of the video to be encoded is the lowest; an encoding module, encoding the video to be encoded through the target encoding parameter of each frame sequence; wherein, the step of determining the target encoding parameter of the current frame sequence based on a plurality of preset initial encoding parameters and a parameter determination principle includes: determining a first correspondence between the encoding parameter and the bit rate, and a second correspondence between the encoding parameter and the quality parameter of the current frame sequence based on the plurality of initial encoding parameters; determining the target encoding parameter of the current frame sequence according to the first correspondence, the second correspondence and the parameter determination principle; the first correspondence between the encoding parameter and the bit rate includes: the encoding parameter and the bit rate are in a logarithmic function relationship; the second correspondence between the encoding parameter and the quality parameter includes: the encoding parameter and the quality parameter are in an exponential function relationship; the step of determining the target encoding parameter of the current frame sequence according to the first correspondence, the second correspondence and the parameter determination principle includes: setting the lowest total bit rate of the video to be encoded as the objective function; determining that the total quality parameter of the video to be encoded satisfies the quality parameter threshold as the constraint relationship; screening out the target encoding parameter from a preset encoding parameter range through the objective function and the constraint relationship; Among them, the code rate corresponding to the target encoding parameter is obtained through the first corresponding relationship; the quality parameter corresponding to the target encoding parameter is obtained through the second corresponding relationship; the total code rate of the video to be encoded is obtained by weighting the code rates corresponding to the target encoding parameters of each frame sequence; the total quality parameter of the video to be encoded is obtained by weighting the quality parameters corresponding to the target encoding parameters of each frame sequence.

6. An electronic device characterized in that it includes a processor and a memory, the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the video encoding method according to any one of claims 1 to 4.

7. A machine-readable storage medium characterized in that the machine-readable storage medium stores machine-executable instructions, and when the machine-executable instructions are called and executed by a processor, the machine-executable instructions cause the processor to implement the video encoding method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Techniques for optimizing bitrates and resolutions during encoding

    CN107439016A