Video encoding method, device and computer equipment
By selecting different numbers of reference frames for encoding according to the encoding quality requirements of the video frames, the problem of balancing encoding quality and efficiency in the existing technology is solved, and high-quality and efficient video encoding is achieved.
Patent Information
- Application Number
- CN202211502892.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-11-23
AI Technical Summary
Existing video coding methods cannot balance coding quality and efficiency, resulting in low versatility.
According to different encoding quality requirements of the image frames, different numbers of reference frames are selected for encoding processing. Frames with high quality requirements select more reference frames, while frames with low quality requirements select fewer reference frames.
Improved encoding quality, reduced encoding time and improved encoding efficiency.
Smart Images

Figure CN115834877B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a video encoding method, apparatus, and computer equipment. Background Art
[0002] Efficient video processing can promote the further development of computer technology and bring more convenience to daily life. Therefore, research on video processing technology has never ceased in the field of computer technology. Taking video coding technology as an example, the efficiency and quality of video coding are closely related to the processing efficiency of video transmission and video conversion. Video coding refers to the method of converting original video format files into another video format through compression technology.
[0003] Typically, video encoding is achieved by encoding individual video frames, and each frame requires reference to one or more reference frames. The greater the number of reference frames, the higher the video encoding quality, but the longer the encoding process. Current video encoding methods fail to balance video encoding quality and efficiency when determining reference frames for the image frames to be encoded, resulting in low versatility. Therefore, balancing video encoding efficiency and quality has become a hot topic that needs to be addressed. Summary of the Invention
[0004] The embodiments of the present application provide a video encoding method, apparatus, and computer device that can improve encoding efficiency while ensuring encoding quality.
[0005] On the one hand, an embodiment of the present application provides a video encoding method, including:
[0006] Acquire a target video, where the target video includes at least a first image frame and a second image frame, and a required encoding quality level of the first image frame is higher than a required encoding quality level of the second image frame;
[0007] determining a first number of reference frames for the first image frame and a second number of reference frames for the second image frame from the target video, the first number being greater than the second number;
[0008] performing encoding processing on the first image frame based on the first number of reference frames, and performing encoding processing on the second image frame based on the second number of reference frames;
[0009] using the first image frame as a candidate reference frame for a third number of image frames in the target video, and encoding the third number of image frames based on the first image frame;
[0010] The second image frame is used as a candidate reference frame for a fourth number of image frames in the target video, and encoding processing is performed on the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
[0011] On the other hand, an embodiment of the present application provides a video encoding device, including:
[0012] An acquisition unit, configured to acquire a target video, the target video including at least a first image frame and a second image frame, wherein a coding quality requirement of the first image frame is higher than a coding quality requirement of the second image frame;
[0013] a determining unit, configured to determine a first number of reference frames for the first image frame and a second number of reference frames for the second image frame from the target video, wherein the first number is greater than the second number;
[0014] an encoding unit, configured to perform encoding processing on the first image frame based on the first number of reference frames, and to perform encoding processing on the second image frame based on the second number of reference frames;
[0015] a processing unit, configured to use the first image frame as a candidate reference frame for a third number of image frames in the target video, and perform encoding processing on the third number of image frames based on the first image frame;
[0016] The processing unit is further configured to use the second image frame as a candidate reference frame for a fourth number of image frames in the target video, and to perform encoding processing on the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
[0017] On the other hand, an embodiment of the present application further provides a computer device, including:
[0018] a processor configured to execute one or more computer programs;
[0019] A computer storage medium storing one or more computer programs, wherein the one or more computer programs are suitable for being loaded by the processor and implementing the video encoding method according to the first aspect.
[0020] On the other hand, an embodiment of the present application provides a storage medium, wherein the storage medium stores one or more computer programs, and the one or more computer programs are suitable for being loaded by the processor and implementing the above-mentioned video encoding method.
[0021] On the other hand, an embodiment of the present application provides a program product, which includes a computer program, and the computer program is suitable for being loaded by a processor and executing the above-mentioned video encoding method.
[0022] In an embodiment of the present application, for image frames with higher encoding quality requirements, more reference frames are selected for the image frames during video encoding. This allows the computer device to determine a target reference frame that has a higher degree of match with the image frame during encoding based on the selected reference frames, thereby making the image information retained in the encoded data obtained by encoding based on the target reference frame more comprehensive and realistic, thereby ensuring the encoding quality of the image frame. Furthermore, the computer device uses image frames with high encoding quality as candidate reference frames for more unencoded image frames. This makes it more likely that the computer device will refer to image frames with high encoding quality when encoding the unencoded image frames, thereby ensuring a certain quality of the encoding results of the unencoded image frames. In addition, for image frames with lower encoding quality requirements, the computer device selects fewer reference frames for the image frames during video encoding, thereby reducing the time consumed during encoding processing for the image frames, allowing the image frames to complete encoding processing quickly, thereby ensuring the efficiency of the computer device in encoding the target video to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0024] Figure 1 is a schematic diagram of a target video and image frame provided in an embodiment of the present application;
[0025] Figure 2 is a schematic flow chart of a video encoding method provided in an embodiment of the present application;
[0026] Figure 3 is a schematic flow chart of another video encoding method provided in an embodiment of the present application;
[0027] Figure 4a is a schematic diagram of a preset time domain reference structure provided in an embodiment of the present application;
[0028] Figure 4b is a schematic diagram of another preset time domain reference structure provided in an embodiment of the present application;
[0029] Figure 4c is a schematic diagram of another preset time domain reference structure provided in an embodiment of the present application;
[0030] Figure 5This is a schematic diagram of a video encoding process provided by an embodiment of the present application;
[0031] Figure 6 is a structural diagram of a video encoding device provided in an embodiment of the present application;
[0032] Figure 7 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] In order to take into account both the coding quality and coding efficiency of video coding during the video coding process, an embodiment of the present application proposes a video coding scheme, which points out that: when encoding a target video, based on the coding quality requirements of each video frame (or image frame), one or more reference frames that match the coding quality requirements are selected from the target video for each video frame, and then each video frame is encoded based on the corresponding one or more reference frames. In addition, during the encoding process of the target video, the video frame with a higher coding quality requirement will be used as a candidate reference frame for more video frames after being encoded, so as to implement encoding processing for the corresponding video frames. Among them, the coding quality requirement can be measured by the coding quality requirement level. The higher the coding quality requirement level, the higher the coding quality requirement. Based on this, "matching the coding quality requirement" means that the number of reference frames selected for the video frame is positively correlated with the coding quality requirement of the video frame. That is to say, for video frames with higher coding quality requirements, more reference frames will be selected for them when the embodiment of the present application is used to encode the video frame, so as to ensure that in the process of encoding the video frame based on the selected reference frame, a target reference frame with a higher matching degree with the video frame can be determined, so that the image information retained by the encoded data obtained based on the target reference frame encoding process is more comprehensive and true, thereby ensuring the coding quality of the video frame. Then, by using video frames with higher coding quality requirements as reference frames, encoding processing can be performed based on encoding data with more comprehensive and true image information, and thus the coding quality of video frames using video frames with higher quality requirements as reference frames can also be guaranteed to a certain extent. Correspondingly, for video frames with lower coding quality requirements, fewer reference frames will be selected for them when the embodiment of the present application is used to encode the video frame. Since there are fewer reference frames for the image frame to be encoded in video encoding, the time required to determine the target reference frame that matches the image frame from the reference frames during video encoding is also less, which makes the time required for encoding processing shorter. Therefore, allocating fewer reference frames for video frames with lower encoding quality requirements can enable such video frames to complete the encoding processing quickly, thereby ensuring the efficiency of video encoding of the target video to a certain extent.
[0034] In order to more clearly understand the video encoding scheme proposed in the embodiment of the present application, the principle of the above video encoding scheme is described in more detail below in combination with the first image frame and the second image frame in the target video. The target video includes multiple image frames, and the encoding quality requirement level of the first image frame in the target video is higher than the encoding quality requirement level of the second image frame. For example, the target video may include the following: Figure 1 The multiple image frames shown are Figure 1 The image marked by 101 and the image marked by 102 are both image frames included in the target video. Based on this, that is, when the target video is encoded using the embodiment of the present application, a first number of reference frames can be first determined for the first image frame from the target video, and a second number of reference frames can be determined for the second image frame, and the first number is greater than the second number, so as to further encode the first image frame based on the first number of reference frames, and encode the second image frame based on the second number of reference frames. In addition, the first image frame can be used as a candidate reference frame for a third number of image frames, and the second image frame can be used as a candidate reference frame for a fourth number of image frames, so as to encode the third number of video frames based on the first image frame, and encode the fourth number of video frames based on the second image frame, wherein the third number is greater than the fourth number.
[0035] In one embodiment, the video encoding scheme proposed in the embodiment of the present application can be executed by a computer device. Specifically, the computer device can be a terminal device, or a server, or a coding device with video encoding function jointly constructed based on the terminal device and the server, and the embodiment of the present application does not impose any restrictions on this. Among them, the terminal device can include but is not limited to: smart phones, tablet computers, laptops, desktop computers, vehicle terminals, smart TVs, game consoles, etc. The server can specifically include but is not limited to: an independent physical server, a server cluster or distributed system composed of multiple physical servers, and a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and basic cloud computing services such as big data and artificial intelligence platforms, etc., and the embodiment of the present application does not impose any specific restrictions on this.
[0036] Among them, when the computer device includes a terminal device, a multimedia client can be run in the terminal device, and the multimedia client can include one or more functions such as video playback, video upload and video download, so that the computer device can obtain the target video. Of course, other various clients can also be run in the terminal device, such as social clients, game clients and image processing clients, etc., which are not described in detail in the embodiments of the present application. When the computer device includes a server, the computer device can have the ability to provide background services for the multimedia client, and the background services can include but are not limited to services such as video encoding, video decoding and video storage.
[0037] Based on the principle of the above video encoding scheme, the embodiment of the present application proposes a video encoding method, which can also be executed by the above computer device. Figure 2 , Figure 2 This is a flow chart of the video encoding method. Figure 2 As shown, the method may include steps S201-S205:
[0038] S201: Acquire a target video, where the target video includes at least a first image frame and a second image frame, and a required encoding quality level of the first image frame is higher than a required encoding quality level of the second image frame.
[0039] In one embodiment, the computer device can obtain the target video after receiving the encoding request for the target video. Wherein, the encoding request can carry or include one or more of the video identification and video storage location of the target video, so that the computer device can determine the target video based on the video identification and / or video storage location, thereby obtaining the target video. Exemplarily, the video storage location of the target video can be the storage location of the target video in the computer device, or it can be the storage location in the cloud database, or it can be the storage location in other devices that have a communication connection with the computer device, and the embodiment of the present application does not limit this. In another embodiment, the computer device can receive and process the target video based on the upload interface of the target video after detecting the upload operation for the target video, thereby achieving the acquisition of the target video. Wherein, the upload operation can be an operation for uploading the target video to a database in the cloud, or it can be an operation for uploading the target video to a local storage device, and the embodiment of the present application does not limit this.
[0040] The database (or cloud database) mentioned above can be understood as an electronic file cabinet, or as a place for storing electronic files. In the field of computer technology, a database specifically refers to a collection of data that is stored together in a certain manner, can be shared with multiple users, has as little redundancy as possible, and is independent of the applications running on the computer device. In actual applications, the database can be managed using a database management system so that users can add, query, update, delete, and other operations on the data in the database based on the database management system. Among them, the database management system (DBMS) has basic functions such as storage, interception, security, and backup. In addition, the database management system can be classified according to the database model it supports, such as relational, XML (Extensible Markup Language), etc. Optionally, the database management system can also be classified according to the query language it uses, such as SQL (Structured Query Language) and XQuery. Of course, in other embodiments, the database management system can also use one or more other classification criteria, such as management performance and the type of computer device supported, which will not be described in detail in the embodiments of the present application.
[0041] In one embodiment, the first image frame and the second image frame do not specifically refer to two image frames, but rather generally refer to two image frames in the target video with different encoding quality requirements. That is, for two image frames in the target video, the computer device may use the image frame with the higher encoding quality requirement of the two image frames as the first image frame, and the image frame with the lower encoding quality requirement as the second image frame. It is not difficult to understand that different first image frames and second image frames can be determined based on two or more different image frames in the target video. In addition, the encoding quality requirement level is used to indicate the quality requirements for the encoded data obtained after encoding the video frame, such as the requirements for the amount of information contained in the encoded data and / or the requirements for the data size of the encoded data. In practical applications, the video frame with higher importance can be used as the video frame with a higher encoding quality requirement level, and the encoding quality requirement level can be represented by numbers, letters, or text, etc., and this embodiment of the application does not impose specific limitations. During the actual encoding process, frames that are coded earlier in the order are more likely to be used as reference frames. When encoding a target frame (a target frame is defined as the frame that is used for video encoding) based on a reference frame, the quality of the reference frame will affect the quality of the encoded data obtained after encoding the target frame. Therefore, a computer device may consider frames that are coded earlier in the order to have higher encoding quality requirements.
[0042] In other embodiments, the computer device may also obtain a preset setting rule for the encoding quality requirement level to determine the level of encoding quality requirement between the first image frame and the second image frame according to the rule. The rule may include determining the encoding quality requirement level of the first image frame and the second image frame according to the display order of the first image frame and the second image frame, or randomly determining the encoding quality requirement level of the first image frame and the second image frame. Of course, in other implementations, the computer device may also display corresponding prompt information when the target video needs to be encoded, so that relevant technicians can specify the encoding quality requirement level of the first image frame and the second image frame in the computer device. The prompt information is used to prompt the technician to select the encoding quality requirement level of the first image frame and the second image frame, or to prompt the technician to determine the level of encoding quality requirement between the first image frame and the second image frame, and the embodiments of the present application do not limit this.
[0043] S202: Determine a first number of reference frames for the first image frame from the target video, and determine a second number of reference frames for the second image frame, where the first number is greater than the second number.
[0044] In one embodiment, to ensure the encoding rate of a target video, for any image frame between the first image frame and the second image frame (hereinafter referred to as the encoding frame for ease of description), the computer device may first determine an image frame that has already been encoded from the target video when determining the reference frame for the encoding frame, and then select a corresponding number of reference frames from the already encoded image frames. Because the reference frame is an already encoded image frame, the computer device can quickly obtain one or more encoding information generated by the reference frame during the encoding process when using it as a reference frame for the encoding frame. In the actual video encoding process, one or more encoding information of the reference frame can be used to implement video encoding of the encoding frame. Therefore, using the already encoded image frame as the reference frame can shorten the time it takes for the computer device to obtain the encoding information of the reference frame, thereby accelerating the video encoding rate to a certain extent. For example, the encoding information may include motion vectors, predicted motion vectors, image features, etc.
[0045] In order to balance the encoding rate and encoding quality of the target video, when selecting a corresponding number of reference frames from the already encoded image frames (hereinafter referred to as encoded frames for ease of description), the computer device can first determine one or more encoded frames with a higher encoding quality requirement level than the encoded frame from the determined encoded frames, and then select a corresponding number of reference frames from the one or more encoded frames. Because the reference frame is an encoded frame with a higher encoding quality requirement level, the encoding quality of the reference frame was guaranteed when the computer device previously encoded the reference frame. Encoding the encoded frame based on the reference frame with higher encoding quality can, to a certain extent, ensure the encoding quality of the encoded frame, thereby ensuring the encoding quality of the target video.
[0046] Optionally, in order to further improve the encoding rate of the target video, the computer device may also randomly select a corresponding number of reference frames from one or more determined encoded frames. Of course, in other embodiments, in order to adapt to other application scenarios, the computer device may also adopt other methods to select reference frames of the encoded frames from the determined encoded frames, such as: the computer device first determines the image similarity between each encoded frame and the encoded frame, and then selects a corresponding number of reference frames from each encoded frame in descending order of image similarity. The embodiment of the present application does not impose any specific restrictions on the manner in which the computer device selects reference frames, as long as the number of reference frames determined by the image frames with higher encoding quality requirements in the corresponding multiple image frames is greater than the number of reference frames of the image frames with lower encoding quality requirements.
[0047] S203 : Encode the first image frame based on the first number of reference frames, and encode the second image frame based on the second number of reference frames.
[0048] In one embodiment, when a computer device encodes an image frame in a target video, it may first perform macroblock division on the image frame to obtain one or more coding blocks of the same size, so as to implement encoding of the image frame by encoding each coding block. A coding block is a local image in the image frame. In addition, when a computer device encodes each coding block in an image frame, it may first perform macroblock division on the reference frame of the image frame to obtain one or more candidate matching blocks of the same size as the coding block. Furthermore, for each coding block, the computer device may search for a target matching block from multiple candidate matching blocks, the matching degree of which is greater than or equal to a matching degree threshold, and then encode the coding block based on a motion vector between the target matching block and the coding block, thereby implementing encoding of the image frame by performing the above encoding process on each coding block in the image frame.
[0049] The matching degree threshold mentioned above may be pre-set or determined during the encoding process, such as determining the maximum matching degree between each candidate matching block and the encoding block as the matching degree threshold, so that the target matching block is the candidate matching block with the highest matching degree with the matching block among the candidate matching blocks. In addition, exemplarily, when the computer device encodes the encoding block based on the motion vector between the target matching block and the encoding block, the steps may specifically include the following: the computer device determines the relative displacement between the encoding block and the target matching block as the target motion vector, and uses advanced motion vector prediction technology to perform motion vector prediction on the target encoding block to obtain a predicted motion vector of the encoding block; further, the computer device may determine the motion residual between the target motion vector and the predicted motion vector, and encode the motion residual to implement encoding processing of the encoding block.
[0050] S204: Use the first image frame as a candidate reference frame for a third number of image frames in the target video, and perform encoding processing on the third number of image frames based on the first image frame.
[0051] S205 : Use the second image frame as a candidate reference frame for a fourth number of image frames in the target video, and perform encoding processing on the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
[0052] In one embodiment, using image frame A as a candidate reference frame for image frame B means that image frame A exists in one or more reference frames that can be used as image frame B. That is to say, image frame A is not necessarily a reference frame for image frame B, and image frame B does not necessarily have to use image frame A to implement encoding processing. Then, the above-mentioned encoding processing of the third number of image frames based on the first image frame can be understood as: the computer device selects a reference frame from the set of candidate reference frames including the first image frame, and performs encoding processing based on the selected reference frame. For the understanding of the encoding processing of the fourth number of image frames based on the second image frame in step S205, reference can be made to the relevant description of the first image frame mentioned above, and the embodiment of the present application will not be described in detail here.
[0053] In an embodiment of the present application, for image frames with higher encoding quality requirements, more reference frames are selected for the image frames during video encoding. This allows the computer device to determine a target reference frame that has a higher degree of match with the image frame during encoding based on the selected reference frames, thereby making the image information retained in the encoded data obtained by encoding based on the target reference frame more comprehensive and realistic, thereby ensuring the encoding quality of the image frame. Furthermore, the computer device uses image frames with high encoding quality as candidate reference frames for more unencoded image frames. This makes it more likely that the computer device will refer to image frames with high encoding quality when encoding the unencoded image frames, thereby ensuring a certain quality of the encoding results of the unencoded image frames. In addition, for image frames with lower encoding quality requirements, the computer device selects fewer reference frames for the image frames during video encoding, thereby reducing the time consumed during encoding processing of the image frame, allowing the image frame to complete encoding processing quickly, thus ensuring the efficiency of the computer device in encoding the target video to a certain extent.
[0054] Based on the above video encoding method, the embodiment of the present application also proposes a video encoding method, which can also be executed by the above computer device. Figure 3 , Figure 3 This is a flow chart of the video encoding method. Figure 3 As shown, the method may include steps S301-S307:
[0055] S301: Acquire a target video, where the target video at least includes a first image frame and a second image frame.
[0056] In one embodiment, the implementation method of obtaining the target video in step S301 can refer to the relevant description of step S201, and will not be repeated here in this embodiment of the present application.
[0057] In one embodiment, after acquiring a target video, a computer device may segment the target video to obtain at least one coded picture group (i.e., GOP, Group Of Pictures), and implement coding of the target video by encoding the image frames in each coded picture group. Each coded picture group includes at least a first image frame and a second image frame, and illustratively, the number of each coded picture group may be an integer power of 2, such as 2, 4, 8, etc. The computer device may then traverse the at least one coded picture group and execute steps S302 to S307 for the first and second image frames in each coded picture group, to implement coding of the first image frame in the currently traversed coded picture group based on the first number of reference frames, and to implement coding of the second image frame in the currently traversed coded picture group based on the second number of reference frames.
[0058] S302: Determine a coding reference relationship between the first image frame and the second image frame.
[0059] In one embodiment, the coding reference relationship can be used to determine which image frame is which in the first image frame and the second image frame. For example, the first image frame is the reference frame of the second image frame, or the second image frame is the reference frame of the first image frame. Then, because under normal circumstances, an image frame cannot refer to an image frame that is later in the coding order than it when encoding. Therefore, the computer device can determine the coding reference relationship between the two by determining the coding order of the first image frame and the second image frame. In practical applications, the coding order can be determined by a time domain layering identifier. Then, when determining the coding reference relationship, the computer device can first perform time domain layering processing on the image frames included in the target video according to a preset time domain reference structure to obtain the time domain layering identifiers of the first image frame and the second image frame.
[0060] The preset time domain reference structure can be determined based on one or more reference frame configurations among full intra-frame configuration (AI configuration), low delay configuration (ie, LD configuration), and random access configuration (or RA configuration). For example, the preset time domain reference structure determined based on the full intra-frame configuration can be as follows: Figure 4a As shown, Figure 4a Each block in the image (such as the block marked by 401, the block marked by 402, etc.) represents an image frame. Figure 4a The content marked by 403 in the is the display order (such as the number on the left of the slash) and the encoding order (such as the number on the right of the slash) of the corresponding image frames. The smaller the number, the higher the order. Figure 4aIt can be seen that the encoding order of each image frame in the target video determined by the full-frame configuration is the display order of each image frame, and there is no encoding reference relationship between each image frame. In addition, the preset time domain reference structure determined based on the low-latency configuration can be as follows Figure 4b As shown. Figure 4b In the preset temporal reference structure shown, the display order of the image frames is the same as the encoding and decoding order, and Figure 4b The arrow in the middle indicates the coding reference relationship between image frames. The arrow points to the reference frame. Figure 4a understanding, Figure 4b The numbers in the table indicate the display order and encoding order. The smaller the number, the higher the order.
[0061] In practical applications, the preset time domain reference structure determined based on the random access configuration can be as follows: Figure 4c As shown, Figure 4c Where Ti represents the temporal layer identifier (i is a non-negative integer, such as 0, 1, 2, etc.), and Pj represents the j-th image frame in the target video (j is a non-negative integer, such as 0, 1, 2, etc.). Similarly, Figure 4c The arrow in the middle represents the coding reference relationship between image frames, and the arrow points to the reference frame. Figure 4c The number of image frames corresponding to each temporal layer number determined by the preset temporal reference structure shown forms an inverted pyramid structure. Specifically, except for image frames that can be encoded without reference frames, the lower the temporal layer number, the fewer the image frames, while the higher the temporal layer number, the more the image frames. Figure 4c In the video encoding process, the image frame with temporal layer number T0 is an image frame that can be encoded without referencing other frames (this is called an I-frame in video encoding). There is one image frame with temporal layer number T1, two with temporal layer number T2, four with temporal layer number T3, and eight with temporal layer number T4. Based on this inverted pyramid structure, the computer device determines a larger number of reference frames for images with lower temporal layer numbers and a smaller number for images with higher temporal layer numbers. This does not result in an excessive number of reference frames, thus preventing a decrease in encoding speed. On the contrary, because images with lower temporal layer numbers are encoded using a larger number of reference frames, the computer device can use the higher-quality encoding results of the reference frames to encode images with higher temporal layer numbers, thereby achieving better cost-effectiveness.
[0062] In one embodiment, when the encoding order indicated by the temporal layer identifier of the first image frame precedes the encoding order indicated by the temporal layer identifier of the second image frame, the computer device may determine that the encoding reference relationship indicates that the candidate reference frames for the second image frame include the first image frame, and the candidate reference frames for the first image frame do not include the second image frame. In other words, the first image frame cannot refer to the second image frame during encoding, but the second image frame can refer to the first image frame during encoding. The temporal layer identifier may include a temporal layer number, and illustratively, the temporal layer number may be a non-negative integer, such as 0, 1, 2, etc. Therefore, assuming that the image frame currently to be encoded is an image frame with a temporal layer number of 1, the computer device can only select a reference frame for the image frame from the image frames with temporal layer numbers 1 and 0. It should be noted that in other embodiments, the temporal layer identifier may also be marked with other identifiers, which may include but are not limited to one or more of characters and text.
[0063] In addition, it is worth mentioning that, in actual applications, the time domain layer identifiers of the first image frame and the second image frame determined by the computer device may be the same. In this case, the coding reference relationship between the first image frame and the second image frame is used to indicate that the first image frame and the second image frame can be reference frames of each other. Then, optionally, in one coding implementation method, the computer device may select a reference frame of the first image frame from other image frames except the second image frame to implement the coding of the first image frame, and at the same time select a reference frame of the second image frame from other image frames except the first image frame to implement the coding processing of the second image frame. Of course, in other coding implementation methods, the computer device may also randomly specify the actual coding order of the first image frame and the second image frame, and perform coding processing on the first image frame and the second image frame according to the determined actual coding order, so as to redefine the coding reference relationship between the first image frame and the second image frame, so that the image frame that has been completed coding can be used as a reference frame of another image frame.
[0064] S303: When the coding reference relationship indicates that the candidate reference frame of the second image frame includes the first image frame, and the candidate reference frame of the first image frame does not include the second image frame, determine that the coding quality requirement level of the first image frame is higher than the coding quality requirement level of the second image frame.
[0065] In one embodiment, when the coding reference relationship indicates that the candidate reference frames for the second image frame include the first image frame, and the candidate reference frames for the first image frame include the second image frame, the computer device may determine that the required coding quality level of the first image frame is equal to the required coding quality level of the second image frame. In this case, when encoding the first and second image frames, the computer device needs to determine the same number of reference frames for the first and second image frames from the target video, and then encode the corresponding image frames based on the determined reference frames.
[0066] In one embodiment, the computer device may also determine that the encoding quality requirement level of the first image frame is higher than the encoding quality requirement level of the second image frame through the following steps (1)-(2). That is, in the specific implementation of the embodiment of the present application, the computer device may adopt the following steps (1) and (2) instead of the implementation described in the above steps S302 to S303. Among them, (1) the quality of the first image frame and the second image frame are respectively evaluated to obtain the image quality of the first image frame and the image quality of the second image frame. Among them, the computer device may perform quality evaluation on the image frame based on one or both of the image content contained in the image frame and the clarity of the image frame, and the embodiment of the present application does not limit this. In addition, illustratively, the more target content the image frame includes, the higher the image quality indicated by the quality evaluation result of the image frame. The target content may be characters and scenes related to current hot topics, etc. In other implementations, the higher the clarity of the image frame, the higher the image quality indicated by the quality evaluation result of the image frame. The clarity of the image frame can be obtained by calculating the gradient value of the pixel value of each pixel point in the image frame, so as to indicate the clarity using the calculated gradient value, wherein the larger the gradient value, the higher the clarity. (2) If the image quality of the first image frame is higher than the image quality of the second image frame, it is determined that the encoding quality requirement level of the first image frame is higher than the encoding quality requirement level of the second image frame.
[0067] S304: Determine a first number of reference frames for the first image frame from the target video, and determine a second number of reference frames for the second image frame, where the first number is greater than the second number.
[0068] In one embodiment, for any one of the first and second image frames, the computer device may determine a reference frame for the image frame by identifying at least one candidate reference frame from the target video whose coding quality requirement is lower than or equal to the coding quality requirement of the image frame, and selecting a target number of candidate reference frames from the at least one candidate reference frame as reference frames for the image frame. When the image frame is the first image frame, the target number is a first number, and when the image frame is the second image frame, the target number is a second number. Furthermore, the image frame whose coding quality requirement is lower than or equal to the coding quality requirement of the image frame may be an image frame that precedes the image frame in the coding order. Since the coding order can be determined by a temporal layer identifier, the computer device may also determine the difference in coding quality requirement between image frames based on the temporal layer identifier (e.g., the temporal layer number). For example, the computer device may select image frames in the target video whose temporal layer numbers are lower than or equal to the image frame as candidate reference frames.
[0069] In one embodiment, before determining the first number of reference frames for a first image frame, the computer device may first determine the first number. Correspondingly, before determining the second number of reference frames for a second image frame, the computer device may first determine the second number. The following describes in detail how to determine the first and second numbers, using specific examples.
[0070] In a specific implementation, the computer device may, based on a preset correspondence between the required encoding quality level and the number of reference frames, use the number of reference frames corresponding to the required encoding quality level of the first image frame as the first number, and use the number of reference frames corresponding to the required encoding quality level of the second image frame as the second number. The preset correspondence may be stored in the computer device by a relevant technician in the form of a file (e.g., a data table), or may be stored in another device that is communicatively connected to the computer device, and this is not limited in this embodiment of the present application. Furthermore, optionally, in other implementations, the computer device may determine the first number based on a preset reference number and the required encoding quality level of the first image frame, and determine the second number based on the preset reference number and the required encoding quality level of the second image frame. Both the first number and the second number are positively correlated with the required encoding quality level. Furthermore, the preset reference number is used to indicate a reference value for the number of reference frames of each image frame, so that both the first number and the second number can be determined based on the preset reference number.
[0071] Specifically, the method in which the computer device determines the first quantity based on the preset reference quantity may include: the computer device first obtains the encoding quality requirement level corresponding to the preset reference quantity, and determines the level difference between the encoding quality requirement level of the first image frame and the determined encoding quality requirement level, and then determines the first quantity based on the level difference and the preset reference quantity. The level difference may include but is not limited to: the difference between the levels (such as a difference of 2 levels or 3 levels) or the ratio between the levels (such as 1 / 2 or 2 / 3, etc.). The encoding quality requirement level corresponding to the preset reference quantity may be randomly specified by the computer device within a certain range, or may be determined based on the encoding quality requirement level of each video frame in the target video. When the encoding quality requirement level corresponding to the preset reference quantity is determined based on the encoding quality requirement level of each video frame in the target video, the computer device may first determine the encoding quality requirement level of each video frame in the target video, and then select the encoding quality requirement level corresponding to the preset reference quantity from the encoding quality requirement levels corresponding to the video frames included in the target video. Exemplarily, the selection method may include but is not limited to any one of the following three methods:
[0072] (1) Random selection.
[0073] (2) The encoding quality requirement level corresponding to the video frame at the preset position in the display order is used as the encoding quality requirement level corresponding to the preset reference number.
[0074] (3) The middle level among the various coding quality requirement levels determined based on the video frames of the target video is used as the coding quality requirement level corresponding to the preset reference quantity. The middle level can be understood as the coding quality requirement level at the midpoint arrangement position after arranging the various coding quality requirement levels determined based on the target video in order from high to low (or from low to high). For example, the sequence obtained after arranging the coding quality requirement levels determined based on the target video is {1, 2, 3, 4, 5}. It can be seen that level 3 is located at the midpoint arrangement position in the sequence {1, 2, 3, 4, 5}, so the computer device can use level 3 as the coding quality requirement level corresponding to the preset reference quantity.
[0075] Based on this, when the level difference includes a difference between levels, the computer device may determine the first quantity by determining the difference between the required encoding quality level of the first image frame (for ease of description, referred to as the first level) and the required encoding quality level corresponding to the preset reference quantity (for ease of description, referred to as the reference level), and then determining the first quantity based on the difference, the first step length, and the preset reference quantity. If the first level is higher than the reference level, the determined first quantity is greater than the preset reference quantity. Correspondingly, if the first level is lower than the reference level, the determined first quantity is less than the preset reference quantity. The preset reference quantity may be pre-set, and the first step length indicates the absolute value of the difference between the determined first quantity and the preset reference quantity when the reference level differs from the first level by one level. For example, assuming the difference indicated by the first step length is 1, the preset reference quantity is 5, and the reference level corresponding to the preset reference quantity is level 3. In this case, if the first level is level 1, and in this example, level 1 is higher than level 3, the difference between the reference level and the first level is 2. Then, the calculation method of the first quantity can be "preset reference quantity + 2*first step length", and the final calculation result is 7 (ie 5+2=7). It can be seen that the preset reference quantity 5 is smaller than the first quantity 7.
[0076] In addition, when the level difference includes a ratio between levels, the computer device may determine the first quantity by determining the ratio between the coding quality requirement level of the first image frame and the coding quality requirement level corresponding to a preset reference quantity, and determining the first quantity based on the ratio, a second step size, and the preset reference quantity. The second step size is used to indicate the absolute value of the difference between the determined first quantity and the preset reference quantity when the ratio between the coding quality requirement level of the first image frame and the coding quality requirement level corresponding to the preset reference quantity is 1 times the preset ratio. Optionally, the second step size and the first step size may be the same. Similarly, if the first level is higher than the reference level, the determined first quantity is greater than the preset reference quantity. Correspondingly, if the first level is lower than the reference level, the determined first quantity is less than the preset reference quantity. Specifically, when the first level is higher than the reference level, the computer device may determine the first quantity based on the ratio, the second step length, and the preset reference quantity in the following manner: the computer device may first divide the ratio by the preset ratio to determine how many times the ratio is the preset ratio (assuming it is N times, where N is a non-negative real number), and then the computer device may determine the first quantity in the following manner: "first quantity = preset reference quantity - N * second step length." Correspondingly, when the first level is lower than the reference level, the computer device may determine the first quantity based on the ratio, the second step length, and the preset reference quantity in the following manner: the computer device may first determine how many times the ratio is the preset ratio (assuming it is N times, where N is a non-negative real number), and then the computer device may determine the first quantity in the following manner: "first quantity = preset reference quantity + N * second step length."
[0077] S305 : Encode the first image frame based on the first number of reference frames, and encode the second image frame based on the second number of reference frames.
[0078] In one embodiment, the encoding quality of the computer device is also related to the encoding bit rate. When encoding an image frame, the higher the encoding bit rate used, the higher the encoding quality of the image frame. Based on this, when encoding the first image frame and the second image frame, the embodiment of the present application can also allocate a first encoding bit rate to the first image frame and allocate a second encoding bit rate to the second image frame, wherein the first encoding bit rate is greater than or equal to the second encoding bit rate, so as to ensure that more bit rates are allocated to image frames with higher encoding quality requirements, so that the encoding results of the image frames have higher quality. In this case, the computer device encodes the first image frame based on the first number of reference frames, which specifically means that the computer device uses the first encoding bit rate to encode the first image frame based on the first number of reference frames. Similarly, the computer device encodes the second image frame based on the second number of reference frames, which specifically means that the computer device uses the second encoding bit rate to encode the second image frame based on the second number of reference frames.
[0079] S306: Use the first image frame as a candidate reference frame for a third number of image frames in the target video, and perform encoding processing on the third number of image frames based on the first image frame.
[0080] S307 : Use the second image frame as a candidate reference frame for a fourth number of image frames in the target video, and perform encoding processing on the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
[0081] In one embodiment, the specific implementation of steps S306 to S307 can refer to the relevant embodiments of the above-mentioned steps S204 to S205, which will not be repeated here.
[0082] Based on the above description, the embodiment of the present application proposes a specific process of video encoding. The flowchart can be found in Figure 5 As shown. The following combination Figure 5 The manner in which a computer device encodes a target video is exemplified.
[0083] Specifically, the computer device may first segment the target video to obtain at least one coded picture group (Group Of Picture, i.e. Figure 5 For each GOP, the computer device may determine the temporal layer number of each image frame in the GOP. For example, the computer device may determine the temporal layer number of each image frame in the GOP by arranging the image frame to be encoded (i.e., Figure 5 The temporal layer number corresponding to the frame number of the current coded frame in the GOP is used as the temporal layer number of the current coded frame. The correspondence table can be determined by a computer device based on a specific GOP, or can be preset by other means, and this application is not limited thereto. Furthermore, the frame number can be used to indicate the arrangement position of the current coded frame in the GOP, such as the i-th position, where i is a positive integer less than the GOP length. The GOP length refers to the number of image frames contained in a GOP. In one implementation, the GOP can be divided by a computer device according to the display order of each video frame in the target video. For example, when the GOP is 10, image frames displayed in the order 1-10 constitute one GOP, and image frames displayed in the order 11-20 constitute another GOP. Based on this, the frame number can be determined by taking the modulo operation between the display order of the current coded frame in the target video and the GOP. Specifically, the determined modulo is the frame number of the current coded frame within the current GOP.
[0084] Assuming that the temporal layer number determined by the computer device for the current coding frame is T, the computer device can further use the number corresponding to temporal layer number T in a preset table of temporal layer number and reference frame number as the number of reference frames for the current coding frame (assuming it is M). This allows the computer device to determine a reference frame queue consisting of reference frames from the already encoded video frames of the target video based on M, and then encode the current coding frame based on the reference frames in the reference frame queue. The temporal layer numbers corresponding to the image frames included in each GOP are typically the same (e.g., each GOP corresponds to temporal layer number 1, temporal layer number 2, and temporal layer number 3). Therefore, the preset table of temporal layer number and reference frame number can be determined by the computer device based on a single GOP. Furthermore, the number of reference frames included in the reference frame queue determined by the computer device can be equal to M. In special cases (e.g., when the number of already encoded video frames in the target video is less than M), the number of reference frames included in the determined reference frame queue can also be less than M. After the current encoding frame is encoded, determine whether the current encoding frame is the last frame of the target video. If not, re-determine a video frame from the target video as the current encoding frame (usually an image frame that is next in the encoding order to the current encoding frame), and continue to execute the above-mentioned steps for encoding the current encoding frame until all video frames in the target video have completed encoding processing.
[0085] In an embodiment of the present application, when a computer device determines a reference frame for an image frame in a target video, it does so from frames with a lower temporal layer number than or the same temporal layer number as the target video frame. The temporal layer number indicates the encoding order of the image frames, with a lower temporal layer number indicating an earlier encoding order. Therefore, since the reference frame determined during encoding of each image frame in the target video also serves as a reference frame when decoding each image frame, when the decoder needs to drop frames due to limited decoding capabilities, frames with higher temporal layer numbers can be preferentially discarded. This reduces the decoding pressure on the decoder while ensuring that frames with lower temporal layer numbers can also be properly decoded. Furthermore, frames with lower temporal layer numbers are used as references by more frames during encoding, and therefore, their encoding quality affects a greater number of frames. In other words, the lower the temporal layer number of an image frame, the higher the encoding quality requirement level. In the embodiment of the present application, for image frames with higher encoding quality requirements, more reference frames and a higher encoding bit rate are allocated to them, so that the image frame can be encoded with high quality, ensuring the encoding quality of each image frame in the target video. Correspondingly, for image frames with higher temporal layer numbers, the computer device will determine fewer reference frames and a lower encoding bit rate for them, so that the computer device can quickly complete the encoding process of the image frame. In summary, it can be seen that the embodiment of the present application, when actually applied to video encoding, can take into account both the encoding quality and encoding efficiency of video encoding.
[0086] Based on the above Figure 2 as well as Figure 3 In a related embodiment of the present application, a video encoding device is provided. The device is a computer program running on the computer device mentioned above. In a specific embodiment, the video encoding device can be used to perform the following steps: Figure 2 as well as Figure 3 The video encoding method shown in . Figure 6 The video encoding device may include at least an acquisition unit 601, a determination unit 602, an encoding unit 603, and a processing unit 604.
[0087] An acquiring unit 601 is configured to acquire a target video, where the target video includes at least a first image frame and a second image frame, and a required encoding quality level of the first image frame is higher than a required encoding quality level of the second image frame;
[0088] a determining unit 602 configured to determine a first number of reference frames for the first image frame and a second number of reference frames for the second image frame from the target video, wherein the first number is greater than the second number;
[0089] an encoding unit 603, configured to perform encoding processing on the first image frame based on the first number of reference frames, and perform encoding processing on the second image frame based on the second number of reference frames;
[0090] a processing unit 604 configured to use the first image frame as a candidate reference frame for a third number of image frames in the target video, and perform encoding processing on the third number of image frames based on the first image frame;
[0091] The processing unit 604 is further configured to use the second image frame as a candidate reference frame for a fourth number of image frames in the target video, and to encode the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
[0092] In one implementation, the determining unit 602 may further be configured to execute:
[0093] According to the correspondence between the preset coding quality requirement level and the number of reference frames, the number of reference frames corresponding to the coding quality requirement level of the first image frame is used as the first number, and the number of reference frames corresponding to the coding quality requirement level of the second image frame is used as the second number.
[0094] In yet another embodiment, the determining unit 602 may be further configured to execute:
[0095] determining the first number according to a preset reference number and a required encoding quality level of the first image frame;
[0096] Determining the second number according to the preset reference number and the required encoding quality level of the second image frame;
[0097] The first quantity and the second quantity are both positively correlated with the coding quality requirement level.
[0098] In another embodiment, when the determining unit 602 is used to determine any one of the first quantity and the second quantity, it may further be used to perform:
[0099] Obtaining a coding quality requirement level corresponding to the preset reference quantity;
[0100] Determine a level difference between a required encoding quality level of the image frames corresponding to any number and a required encoding quality level corresponding to the preset reference number;
[0101] The arbitrary quantity is determined according to the level difference and the preset reference quantity.
[0102] In yet another embodiment, the determining unit 602 may be further configured to execute:
[0103] Determine a difference between the required encoding quality level of the image frames corresponding to any number and the required encoding quality level corresponding to the preset reference number;
[0104] The determining of any quantity according to the level difference and the preset reference quantity includes:
[0105] The arbitrary quantity is determined according to the difference, the first step length and the preset reference quantity.
[0106] In yet another embodiment, the determining unit 602 may be further configured to execute:
[0107] Determine a ratio between the required encoding quality levels of the image frames corresponding to any number and the required encoding quality levels corresponding to the preset reference number;
[0108] The determining of any quantity according to the level difference and the preset reference quantity includes:
[0109] The arbitrary quantity is determined according to the ratio, the second step length and the preset reference quantity.
[0110] In yet another embodiment, the determining unit 602 may also be configured to execute:
[0111] determining a coding reference relationship between the first image frame and the second image frame;
[0112] When the encoding reference relationship indicates that the candidate reference frames of the second image frame include the first image frame, and the candidate reference frames of the first image frame do not include the second image frame, it is determined that the encoding quality requirement level of the first image frame is higher than the encoding quality requirement level of the second image frame.
[0113] In yet another embodiment, the determining unit 602 may also be configured to execute:
[0114] Performing temporal layering processing on image frames included in the target video according to a preset temporal reference structure to obtain temporal layer identifiers of the first image frame and the second image frame, wherein the temporal layer identifiers are used to indicate a coding order of corresponding image frames;
[0115] When the coding order indicated by the time domain layer identifier of the first image frame is before the coding order indicated by the time domain layer identifier of the second image frame, it is determined that the coding reference relationship indicates that the candidate reference frames of the second image frame include the first image frame, and the candidate reference frames of the first image frame do not include the second image frame.
[0116] In yet another embodiment, the determining unit 602 may also be configured to execute:
[0117] When the coding reference relationship indicates that the candidate reference frames for the second image frame include the first image frame, and the candidate reference frames for the first image frame include the second image frame, determining that the required coding quality level of the first image frame is equal to the required coding quality level of the second image frame;
[0118] From the target video, the same number of reference frames is determined for the first image frame and the second image frame, and encoding processing is performed on the corresponding image frames based on the determined reference frames.
[0119] In yet another embodiment, the video encoding apparatus may further include a segmentation unit 605, which may be configured to perform:
[0120] Segmenting the target video to obtain at least one coded image group, where each coded image group includes at least a first image frame and a second image frame;
[0121] Traverse the at least one coded image group, encode the first image frame in the currently traversed coded image group based on the first number of reference frames, and encode the second image frame in the currently traversed coded image group based on the second number of reference frames.
[0122] In yet another embodiment, the determining unit 602 may also be configured to execute:
[0123] Performing quality evaluation on the first image frame and the second image frame respectively to obtain image quality of the first image frame and image quality of the second image frame;
[0124] If the image quality of the first image frame is higher than the image quality of the second image frame, it is determined that the encoding quality requirement level of the first image frame is higher than the encoding quality requirement level of the second image frame.
[0125] In yet another embodiment, the determining unit 602 may also be configured to execute:
[0126] Determining, from the target video, at least one candidate reference frame whose encoding quality requirement level is lower than or equal to the encoding quality requirement level of any image frame;
[0127] Selecting a target number of candidate reference frames from the at least one candidate reference frame as reference frames for any one of the image frames;
[0128] When any one of the image frames is the first image frame, the target number is the first number; and when any one of the image frames is the second image frame, the target number is the second number.
[0129] In yet another embodiment, the encoding unit 603 may also be configured to execute:
[0130] Allocating a first encoding rate to the first image frame and allocating a second encoding rate to the second image frame, wherein the first encoding rate is greater than or equal to the second encoding rate;
[0131] The encoding process of the first image frame based on the first number of reference frames, and the encoding process of the second image frame based on the second number of reference frames, includes:
[0132] encoding the first image frame based on the first number of reference frames using the first encoding rate;
[0133] The second image frame is encoded based on the second number of reference frames using the second encoding rate.
[0134] According to one embodiment of the present application, Figure 2 as well as Figure 3 The various steps in the video encoding method shown can be represented by Figure 6 The video encoding device shown in FIG. Figure 2 Step S201 in the Figure 6 The acquisition unit 601 in the video encoding device shown in FIG. 1 is executed, and step S202 can be performed by Figure 6 The video encoding apparatus shown in FIG. 1 is used to determine the unit 602, and step S203 can be performed by Figure 6 The encoding unit 603 in the video encoding device shown in FIG. 1 is used to perform the encoding, and step S204 and step S205 can be performed by Figure 6 The processing unit 604 in the video encoding device shown in FIG. Figure 3 Step S301 in the Figure 6 The acquisition unit 601 in the video encoding device shown in FIG. 1 is used to perform the operation. Steps S302 to S304 can be performed by Figure 6 The video encoding apparatus shown in FIG. 1 is used to determine the unit 602, and step S305 can be performed by Figure 6 The encoding unit 603 in the video encoding device shown in FIG. 1 is used to perform the encoding. Steps S306 and S307 can be performed by Figure 6 The processing unit 604 in the video encoding apparatus shown is executed.
[0135] According to another embodiment of the present application, Figure 6The various units in the video encoding device shown are divided based on logical functions. The above-mentioned units can be individually or all merged into one or several other units to form a unit, or one (some) of the units can be further divided into multiple functionally smaller units to form a unit, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. In other embodiments of the present application, the above-mentioned video encoding device may also include other units. In actual applications, these functions can also be assisted by other units, and can be assisted by multiple units.
[0136] According to another embodiment of the present application, a program that can execute the following operations can be executed on a general communication device such as the above-mentioned computer device, which includes a central processing unit (CPU), a random access memory (RAM), a read-only memory (ROM), and other processing elements and storage elements. Figure 2 and Figure 3 A computer program (including program code) for each step of the method shown is used to construct Figure 6 The video encoding device shown in the figure and the video encoding method according to the embodiment of the present application are used to implement the video encoding method according to the embodiment of the present application. The computer program can be recorded on a computer storage medium, for example, and loaded into the above-mentioned computer device through the computer storage medium and run therein.
[0137] In an embodiment of the present application, for image frames with higher encoding quality requirements, the video encoding device selects more reference frames when encoding the image frames. This allows the video encoding device to determine a target reference frame that has a higher degree of match with the image frame during encoding based on the selected reference frames, thereby making the image information retained in the encoded data obtained by encoding based on the target reference frame more comprehensive and realistic, thereby ensuring the encoding quality of the image frame. Furthermore, the video encoding device uses image frames with high encoding quality as candidate reference frames for more unencoded image frames. This increases the likelihood that the video encoding device will reference image frames with high encoding quality when encoding the unencoded image frames, thereby ensuring a certain level of quality in the encoding results of the unencoded image frames. In addition, for image frames with lower encoding quality requirements, the video encoding device selects fewer reference frames when encoding the image frames, thereby reducing the time consumed in encoding the image frames, allowing the image frames to be encoded quickly, and thus, to a certain extent, ensuring the efficiency of the video encoding device in encoding the target video.
[0138] Based on the above descriptions of the method embodiment and the apparatus embodiment, the present application also provides a computer device. Figure 7. The computer device includes at least a processor 701 and a computer storage medium 702, and the processor 701 and the computer storage medium 702 are connected via a bus or other means. Among them, the computer storage medium 702 mentioned above is a memory device in the computer device, which is used to store programs and data. It can be understood that the computer storage medium 702 here can include both the built-in storage medium in the computer device and, of course, the extended storage medium supported by the computer device. The computer storage medium 702 provides a storage space, which stores the operating system of the computer device. In addition, one or more computer programs suitable for being loaded and executed by the processor 701 are also stored in the storage space. These computer programs can be one or more program codes. It should be noted that the computer storage medium here can be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as at least one disk storage; optionally, it can also be at least one storage medium located away from the aforementioned processor. The processor 701 (also called CPU (Central Processing Unit)) is the computing core and control core of the computer device, which is suitable for implementing one or more computer programs, specifically suitable for loading and executing one or more computer programs to implement corresponding method processes or corresponding functions.
[0139] In one embodiment, the processor 701 may load and execute one or more computer programs stored in the computer storage medium 702 to implement the above-mentioned Figure 2 as well as Figure 3 Corresponding method steps in the method embodiment shown. In a specific implementation, one or more computer programs in the computer storage medium 702 can be loaded by the processor 701 and execute the following steps:
[0140] Acquire a target video, where the target video includes at least a first image frame and a second image frame, and a required encoding quality level of the first image frame is higher than a required encoding quality level of the second image frame;
[0141] determining a first number of reference frames for the first image frame and a second number of reference frames for the second image frame from the target video, the first number being greater than the second number;
[0142] performing encoding processing on the first image frame based on the first number of reference frames, and performing encoding processing on the second image frame based on the second number of reference frames;
[0143] using the first image frame as a candidate reference frame for a third number of image frames in the target video, and encoding the third number of image frames based on the first image frame;
[0144] The second image frame is used as a candidate reference frame for a fourth number of image frames in the target video, and encoding processing is performed on the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
[0145] In one embodiment, the processor 701 may further be configured to load and execute:
[0146] According to the correspondence between the preset coding quality requirement level and the number of reference frames, the number of reference frames corresponding to the coding quality requirement level of the first image frame is used as the first number, and the number of reference frames corresponding to the coding quality requirement level of the second image frame is used as the second number.
[0147] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0148] determining the first number according to a preset reference number and a required encoding quality level of the first image frame;
[0149] Determining the second number according to the preset reference number and the required encoding quality level of the second image frame;
[0150] The first quantity and the second quantity are both positively correlated with the coding quality requirement level.
[0151] In yet another embodiment, when the processor 701 is configured to load and execute the process of determining any one of the first quantity and the second quantity, the processor 701 may further be configured to load and execute:
[0152] Obtaining a coding quality requirement level corresponding to the preset reference quantity;
[0153] Determine a level difference between a required encoding quality level of the image frames corresponding to any number and a required encoding quality level corresponding to the preset reference number;
[0154] The arbitrary quantity is determined according to the level difference and the preset reference quantity.
[0155] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0156] Determine a difference between the required encoding quality level of the image frames corresponding to any number and the required encoding quality level corresponding to the preset reference number;
[0157] The determining of any quantity according to the level difference and the preset reference quantity includes:
[0158] The arbitrary quantity is determined according to the difference, the first step length and the preset reference quantity.
[0159] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0160] Determine a ratio between the required encoding quality levels of the image frames corresponding to any number and the required encoding quality levels corresponding to the preset reference number;
[0161] The determining of any quantity according to the level difference and the preset reference quantity includes:
[0162] The arbitrary quantity is determined according to the ratio, the second step length and the preset reference quantity.
[0163] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0164] determining a coding reference relationship between the first image frame and the second image frame;
[0165] When the encoding reference relationship indicates that the candidate reference frames of the second image frame include the first image frame, and the candidate reference frames of the first image frame do not include the second image frame, it is determined that the encoding quality requirement level of the first image frame is higher than the encoding quality requirement level of the second image frame.
[0166] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0167] Performing temporal layering processing on image frames included in the target video according to a preset temporal reference structure to obtain temporal layer identifiers of the first image frame and the second image frame, wherein the temporal layer identifiers are used to indicate a coding order of corresponding image frames;
[0168] When the coding order indicated by the time domain layer identifier of the first image frame is before the coding order indicated by the time domain layer identifier of the second image frame, it is determined that the coding reference relationship indicates that the candidate reference frames of the second image frame include the first image frame, and the candidate reference frames of the first image frame do not include the second image frame.
[0169] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0170] When the coding reference relationship indicates that the candidate reference frames for the second image frame include the first image frame, and the candidate reference frames for the first image frame include the second image frame, determining that the required coding quality level of the first image frame is equal to the required coding quality level of the second image frame;
[0171] From the target video, the same number of reference frames is determined for the first image frame and the second image frame, and encoding processing is performed on the corresponding image frames based on the determined reference frames.
[0172] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0173] Segmenting the target video to obtain at least one coded image group, where each coded image group includes at least a first image frame and a second image frame;
[0174] Traverse the at least one coded image group, encode the first image frame in the currently traversed coded image group based on the first number of reference frames, and encode the second image frame in the currently traversed coded image group based on the second number of reference frames.
[0175] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0176] Performing quality evaluation on the first image frame and the second image frame respectively to obtain image quality of the first image frame and image quality of the second image frame;
[0177] If the image quality of the first image frame is higher than the image quality of the second image frame, it is determined that the encoding quality requirement level of the first image frame is higher than the encoding quality requirement level of the second image frame.
[0178] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0179] Determining, from the target video, at least one candidate reference frame whose encoding quality requirement level is lower than or equal to the encoding quality requirement level of any image frame;
[0180] Selecting a target number of candidate reference frames from the at least one candidate reference frame as reference frames for any one of the image frames;
[0181] When any one of the image frames is the first image frame, the target number is the first number; and when any one of the image frames is the second image frame, the target number is the second number.
[0182] In yet another embodiment, the processor 701 may further be configured to load and execute:
[0183] Allocating a first encoding rate to the first image frame and allocating a second encoding rate to the second image frame, wherein the first encoding rate is greater than or equal to the second encoding rate;
[0184] The encoding process of the first image frame based on the first number of reference frames, and the encoding process of the second image frame based on the second number of reference frames, includes:
[0185] encoding the first image frame based on the first number of reference frames using the first encoding rate;
[0186] The second image frame is encoded based on the second number of reference frames using the second encoding rate.
[0187] In an embodiment of the present application, for image frames with higher encoding quality requirements, more reference frames are selected for the image frames during video encoding. This allows the computer device to determine a target reference frame that has a higher degree of match with the image frame during encoding based on the selected reference frames, thereby making the image information retained in the encoded data obtained by encoding based on the target reference frame more comprehensive and realistic, thereby ensuring the encoding quality of the image frame. Furthermore, the computer device uses image frames with high encoding quality as candidate reference frames for more unencoded image frames. This makes it more likely that the computer device will refer to image frames with high encoding quality when encoding the unencoded image frames, thereby ensuring a certain quality of the encoding results of the unencoded image frames. In addition, for image frames with lower encoding quality requirements, the computer device selects fewer reference frames for the image frames during video encoding, thereby reducing the time consumed during encoding processing for the image frames, allowing the image frames to complete encoding processing quickly, thereby ensuring the efficiency of the computer device in encoding the target video to a certain extent.
[0188] This application also provides a storage medium storing one or more computer programs corresponding to the above-described video encoding method. When a processor loads and executes the one or more computer programs, the video encoding method described in the embodiments can be implemented, which is not further described here. The description of the beneficial effects of using the same method is not further described here. It is understood that the computer program can be deployed and executed on one or more devices capable of communicating with each other.
[0189] It should be noted that, according to one aspect of the embodiments of the present application, a program product is also provided, the program product including a computer program, the computer program being stored in a computer storage medium. A processor in a computer device reads the computer program from the computer storage medium and then executes the computer program, thereby enabling the computer device to perform the above-mentioned Figure 2 as well as Figure 3 The video encoding method shown in the embodiment is provided in various optional aspects.
[0190] Those skilled in the art will appreciate that all or part of the processes in the above-described embodiment can be implemented by instructing related hardware through a computer program. The computer program can be stored in a computer storage medium. When executed, the computer program can include the processes in the above-described embodiment of the video encoding method. The computer storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0191] It is understandable that what is disclosed above is only a partial embodiment of the present application, and it certainly cannot be used to limit the scope of rights of the present application. A person skilled in the art can understand that all or part of the processes of the above embodiments and equivalent changes made in accordance with the claims of the present application are still within the scope covered by the present application.
Claims
1. A video encoding method, characterized in that: include: Acquire a target video, where the target video includes at least a first image frame and a second image frame, and a required encoding quality level of the first image frame is higher than a required encoding quality level of the second image frame; determining a first number of reference frames for the first image frame and a second number of reference frames for the second image frame from the target video, the first number being greater than the second number; performing encoding processing on the first image frame based on the first number of reference frames, and performing encoding processing on the second image frame based on the second number of reference frames; using the first image frame as a candidate reference frame for a third number of image frames in the target video, and encoding the third number of image frames based on the first image frame; The second image frame is used as a candidate reference frame for a fourth number of image frames in the target video, and encoding processing is performed on the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
2. The method according to claim 1, characterized in that The method further comprises: According to the correspondence between the preset coding quality requirement level and the number of reference frames, the number of reference frames corresponding to the coding quality requirement level of the first image frame is used as the first number, and the number of reference frames corresponding to the coding quality requirement level of the second image frame is used as the second number.
3. The method according to claim 1, characterized in that The method further comprises: determining the first number according to a preset reference number and a required encoding quality level of the first image frame; Determining the second number according to the preset reference number and the required encoding quality level of the second image frame; The first quantity and the second quantity are both positively correlated with the coding quality requirement level.
4. The method according to claim 3, characterized in that A method for determining any one of the first quantity and the second quantity includes: Obtaining a coding quality requirement level corresponding to the preset reference quantity; Determine a level difference between a required encoding quality level of the image frames corresponding to any number and a required encoding quality level corresponding to the preset reference number; The arbitrary quantity is determined according to the level difference and the preset reference quantity.
5. The method according to claim 4, characterized in that The determining of a difference between the required encoding quality level of the image frames corresponding to any number and the required encoding quality level corresponding to the preset reference number includes: Determine a difference between the required encoding quality level of the image frames corresponding to any number and the required encoding quality level corresponding to the preset reference number; The determining of any quantity according to the level difference and the preset reference quantity includes: The arbitrary quantity is determined according to the difference, the first step length and the preset reference quantity.
6. The method according to claim 4, characterized in that The determining of a difference between the required encoding quality level of the image frames corresponding to any number and the required encoding quality level corresponding to the preset reference number includes: Determine a ratio between the required encoding quality levels of the image frames corresponding to any number and the required encoding quality levels corresponding to the preset reference number; The determining of any quantity according to the level difference and the preset reference quantity includes: The arbitrary quantity is determined according to the ratio, the second step length and the preset reference quantity.
7. The method according to claim 1, characterized in that The method further comprises: determining a coding reference relationship between the first image frame and the second image frame; When the encoding reference relationship indicates that the candidate reference frames of the second image frame include the first image frame, and the candidate reference frames of the first image frame do not include the second image frame, it is determined that the encoding quality requirement of the first image frame is higher than the encoding quality requirement of the second image frame.
8. The method according to claim 7, characterized in that The determining of the coding reference relationship between the first image frame and the second image frame includes: Performing temporal layering processing on image frames included in the target video according to a preset temporal reference structure to obtain temporal layer identifiers of the first image frame and the second image frame, wherein the temporal layer identifiers are used to indicate a coding order of corresponding image frames; When the coding order indicated by the time domain layer identifier of the first image frame is before the coding order indicated by the time domain layer identifier of the second image frame, it is determined that the coding reference relationship indicates that the candidate reference frames of the second image frame include the first image frame, and the candidate reference frames of the first image frame do not include the second image frame.
9. The method according to claim 7 or 8, characterized in that The method further comprises: When the coding reference relationship indicates that the candidate reference frames for the second image frame include the first image frame, and the candidate reference frames for the first image frame include the second image frame, determining that the coding quality requirement of the first image frame is equal to the coding quality requirement of the second image frame; From the target video, the same number of reference frames is determined for the first image frame and the second image frame, and encoding processing is performed on the corresponding image frames based on the determined reference frames.
10. The method according to claim 1, characterized in that The method further comprises: Segmenting the target video to obtain at least one coded image group, where each coded image group includes at least a first image frame and a second image frame; Traverse the at least one coded image group, encode the first image frame in the currently traversed coded image group based on the first number of reference frames, and encode the second image frame in the currently traversed coded image group based on the second number of reference frames.
11. The method according to claim 1, wherein The method further comprises: Performing quality evaluation on the first image frame and the second image frame respectively to obtain image quality of the first image frame and image quality of the second image frame; If the image quality of the first image frame is higher than the image quality of the second image frame, it is determined that the encoding quality requirement of the first image frame is higher than the encoding quality requirement of the second image frame.
12. The method according to claim 1, characterized in that For any one of the first image frame and the second image frame, a method of determining a reference frame for the any one of the image frame includes: Determining, from the target video, at least one candidate reference frame having a coding quality requirement lower than or equal to a coding quality requirement of any image frame; Selecting a target number of candidate reference frames from the at least one candidate reference frame as reference frames for any one of the image frames; When any one of the image frames is the first image frame, the target number is the first number; and when any one of the image frames is the second image frame, the target number is the second number.
13. The method according to claim 1, wherein The method further comprises: Allocating a first encoding rate to the first image frame and allocating a second encoding rate to the second image frame, wherein the first encoding rate is greater than or equal to the second encoding rate; The encoding process of the first image frame based on the first number of reference frames, and the encoding process of the second image frame based on the second number of reference frames, includes: encoding the first image frame based on the first number of reference frames using the first encoding rate; The second image frame is encoded based on the second number of reference frames using the second encoding rate.
14. A video encoding device, characterized in that: include: an acquiring unit, configured to acquire a target video, the target video comprising at least a first image frame and a second image frame, wherein a required encoding quality level of the first image frame is higher than a required encoding quality level of the second image frame; a determining unit, configured to determine a first number of reference frames for the first image frame and a second number of reference frames for the second image frame from the target video, wherein the first number is greater than the second number; an encoding unit, configured to perform encoding processing on the first image frame based on the first number of reference frames, and to perform encoding processing on the second image frame based on the second number of reference frames; a processing unit, configured to use the first image frame as a candidate reference frame for a third number of image frames in the target video, and perform encoding processing on the third number of image frames based on the first image frame; The processing unit is further configured to use the second image frame as a candidate reference frame for a fourth number of image frames in the target video, and to perform encoding processing on the fourth number of image frames based on the second image frame; wherein the third number is greater than the fourth number.
15. A computer device, characterized in that: include: a processor configured to execute one or more computer programs; A computer storage medium storing one or more computer programs, wherein the one or more computer programs are suitable for being loaded by the processor and implementing the video encoding method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Video coding method, device, storage medium and electronic equipment
CN113891090A
Reference frame selection method and device, equipment and medium
CN114286089A