Video encoding method and device, electronic device and computer medium

By adjusting the quantization parameters and encoding mode based on the pixel difference information of macroblocks in video encoding, the problem of insufficient encoding quality and efficiency of key frames and non-key frames in the existing technology is solved, and higher encoding quality and efficiency are achieved.

CN116320446BActive Publication Date: 2026-05-19JD DIGITS HAIYI INFORMATION TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
JD DIGITS HAIYI INFORMATION TECHNOLOGY CO LTD
Filing Date
2023-03-22
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

In existing video coding technologies, there is still room for improvement in the coding quality and efficiency of key frames and non-key frames. In particular, the decision-making complexity of the coding mode for non-key frames is high, which affects coding efficiency.

Method used

By acquiring the pixel difference information of each macroblock in the video frame to be encoded, the macroblock is divided into the first macroblock and the second macroblock. The quantization parameters of the keyframe are adjusted according to the number of macroblocks, and the non-keyframes are encoded using the standard encoding mode.

Benefits of technology

It improves the encoding quality and efficiency of video encoding by retaining the detailed features of key frames, reducing the encoding complexity of non-key frames, and adjusting the bitrate through the adjustment of quantization parameters.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116320446B_ABST
    Figure CN116320446B_ABST
Patent Text Reader

Abstract

This disclosure provides a video encoding method, apparatus, electronic device, and computer medium; relating to the field of image processing technology. The video encoding method includes: acquiring a video frame to be encoded and determining the pixel difference information contained in each macroblock of the video frame; determining a macroblock as a first macroblock or a second macroblock based on the pixel difference information, wherein the pixel difference of the second macroblock is greater than that of the first macroblock; determining an encoding strategy based on the number of first macroblocks and the number of second macroblocks; the encoding strategy includes: when the video frame to be encoded is a keyframe, updating the quantization parameters during its encoding process based on the number of second macroblocks in the video frame; when the video frame to be encoded is a non-keyframe, encoding the first macroblock in the video frame to be encoded using a standard encoding mode. This disclosure can improve the encoding quality and efficiency of video encoding to a certain extent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of image processing technology, and more specifically, to a video encoding method, a video encoding apparatus, an electronic device, and a computer-readable storage medium. Background Technology

[0002] With the continuous development of digital media technology and network communication services, video coding technology has been applied to many fields, such as video conferencing, security monitoring, and classroom recording.

[0003] During video encoding, the encoder encodes the video to obtain multiple Group of Pictures (GOPs). A GOP is usually composed of key frames and non-key frames. Key frames are internally coded frames (also called I-frames), and non-key frames include forward predictive frames (also called P-frames) and bidirectional predictive coded frames (also called B-frames).

[0004] In some existing video coding technologies, for keyframes, the quantization parameters during encoding are determined solely by the video resolution, input frame rate, and bit rate; however, for non-keyframes, the encoder needs to make coding mode decisions for all macroblocks during encoding. There is still room for improvement in both the encoding quality and efficiency of video coding.

[0005] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention

[0006] The purpose of this disclosure is to provide a video encoding method, a video encoding apparatus, an electronic device, and a computer-readable storage medium, thereby improving the encoding quality and efficiency of video encoding to at least a certain extent.

[0007] According to a first aspect of this disclosure, a video coding method is provided, comprising:

[0008] Acquire the video frame to be encoded and determine the pixel difference information contained in each macroblock of the video frame to be encoded;

[0009] The macroblock is determined as a first macroblock or a second macroblock based on the pixel difference information, wherein the pixel difference of the second macroblock is greater than the pixel difference of the first macroblock;

[0010] The encoding strategy is determined based on the number of the first macroblock and the number of the second macroblock;

[0011] The encoding strategy includes: when the video frame to be encoded is a key frame, updating the quantization parameters during the encoding process according to the number of the second macroblocks in the video frame to be encoded; when the video frame to be encoded is a non-key frame, encoding the first macroblocks in the video frame to be encoded using a standard encoding mode.

[0012] According to a second aspect of this disclosure, a video encoding apparatus is provided, comprising:

[0013] The pixel difference module is used to determine the pixel difference information contained in each macroblock in the video frame to be encoded;

[0014] A macroblock determination module is used to determine the macroblock as a first macroblock or a second macroblock based on the pixel difference information, wherein the pixel difference of the second macroblock is greater than the pixel difference of the first macroblock;

[0015] The encoding strategy module is used to determine the encoding strategy based on the number of the first macroblock and the number of the second macroblock;

[0016] The encoding strategy includes: when the video frame to be encoded is a key frame, updating the quantization parameters during the encoding process according to the number of the second macroblocks in the video frame to be encoded; when the video frame to be encoded is a non-key frame, encoding the first macroblocks in the video frame to be encoded using a standard encoding mode.

[0017] According to a third aspect of this disclosure, an electronic device is provided, comprising: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform the method described in any of the preceding methods by executing the executable instructions.

[0018] According to a fourth aspect of this disclosure, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method described in any of the preceding claims.

[0019] Exemplary embodiments of this disclosure may have some or all of the following beneficial effects:

[0020] In the video encoding method provided by the exemplary embodiments of this disclosure, a macroblock can be determined as a first macroblock or a second macroblock by using the pixel difference information contained in each macroblock in the video frame to be encoded. When the video frame to be encoded is a keyframe, the quantization parameters in its encoding process are updated according to the number of second macroblocks in the video frame to be encoded; when the video frame to be encoded is a non-keyframe, the first macroblock in the video frame to be encoded is encoded using a standard encoding mode. On the one hand, updating the quantization parameters in the keyframe encoding process according to the pixel difference information contained in each macroblock in the video frame takes into account the detailed features of the video frame. By updating the quantization parameters, the detailed features of the video frame that are sensitive to the human eye are further preserved, which can improve the encoding quality of video encoding to a certain extent. On the other hand, directly encoding the first macroblock in the video frame corresponding to a non-keyframe using a standard encoding mode can not only achieve rapid decision-making on the encoding mode, but also reduce the encoding complexity, thereby improving the encoding efficiency of video encoding to a certain extent. Furthermore, updating the quantization parameters in the keyframe encoding process can play a role in adjusting the bitrate to a certain extent.

[0021] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0022] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure. It is obvious that the drawings described below are merely some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0023] Figure 1 A schematic diagram of an exemplary system architecture for a video encoding method and apparatus to which embodiments of the present disclosure can be applied is shown;

[0024] Figure 2 A flowchart illustrating a video encoding method according to an embodiment of the present disclosure is shown schematically;

[0025] Figure 3 The flowchart illustrates a method for obtaining pixel difference information contained in each macroblock according to an embodiment of the present disclosure.

[0026] Figure 4 This illustration schematically shows a diagram of video frame division according to an embodiment of the present disclosure;

[0027] Figure 5 The flowchart illustrates an alternative method for obtaining pixel difference information contained in each macroblock according to an embodiment of the present disclosure.

[0028] Figure 6 This schematically illustrates a flowchart of determining whether a macroblock is a first macroblock or a second macroblock according to one embodiment of the present disclosure;

[0029] Figure 7 This schematically illustrates a flowchart of updating quantization parameters during keyframe encoding according to an embodiment of the present disclosure;

[0030] Figure 8 The illustration shows an example diagram of a video encoding process according to an embodiment of the present disclosure;

[0031] Figure 9 A block diagram of a video encoding apparatus according to an embodiment of the present disclosure is shown schematically;

[0032] Figure 10 The schematic diagram illustrates a structural schematic of a computer system suitable for implementing an electronic device according to embodiments of the present disclosure. Detailed Implementation

[0033] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided to make this disclosure more comprehensive and complete, and to fully convey the concept of the example embodiments to those skilled in the art. The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a full understanding of embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced with one or more specific details omitted, or other methods, components, apparatus, steps, etc., can be employed. In other instances, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of this disclosure.

[0034] Furthermore, the accompanying drawings are merely illustrative of this disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0035] Figure 1 A system architecture diagram illustrating an exemplary application environment in which the video editing methods and apparatus of the present disclosure embodiments can be applied.

[0036] like Figure 1As shown, system architecture 100 may include one or more of terminal devices 101, 102, and 103, and network 104. Network 104 is used as a medium to provide communication links between terminal devices 101, 102, and 103. Network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc. Terminal devices 101, 102, and 103 may be various electronic devices with displays, including but not limited to desktop computers, portable computers, smartphones, and tablets, etc. It should be understood that... Figure 1 The number of terminal devices and networks shown is merely illustrative. Depending on implementation needs, any number of terminal devices and networks can be included.

[0037] For example, in one exemplary embodiment, terminal device 101 and terminal device 102 may perform one-way video data transmission. One-way video transmission may occur in scenarios such as live video streaming, IPTV, and network monitoring. Specifically, terminal device 101 may encode video data, and terminal device 102 may receive encoded video data from network 103, decode the encoded video data to obtain video data, and display video images based on the video data.

[0038] In another exemplary embodiment, terminal device 102 and terminal device 103 may perform bidirectional video data transmission, which can occur in scenarios such as web conferencing, video calls, and online classes. Specifically, terminal device 102 and terminal device 103 may encode video data, and then transmit the encoded video data to another terminal device within terminal device 102 and terminal device 103 via network 103. Terminal device 102 and terminal device 103 may then decode the encoded video data to obtain video data and display video images based on the video data.

[0039] The technical solutions of the exemplary embodiments of this disclosure are described in detail below:

[0040] This exemplary embodiment provides a video encoding method that can be applied to any terminal device in the system architecture described above. (Reference) Figure 2 As shown, the video encoding method may include the following steps:

[0041] Step S210: Obtain the video frame to be encoded and determine the pixel difference information contained in each macroblock of the video frame to be encoded;

[0042] Step S220: Based on the pixel difference information, the macroblock is determined to be either a first macroblock or a second macroblock, wherein the pixel difference of the second macroblock is greater than the pixel difference of the first macroblock.

[0043] Step S230: Determine the encoding strategy based on the number of the first macroblock and the number of the second macroblock;

[0044] The encoding strategy includes: when the video frame to be encoded corresponds to a keyframe, the quantization parameters during the encoding process are updated according to the number of second macroblocks in the video frame to be encoded; when the video frame to be encoded corresponds to a non-keyframe, the first macroblock in the video frame to be encoded is encoded using the standard encoding mode.

[0045] In the video encoding strategy provided in this exemplary embodiment, on the one hand, the quantization parameters in the keyframe encoding process are updated according to the pixel difference information contained in each macroblock in the video frame, taking into account the detailed features of the video frame. By updating the quantization parameters, the detailed features of the video frame that are sensitive to the human eye are further preserved, which can improve the encoding quality of the video encoding to a certain extent. On the other hand, the first macroblock in the video frame corresponding to the non-keyframe is directly encoded using the standard encoding mode, which can not only realize the rapid decision of the encoding mode, but also reduce the encoding complexity, thereby improving the encoding efficiency of the video encoding to a certain extent. Furthermore, updating the quantization parameters in the keyframe encoding process can play a role in adjusting the bit rate to a certain extent.

[0046] The steps described above will now be explained in more detail in another exemplary embodiment.

[0047] In step S210, the video frame to be encoded is acquired, and the pixel difference information contained in each macroblock of the video frame to be encoded is determined.

[0048] Specifically, a video frame is the smallest unit of image in a video. A single video frame is a still image, while consecutive video frames form animations or videos. Utilizing the persistence of vision, displaying multiple consecutive video frames rapidly creates the illusion of motion. However, transmitting only the raw video frames during video transmission results in a massive amount of data, which is difficult to achieve with current network and storage technologies. Therefore, video encoding can be used to leverage the high similarity between consecutive video frames. This involves using compression techniques to convert the original video file into another video format. Video encoding removes spatial and temporal redundancy from video frames, significantly reducing the amount of data during video transmission and storage.

[0049] A macroblock is the basic unit in the video coding process. A macroblock usually consists of a luma pixel block and two additional chroma pixel blocks. In the video coding process, a video frame is usually first divided into multiple macroblocks, and then encoded in units of macroblocks.

[0050] In this exemplary embodiment, pixel difference information represents the difference in pixel values ​​between different regions within a macroblock. By obtaining the pixel difference information contained in each macroblock of a video frame, the difference in pixel values ​​of the entire video frame can be obtained. Generally speaking, the human eye is more sensitive to video frames with small differences and less sensitive to video frames with large differences. This is because when the difference of a video frame is large, the difference of its adjacent video frames is also large, while the similarity between consecutive video frames is extremely high. When a video frame loses certain details, the human eye usually cannot perceive it.

[0051] In this exemplary embodiment, the video frame to be encoded can be a video frame encoded based on the AVC / H.264 standard, a video frame encoded based on the HEVC / H.265 standard, or a video frame encoded based on the VVC / H.266 standard. In addition, the video frame to be encoded can also be a video frame encoded based on other video coding standards that include a quantization process.

[0052] In one exemplary embodiment, macroblocks in the video frame to be encoded are divided into a preset number of subblocks. The preset number can be 4, 9, or other numbers; this exemplary embodiment does not impose any specific limitation. (See reference) Figure 3 As shown, the pixel difference information contained in each macroblock of the video frame to be encoded can be determined through steps S310 to S320. Wherein:

[0053] In step S310, the average pixel value corresponding to each sub-block in the macroblock is obtained.

[0054] Sub-blocks are components of macroblocks. In video coding technology, a macroblock can be divided into several sub-blocks on an average basis. For example, with a 16×16 macroblock as the smallest coding unit, a macroblock can be divided into 16 4×4 or 4 8×8 sub-blocks.

[0055] The pixel mean value refers to the average pixel value of all pixels in a sub-block. For video frames, in existing video technologies, they are usually represented by a pixel matrix in RGB or YUV color space. RGB-based video frames divide pixel information into three channels: red, green, and blue. YUV-based video frames divide pixel information into one luminance channel and two chrominance channels.

[0056] Specifically, for three-channel RGB or YUV format video frames, when calculating the pixel mean of a sub-block, one can first calculate the pixel mean of each channel within the sub-block separately, and then use the average of the three channel pixel mean values ​​as the pixel mean of that sub-block. Alternatively, the pixel mean of the sub-block can be calculated by assigning certain weights to the pixel values ​​of different channels. For example, for YUV format video frames, the pixel values ​​of the Y, U, and V channels of the video frame can be preprocessed with weights of 1, 0.5, and 0.5 respectively. This is because the spatial resolution of luminance signals is greater than that of chrominance signals for the human eye. Then, the pixel mean of each channel within each sub-block of the preprocessed video frame is calculated, and then... The average of the pixel values ​​of the three channels is used as the pixel average of the sub-block. Alternatively, the three-channel video frame can be converted into a single-channel grayscale image, and then the average of the grayscale values ​​of the grayscale image is used as the pixel average of the sub-block. For example, for an RGB format video frame, the RGB video frame can be converted to grayscale based on GRAY = B × 0.114 + G × 0.587 + R × 0.299, where GRAY represents the grayscale value, and B, G, and R represent the pixel values ​​of different channels of each pixel in the RGB video frame, respectively. Then, the average of all grayscale values ​​in the single-channel sub-block is used as the pixel average of the sub-block. Of course, the pixel average can also be obtained in other ways, and this exemplary embodiment is not limited to this.

[0057] In step S320, the pixel difference information contained in the macroblock is calculated based on the pixel mean.

[0058] Among them, pixel difference information represents the difference in pixel values ​​between different regions within a macroblock, which can be obtained by calculating the proportional relationship between the average pixel values ​​of different sub-blocks.

[0059] In one exemplary embodiment, calculating pixel difference information contained in a macroblock based on pixel mean includes: calculating the ratio of the pixel mean values ​​of any two sub-blocks among a preset number of sub-blocks, and using the ratio of the pixel mean values ​​as pixel difference information. (See reference) Figure 4 As shown, the video frame is divided into multiple 16×16 macroblocks, and each 16×16 macroblock is further divided into four 8×8 subblocks. Then, according to... Figure 4 The order shown can be represented by a0, a1, a2, and a3 to represent the pixel mean of different sub-blocks, respectively. Then, the pixel difference information of the macroblock can be obtained by the following equations (1) to (5):

[0060] r0=a1 / a0 (1)

[0061] r1=a2 / a0 (2)

[0062] r2=a3 / a1 (3)

[0063] r3=a3 / a2 (4)

[0064] r4=a3 / a0 (5)

[0065] Where r0, r1, r2, r3, and r4 represent the pixel difference information contained in the macroblock. Unless otherwise specified below, the subblocks corresponding to the pixel averages a0, a1, a2, and a3 are all defined according to... Figure 4 The correspondence is shown. In other exemplary embodiments of this disclosure, the macroblock can also be divided into other numbers of subblocks, such as nine 8×8 subblocks, but when calculating the pixel difference information contained in the macroblock, according to... Figure 4 The calculation strategy for the corresponding macroblock is used, which involves calculating the rate of change of the average pixel value of sub-blocks within the macroblock from left to right or from top to bottom. Alternatively, other calculation strategies can be used to calculate the pixel difference information contained in the macroblock, and the subsequent first and second macroblocks will be determined according to the rules corresponding to that calculation strategy.

[0066] In one exemplary embodiment, reference is made to Figure 5 As shown, the pixel difference information contained in each macroblock of the video frame to be encoded can be determined through steps S510 to S520. Wherein:

[0067] In step S510, the pixel values ​​within each macroblock of the video frame to be encoded are obtained. The pixel value is a value assigned by the computer when the original video image is digitized; it represents the average brightness information of a small square in the video image.

[0068] In step S520, pixel difference information is determined based on the degree of dispersion of pixel values.

[0069] Specifically, for multi-channel video frames, the target video frame can first be converted into a grayscale image. Then, for each macroblock, the pixel grayscale value dispersion data of the macroblock can be calculated to represent the dispersion of the pixel values ​​of that macroblock. Figure 4 Taking the macroblock shown as an example, the absolute deviation D of the macroblock's pixel grayscale values ​​can be used to characterize the dispersion of its pixel values; for example... Where n represents the number of pixels in the macroblock. x represents the mean grayscale value of all pixels in the macroblock; i This represents the grayscale value of the i-th pixel in the macroblock.

[0070] Furthermore, in other exemplary embodiments of this disclosure, the degree of pixel value dispersion can also be characterized by other statistical data; for example, for Figure 4 Macroblocks in the data can also be analyzed using the mean absolute deviation. It can also be characterized by the dispersion of its pixel values; it can also be represented by the mean square error. Characterizing the dispersion of pixel grayscale values, etc.; these are also within the scope of protection of this disclosure.

[0071] In addition, for multi-channel video frames, the dispersion of pixel values ​​in different channels within a macroblock can be calculated first, and then the average of the dispersion of pixel values ​​in different channels can be used to represent the dispersion of pixel values ​​in the macroblock. After obtaining the dispersion of pixel values ​​in the macroblock, the dispersion of pixel values ​​can be used to represent the pixel difference information of the corresponding macroblock.

[0072] by Figure 4 Taking the macroblock shown as an example, after determining the dispersion of pixel values ​​in each macroblock, each macroblock is determined as a first macroblock or a second macroblock based on a preset dispersion threshold. For example, when the absolute deviation of the macroblock pixel values ​​is less than 9, the macroblock is determined as a first macroblock, and when the absolute deviation of the macroblock pixel values ​​is greater than 64, the macroblock is determined as a second macroblock. Alternatively, when the average absolute deviation of the macroblock pixel values ​​is less than 1, the macroblock is determined as a first macroblock, and when the average absolute deviation of the macroblock pixel values ​​is greater than 4, the macroblock is determined as a second macroblock. Alternatively, when the mean square error of the macroblock pixel values ​​is less than 1, the macroblock is determined as a first macroblock, and when the mean square error of the macroblock pixel values ​​is greater than 2, the macroblock is determined as a second macroblock. In addition, the dispersion threshold can be set according to the number of pixels in the macroblock, and other methods can also be used to determine each macroblock as a first macroblock or a second macroblock based on the preset dispersion threshold. This exemplary embodiment does not impose any special limitations on this.

[0073] In step S220, a macroblock is determined as a first macroblock or a second macroblock based on the pixel difference information, wherein the pixel difference of the second macroblock is greater than that of the first macroblock.

[0074] In this embodiment, the pixel differences of the first macroblock are relatively small, while the pixel differences of the second macroblock are relatively large. In one exemplary embodiment, reference is made to... Figure 6 As shown, a macroblock can be determined as a first macroblock or a second macroblock through the steps shown in S610 to S630. Wherein:

[0075] In step S610, the standard number corresponding to a macroblock is determined based on the number of pixels whose average pixel ratio is greater than a first preset threshold. The first preset threshold is a preset parameter.

[0076] Based on the above Figure 4Taking the pixel difference information corresponding to a macroblock in the data as an example, the number of r0, r1, r2, r3, and r4 that are greater than a first preset threshold is obtained and recorded as the standard number. Alternatively, for example, when r4 is not equal to 1, the standard number can be increased, for example, by increasing the standard number by 1 or other values. This is because, for the same macroblock, generally speaking, adjacent sub-blocks on the left and right or top and bottom have higher correlation, while diagonally adjacent or non-adjacent sub-blocks have lower correlation. When r4 is not equal to 1, it indicates that the pixel values ​​of two diagonally adjacent sub-blocks are different, which can indicate to some extent that the pixel difference of the macroblock is large. Therefore, the standard number corresponding to the macroblock can be increased to indicate its large difference. In other exemplary embodiments of this disclosure, when the macroblock is divided into 9 or other numbers of sub-blocks on average, the standard number corresponding to the macroblock can be increased when the pixel ratio of two non-adjacent sub-blocks is not equal to 1.

[0077] For example, the first preset threshold is 1.25. When r4 is not equal to 1, the standard number increases by 1. If the pixel difference information r0, r1, r2, r3, and r4 of the macroblock are 3.9, 3.1, 2.8, 1, and 1 respectively, then the standard number corresponding to the macroblock is 4.

[0078] In one exemplary embodiment, it is also possible to add equation (6): r5 = a2 / a1, and then adjust the standard quantity based on r4 and r5. It can be that if the number of r4 and r5 that is not equal to 1 is n, then the standard quantity is increased by n; it can also be that if at least one of r4 and r5 is not equal to 1, then the standard quantity is increased by 1; of course, it can also be based on other preset standards to adjust the standard quantity. This exemplary embodiment does not make any special limitations here.

[0079] In step S620, when the number of standard items is less than or equal to the first standard item threshold, the macroblock is determined as the first macroblock.

[0080] Wherein, if the number of standards corresponding to a macroblock is less than or equal to the first standard number threshold, it indicates that the pixel difference of the macroblock is small; for example, the first standard number threshold can be 1, and in other exemplary embodiments of this disclosure, the first standard number threshold can also be 2 or other values, which can be set according to the number of subblocks and the needs of video encoding.

[0081] In step S630, when the number of standard items is greater than the second standard item threshold, the macroblock is determined as the second macroblock.

[0082] Wherein, if the number of standards corresponding to a macroblock is greater than the second standard number threshold, it indicates that the pixel difference of the macroblock is large; for example, the second standard number threshold can be 4, and in other exemplary embodiments of this disclosure, the second standard number threshold can also be 5 or other values, which can be set according to the number of subblocks and the needs of video encoding.

[0083] In step S230, the encoding strategy is determined based on the number of the first macroblock and the number of the second macroblock;

[0084] The encoding strategy includes: when the video frame to be encoded is a key frame, the quantization parameters during the encoding process are updated according to the number of second macroblocks in the video frame to be encoded; when the video frame to be encoded is a non-key frame, the first macroblock in the video frame to be encoded is encoded using the standard encoding mode.

[0085] Keyframes are intra-coded picture frames, also known as I-frames, which use full-frame compression coding. The number of keyframes in a video frame sequence is directly related to the size of the Group of Pictures (GOP).

[0086] Non-key frames include forward-predicted frames (P-frames) and bidirectional predictive coded frames (B-frames). A P-frame represents the difference between the current video frame and the previous I-frame or P-frame; it uses the previous I-frame or P-frame as a reference frame. During encoding, only the difference data between the current frame and the reference frame is recorded. During decoding, the difference data between the current frame and the reference frame is superimposed on the reference frame to obtain the complete P-frame video image. B-frames are typically inserted between P-frames and I-frames. They can reduce the frame rate and improve the video compression rate by predicting the preceding and following frames. Their compression rate is higher than that of P-frames and I-frames because they can reduce redundant data through prediction between the preceding and following frames.

[0087] The quantization parameter (QP) is the index of the quantization step size (Qstep), ranging from 0 to 51. A minimum value of 0 indicates the finest quantization, while a maximum value of 51 indicates the coarsest quantization. A smaller quantization parameter results in better quality video image after encoding and decoding, but at a higher bitrate. Conversely, a larger quantization parameter results in a lower bitrate, greater image distortion, and poorer image quality. The quantization parameter and quantization step size are linearly correlated; the quantization step size increases with the quantization parameter, doubling for every 6 increases in the quantization parameter. Quantization allows for a reduction in image encoding length without compromising visual quality, thus minimizing unnecessary information in visual reconstruction.

[0088] The encoding mode refers to the encoding method used when encoding video frames. During video encoding, video frames are first divided into several macroblocks, and the encoding process is carried out on a macroblock-by-macroblock basis. In the process of an encoder encoding a macroblock, the two most complex modules are the motion search module and the mode decision module. The role of the mode decision module is to select the most efficient encoding mode for the current video macroblock data from among the many candidate encoding modes provided by the video encoder. However, in newer international video coding standards, such as H.264 / AVC, encoders offer a rich variety of encoding modes, significantly increasing the complexity of the mode decision module. Therefore, improving encoding efficiency by enabling the mode decision module to make rapid decisions has become an important aspect of encoding technology optimization.

[0089] In one exemplary embodiment, reference is made to Figure 7 As shown, the quantization parameters in the keyframe encoding process can be updated through steps S710 to S720. Wherein:

[0090] In step S710, when the video frame to be encoded is a keyframe, the number of second macroblocks in the video frame to be encoded and the total number of macroblocks in the video frame to be encoded are obtained.

[0091] The number of macroblocks in a video frame represents the average number of macroblocks into which the video frame is divided. For example, for a 1280×720 video frame, the number of the second macroblock in the current video frame to be encoded can be 3218. If the size of the macroblock is 16×16, then the total number of macroblocks in the video frame is 3600.

[0092] In step S720, the quantization parameters in the encoding process are updated according to the ratio of the number of second macroblocks in the video frame to the total number of macroblocks in the video frame.

[0093] Updating the quantization parameter means decreasing or increasing it. Adjusting the quantization parameter based on the pixel differences of video frames can reduce the quantization parameter for video frames that are sensitive to human vision, so that the details of the video frame are preserved as much as possible, which can improve the quality of video encoding and thus improve the user's video viewing experience to a certain extent. On the other hand, increasing the quantization parameter for video frames that are not sensitive to human vision can reduce the amount of video encoding data to a certain extent, thereby reducing the bitrate without affecting the encoding quality.

[0094] In one exemplary embodiment, updating the quantization parameters during the encoding process based on the ratio of the number of second macroblocks in the video frame to the total number of macroblocks in the video frame can be achieved by increasing the quantization parameters during the encoding process when the ratio is greater than a second preset threshold, and decreasing the quantization parameters during the encoding process when the ratio is less than a third preset threshold.

[0095] The second and third preset thresholds are preset parameters that can be set according to the specific requirements of video encoding. Of course, the second and third preset thresholds can also be equal.

[0096] In one exemplary embodiment, the second preset threshold can be 0.85. When the ratio of the number of second macroblocks in the video frame to be encoded to the total number of macroblocks in the video frame to be encoded is greater than 0.85, the quantization parameter in the encoding process is incremented by 1.

[0097] If the ratio of the number of second macroblocks to the total number of macroblocks in a video frame is greater than 0.85, it indicates that the video frame has significant differences that are not easily perceived by the human eye. In this case, the bitrate can be reduced by increasing the quantization parameter by 1 to cause some details of the video frame to be lost. Alternatively, if the quantization parameter corresponding to the video frame is the maximum value, such as 51, the quantization parameter remains unchanged if the ratio of the number of second macroblocks to the total number of macroblocks in the video frame is greater than 0.85.

[0098] Furthermore, in other exemplary embodiments of this disclosure, the second preset threshold and the increase in quantization parameters can also be other values ​​set according to encoding requirements. For example, when the ratio of the number of second macroblocks in a video frame to the number of all macroblocks in the video frame is greater than 0.98, the quantization parameters in the encoding process are increased by 2; this exemplary embodiment does not impose any special limitations here.

[0099] In one exemplary embodiment, the third preset threshold can be 0.1. When the ratio of the number of second macroblocks in the video frame to be encoded to the total number of macroblocks in the video frame to be encoded is less than 0.1, the quantization parameter in the encoding process is reduced by 1.

[0100] If the ratio of the number of second macroblocks to the total number of macroblocks in a video frame is less than 0.1, it indicates that the differences in the video frame are small and not sensitive to human eyes. In this case, the video frame's detailed features can be preserved as much as possible by reducing the quantization parameter by 1, thereby improving the quality of video encoding. In addition, when the quantization parameter corresponding to the video frame is 0, if the ratio of the number of second macroblocks to the total number of macroblocks in the video frame is less than 1, the quantization parameter remains unchanged.

[0101] Furthermore, in other exemplary embodiments of this disclosure, the third preset threshold and the reduction amount of the quantization parameter can also be other values ​​set according to encoding requirements. For example, when the ratio of the number of second macroblocks in a video frame to the number of all macroblocks in the video frame is less than 0.2, the quantization parameter in the encoding process is reduced by 2; this exemplary embodiment does not impose any special limitations here.

[0102] In one exemplary embodiment, the standard encoding mode can be the Skip encoding mode. When the video frame to be encoded is a non-key frame, the first macroblock in the video frame to be encoded is encoded using the Skip encoding mode.

[0103] The Skip coding mode is a special mode within the Merge coding mode. Its difference lies in that the Skip mode does not transmit residual information and directly treats the reference frame as the current frame. The information transmitted by the coded segment includes the Skip-flag and the candidate list index.

[0104] Specifically, since the pixel differences of the first macroblock are relatively small, the encoder can directly encode the first macroblock using the Skip coding mode without performing a mode decision step. This not only enables rapid decision-making on the coding mode but also reduces coding complexity, thereby improving the coding efficiency of video encoding to some extent. Furthermore, the standard coding mode can also be other coding modes, such as the Merge coding mode, etc., which are not specifically limited in this exemplary embodiment.

[0105] In addition, for macroblocks and video frames that do not meet the specific requirements of the above encoding method, the encoding is completed according to the conventional encoding steps. Furthermore, the above encoding method is not performed on the first frame of the video frame sequence to avoid affecting the encoding quality of subsequent video frames.

[0106] In one exemplary embodiment, the video frame to be encoded may be downsampled before determining the pixel difference information contained in each macroblock in the video frame to be encoded.

[0107] Subsampling involves reducing the size of the video frame to be encoded by a certain proportion. While maintaining the same field of view, it can remove redundant information and reduce the amount of video data to a certain extent, thereby improving the encoding speed. In this exemplary embodiment, subsampling can be used to reduce a video frame of size M×N by a factor of s to obtain a video frame of size (M / s)×(N / s), where s must be a common divisor of M and N. Subsampling can also be used to remove one row from every six rows of the video frame to make it five rows, and remove one column from every nine columns of the video frame to make it eight columns. Of course, other methods can also be used for subsampling, and this exemplary embodiment does not impose any special limitations on them.

[0108] In one exemplary embodiment, reference is made to Figure 8 As shown, video encoding can be performed using the illustrated method. Specifically, for a sequence of video frames to be encoded, the video frames are divided into multiple macroblocks, and each macroblock is further divided into several subblocks. Then, based on the pixel differences between each macroblock, the macroblock is determined to be either the first macroblock or the second macroblock. When a video frame corresponds to a keyframe, the quantization parameters during the encoding process are updated based on the number of second macroblocks in the video frame. When a video frame corresponds to a non-keyframe, the first macroblock in the video frame is encoded using a standard encoding mode. After the encoder encodes the video frames, it obtains encoded video data. The decoder then receives the encoded video data and decodes it to obtain the output video stream.

[0109] It should be noted that although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.

[0110] Furthermore, in one exemplary embodiment, a video encoding apparatus is also provided. (See reference...) Figure 9 As shown, the video encoding device 900 may include a pixel difference module 910, a macroblock determination module 920, and an encoding strategy module 930, wherein:

[0111] The pixel difference module 910 can be used to acquire the video frame to be encoded and determine the pixel difference information contained in each macroblock of the video frame to be encoded.

[0112] The macroblock determination module 920 can be used to determine a macroblock as a first macroblock or a second macroblock based on pixel difference information, wherein the pixel difference of the second macroblock is greater than that of the first macroblock;

[0113] The encoding strategy module 930 can be used to determine the encoding strategy based on the number of the first macroblock and the number of the second macroblock;

[0114] The encoding strategy includes: when the video frame to be encoded is a key frame, updating the quantization parameters during the encoding process according to the number of the second macroblocks in the video frame to be encoded; when the video frame to be encoded is a non-key frame, encoding the first macroblocks in the video frame to be encoded using a standard encoding mode.

[0115] The specific details of each module in the aforementioned video encoding device have been described in detail in the corresponding video encoding methods, so they will not be repeated here.

[0116] In another respect, this disclosure also provides an electronic device, Figure 10 A schematic diagram of the structure of a computer system suitable for implementing the embodiments of the present disclosure is shown.

[0117] It should be noted that, Figure 10 The computer system 1000 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of the embodiments disclosed herein.

[0118] like Figure 10 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 1002 or programs loaded from storage section 1008 into random access memory (RAM) 1003. The RAM 1003 also stores various programs and data required for system operation. The CPU 1001, ROM 1002, and RAM 1003 are interconnected via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.

[0119] The following components are connected to I / O interface 1005: an input section 1006 including a keyboard, mouse, etc.; an output section 1007 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN card, modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to I / O interface 1005 as needed. A removable medium 1011, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 1010 as needed so that computer programs read from it can be installed into storage section 1008 as needed.

[0120] In particular, according to embodiments of this disclosure, the processes described below with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1001, and / or installed from removable medium 1011. When the computer program is executed by central processing unit (CPU) 1001, it performs various functions defined in the methods and apparatus of this disclosure. In some embodiments, the computer system 1000 may further include a data processor for processing computational operations related to video encoding data.

[0121] In another aspect, this disclosure also provides a computer-readable medium, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The computer-readable medium carries one or more programs that, when executed by the electronic device, cause the electronic device to perform the methods as described in the above embodiments.

[0122] It should be noted that the computer-readable medium disclosed herein may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0123] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0124] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

Claims

1. A video encoding method, characterized in that, include: Acquire the video frame to be encoded and determine the pixel difference information contained in each macroblock of the video frame to be encoded; A macroblock is the basic unit in the video coding process. A macroblock consists of a luma pixel block and two additional chroma pixel blocks. The macroblock is determined as either a first macroblock or a second macroblock based on the pixel difference information, wherein the pixel difference of the second macroblock is greater than that of the first macroblock; the macroblock is divided into a preset number of subblocks on an average basis; determining the pixel difference information contained in each macroblock in the video frame to be encoded includes: obtaining the average pixel value corresponding to each subblock in the macroblock; calculating the pixel difference information contained in the macroblock based on the average pixel value; calculating the pixel difference information contained in the macroblock based on the average pixel value includes: calculating the ratio of the average pixel values ​​of any two subblocks in the preset number of subblocks respectively, and using the ratio of the average pixel values ​​as the pixel difference information; The encoding strategy is determined based on the number of the first macroblock and the number of the second macroblock; The encoding strategy includes: when the video frame to be encoded is a key frame, updating the quantization parameters during the encoding process according to the number of the second macroblocks in the video frame to be encoded; when the video frame to be encoded is a non-key frame, encoding the first macroblocks in the video frame to be encoded using a standard encoding mode.

2. The method according to claim 1, characterized in that, The step of determining the pixel difference information contained in each macroblock of the video frame to be encoded includes: Obtain the pixel values ​​within each macroblock of the video frame to be encoded; The pixel difference information is determined based on the degree of dispersion of the pixel values.

3. The method according to claim 1, characterized in that, The step of determining the macroblock as a first macroblock or a second macroblock based on the pixel difference information includes: The standard number corresponding to the macroblock is determined based on the number of pixels whose ratio of average pixel values ​​is greater than a first preset threshold. When the number of standards is less than or equal to the first standard number threshold, the macroblock is determined as the first macroblock; When the number of standard values ​​is greater than the second standard value threshold, the macroblock is identified as the second macroblock.

4. The method according to claim 1, characterized in that, When the video frame to be encoded is a keyframe, the quantization parameters during the encoding process are updated according to the number of the second macroblocks in the video frame to be encoded, including: When the video frame to be encoded is a keyframe, obtain the number of the second macroblocks in the video frame to be encoded and the total number of all macroblocks in the video frame to be encoded; The quantization parameters during the encoding process are updated based on the ratio of the number of the second macroblocks in the video frame to the total number of macroblocks in the video frame.

5. The method according to claim 4, characterized in that, The step of updating the quantization parameters during the encoding process based on the ratio of the number of the second macroblocks in the video frame to the total number of macroblocks in the video frame includes: When the ratio of the number of the second macroblocks in the video frame to be encoded to the total number of all macroblocks in the video frame to be encoded is greater than a second preset threshold, the quantization parameter in the encoding process is increased. When the ratio of the number of the second macroblocks in the video frame to be encoded to the total number of macroblocks in the video frame to be encoded is less than a third preset threshold, the quantization parameter in the encoding process is reduced.

6. A video encoding device, characterized in that, include: The pixel difference module is used to acquire the video frame to be encoded and determine the pixel difference information contained in each macroblock of the video frame to be encoded. A macroblock is the basic unit in the video coding process. A macroblock consists of a luma pixel block and two additional chroma pixel blocks. A macroblock determination module is used to determine the macroblock as a first macroblock or a second macroblock based on the pixel difference information, wherein the pixel difference of the second macroblock is greater than the pixel difference of the first macroblock; the macroblock is divided into a preset number of subblocks on an average basis; the step of determining the pixel difference information contained in each macroblock in the video frame to be encoded is configured to: obtain the average pixel value corresponding to each subblock in the macroblock; calculate the pixel difference information contained in the macroblock based on the average pixel value; the step of calculating the pixel difference information contained in the macroblock based on the average pixel value is configured to: calculate the ratio of the average pixel values ​​of any two subblocks in the preset number of subblocks respectively, and use the ratio of the average pixel values ​​as the pixel difference information; The encoding strategy module is used to determine the encoding strategy based on the number of the first macroblock and the number of the second macroblock; The encoding strategy includes: when the video frame to be encoded is a key frame, updating the quantization parameters during the encoding process according to the number of the second macroblocks in the video frame to be encoded; when the video frame to be encoded is a non-key frame, encoding the first macroblocks in the video frame to be encoded using a standard encoding mode.

7. An electronic device, characterized in that, include: processor; as well as Memory for storing the executable instructions of the processor; The processor is configured to execute the method of any one of claims 1-5 by executing the executable instructions.

8. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-5.