A method for switching inter-frame prediction mode and related device
By comparing the similarity between the video frame to be encoded and the encoded video frame, dynamically adjusting the inter-frame prediction mode of the video encoder, the problem of failing to adaptively switch long and short reference frame modes in the prior art is solved, and more efficient videos are achieved Coding effect.
Patent Information
- Application Number
- CN202311767044.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-21
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2043-12-21
AI Technical Summary
Existing video encoders fail to switch long reference frame modes and short reference frame modes adaptively, resulting in poor encoding.
By comparing the similarity between the video frame to be encoded and the encoded video frame, we judge whether the video frame to be encoded has changed screens, and dynamically adjust the inter-frame prediction mode of the video encoder according to the judgment results, and switch from the long reference frame mode to the short reference frame. mode, or switch from short reference frame mode to long reference frame mode.
Adaptive switching between long reference frame mode and short reference frame mode is realized, which improves the efficiency and quality of video encoding and adapts to the dynamic changes of video flow in different scenarios.
Smart Images

Figure CN117676153B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method for switching an inter-frame prediction mode and a related device. Background Art
[0002] The main responsibility of a video encoder is to compress the original video images collected in order to reduce the storage space or network transmission bandwidth occupied by the video code stream. The core task of encoding is to reduce the video bit rate as much as possible while ensuring the quality of the original image.
[0003] Modern video encoders all use block-based prediction methods to compress videos, such as H.264. Prediction methods are divided into intra-frame prediction and inter-frame prediction. Intra-frame prediction is to divide an image into multiple blocks. The prediction of each block is only based on the adjacent blocks in the reference image, and does not rely on other images when decoding. Inter-frame prediction is to select an image that best matches the current image to be encoded in the already encoded image as the reference image, the so-called reference frame. Reference frames are divided into long reference frames (LTRLong term reference) and short reference frames (STR Short term reference). Therefore, inter-frame prediction mode can be divided into long reference frame mode and short reference frame mode. Most video encoders only provide short reference frame mode implementation by default. For the long reference frame mode, the video encoder only provides an interface, and the specific use requires the interface caller to implement it.
[0004] Currently, video encoders only execute one of the long reference frame mode and the short reference frame mode separately, and do not implement image encoding by adaptively switching between the long reference frame mode and the short reference frame mode in response to different situations. Summary of the invention
[0005] The main purpose of the present invention is to provide a method, device, computer equipment and storage medium for switching inter-frame prediction modes, which can solve the problem in the prior art that long reference frame mode and short reference frame mode cannot be switched adaptively.
[0006] To achieve the above object, the first aspect of the present invention provides a method for switching an inter-frame prediction mode, the method comprising:
[0007] Acquire a currently captured video frame to be encoded, and compare the video frame to be encoded with a target video frame to determine whether a picture change occurs in the video frame to be encoded; wherein the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded;
[0008] The inter-frame prediction mode of the current video encoder is obtained, and based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder, it is determined whether to change the inter-frame prediction mode of the current video encoder.
[0009] In combination with the first aspect, in a possible implementation method, the above-mentioned determination whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder includes: if the inter-frame prediction mode of the current video encoder is a long reference frame mode, and the judgment result is that the to-be-encoded video frame has a picture change, then the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode; if the inter-frame prediction mode of the current video encoder is a short reference frame mode, and the judgment result is that the to-be-encoded video frame has a picture change, then the inter-frame prediction mode is maintained as the short reference frame mode.
[0010] In combination with the first aspect, in a possible implementation method, the above-mentioned determination of whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the picture change occurs in the video frame to be encoded and the inter-frame prediction mode of the current video encoder also includes: if the inter-frame prediction mode of the current video encoder is a long reference frame mode, and the judgment result is that the picture change does not occur in the video frame to be encoded, then the inter-frame prediction mode is maintained as the long reference frame mode; if the inter-frame prediction mode of the current video encoder is a short reference frame mode, and the judgment result is that the picture change does not occur in the video frame to be encoded, then the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode.
[0011] In combination with the first aspect, in a possible implementation method, the above-mentioned comparing the video frame to be encoded with the target video frame to determine whether the picture change occurs in the video frame to be encoded includes: respectively calculating the similarity between the target video frame and the video frame to be encoded to obtain a preset number of similarities; if the preset number of similarities are all less than a preset similarity threshold, determining that the picture change occurs in the video frame to be encoded; if the preset number of similarities are not all less than the preset similarity threshold, determining that the picture change does not occur in the video frame to be encoded.
[0012] In combination with the first aspect, in a possible implementation method, if the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the picture change occurs in the video frame to be encoded, the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode, including: if the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the picture change occurs in the video frame to be encoded, the short reference frame mode is entered with the previous encoded video frame of the video frame to be encoded as the short reference frame.
[0013] In combination with the first aspect, in a possible implementation, if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the video frame to be encoded has not undergone a picture change, the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode, including: if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the video frame to be encoded has not undergone a picture change, then obtaining the optimal video frame among the encoded video frames output by the current video encoder before the video frame to be encoded; wherein the optimal video frame is an encoded video frame whose quantization value does not reach a preset quantization threshold and whose time difference with the video frame to be encoded is the smallest; and entering the long reference frame mode with the optimal video frame as the long reference frame.
[0014] In combination with the first aspect, in a possible implementation manner, the obtaining of the best video frame among the encoded video frames output by the current video encoder before the video frame to be encoded includes:
[0015] Obtain the quantization value of the Q-th encoded video frame, determine whether the quantization value of the Q-th encoded video frame reaches a preset quantization threshold, and if the quantization value of the Q-th encoded video frame does not reach the preset quantization threshold, determine the Q-th encoded video frame as the optimal video frame; wherein Q is the total number of encoded video frames output by the current video encoder before the video frame to be encoded; if the quantization value of the Q-th encoded video frame reaches the preset quantization threshold, set Q=Q-1, and return to the step of obtaining the quantization value of the Q-th encoded video frame and determining whether the quantization value of the Q-th encoded video frame reaches the preset quantization threshold.
[0016] To achieve the above object, the second aspect of the present invention provides a switching device for an inter-frame prediction mode, the device comprising:
[0017] A scene judgment module is used to obtain the currently acquired video frame to be encoded, and compare the video frame to be encoded with the target video frame to determine whether the video frame to be encoded has a picture change; wherein the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded;
[0018] Mode switching module: used to obtain the inter-frame prediction mode of the current video encoder, and determine whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder.
[0019] To achieve the above object, the third aspect of the present invention provides a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor performs the following steps:
[0020] Acquire a currently captured video frame to be encoded, and compare the video frame to be encoded with a target video frame to determine whether a picture change occurs in the video frame to be encoded; wherein the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded;
[0021] The inter-frame prediction mode of the current video encoder is obtained, and based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder, it is determined whether to change the inter-frame prediction mode of the current video encoder.
[0022] To achieve the above object, a fourth aspect of the present invention provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the following steps:
[0023] Acquire a currently captured video frame to be encoded, and compare the video frame to be encoded with a target video frame to determine whether a picture change occurs in the video frame to be encoded; wherein the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded;
[0024] The inter-frame prediction mode of the current video encoder is obtained, and based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder, it is determined whether to change the inter-frame prediction mode of the current video encoder.
[0025] The embodiments of the present invention have the following beneficial effects:
[0026] The present invention provides a method for switching an inter-frame prediction mode, by comparing a video frame to be encoded with an encoded video frame, judging whether a picture change occurs in the video frame to be encoded, obtaining an inter-frame prediction mode of a current video encoder, and determining whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether a picture change occurs in the video frame to be encoded and the inter-frame prediction mode of the current video encoder. The present invention adaptively adjusts the inter-frame prediction mode of a video encoder by judging whether a picture change occurs in the video frame to be encoded, and can realize automatic switching between a long reference frame mode and a short reference frame mode to improve the encoding effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0028] in:
[0029] Figure 1 A schematic diagram of a flow chart of a method for switching an inter-frame prediction mode in an embodiment of the present invention;
[0030] Figure 2 A schematic diagram of a flow chart of a method for determining an optimal video frame in an embodiment of the present invention;
[0031] Figure 3 is a structural block diagram of a switching device for an inter-frame prediction mode in an embodiment of the present invention;
[0032] Figure 4 4 is a structural block diagram of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0034] An embodiment of the present invention provides a method for switching an inter-frame prediction mode. The method can be applied to a terminal device, which can be a video encoder or a device that has a communication connection with the video encoder. The method is applicable to any scenario of switching the inter-frame prediction mode of the video encoder.
[0035] Reference Figure 1 , Figure 1 A schematic diagram of a flow chart of a method for switching an inter-frame prediction mode provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the method is specifically shown in step S101-step S102:
[0036] Step S101: Acquire a currently captured video frame to be encoded, and compare the video frame to be encoded with a target video frame to determine whether a picture change occurs in the video frame to be encoded.
[0037] In a possible implementation, the terminal device includes a video image acquisition module, a video screen change detection module and an adaptive reference frame module. The video image acquisition module is communicatively connected to the video screen change detection module. The video image acquisition module can be connected to a camera device to acquire a video stream output by the camera device (such as a camera). The video stream can include at least one video frame. The video frame is a still image in the video stream. The video frame can be input into a video encoder, so the video frame can be understood as a video frame to be encoded. In this embodiment, each video frame in the video stream is sequentially input into the video encoder from front to back according to the acquisition time for encoding to output the corresponding encoded video frame. The video image acquisition module transmits the video frame to be encoded to the video screen change detection module.
[0038] The video picture change detection module is used to compare the currently acquired video frame to be encoded with the target video frame to determine whether the picture of the video frame to be encoded has changed. Among them, the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded. The target video frame can be understood as the first n frames of encoded video frames before the video frame to be encoded, and n is a preset number. Since the video encoder encodes in sequence according to the video frame acquisition time, the first n frames of encoded video frames are temporally continuous. For example, if the video frame to be encoded is the 10th frame of the video frame, the previous frame of the encoded video frame before the video frame to be encoded is the 9th frame of the encoded video frame. If n=3, the target video frames are the 7th frame of the encoded video frame, the 8th frame of the encoded video frame, and the 9th frame of the encoded video frame.
[0039] When the image similarity between the target video frame and the to-be-encoded video frame is high, this indicates that the image pictures of the target video frame and the to-be-encoded video frame are very similar, indicating that the picture changes little or even basically no change, which means that the picture is relatively stable.
[0040] In this embodiment, the currently collected video frame to be encoded is compared with the target video frame to determine whether the video frame to be encoded has a screen change. The specific method is: respectively calculate the similarity between the target video frame and the video frame to be encoded, and obtain a preset number of similarities. If the preset number of similarities are all less than the preset similarity threshold, it is determined that the video frame to be encoded has a screen change. If the preset number of similarities are not all less than the preset similarity threshold, it is determined that the video frame to be encoded has not a screen change. In a possible implementation, a deep learning algorithm can be used to calculate image similarity, such as a twin network.
[0041] In one possible implementation, the terminal device also includes an encoded image buffer, the memory size of the encoded image buffer is limited, the encoded image buffer can be used to store the target video frame, the encoded image buffer is communicatively connected to the video screen change detection module, in this embodiment, the video screen change detection module can obtain the target video frame from the encoded image buffer, that is, the target video frame can be transmitted from the encoded image buffer to the video screen change detection module, the video screen change detection module is used to compare the video frame to be encoded with the target video frame to determine whether the video frame to be encoded has a screen change.
[0042] Step S102: obtaining the inter-frame prediction mode of the current video encoder, and determining whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder.
[0043] The video picture change detection module is in communication connection with the adaptive reference frame module, and the video picture change detection module transmits the judgment result to the adaptive reference frame module.
[0044] The adaptive reference frame module is used to obtain the inter-frame prediction mode of the current video encoder, and receive the judgment result sent by the video picture change detection module. Based on the inter-frame prediction mode of the current video encoder and the received judgment result, the inter-frame prediction mode of the current video encoder is adaptively switched, wherein, in a possible implementation, the inter-frame prediction mode is divided into a long reference frame mode (LTR mode) and a short reference frame mode (STR mode), the long reference frame mode is an inter-frame prediction mode in which the reference frame is a long reference frame (LTR Long term reference), and the short reference frame mode is an inter-frame prediction mode in which the reference frame is a short reference frame (STR Shortterm reference). If the current video stream sequence picture is relatively stable, if an encoded video frame with higher encoding quality is selected as LTR, then the encoding bit rate can be greatly reduced while ensuring the quality of the current encoded image, thereby improving the transmission efficiency. If the video stream picture is unstable, quickly switching to STR mode can ensure the quality of video encoding.
[0045] In this embodiment, the inter-frame prediction mode of the current video encoder is obtained, and based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder, it is determined whether to change the inter-frame prediction mode of the current video encoder, as shown in steps S201 to S204:
[0046] Step S201: If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame has a picture change, the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode.
[0047] Step S202: If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the to-be-encoded video frame undergoes a picture change, then the inter-frame prediction mode is maintained as the short reference frame mode.
[0048] Step S203: If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame has no picture change, then the inter-frame prediction mode is maintained as the long reference frame mode.
[0049] Step S204: If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the to-be-encoded video frame has no picture change, the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode.
[0050] If the to-be-encoded video frame has undergone a picture change, it indicates that the current video stream sequence is unstable. In this case, the short reference frame mode has a higher video encoding quality than the long reference frame mode. Therefore, at this time, the inter-frame prediction mode of the current video encoder is in a short reference frame mode, and the encoding quality is better than the encoding quality of the long reference frame mode. If the to-be-encoded video frame has not undergone a picture change, it indicates that the current video stream sequence is relatively stable. In this case, the long reference frame mode has a higher video encoding quality than the short reference frame mode. Therefore, if the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the picture change occurs in the video frame to be encoded, the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode; if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the picture change occurs in the video frame to be encoded, the inter-frame prediction mode is maintained as the short reference frame mode; if the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the picture change does not occur in the video frame to be encoded, the inter-frame prediction mode is maintained as the long reference frame mode; if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the picture change does not occur in the video frame to be encoded, the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode.
[0051] If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame has a picture change, the short reference frame mode is entered using the previous encoded video frame of the to-be-encoded video frame as the short reference frame.
[0052] If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the video frame to be encoded has no picture change, then the best video frame among the encoded video frames output by the current video encoder before the video frame to be encoded is obtained, and the long reference frame mode is entered with the best video frame as the long reference frame. Among them, the best video frame is the encoded video frame whose quantization value does not reach the preset quantization threshold and has the smallest time difference with the video frame to be encoded.
[0053] If the inter-frame prediction mode of the current video encoder changes from the short reference frame mode to the long reference frame mode, it is necessary to determine the long reference frame. Since the higher the quality of the long reference frame, the higher the subsequent encoding quality of the current video encoder will be, the best video frame among the encoded video frames should be found as the long reference frame as much as possible. The quantization value (Quantity parameter, quantization parameter, referred to as QP value) of the video frame can characterize the quality of the video frame. The smaller the QP value, the smaller the quantization step, the higher the quantization accuracy, and the higher the quality of the video frame. Therefore, in this embodiment, the encoded video frame whose quantization value does not reach the preset quantization threshold is determined as a video frame with good quality. However, since there may be multiple encoded video frames whose quantization value does not reach the preset quantization threshold, it is also necessary to select the best video frame from the encoded video frames whose quantization value does not reach the preset quantization threshold. Since the video frame that is closer to the acquisition time of the currently acquired video frame to be encoded is better as the reference frame of the currently acquired video frame to be encoded, in this embodiment, the encoded video frame whose quantization value does not reach the preset quantization threshold and the encoded video frame with the smallest time difference with the video frame to be encoded is used as the best video frame.
[0054] This embodiment proposes a method for determining an optimal video frame, referring to Figure 2 , Figure 2 A flowchart of a method for determining an optimal video frame proposed in this embodiment is shown in FIG. Figure 2 As shown, the determination method is specifically shown in step S301-step S302:
[0055] Step S301, obtain the quantization value of the Q-th encoded video frame, and determine whether the quantization value of the Q-th encoded video frame reaches a preset quantization threshold; if the quantization value of the Q-th encoded video frame does not reach the preset quantization threshold, determine the Q-th encoded video frame as the optimal video frame.
[0056] Wherein, Q is the total number of encoded video frames output by the current video encoder before the video frame to be encoded.
[0057] Since it is necessary to determine the encoded video frame with the smallest time difference with the video frame to be encoded among the encoded video frames whose quantization values do not reach the preset quantization threshold in this embodiment, in order to reduce the amount of data calculation and improve the speed of determining the optimal video frame, the quantization value QP is calculated from the encoded video frame before the currently acquired video frame to be encoded, and compared with the quantization threshold, and the encoded video frame whose quantization value QP first confirmed does not reach the preset quantization threshold is determined as the optimal video frame. Specifically, the quantization value of the Q-th frame encoded video frame is obtained, and it is determined whether the quantization value of the Q-th frame encoded video frame reaches the preset quantization threshold. If the quantization value of the Q-th frame encoded video frame does not reach the preset quantization threshold, the Q-th frame encoded video frame is determined as the optimal video frame.
[0058] Step S302: If the quantization value of the Q-th encoded video frame reaches the preset quantization threshold, set Q=Q-1, return to the step of obtaining the quantization value of the Q-th encoded video frame, and determine whether the quantization value of the Q-th encoded video frame reaches the preset quantization threshold.
[0059] If the quantization value of the Qth frame of the encoded video frame reaches the preset quantization threshold, it means that this frame cannot be used as the optimal video frame, and continue to determine whether the quantization value QP of the frame before this frame reaches the preset quantization threshold. Specifically, let Q=Q-1, return to execute the step of obtaining the quantization value of the Qth frame of the encoded video frame, and determine whether the quantization value of the Qth frame of the encoded video frame reaches the preset quantization threshold.
[0060] Based on the above method, by comparing the video frame to be encoded with the encoded video frame, it is determined whether the video frame to be encoded has a picture change, the inter-frame prediction mode of the current video encoder is obtained, and based on the judgment result of whether the video frame to be encoded has a picture change and the inter-frame prediction mode of the current video encoder, it is determined whether to change the inter-frame prediction mode of the current video encoder. The present invention adaptively adjusts the inter-frame prediction mode of the video encoder by whether the video frame to be encoded has a picture change, and can realize the automatic switching of the long reference frame mode and the short reference frame mode to improve the compression effect. If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the video frame to be encoded has a picture change, the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode; if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the video frame to be encoded has a picture change, the inter-frame prediction mode is maintained as the short reference frame mode. If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the video frame to be encoded has not changed, the inter-frame prediction mode is maintained as the long reference frame mode; if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the video frame to be encoded has not changed, the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode. If the video frame to be encoded has not changed, it means that the current video sequence is relatively stable. The long reference frame mode can greatly reduce the encoding bit rate while ensuring the quality of the current encoded image, thereby improving the transmission efficiency. If the video frame to be encoded has changed, it means that the video picture is unstable, and then quickly switching to the short reference frame mode can ensure the quality of video encoding.
[0061] In order to better implement the above method, the embodiment of the present invention provides a switching device for inter-frame prediction mode, which can perform the relevant functions of all the steps of the above method, referring to Figure 3 , Figure 3 A structural block diagram of a switching device for an inter-frame prediction mode provided by an embodiment of the present invention, such as Figure 3 As shown, the device 30 specifically includes the following:
[0062] The scene judgment module 301 is used to obtain the currently captured video frame to be encoded, and compare the video frame to be encoded with the target video frame to determine whether the video frame to be encoded has any picture change; wherein the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded.
[0063] Mode switching module 302: used to obtain the inter-frame prediction mode of the current video encoder, and determine whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder.
[0064] In a possible design, the scene judgment module 301 is specifically used to: respectively calculate the similarity between the target video frame and the video frame to be encoded to obtain a preset number of similarities; if the preset number of similarities are all less than a preset similarity threshold, it is determined that the video frame to be encoded has a screen change; if the preset number of similarities are not all less than the preset similarity threshold, it is determined that the video frame to be encoded has not a screen change.
[0065] In a possible design, the above-mentioned mode switching module 302 is specifically used for: if the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the picture of the video frame to be encoded has changed, then the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode; if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the picture of the video frame to be encoded has changed, then the inter-frame prediction mode is maintained as the short reference frame mode.
[0066] In a possible design, the mode switching module 302 is specifically used to: if the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the video frame to be encoded has not undergone any picture change, then maintain the inter-frame prediction mode as the long reference frame mode; if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the video frame to be encoded has not undergone any picture change, then switch the inter-frame prediction mode from the short reference frame mode to the long reference frame mode.
[0067] In a possible design, the mode switching module 302 is specifically used for: if the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the picture of the video frame to be encoded has changed, then the short reference frame mode is entered using the previous encoded video frame of the video frame to be encoded as the short reference frame.
[0068] In a possible design, the mode switching module 302 is specifically used for: if the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the video frame to be encoded has not undergone any picture change, then obtaining the optimal video frame among the encoded video frames output by the current video encoder before the video frame to be encoded; wherein the optimal video frame is an encoded video frame whose quantization value does not reach a preset quantization threshold and whose time difference with the video frame to be encoded is the smallest; and entering the long reference frame mode with the optimal video frame as the long reference frame.
[0069] In a possible design, the mode switching module 302 is specifically used to: obtain the quantization value of the Q-th encoded video frame, determine whether the quantization value of the Q-th encoded video frame reaches a preset quantization threshold, and if the quantization value of the Q-th encoded video frame does not reach the preset quantization threshold, determine the Q-th encoded video frame as the optimal video frame; wherein Q is the total number of encoded video frames output by the current video encoder before the video frame to be encoded; if the quantization value of the Q-th encoded video frame reaches the preset quantization threshold, set Q=Q-1, and return to execute the steps of obtaining the quantization value of the Q-th encoded video frame and determining whether the quantization value of the Q-th encoded video frame reaches the preset quantization threshold.
[0070] Based on the above device, the long reference frame mode and the short reference frame mode can be switched automatically to improve the encoding effect.
[0071] Figure 4 FIG. 1 shows an internal structure diagram of a computer device in an embodiment. The computer device may be a terminal or a server. Figure 4 As shown, the computer device includes a processor, a memory and a network interface connected via a system bus. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program. When the computer program is executed by the processor, the processor can implement all the steps of the above method. The internal memory may also store a computer program. When the computer program is executed by the processor, the processor can implement all the steps of the above method. Those skilled in the art will understand that Figure 4 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0072] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes each step of the aforementioned method.
[0073] In one embodiment, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, the processor executes each step of the aforementioned method.
[0074] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0075] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0076] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for switching an inter-frame prediction mode, characterized in that: The method comprises: Acquire a currently captured video frame to be encoded, and compare the video frame to be encoded with a target video frame to determine whether a picture change occurs in the video frame to be encoded; wherein the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded; Obtaining an inter-frame prediction mode of a current video encoder, and determining whether to change the inter-frame prediction mode of the current video encoder based on a result of determining whether a picture change occurs in the video frame to be encoded and the inter-frame prediction mode of the current video encoder; The determining whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder comprises: If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame undergoes a picture change, the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode; If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the to-be-encoded video frame undergoes a picture change, then the inter-frame prediction mode is maintained as the short reference frame mode; If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame has no picture change, then the inter-frame prediction mode is maintained as the long reference frame mode; If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the to-be-encoded video frame has no picture change, the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode.
2. The method according to claim 1, characterized in that The step of comparing the to-be-encoded video frame with the target video frame to determine whether a picture change occurs in the to-be-encoded video frame includes: Calculating the similarity between the target video frame and the to-be-encoded video frame respectively to obtain a preset number of similarities; If the similarities of the preset number are all less than the preset similarity threshold, it is determined that the to-be-encoded video frame has a picture change; if the similarities of the preset number are not all less than the preset similarity threshold, it is determined that the to-be-encoded video frame has no picture change.
3. The method according to claim 1, characterized in that If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame undergoes a picture change, the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode, including: If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame has a picture change, the short reference frame mode is entered using the previous encoded video frame of the to-be-encoded video frame as the short reference frame.
4. The method according to claim 1, characterized in that: If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the to-be-encoded video frame has no picture change, the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode, including: If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the to-be-encoded video frame has no picture change, then obtaining an optimal video frame among the encoded video frames output by the current video encoder before the to-be-encoded video frame; wherein the optimal video frame is an encoded video frame whose quantization value does not reach a preset quantization threshold and whose time difference with the to-be-encoded video frame is the smallest among the encoded video frames; Entering a long reference frame mode using the optimal video frame as a long reference frame.
5. The method according to claim 4, characterized in that The obtaining of the best video frame among the encoded video frames output by the current video encoder before the video frame to be encoded comprises: Obtaining a quantization value of the Q-th encoded video frame, determining whether the quantization value of the Q-th encoded video frame reaches a preset quantization threshold, and if the quantization value of the Q-th encoded video frame does not reach the preset quantization threshold, determining the Q-th encoded video frame as an optimal video frame; wherein Q is the total number of encoded video frames output by the current video encoder before the video frame to be encoded; If the quantization value of the Qth frame of the encoded video frame reaches the preset quantization threshold, set Q=Q-1, return to the step of obtaining the quantization value of the Qth frame of the encoded video frame, and determine whether the quantization value of the Qth frame of the encoded video frame reaches the preset quantization threshold.
6. A switching device for an inter-frame prediction mode, characterized in that: The device comprises: A scene judgment module is used to obtain the currently acquired video frame to be encoded, and compare the video frame to be encoded with the target video frame to determine whether the video frame to be encoded has a picture change; wherein the target video frame is a preset number of encoded video frames that are temporally continuous with the video frame to be encoded; A mode switching module: used for obtaining the inter-frame prediction mode of the current video encoder, and determining whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder; The determining whether to change the inter-frame prediction mode of the current video encoder based on the judgment result of whether the to-be-encoded video frame has a picture change and the inter-frame prediction mode of the current video encoder comprises: If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame undergoes a picture change, the inter-frame prediction mode is switched from the long reference frame mode to the short reference frame mode; If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the to-be-encoded video frame undergoes a picture change, then the inter-frame prediction mode is maintained as the short reference frame mode; If the inter-frame prediction mode of the current video encoder is the long reference frame mode, and the judgment result is that the to-be-encoded video frame has no picture change, then the inter-frame prediction mode is maintained as the long reference frame mode; If the inter-frame prediction mode of the current video encoder is the short reference frame mode, and the judgment result is that the to-be-encoded video frame has no picture change, the inter-frame prediction mode is switched from the short reference frame mode to the long reference frame mode.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 5.
8. A computer device comprising a memory and a processor, characterized in that: The memory stores a computer program, and when the computer program is executed by the processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Image processing device and method
CN107071476A
Long-term reference image selection method and device
CN107820095A