Video encoding method and device, electronic device and storage medium
By dividing image groups of different lengths according to the image complexity of the video frame and determining the encoding reference relationship, the problem that the fixed-length MiniGOP in the existing technology cannot adapt to dynamic scenes is solved, and the video encoding quality and efficiency are improved.
Patent Information
- Application Number
- CN202410693545.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-05-31
AI Technical Summary
The use of fixed-length MiniGOPs in existing video coding technology results in the video encoder being unable to adapt to dynamic scene changes, resulting in reduced compression rates and reduced image quality.
By determining the image complexity of the video frame to be encoded, it is divided into first image groups that support different lengths, and the encoding reference relationship is flexibly determined according to the length of each image group to adapt to dynamic scene changes.
It improves the quality of video encoding images, enhances the adaptability to dynamic scene changes, and improves video encoding efficiency.
Smart Images

Figure CN118264798B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a video encoding method and device, an electronic device, and a storage medium. Background Art
[0002] Video is composed of a series of time-continuous video frame images. During the video encoding and compression process, the video will first be divided into several small groups of pictures (Group of Pictures, GOP). In each GOP, according to the relationship between P frames and B frames, a series of MiniGOPs are formed with P frames as the boundary. In the current mainstream video encoding technology, a fixed-length MiniGOP is usually used for encoding. When a fixed-length MiniGOP is used for encoding, the video frames to be encoded will use a fixed encoding reference relationship, which will cause the video encoder to be unable to adapt to dynamic scene changes, reduce video compression rate, and degrade image quality. Summary of the invention
[0003] The present disclosure proposes a technical solution of a video encoding method and device, an electronic device and a storage medium.
[0004] According to one aspect of the present disclosure, a video encoding method is provided, comprising: determining the image complexity of each video frame to be encoded among a plurality of video frames to be encoded; dividing the plurality of video frames to be encoded into a plurality of first image groups according to the image complexity of each video frame to be encoded, wherein the number of video frames to be encoded included in each first image group is used to indicate the length of the first image group, and different first image groups support different lengths; determining the encoding reference relationship of the plurality of video frames to be encoded according to the length of each first image group; and performing video encoding on the plurality of video frames to be encoded according to the encoding reference relationship of the plurality of video frames to be encoded.
[0005] In a possible implementation, determining the image complexity of each of the multiple video frames to be encoded includes: for any one of the video frames to be encoded, determining the SATD cost corresponding to the video frame to be encoded; and performing weighted processing on the SATD cost, image resolution, and image bit depth corresponding to the video frame to be encoded to obtain the image complexity of the video frame to be encoded.
[0006] In one possible implementation, determining the SATD cost corresponding to the video frame to be encoded includes: downsampling the video frame to be encoded to obtain a downsampled image corresponding to the video frame to be encoded; dividing the downsampled image into multiple image blocks based on a preset size, and determining the SATD cost corresponding to each image block; summing the SATD costs corresponding to the multiple image blocks to determine the SATD cost corresponding to the video frame to be encoded.
[0007] In a possible implementation, the method divides the multiple video frames to be encoded into multiple first image groups according to the image complexity of each video frame to be encoded, including: determining a sequence to be processed based on the ungrouped video frames to be encoded in the multiple video frames to be encoded; performing grouping processing on the sequence to be processed to obtain the first image group; and determining that the grouping is completed in response to the absence of ungrouped video frames to be encoded in the multiple video frames to be encoded; wherein the grouping processing includes: determining a target video frame to be encoded in the sequence to be processed, wherein the target video frame to be encoded is the video frame to be encoded with the highest image complexity in the sequence to be processed, and the sequence number of the target video frame to be encoded in the sequence to be processed is F, and F is a positive integer greater than or equal to 1; obtaining a corresponding first image group based on the target video frame to be encoded, wherein the length of the first image group is F, including the 1st to Fth video frames to be encoded in the sequence to be processed, the Fth video frame to be encoded is a P frame, and the 1st to F-1st video frames to be encoded are B frames.
[0008] In a possible implementation, the determining of the coding reference relationship of the multiple video frames to be encoded based on the length of each first image group includes: for the current first image group to be encoded, determining at least two reference frames corresponding to the P frames in the current first image group to be encoded based on the length of the current first image group to be encoded and the length of at least one encoded first image group before the current first image group to be encoded; and determining a referenceable B frame in the current first image group to be encoded that can be used as a reference frame based on the number of B frames in the current first image group to be encoded, wherein the referenceable B frame and other B frames in the current first image group to be encoded other than the referenceable B frame have a coding reference relationship.
[0009] In a possible implementation, a P frame in the current first image group to be encoded corresponds to two reference frames; the determining, according to the length of the current first image group to be encoded and the length of at least one encoded first image group before the current first image group to be encoded, at least two reference frames corresponding to the P frame in the current first image group to be encoded includes: the POC of the first reference frame corresponding to the P frame in the current first image group to be encoded is -1×F c , where F c is the length of the first picture group to be encoded; the POC of the second reference frame corresponding to the P frame in the first picture group to be encoded is -1×(F c +F p ), where F p The length of the previous encoded first picture group adjacent to the current first picture group to be encoded.
[0010] In a possible implementation, the first image group to be encoded currently includes M B frames, where M is a positive integer greater than or equal to 1; and determining the reference B frame in the first image group to be encoded currently that can be used as a reference frame according to the number of B frames in the first image group to be encoded currently includes: when M is an odd number, B frames are determined as reference B frames; when M is an even number, the first B frame in the current first image group to be encoded is B frames are determined as reference B frames.
[0011] According to one aspect of the present disclosure, a video encoding device is provided, including: an image complexity determination module, used to determine the image complexity of each video frame to be encoded in a plurality of video frames to be encoded; an image group division module, used to divide the plurality of video frames to be encoded into a plurality of first image groups according to the image complexity of each video frame to be encoded, wherein the number of video frames to be encoded included in each first image group is used to indicate the length of the first image group, and different first image groups support different lengths; a reference relationship determination module, used to determine the encoding reference relationship of the plurality of video frames to be encoded according to the length of each first image group; and an encoding module, used to perform video encoding on the plurality of video frames to be encoded according to the encoding reference relationship of the plurality of video frames to be encoded.
[0012] According to one aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to call the instructions stored in the memory to execute the above method.
[0013] According to one aspect of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor.
[0014] In an embodiment of the present disclosure, the image complexity of each video frame to be encoded in a plurality of video frames to be encoded is determined. Since the change in image complexity of different video frames to be encoded can reflect the dynamic change of the video scene to a certain extent, therefore, according to the image complexity of each video frame to be encoded, the plurality of video frames to be encoded can be flexibly divided into a plurality of first image groups supporting different lengths to adapt to various dynamically changing video scenes. Furthermore, since the plurality of first image groups support different lengths, the encoding reference relationship of the plurality of video frames to be encoded can be flexibly determined according to the length of each first image group, so that video encoding of the plurality of video frames to be encoded can be performed according to the encoding reference relationship of the plurality of video frames to be encoded, which can effectively improve the video encoding image quality.
[0015] It should be understood that the above general description and the following detailed description are exemplary and explanatory only and do not limit the present disclosure. Other features and aspects of the present disclosure will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used to illustrate the technical solutions of the present disclosure together with the specification.
[0017] Figure 1 A flowchart of a video encoding method according to an embodiment of the present disclosure is shown.
[0018] Figure 2 A schematic diagram of determining a coding reference relationship according to an embodiment of the present disclosure is shown.
[0019] Figure 3 A block diagram of a video encoding device according to an embodiment of the present disclosure is shown.
[0020] Figure 4 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0021] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.
[0022] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.
[0023] The term "and / or" herein is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can represent including any one or more elements selected from the set consisting of A, B, and C.
[0024] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.
[0025] Video is composed of a series of time-continuous video frame images. During the video encoding and compression process, the video will first be divided into several small groups of pictures (Group of Pictures, GOP). In each GOP, according to the relationship between P frames and B frames, a series of MiniGOPs are formed with P frames as the boundary. In the current mainstream video encoding technology, a fixed-length MiniGOP is usually used for encoding. When a fixed-length MiniGOP is used for encoding, the video frames to be encoded will use a fixed encoding reference relationship, which will cause the video encoder to be unable to adapt to dynamic scene changes, reduce video compression rate, and degrade image quality.
[0026] The disclosed embodiment provides a video encoding method, which is mainly used for dividing a video frame in a GOP into MiniGOPs, and determining an application scenario of an encoding reference relationship of a video frame to be encoded, and by adaptively determining multiple MiniGOPs with different lengths, the encoding reference relationship of the video frame to be encoded can be flexibly determined to adapt to various dynamically changing video scenes, and effectively improve the quality of video encoding images. The video encoding method of the disclosed embodiment is described in detail below.
[0027] Figure 1 A flowchart of a video encoding method according to an embodiment of the present disclosure is shown. The method can be executed by an electronic device such as a terminal device or a server. The terminal device can be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The method can be implemented by a processor calling a computer-readable instruction stored in a memory. Alternatively, the method can be executed by a server. Figure 1 As shown, the method includes:
[0028] In step S11 , the image complexity of each to-be-encoded video frame among a plurality of to-be-encoded video frames is determined.
[0029] The multiple video frames to be encoded here may be multiple original video frame images of undetermined frame types (I frame, P frame, B frame). For example, the multiple video frames to be encoded are original YUV video frame images that have not been compressed.
[0030] The process of determining the image complexity of each to-be-encoded video frame will be described in detail later in conjunction with possible implementations of the present disclosure, and will not be elaborated here.
[0031] In step S12, multiple video frames to be encoded are divided into multiple first image groups according to the image complexity of each video frame to be encoded, wherein the number of video frames to be encoded included in each first image group is used to indicate the length of the first image group, and different first image groups support different lengths.
[0032] The first group of images here may be a MiniGOP in a video coding scenario.
[0033] Since the image complexity of different video frames to be encoded can reflect the dynamic changes of video scenes to a certain extent, multiple video frames to be encoded can be flexibly divided into multiple first image groups (MiniGOPs) with different lengths according to the image complexity of each video frame to be encoded to adapt to various dynamically changing video scenes.
[0034] The following text will describe in detail the process of dividing multiple video frames to be encoded into multiple first image groups (MiniGOPs) according to the image complexity of each video frame to be encoded according to possible implementation methods of the present disclosure, which will not be repeated here.
[0035] In step S13, the encoding reference relationship of the plurality of to-be-encoded video frames is determined according to the length of each first group of images.
[0036] Since the multiple first image groups (MiniGOPs) support different lengths, the encoding reference relationship of the multiple to-be-encoded video frames can be flexibly determined according to the length of each first image group (MiniGOP).
[0037] For any video frame to be encoded, the encoding reference relationship of the video frame to be encoded refers to the encoded video frame that needs to be referenced when encoding the video frame to be encoded.
[0038] The process of determining the encoding reference relationship of multiple to-be-encoded video frames according to the length of each first image group (MiniGOP) will be described in detail later in conjunction with possible implementation methods of the present disclosure, and will not be elaborated here.
[0039] In step S14, video encoding is performed on the multiple video frames to be encoded according to the encoding reference relationship of the multiple video frames to be encoded.
[0040] After determining the coding reference relationship of multiple video frames to be coded, the multiple video frames to be coded can be coded according to the coding reference relationship to obtain the coding result of each video frame to be coded. The specific coding process can refer to the relevant video coding technology, which is not specifically limited in this disclosure.
[0041] In an embodiment of the present disclosure, the image complexity of each video frame to be encoded among multiple video frames to be encoded is determined. Since the change in image complexity of different video frames to be encoded can reflect the dynamic changes of the video scene to a certain extent, therefore, according to the image complexity of each video frame to be encoded, the multiple video frames to be encoded can be flexibly divided into multiple first image groups (MiniGOPs) with different lengths to adapt to various dynamically changing video scenes. Furthermore, since the multiple first image groups (MiniGOPs) support different lengths, the encoding reference relationship of the multiple video frames to be encoded can be flexibly determined according to the length of each first image group (MiniGOP), so that the video encoding of the multiple video frames to be encoded is performed according to the encoding reference relationship of the multiple video frames to be encoded, which can effectively improve the video encoding image quality.
[0042] In a possible implementation, the image complexity of each of a plurality of video frames to be encoded is determined, including: for any video frame to be encoded, determining a sum of absolute transformed differences (SATD) cost corresponding to the video frame to be encoded; and weighted processing is performed on the SATD cost, image resolution, and image bit depth corresponding to the video frame to be encoded to obtain the image complexity of the video frame to be encoded.
[0043] SATD cost can be used to measure the difference between image blocks. A higher SATD cost usually means a larger difference between image blocks. Therefore, the SATD cost corresponding to the image can be used as an indicator to measure the complexity of the image.
[0044] In one possible implementation, determining the SATD cost corresponding to a video frame to be encoded includes: downsampling the video frame to be encoded to obtain a downsampled image corresponding to the video frame to be encoded; dividing the downsampled image into multiple image blocks based on a preset size, and determining the SATD cost corresponding to each image block; summing the SATD costs corresponding to the multiple image blocks to determine the SATD cost corresponding to the video frame to be encoded.
[0045] In order to reduce the computational complexity, the video frame to be encoded can be downsampled to obtain a smaller downsampled image, and then the SATD cost is determined based on the smaller downsampled image. The specific process of downsampling can refer to the related image downsampling processing method, and the specific value of the downsampling multiple can be flexibly set according to the actual situation, and the present disclosure does not make specific limitations on this.
[0046] The downsampled image is divided into multiple image blocks based on the preset size to prepare for the subsequent determination of the SATD cost. The specific value of the preset size can be flexibly set according to actual conditions, and the present disclosure does not make specific restrictions on this. For example, the preset size is 8×8, and the downsampled image is divided into multiple image blocks of 8×8.
[0047] In one example, in order to reduce computational complexity, for any image block, the original brightness component of the image block may be extracted, and the SATD cost corresponding to the image block may be determined based only on the original brightness component of the image block.
[0048] For example, for any image block, the predicted brightness component corresponding to the image block is determined based on the motion estimation method; the original brightness component corresponding to the image block and the predicted brightness component are subtracted to obtain the brightness residual corresponding to the image block; the SATD cost is calculated for the brightness residual corresponding to the image block to obtain the SATD cost corresponding to the image block. The SATD cost calculation process can refer to the relevant technology, and the present disclosure does not make specific limitations on this.
[0049] For any video frame to be encoded, the sum of the SATD costs corresponding to each image block in the down-sampled image corresponding to the video frame to be encoded is determined as the SATD cost corresponding to the video frame to be encoded.
[0050] Image resolution refers to the number and arrangement of pixels in an image. Higher image resolution means more pixels and more detailed image content. Generally, high-resolution images contain more details and textures. Therefore, image resolution can be used as an indicator of image complexity.
[0051] Image bit depth determines the number of colors or gray levels that each pixel can represent. A higher bit depth means more colors or gray levels, which can represent more subtle image color differences or image brightness changes. Therefore, image bit depth can be used as an indicator to measure image complexity.
[0052] For any video frame to be encoded, the image resolution and the image bit depth are the image attributes of the video frame to be encoded, and can be directly obtained from the video frame to be encoded.
[0053] For any video frame to be encoded, the image complexity of the video frame to be encoded can be comprehensively determined using SATD cost, image resolution, and image bit depth. Furthermore, the changes in image complexity of different video frames to be encoded can effectively reflect the dynamic changes of the video scene.
[0054] For example, the image complexity of the video frame to be encoded can be determined using the following formula (1):
[0055] Image complexity = w1 × image resolution + w2 × image bit depth + w3 × SATD cost (1).
[0056] Among them, w1, w2, and w3 are weights with values greater than 0 and less than 1. The specific values of w1, w2, and w3 can be flexibly set according to actual conditions, and the present disclosure does not make specific limitations on this.
[0057] After the image complexity of each of the multiple video frames to be encoded is determined, the multiple video frames to be encoded may be divided into multiple first groups of pictures (MiniGOPs) according to the image complexity of each video frame to be encoded.
[0058] In a possible implementation, multiple video frames to be encoded are divided into multiple first image groups according to the image complexity of each video frame to be encoded, including: determining a sequence to be processed based on ungrouped video frames to be encoded in the multiple video frames to be encoded; performing grouping processing on the sequence to be processed to obtain a first image group; in response to the absence of ungrouped video frames to be encoded in the multiple video frames to be encoded, determining that the grouping is completed; wherein the grouping processing includes: determining a target video frame to be encoded in the sequence to be processed, wherein the target video frame to be encoded is a video frame to be encoded with the highest image complexity in the sequence to be processed, and the sequence number of the target video frame to be encoded in the sequence to be processed is F, and F is a positive integer greater than or equal to 1; obtaining a corresponding first image group based on the target video frame to be encoded, wherein the length of the first image group is F, including the 1st to Fth video frames to be encoded in the sequence to be processed, the Fth video frame to be encoded is a P frame, and the 1st to F-1st video frames to be encoded are B frames.
[0059] When multiple video frames to be encoded are in the same second group of pictures (GOP), the multiple video frames to be encoded are grouped, that is, the multiple video frames to be encoded in the second group of pictures (GOP) are divided into multiple first groups of pictures (MiniGOP).
[0060] Ungrouped video frames to be encoded among multiple video frames to be encoded are determined as a sequence to be processed. When the spatial complexity of a certain video frame to be encoded in the sequence to be processed is large, the video frame to be encoded can be determined as a P frame, and the video frame to be encoded before the P frame can be determined as a B frame. The P frame and the B frame before it constitute a first image group (MiniGOP).
[0061] For example, the multiple video frames to be encoded include time-continuous N=32 ungrouped video frames to be encoded, ie, the 1st to 32nd video frames to be encoded, and the 32 video frames to be encoded are in the same second group of pictures (GOP). First, the 1st to 32nd to-be-encoded video frames are determined as a sequence to be processed, and the sequence number F1=8 of the to-be-encoded video frame with the highest image complexity among the 32 to-be-encoded video frames in the sequence to be processed is determined; then, the F1=8th to-be-encoded video frame in the sequence to be processed is determined as a P frame, and the 1st to F1-1=7th to-be-encoded video frames in the sequence to be processed are determined as B frames, and the 1st to F1=8 to-be-encoded video frames in the sequence to be processed constitute a first image group (MiniGOP) with a length of F1=8; then, the 9th to 32nd to-be-encoded video frames that are not grouped among the 32 to-be-encoded video frames are determined as an updated sequence to be processed, and the sequence number F2 of the to-be-encoded video frame with the highest image complexity among the 24 to-be-encoded video frames in the sequence to be processed is determined in the sequence to be processed =4; then, the F2=4th video frame to be encoded in the sequence to be processed (the 12th video frame to be encoded in the 32 video frames to be encoded) is determined as a P frame, and the 1st to F2-1=3 video frames to be encoded in the sequence to be processed (the 9th to 11th video frames to be encoded in the 32 video frames to be encoded) are determined as B frames, and the 1st to F2=4 video frames to be encoded in the sequence to be processed (the 9th to 12th video frames to be encoded in the 32 video frames to be encoded) constitute a first image group (MiniGOP) with a length of F2=4; then, the ungrouped 13th to 32nd video frames to be encoded in the 32 video frames to be encoded are determined as the updated sequence to be processed, and the above operation is iteratively performed until there are no ungrouped video frames to be encoded in the 32 video frames to be encoded, and the grouping is completed.
[0062] Since the multiple video frames to be encoded are grouped based on the image complexity of each video frame to be encoded, the multiple video frames to be encoded can be flexibly divided into multiple first image groups (MiniGOPs) with different lengths to adapt to various dynamically changing video scenes.
[0063] In a possible implementation, a coding reference relationship of multiple video frames to be encoded is determined according to the length of each first image group, including: for a current first image group to be encoded, according to the length of the current first image group to be encoded and the length of at least one encoded first image group before the current first image group to be encoded, at least two reference frames corresponding to the P frames in the current first image group to be encoded are determined; according to the number of B frames in the current first image group to be encoded, a referenceable B frame in the current first image group to be encoded that can be used as a reference frame is determined, wherein the referenceable B frame has a coding reference relationship with other B frames other than the referenceable B frame in the current first image group to be encoded.
[0064] Since the lengths of different first groups of images (MiniGOPs) may be different, the coding reference relationship of the to-be-coded video frames can be flexibly mapped.
[0065] For the current first group of images to be encoded (MiniGOP), at least two reference frames corresponding to the P frame in the current first group of images to be encoded (MiniGOP) can be flexibly determined according to the length of the current first group of images to be encoded (MiniGOP) and the length of at least one encoded first group of images (MiniGOP) before the current first group of images to be encoded (MiniGOP). The total number of reference frames corresponding to a P frame to be encoded can be flexibly set according to the actual application scenario, and the present disclosure does not make specific restrictions on this.
[0066] Since the reference frame corresponding to the P frame to be encoded in the current first image group (MiniGOP) to be encoded needs to be a previously encoded P frame or I frame, after the aforementioned grouping, the last frame in each first image group (MiniGOP) is a P frame. Therefore, according to the length of the current first image group (MiniGOP) to be encoded and the length of at least one encoded first image group (MiniGOP) before the current first image group (MiniGOP) to be encoded, at least two reference frames corresponding to the P frame to be encoded in the current first image group (MiniGOP) to be encoded can be determined.
[0067] For the current first group of images to be encoded (MiniGOP), the referenceable B frames in the current first group of images to be encoded (MiniGOP) that can be used as reference frames can be determined according to the number of B frames to be encoded in the current first group of images to be encoded (MiniGOP). Among them, the referenceable B frames in a first group of images (MiniGOP) can be used as reference frames for other non-referenceable B frames in the first group of images (MiniGOP), and the number of referenceable B frames in a first group of images (MiniGOP) can be flexibly set according to actual scenarios, and the present disclosure does not make specific restrictions on this.
[0068] In a possible implementation, a P frame in a current first image group to be encoded corresponds to two reference frames; and according to a length of the current first image group to be encoded and a length of at least one encoded first image group before the current first image group to be encoded, determining at least two reference frames corresponding to the P frame in the current first image group to be encoded includes: a picture sequence number POC of a first reference frame corresponding to the P frame in the current first image group to be encoded is -1×F c , where F c is the length of the first picture group to be encoded; the POC of the second reference frame corresponding to the P frame in the first picture group to be encoded is -1×(F c +F p ), where F pThe length of the previous encoded first picture group adjacent to the current first picture group to be encoded.
[0069] The current first MiniGOP to be encoded is the i-th first MiniGOP, with a length of F c , the first picture group that has been encoded before the current first picture group to be encoded is the i-1th first picture group (MiniGOP), and its length is F p .
[0070] At this time, the first reference frame image sequence number corresponding to the P frame to be encoded in the i-th MiniGOP to be encoded is POC, which is -1×F c , which is the encoding result of the last video frame in the i-1 MiniGOP that has been encoded (encoded P frame / I frame); the second reference frame image sequence number corresponding to the P frame to be encoded in the i-th MiniGOP to be encoded is POC is -1×(F c +F p ), which is the encoding result of the last video frame in the i-2th MiniGOP (encoded P frame / I frame).
[0071] In the video encoding scenario, POC is the sequence number of natural images in the video, which can also be regarded as the playback sequence number of the video. In video encoding, the encoder will first encode the P frame after the B frame, resulting in a difference between the encoding order of the video frames and the actual video frame order in the video. Therefore, the sequence number of natural images in the video is indicated based on POC.
[0072] Figure 2 FIG. 2 is a schematic diagram showing a method for determining a coding reference relationship according to an embodiment of the present disclosure. Figure 2 As shown, the length of the first image group to be encoded (the i-th MiniGOP) is 4, and the length of the first image group to be encoded before the i-th MiniGOP to be encoded (the i-1th MiniGOP) is 8. The first reference frame image sequence number corresponding to the P frame to be encoded in the i-th MiniGOP to be encoded is POC-1×4, which is the encoding result of the last video frame in the i-1th MiniGOP that has been encoded (the encoded P frame / I frame); the second reference frame image sequence number corresponding to the P frame to be encoded in the i-th MiniGOP to be encoded is POC-1×(4+8), which is the encoding result of the last video frame in the i-2th MiniGOP that has been encoded (the encoded P frame / I frame).
[0073] In a possible implementation, the first image group to be encoded currently includes M B frames, where M is a positive integer greater than or equal to 1; according to the number of B frames in the first image group to be encoded currently, determining a reference B frame in the first image group to be encoded currently that can be used as a reference frame includes: when M is an odd number, B frames are determined as reference B frames; when M is an even number, the first B frame in the current first image group to be encoded is B frames are determined as reference B frames.
[0074] In the case that each first group of pictures (MiniGOP) includes only one reference B frame, an intermediate B frame among all B frames in each first group of pictures (MiniGOP) can be determined as a reference B frame. Therefore, in the case that the current first group of pictures (MiniGOP) to be encoded includes M B frames: if M is an odd number, the first B frame in the current first group of pictures (MiniGOP) to be encoded can be determined as a reference B frame. B frames are determined as reference B frames; if M is an even number, the first B frame in the current first group of images to be encoded (MiniGOP) can be B frames are determined as reference B frames.
[0075] like Figure 2 As shown in the figure, the i-th MiniGOP to be encoded currently includes three B frames B1, B2, and B3, that is, M=3 is an odd number. The first B frame (B2 frame) is determined as a reference B frame. That is, the B2 frame can be used as a reference frame for the B1 frame and the B3 frame.
[0076] In addition, combined with the conventional reference relationship in video coding, the reference frame corresponding to the P frame to be coded is the previously coded I frame / P frame, and the reference frame corresponding to the B frame to be coded is the coded I frame / P frame before and after it. Therefore, based on the coding reference relationship, the video frame to be coded is subjected to video coding.
[0077] against Figure 2The i-th MiniGOP to be encoded is shown in the encoding order: P frame, B2 frame, B1 frame, B3 frame. Among them, the reference frame of the P frame to be encoded at least includes the encoding result of the last video frame in the i-1th MiniGOP that has been encoded (encoded P frame / I frame), and the encoding result of the last video frame in the i-2th MiniGOP that has been encoded (encoded P frame / I frame). After the encoding of the P frame to be encoded is completed, the reference frame of the B2 frame to be encoded at least includes: the encoding result of the last video frame in the i-1th MiniGOP that has been encoded (encoded P frame / I frame), and the above-mentioned encoded P frame in the i-th MiniGOP to be encoded currently. After the encoding of the B2 frame to be encoded is completed, the reference frame of the B1 frame to be encoded at least includes: the encoding result of the last video frame in the i-1th MiniGOP that has been encoded (encoded P frame / I frame), and the above-mentioned encoded B2 frame in the i-th MiniGOP to be encoded currently. After the encoding of the B2 frame to be encoded is completed, the reference frames of the B3 frame to be encoded include at least: the encoded B2 frame in the i-th MiniGOP to be encoded and the encoded P frame in the i-th MiniGOP to be encoded. At this point, the video encoding of the i-th MiniGOP to be encoded is completed.
[0078] In an embodiment of the present disclosure, the image complexity of each video frame to be encoded in a plurality of video frames to be encoded is determined. Since the change in image complexity of different video frames to be encoded can reflect the dynamic change of the video scene to a certain extent, therefore, according to the image complexity of each video frame to be encoded, the plurality of video frames to be encoded can be flexibly divided into a plurality of first image groups supporting different lengths to adapt to various dynamically changing video scenes. Furthermore, since the plurality of first image groups support different lengths, the encoding reference relationship of the plurality of video frames to be encoded can be flexibly determined according to the length of each first image group, so that video encoding of the plurality of video frames to be encoded can be performed according to the encoding reference relationship of the plurality of video frames to be encoded, which can effectively improve the video encoding image quality.
[0079] It can be understood that the above-mentioned various method embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. It can be understood by those skilled in the art that in the above-mentioned method of the specific implementation method, the specific execution order of each step should be determined according to its function and possible internal logic.
[0080] In addition, the present disclosure also provides a video encoding device, an electronic device, a computer-readable storage medium, and a program, all of which can be used to implement any video encoding method provided by the present disclosure. The corresponding technical solutions and descriptions are referred to the corresponding records in the method part and will not be repeated here.
[0081] Figure 3FIG. 2 is a block diagram of a video encoding device according to an embodiment of the present disclosure. Figure 3 As shown, the device 30 includes:
[0082] An image complexity determination module 31, used to determine the image complexity of each to-be-encoded video frame among a plurality of to-be-encoded video frames;
[0083] The image group division module 32 is used to divide the multiple video frames to be encoded into multiple first image groups according to the image complexity of each video frame to be encoded, wherein the number of video frames to be encoded included in each first image group is used to indicate the length of the first image group, and different first image groups support different lengths;
[0084] A reference relationship determination module 33, used to determine the encoding reference relationship of multiple video frames to be encoded according to the length of each first image group;
[0085] The encoding module 34 is used to perform video encoding on multiple video frames to be encoded according to the encoding reference relationship of the video frames to be encoded.
[0086] In a possible implementation, the image complexity determination module 31 is specifically configured to:
[0087] For any video frame to be encoded, determine the SATD cost corresponding to the video frame to be encoded;
[0088] The SATD cost, image resolution, and image bit depth corresponding to the video frame to be encoded are weighted to obtain the image complexity of the video frame to be encoded.
[0089] In a possible implementation, the image complexity determination module 31 is specifically configured to:
[0090] Down-sampling the video frame to be encoded to obtain a down-sampled image corresponding to the video frame to be encoded;
[0091] Based on a preset size, the downsampled image is divided into a plurality of image blocks, and a SATD cost corresponding to each image block is determined;
[0092] The SATD costs corresponding to the multiple image blocks are summed to determine the SATD cost corresponding to the video frame to be encoded.
[0093] In a possible implementation, the image group division module 32 is specifically configured to:
[0094] Determining a sequence to be processed based on ungrouped video frames to be encoded among the plurality of video frames to be encoded;
[0095] Perform grouping processing on the sequence to be processed to obtain a first image group;
[0096] In response to the absence of ungrouped video frames to be encoded among the plurality of video frames to be encoded, determining that the grouping is completed;
[0097] The group processing includes:
[0098] Determine a target video frame to be encoded in the sequence to be processed, wherein the target video frame to be encoded is a video frame to be encoded with the highest image complexity in the sequence to be processed, and the sequence number of the target video frame to be encoded in the sequence to be processed is F, and F is a positive integer greater than or equal to 1;
[0099] A corresponding first image group is obtained based on the target video frame to be encoded, wherein the first image group has a length of F and includes the 1st to Fth video frames to be encoded in the sequence to be processed, the Fth video frame to be encoded is a P frame, and the 1st to F-1th video frames to be encoded are B frames.
[0100] In a possible implementation, the reference relationship determination module 33 is specifically configured to:
[0101] For a current first group of pictures to be encoded, determining at least two reference frames corresponding to a P frame in the current first group of pictures to be encoded according to a length of the current first group of pictures to be encoded and a length of at least one encoded first group of pictures before the current first group of pictures to be encoded;
[0102] According to the number of B frames in the first image group to be encoded, a reference B frame in the first image group to be encoded that can be used as a reference frame is determined, wherein the reference B frame and other B frames other than the reference B frame in the first image group to be encoded have a coding reference relationship.
[0103] In a possible implementation, a P frame in the first group of pictures to be encoded currently corresponds to two reference frames;
[0104] The reference relationship determination module 33 is specifically used to:
[0105] The POC of the first reference frame corresponding to the P frame in the first picture group to be encoded is -1×F c , where F c is the length of the first picture group to be encoded;
[0106] The POC of the second reference frame corresponding to the P frame in the first picture group to be encoded is -1×(F c +F p ), where F p The length of the previous encoded first picture group adjacent to the current first picture group to be encoded.
[0107] In a possible implementation, the first image group to be encoded currently includes M B frames, where M is a positive integer greater than or equal to 1;
[0108] The reference relationship determination module 33 is specifically used for:
[0109] When M is an odd number, the first picture group to be encoded is B frames are determined as reference B frames;
[0110] When M is an even number, the first picture group to be encoded is B frames are determined as reference B frames.
[0111] This method has a specific technical connection with the internal structure of the computer system, and can solve the technical problem of how to improve the hardware computing efficiency or execution effect (including reducing the amount of data storage, reducing the amount of data transmission, increasing the hardware processing speed, etc.), thereby obtaining the technical effect of improving the internal performance of the computer system in accordance with the laws of nature.
[0112] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0113] The embodiment of the present disclosure also provides a computer-readable storage medium on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor. The computer-readable storage medium can be a volatile or non-volatile computer-readable storage medium.
[0114] An embodiment of the present disclosure further proposes an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to call the instructions stored in the memory to execute the above method.
[0115] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above method.
[0116] The electronic device may be provided as a terminal, a server, or a device in other forms.
[0117] Figure 4 A block diagram of an electronic device according to an embodiment of the present disclosure is shown. Figure 4 , the electronic device 1900 can be provided as a server or a terminal device. Figure 4, the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.
[0118] The electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input / output interface 1958. The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as a Microsoft Server operating system (Windows Server 2003). TM ), Apple's graphical user interface operating system (Mac OS X TM ), a multi-user, multi-process computer operating system (Unix TM ), a free and open source Unix-like operating system (Linux TM ), an open source Unix-like operating system (FreeBSD TM ) or similar.
[0119] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.
[0120] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0121] Computer-readable storage media can be a tangible device that can hold and store instructions used by an instruction execution device. Computer-readable storage media can be, for example, (but not limited to) an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive lists) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a convex structure in a groove on which instructions are stored, and any suitable combination thereof. The computer-readable storage media used here is not interpreted as a transient signal itself, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagated by a waveguide or other transmission medium (for example, a light pulse by an optical fiber cable), or an electrical signal transmitted by a wire.
[0122] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0123] The computer program instructions for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The computer-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect through the Internet). In some embodiments, by using the state information of the computer-readable program instructions to personalize an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), the electronic circuit may execute the computer-readable program instructions, thereby implementing various aspects of the present disclosure.
[0124] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of boxes in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0125] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0126] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0127] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0128] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK) and the like.
[0129] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0130] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.
[0131] If the technical solution of this application involves personal information, the product using the technical solution of this application has clearly informed the personal information processing rules and obtained the individual's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using the technical solution of this application has obtained the individual's separate consent before processing the sensitive personal information, and at the same time meets the "explicit consent" requirement. For example, on personal information collection devices such as cameras, clear and prominent signs are set to inform that the personal information collection scope has been entered and personal information will be collected. If the individual voluntarily enters the collection scope, it is deemed that he or she agrees to the collection of his or her personal information; or on the device that processes personal information, the personal information processing rules are notified by obvious signs / information, and the individual's authorization is obtained through pop-up information or by asking the individual to upload his or her personal information; among them, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the type of personal information processed.
[0132] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A video encoding method, characterized in that: include: Determining the image complexity of each of the plurality of video frames to be encoded; According to the image complexity of each video frame to be encoded, the multiple video frames to be encoded are divided into multiple first image groups, wherein the number of video frames to be encoded included in each first image group is used to indicate the length of the first image group, different first image groups support different lengths, and the first image group is MiniGOP; Determining, according to the length of each first group of images, a coding reference relationship of the plurality of to-be-coded video frames; Video encoding is performed on the multiple video frames to be encoded according to the encoding reference relationship of the multiple video frames to be encoded.
2. The method according to claim 1, characterized in that The determining the image complexity of each to-be-encoded video frame among the multiple to-be-encoded video frames comprises: For any video frame to be encoded, determining a sum of absolute transform differences (SATD) cost corresponding to the video frame to be encoded; The SATD cost, image resolution, and image bit depth corresponding to the to-be-encoded video frame are weighted to obtain the image complexity of the to-be-encoded video frame.
3. The method according to claim 2, characterized in that The determining the SATD cost corresponding to the to-be-encoded video frame includes: Down-sampling the to-be-encoded video frame to obtain a down-sampled image corresponding to the to-be-encoded video frame; Based on a preset size, the downsampled image is divided into a plurality of image blocks, and a SATD cost corresponding to each image block is determined; The SATD costs corresponding to the multiple image blocks are summed to determine the SATD cost corresponding to the to-be-encoded video frame.
4. The method according to claim 1, characterized in that The step of dividing the plurality of video frames to be encoded into a plurality of first image groups according to the image complexity of each video frame to be encoded comprises: Determining a sequence to be processed based on ungrouped video frames to be encoded among the plurality of video frames to be encoded; performing grouping processing on the sequence to be processed to obtain the first image group; In response to the absence of ungrouped video frames to be encoded among the plurality of video frames to be encoded, determining that the grouping is completed; The grouping process includes: Determine a target video frame to be encoded in the sequence to be processed, wherein the target video frame to be encoded is a video frame to be encoded with the highest image complexity in the sequence to be processed, and the sequence number of the target video frame to be encoded in the sequence to be processed is F, and F is a positive integer greater than or equal to 1; A corresponding first image group is obtained based on the target video frame to be encoded, wherein the first image group has a length of F and includes the 1st to Fth video frames to be encoded in the sequence to be processed, the Fth video frame to be encoded is a P frame, and the 1st to F-1th video frames to be encoded are B frames.
5. The method according to claim 1, characterized in that The step of determining the coding reference relationship of the plurality of to-be-coded video frames according to the length of each first group of images includes: For a current first group of pictures to be encoded, determining at least two reference frames corresponding to a P frame in the current first group of pictures to be encoded according to a length of the current first group of pictures to be encoded and a length of at least one encoded first group of pictures before the current first group of pictures to be encoded; According to the number of B frames in the current first image group to be encoded, a reference B frame in the current first image group to be encoded that can be used as a reference frame is determined, wherein the reference B frame and other B frames other than the reference B frame in the current first image group to be encoded have a coding reference relationship.
6. The method according to claim 5, characterized in that The P frame in the first picture group to be encoded currently corresponds to two reference frames; The step of determining at least two reference frames corresponding to the P frame in the current first group of images to be encoded according to the length of the current first group of images to be encoded and the length of at least one encoded first group of images before the current first group of images to be encoded comprises: The picture sequence number POC of the first reference frame corresponding to the P frame in the first picture group to be encoded is -1×F c , where F c is the length of the first picture group to be encoded; The POC of the second reference frame corresponding to the P frame in the first picture group to be encoded is -1×(F c +F p ), where F p The length of the previous encoded first picture group adjacent to the current first picture group to be encoded.
7. The method according to claim 5, characterized in that The first image group to be encoded currently includes M B frames, where M is a positive integer greater than or equal to 1; The determining, according to the number of B frames in the first image group to be encoded, a referenceable B frame that can be used as a reference frame in the first image group to be encoded, comprises: When M is an odd number, the first picture group to be encoded is B frames are determined as reference B frames; When M is an even number, the first picture group to be encoded is B frames are determined as reference B frames.
8. A video encoding device, characterized in that: include: An image complexity determination module, used to determine the image complexity of each to-be-encoded video frame among a plurality of to-be-encoded video frames; A picture group division module, used for dividing the multiple video frames to be encoded into multiple first picture groups according to the image complexity of each video frame to be encoded, wherein the number of video frames to be encoded included in each first picture group is used to indicate the length of the first picture group, different first picture groups support different lengths, and the first picture group is MiniGOP; A reference relationship determination module, configured to determine the encoding reference relationship of the plurality of to-be-encoded video frames according to the length of each first image group; The encoding module is used to perform video encoding on the multiple video frames to be encoded according to the encoding reference relationship of the multiple video frames to be encoded.
9. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method described in any one of claims 1 to 7.
10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
