Method, device and equipment for determining target IP ratio based on preset IP ratio
By pre-encoding preset GOPs for multiple preset scenarios, a preset IP ratio is determined, and the QP is adjusted in the target scenario to obtain the target IP ratio. This solves the problem of the inability to adaptively alleviate the breathing effect in static scenarios in existing technologies, and achieves more stable encoding quality.
Patent Information
- Application Number
- CN202511544372.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-27
- Publication Date
- 2026-01-06
AI Technical Summary
Existing CBR, VBR, and AVBR coding control modes cannot adaptively mitigate the breathing effect in static scenes under monitoring scenarios, resulting in unstable coding quality.
By precoding preset GOPs for multiple preset scenarios, the preset IP ratio for each preset scenario is determined. Then, IDR frames and P frames are encoded based on the preset IP ratio in the target scenario, and QP is adjusted to obtain the target IP ratio, thus dynamically adjusting the bitrate allocation.
It effectively alleviates the breathing effect in the target scenario, improving the stability of coding quality and user experience.
Smart Images

Figure CN121284232A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of video processing, in particular to a method and device for determining a target IP ratio based on a preset IP ratio. BACKGROUND
[0002] Currently, AX620E and AX650 support the encoding protocols H.264 and HEVC, and each of the protocols corresponds to a CBR (Constant Bitrate), VBR (Variable Bitrate) and AVBR (Adaptive Variable Bitrate) code control mode. The above code control modes are expected to have a small breathing effect in some relatively static scenes.
[0003] However, in a monitoring scene, the IP ratios of the CBR, VBR and AVBR modes are relatively fixed when the YUV before encoding is determined to be static, or only the rule that the complexity of adjacent frames is close and the QP (Quantization Parameter) is also close is used, which may cause the breathing effect of some static scenes to be unable to adapt. SUMMARY
[0004] Embodiments of the present application provide a method and device for determining a target IP ratio based on a preset IP ratio, and pre-encode a preset GOP of a plurality of preset scenes to obtain a preset IP ratio of each preset scene. Thus, the preset IP ratio of a target scene can be directly obtained, and the target IP ratio is determined based on the preset IP ratio to alleviate the breathing effect of encoding in the target scene. The technical solution is as follows:
[0005] According to a first aspect of an embodiment of the present application, a method for determining a target IP ratio based on a preset IP ratio is provided, comprising:
[0006] pre-encoding a preset GOP in a plurality of preset scenes to obtain a pre-encoding result of each preset scene;
[0007] determining a preset IP ratio of each preset scene corresponding to each pre-encoding result based on each pre-encoding result;
[0008] obtaining an IDR frame of a first GOP in a target scene, encoding the IDR frame based on the preset IP ratio of the IDR frame corresponding to the target scene to obtain an IDR frame encoding result; the target scene is part of the plurality of preset scenes;
[0009] obtaining a first P frame of the first GOP, and encoding the first P frame based on the preset IP ratio corresponding to the target scene to obtain a first P frame encoding result;
[0010] adjusting the QP of the second P frame based on the encoding result of the IDR frame and the encoding result of the first P frame to obtain a target QP of the second P frame;
[0011] calculating the target QP of the second P frame and a real-time code rate of the IDR frame to obtain a target IP ratio.
[0012] In some embodiments, the adjusting the QP of the second P frame based on the encoding result of the IDR frame and the encoding result of the first P frame to obtain a target QP of the second P frame comprises:
[0013] calculating a first peak signal-to-noise ratio based on the IDR frame and the encoding result of the IDR frame;
[0014] calculating a second peak signal-to-noise ratio based on the first P frame and the encoding result of the first P frame;
[0015] if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not satisfy a preset condition, adjusting the QP of the second P frame based on the first peak signal-to-noise ratio to obtain a target QP of the second P frame; the preset condition comprises that an absolute value of a difference between the first peak signal-to-noise ratio and the second peak signal-to-noise ratio is less than a first quality threshold, and the first peak signal-to-noise ratio and the second peak signal-to-noise ratio are both greater than a second quality threshold.
[0016] In some embodiments, the calculating the target QP of the second P frame and the real-time code rate of the IDR frame to obtain a target IP ratio comprises:
[0017] calculating a target code rate of the P frame based on the target QP of the second P frame and the real-time code rate of the IDR frame;
[0018] calculating a target IP ratio based on the real-time code rate of the IDR frame and the target code rate of the P frame.
[0019] In some embodiments, the method further comprises: if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio satisfy a preset condition, calculating a real-time code rate of the second P frame and the QP of the second P frame to obtain a real-time code rate of the IDR frame;
[0020] calculating the target IP ratio based on the real-time code rate of the IDR frame and the real-time code rate of the P frame.
[0021] In some embodiments, before the adjusting the QP of the second P frame based on the first peak signal-to-noise ratio to obtain a target QP of the second P frame, the method further comprises:
[0022] The real-time bitrate of the IDR frame is obtained by calculating the preset IP ratio and the real-time bitrate of the first P frame.
[0023] The real-time bitrate of the IDR and the real-time bitrate of the first P-frame are calculated to obtain the predicted QP of the second P-frame.
[0024] The predicted QP of the second P-frame and the preset QP of the first P-frame are calculated to obtain the QP of the second P-frame.
[0025] In some embodiments, adjusting the QP of the second P-frame based on the first peak signal-to-noise ratio to obtain the target QP of the second P-frame includes:
[0026] Obtain the difference between the second peak signal-to-noise ratio and the second quality threshold;
[0027] The QP of the second P-frame is adjusted based on the difference to obtain the target QP of the second P-frame.
[0028] In some embodiments, the method further includes:
[0029] Based on the target QP and the target IP ratio of the second P-frame, the second P-frame is encoded to obtain the encoding result of the second P-frame;
[0030] Obtain the real-time bitrate of the second P-frame;
[0031] The real-time bitrate of the second P-frame and the target bitrate of the P-frame are calculated to obtain the bitrate change rate of the P-frame.
[0032] If the bitrate change rate of the P-frame is greater than a preset threshold, the QP of the third P-frame is adjusted to obtain the target QP of the third P-frame.
[0033] In some embodiments, before adjusting the QP of the third P-frame to obtain the target QP of the third P-frame if the bitrate change rate of the P-frame is greater than a preset threshold, the method further includes:
[0034] Based on the target IP ratio, the target bitrate of the IDR frame is determined;
[0035] The real-time bitrate of the second P-frame is calculated to obtain the real-time average bitrate of the P-frame.
[0036] The target bitrate of the IDR frame and the real-time average bitrate of the P frame are calculated to obtain the predicted QP of the third P frame.
[0037] The QP of the second P-frame and the predicted QP of the third P-frame are calculated to obtain the QP of the third P-frame.
[0038] In some embodiments, the step of adjusting the QP of the third P-frame if the bitrate change rate of the P-frame is greater than a preset threshold, to obtain the target QP of the third P-frame, includes:
[0039] Based on the bitrate change rate of the P-frame, the QP of the third P-frame is adjusted to obtain the target QP of the third P-frame.
[0040] In some embodiments, the method further includes:
[0041] Obtain the last P-frame of the nth GOP, encode the last P-frame, and encode the last P-frame based on the preset IP ratio to obtain the encoding result of the last P-frame; n is an integer greater than 1;
[0042] The second peak signal-to-noise ratio is calculated based on the last P-frame and the encoding result of the last P-frame;
[0043] Obtain the IDR frame of the (n+1)th GOP, and encode the IDR frame based on the preset IP ratio to obtain the IDR frame encoding result;
[0044] The first peak signal-to-noise ratio is calculated based on the IDR frame and the IDR frame encoding result;
[0045] If the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not meet the preset conditions, then the QP of the first P frame of the (n+1)th GOP is adjusted based on the first peak signal-to-noise ratio to obtain the target QP of the first P frame;
[0046] The target QP of the first P-frame and the real-time bitrate of the IDR frame are calculated to obtain the target bitrate of the P-frame.
[0047] The target IP ratio is obtained by calculating the real-time bitrate of the IDR frame and the target bitrate of the P frame.
[0048] According to a second aspect of the embodiments of this application, an apparatus for determining a target IP ratio based on a preset IP ratio is provided, comprising:
[0049] The precoding module is used to precode a preset GOP under multiple preset scenarios to obtain the precoding result of each preset scenario;
[0050] The determining module is used to determine the preset IP ratio of the preset scenario corresponding to each precoding result based on each precoding result;
[0051] The first encoding module is used to acquire the IDR frame of the first GOP in the target scene, and encode the IDR frame based on the preset IP ratio of the IDR frame corresponding to the target scene to obtain the IDR frame encoding result; the target scene is a part of multiple preset scenes;
[0052] The second encoding module is used to obtain the first P-frame of the first GOP, and encode the first P-frame based on the preset IP ratio corresponding to the target scene to obtain the encoding result of the first P-frame;
[0053] An adjustment module is used to adjust the QP of the second P frame based on the IDR frame encoding result and the first P frame encoding result to obtain the target QP of the second P frame;
[0054] The calculation module is used to calculate the target QP of the second P frame and the real-time bitrate of the IDR frame to obtain the target IP ratio.
[0055] According to a third aspect of the present application, a computer device is provided, the computer device including a processor and a memory, the memory being used to store at least one program, the at least one program being loaded by the processor and executed as the method for determining a target IP ratio based on a preset IP ratio.
[0056] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided, wherein at least one program is stored in the computer-readable storage medium, the at least one program being loaded and executed by a processor to implement the method for determining a target IP ratio based on a preset IP ratio.
[0057] In embodiments of this application, precoding is performed using preset GOPs (Group of Pictures) under multiple preset scenarios to obtain precoding results for each preset scenario. Based on each precoding result, a preset IP ratio (IP ratio) for the corresponding preset scenario is determined. The target scenario is one of the multiple preset scenarios; therefore, a preset IP ratio that is relatively well-matched to the target scenario can be directly obtained. Encoding the GOP under the target scenario based on the preset IP ratio can effectively alleviate the breathing effect of encoding under the target scenario. Furthermore, a target IP ratio that is even better matched to the target scenario can be determined based on the preset IP ratio. Encoding the GOP under the target scenario based on the target IP ratio can further alleviate the breathing effect of encoding under the target scenario, thereby improving the user experience. Attached Figure Description
[0058] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0059] Figure 1 This is a schematic diagram of an implementation environment provided according to an embodiment of this application;
[0060] Figure 2 This is a flowchart illustrating the first method for determining a target IP ratio based on a preset IP ratio executed by a terminal according to an embodiment of this application.
[0061] Figure 3 This is a flowchart illustrating step S205 executed by a terminal according to an embodiment of this application;
[0062] Figure 4 This is a flowchart illustrating a method for a terminal to obtain the QP of a second P frame, according to an embodiment of this application.
[0063] Figure 5 This is a flowchart illustrating step S2053 executed by a terminal according to an embodiment of this application;
[0064] Figure 6 This is a flowchart illustrating step S206 executed by a terminal according to an embodiment of this application;
[0065] Figure 7 This is a flowchart illustrating a second method for determining a target IP ratio based on a preset IP ratio, executed by a terminal according to an embodiment of this application.
[0066] Figure 8 This is a flowchart illustrating a method for encoding the second P-frame in the first GOP performed by a terminal according to an embodiment of this application.
[0067] Figure 9 This is a flowchart illustrating a method for a terminal to obtain the QP of the third P frame of the first GOP, according to an embodiment of this application.
[0068] Figure 10 This is a flowchart illustrating a second method for determining a target IP ratio based on a preset IP ratio, executed by a terminal according to an embodiment of this application.
[0069] Figure 11 This is a schematic diagram of a device for determining a target IP ratio based on a preset IP ratio, according to an embodiment of this application.
[0070] Figure 12This is a schematic diagram of the structure of a terminal according to an embodiment of this application;
[0071] Figure 13 This is a schematic diagram of the structure of a server according to an embodiment of this application. Detailed Implementation
[0072] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0073] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application.
[0074] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items that have essentially the same function. It should be understood that there is no logical or temporal dependency between "first," "second," and "nth," nor does it limit the quantity or execution order. It should also be understood that although the following description uses the terms "first," "second," etc., to describe various elements, these elements should not be limited by the terms.
[0075] These terms are simply used to distinguish one element from another. For example, without departing from the scope of various examples, the first action can be called the second action, and similarly, the second action can be called the first action. Both the first and second actions can be actions, and in some cases, they can be separate and distinct actions.
[0076] "At least one" refers to one or more actions. For example, at least one action can be one action, two actions, three actions, or any integer number of actions greater than or equal to one. "Multiple" refers to two or more actions. For example, multiple actions can be two actions, three actions, or any integer number of actions greater than or equal to two.
[0077] Figure 1 This is a schematic diagram of an implementation environment provided according to an embodiment of this application. The implementation environment may include a terminal 101 and a server 102.
[0078] Each terminal 101 is equipped with a device for determining the target IP ratio based on a preset IP ratio. For example, the terminal 101 can be a smartphone, wearable device, personal computer, laptop computer, tablet computer, smart TV, and vehicle terminal, etc.
[0079] Server 102 can be a single server, a server cluster consisting of multiple servers, or a cloud processing center.
[0080] Terminal 101 is connected to server 102 via wired or wireless network.
[0081] In related technologies, the AX620E and AX650 support the encoding protocols H.264 and HEVC, with their respective CBR, VBR, and AVBR bitrate control modes. These bitrate control modes aim to minimize the breathing effect in certain relatively static scenes. The breathing effect primarily refers to the visually noticeable fluctuations in quality between different parts of the video or between consecutive frames, caused by the encoder dynamically allocating a limited bitrate budget.
[0082] For example, in VBR static scenes, the desired effect is a sufficiently low actual bitrate, smooth image quality, and stable breathing effect. In CBR static scenes, the desired effect is to maintain the actual bitrate at the target bitrate, with smooth image quality and stable breathing effect. In AVBR static scenes, the desired effect is to maintain the actual bitrate within a defined bitrate range, with smooth image quality and stable breathing effect.
[0083] However, in surveillance scenarios, when the YUV image before encoding is judged to be static, the IP ratio of CBR, VBR, and AVBR modes is relatively fixed, or it is simply based on the rule that adjacent frames have similar complexity and similar QP (Quick Point Advancement) adaptation. This can cause the breathing effect in some static scenes to not adapt adaptively. For example, in a high-texture-complexity scene with a resolution of 2688x1520, a video encoding standard of 265, and a bitrate of 2Mbps, an IP ratio of around 40 can alleviate the breathing effect. However, in a relatively low-texture-complexity darkroom scene with a resolution of 1920x1080, a video encoding standard of 265, and a bitrate of 2Mbps, where most of the walls are gray, an IP ratio of around 70 is needed to alleviate the breathing effect. In other words, in static scenes, a fixed IP ratio cannot alleviate the breathing effect in different scenes at various resolutions.
[0084] To address the aforementioned technical problems, embodiments of this application provide a method for adjusting the IP ratio based on QP. This method pre-encodes preset GOPs (Groups of Pictures, image sequences) of preset scenes with different complexities and resolutions to obtain a preset IP ratio for each preset scene. After determining the target scene, the preset IP ratio of the target scene is selected from the preset IP ratios of IDR (Instantaneous Decoder Refresh) frames of multiple preset scenes. The IDR frame and the first P (Predicted) frame of the first GOP are encoded based on the preset IP ratio of the target scene, yielding the IDR encoding result and the first P frame encoding result. The QP of the second P frame is adjusted using the IDR encoding result and the first P frame encoding result to obtain the target QP of the second P frame. The preset IP ratio is then adjusted based on the target QP of the second P frame to obtain the target IP ratio. Embodiments of this application pre-obtain a preset IP ratio that is relatively well-matched to the target scene. Based on the preset IP ratio, a target IP ratio that better matches the target scene is obtained, thereby mitigating the breathing effect during encoding in the target scene. This solves the problem that directly encoding GOPs based on fixed IPs that do not match the target scenario cannot effectively alleviate the breathing effect.
[0085] Figure 2 This is a flowchart illustrating a first method for determining a target IP ratio based on a preset IP ratio, executed by a terminal according to an embodiment of this application. (Combined with...) Figure 2 A detailed explanation of the method for determining the target IP ratio based on a preset IP ratio is provided. This method includes steps S201 to S206.
[0086] In step S201, the terminal precodes the preset GOPs under multiple preset scenarios to obtain the precoding result for each preset scenario.
[0087] In some examples, different preset scenarios correspond to different levels of complexity and resolution.
[0088] In some examples, each GOP includes an IDR frame as well as multiple P frames.
[0089] In step S202, the terminal determines the preset IP ratio of the preset scenario corresponding to each precoding result based on each precoding result.
[0090] The IP ratio refers to the ratio of the average bitrate allocated to IDR frames and P frames within a GOP.
[0091] In some examples, for each precoding result, the terminal determines whether the precoding result meets expectations; if the precoding result meets expectations, the IP ratio corresponding to the precoding result is used as the preset IP ratio of the preset scenario corresponding to the preset encoding result.
[0092] For example, the terminal obtains user input information and determines whether the precoding result meets expectations based on the user input information. For instance, if the user is satisfied with the image quality of the precoding result, then "satisfied" is input to the terminal. After obtaining the user input information, the terminal uses the IP ratio corresponding to the precoding result as the preset IP ratio of the preset scene corresponding to the preset encoding result.
[0093] For example, the default IP ratio is a range. For instance, the default IP ratio is 30 to 40.
[0094] In the embodiments of this application, by pre-encoding the preset GOPs of each preset scene, the optimal preset IP ratio for each preset scene can be obtained in advance, avoiding the use of a fixed IP ratio for encoding in various different scenes. During encoding, when the target scene is one of multiple preset scenes, the optimal IP ratio for the target scene can be directly obtained, thereby effectively mitigating the breathing effect of the target scene and solving the problem that a fixed IP ratio cannot meet the requirement of minimizing the breathing effect in multi-resolution and multi-complexity scenes.
[0095] In step S203, the terminal obtains the IDR frame of the first GOP in the target scenario, and encodes the IDR frame based on the preset IP ratio of the IDR frame corresponding to the target scenario to obtain the IDR frame encoding result.
[0096] In some examples, the terminal determines a preset scene that matches the target scene based on the complexity and resolution of the target scene, thereby determining the preset IP ratio of the target scene.
[0097] In some examples, the terminal encodes real-time video streams for the target scene. For target scenes with relatively fixed backgrounds and high latency requirements, the preset IP ratio, which is relatively well-matched to the target scene, is adjusted during the encoding of the first GOP to obtain a target IP ratio that is more closely matched to the target scene. "More closely matched to the target scene" can be understood as encoding based on the target IP ratio, which makes the bitrate allocation more stable, thereby ensuring smooth and stable image quality and improving the user experience.
[0098] In step S204, the terminal acquires the first P-frame of the first GOP, encodes the first P-frame based on the preset IP ratio corresponding to the target scene, and obtains the encoding result of the first P-frame.
[0099] In step S205, the terminal adjusts the QP of the second P frame based on the IDR frame encoding result and the first P frame encoding result to obtain the target QP of the second P frame.
[0100] Figure 3This is a flowchart illustrating step S205 executed by a terminal according to an embodiment of this application. (In conjunction with...) Figure 3 Step S205 is described in detail. The method includes steps S2051 to S2053.
[0101] In step S2051, the terminal calculates the IDR frame and the IDR frame encoding result to obtain the first peak signal-to-noise ratio (PSNR).
[0102] In some examples, the terminal calculates the first peak signal-to-noise ratio based on a preset algorithm for the IDR frame and the IDR frame encoding result.
[0103] For example, the first peak signal-to-noise ratio = 10 * log10(MAX) 2 / MSE).
[0104] In the above formula, MAX is the maximum possible value of the pixel; MSE (Mean Square Error) is the mean square error between the IDR frame and the IDR frame encoding result.
[0105] In step S2052, the terminal calculates the first P-frame and the encoding result of the first P-frame to obtain the second peak signal-to-noise ratio.
[0106] For example, the second peak signal-to-noise ratio = 10 * log10(MAX) 2 / MSE).
[0107] In the above formula, MSE is the mean square error between the encoding results of the first P-frame and the first P-frame.
[0108] In step S2053, if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not meet the preset conditions, the terminal adjusts the QP of the second P frame based on the first peak signal-to-noise ratio to obtain the target QP of the second P frame.
[0109] The preset conditions include that the absolute value of the difference between the first peak signal-to-noise ratio (PSNR) and the second PSNR is less than a first quality threshold, and both the first PSNR and the second PSNR are greater than the second quality threshold. For example, the first quality threshold is 2 dB, and the second quality threshold is 28 dB.
[0110] In some examples, encoding subsequent P-frames and subsequent GOPs in the first GOP based on a preset IP comparison can mitigate the breathing effect to some extent. However, in this case, the breathing effect may not be optimal, meaning that the breathing effect can be further mitigated.
[0111] Figure 4This is a flowchart illustrating a method for a terminal to obtain the QP of a second P-frame according to an embodiment of this application. Before executing step S2053, the terminal also needs to obtain the QP of the second P-frame. (Combined with...) Figure 4 The method for obtaining the QP of the second P-frame is described in detail. The method includes steps S401 to S403.
[0112] In step S401, the terminal calculates the preset IP ratio and the real-time bitrate of the first P frame to obtain the real-time bitrate of the IDR frame.
[0113] In some examples, the real-time bitrate of the IDR frame = preset IP ratio × real-time bitrate of the first P frame.
[0114] In step S402, the terminal calculates the real-time bitrate of the IDR and the real-time bitrate of the first P-frame to obtain the predicted QP of the second P-frame.
[0115] In some examples, the terminal calculates the real-time bitrate of the IDR and the real-time bitrate of the first P-frame based on a preset algorithm to obtain the predicted QP of the second P-frame.
[0116] For example, the terminal calculates the real-time bitrate of the IDR and the real-time bitrate of the first P-frame based on the RC curve (Rate Control Curve) to obtain the predicted QP of the second P-frame.
[0117] In step S403, the terminal calculates the predicted QP of the second P-frame and the preset QP of the first P-frame to obtain the QP of the second P-frame.
[0118] In some examples, a preset QP is set for both the IDR frame and the first P frame before encoding.
[0119] For example, the terminal performs a weighted average calculation on the predicted QP of the second P-frame and the preset QP of the first P-frame to obtain the QP of the second P-frame.
[0120] For example, the QP of the second P-frame = 1 / 2 (the predicted QP of the second P-frame + the preset QP of the first P-frame).
[0121] In an embodiment of this application, in order to ensure smooth image quality, the QP of the second P frame is obtained by weighted averaging of the QP of adjacent frames.
[0122] Figure 5 This is a flowchart illustrating step S2053 executed by a terminal according to an embodiment of this application. (In conjunction with...) Figure 5 Step S2053 is described in detail. The method includes steps S20531 to S20532.
[0123] In step S20531, the terminal obtains the difference between the second peak signal-to-noise ratio and the second quality threshold.
[0124] In step S20532, the terminal adjusts the QP of the second P frame based on the difference to obtain the target QP of the second P frame.
[0125] In some examples, when the absolute value of the difference between the first peak signal-to-noise ratio and the second peak signal-to-noise ratio is greater than or equal to the first quality threshold, it indicates that the preset IP is relatively small. In this case, the QP of the second P-frame needs to be reduced to obtain the target QP of the second P-frame.
[0126] For example, the absolute value of the difference between the second peak signal-to-noise ratio and the second quality threshold is obtained. The absolute value of the difference and a preset multiple are calculated to obtain an adjustment value, and the QP of the second P-frame is increased by the adjustment value to obtain the target QP of the second P-frame.
[0127] For example, the adjustment value = the absolute value of the difference / the preset multiple.
[0128] The target QP of the second P-frame = QP of the second P-frame + adjustment value.
[0129] When the QP of the second P-frame is 35, the preset multiplier is 6, and the second peak signal-to-noise ratio is 40dB, the absolute value of the difference is 12dB, the adjustment value is 2, and the target QP of the second P-frame is 37.
[0130] In step S206, the terminal calculates the target QP of the second P frame and the real-time bitrate of the IDR frame to obtain the target IP ratio.
[0131] Figure 6 This is a flowchart illustrating step S206 executed by a terminal according to an embodiment of this application. (In conjunction with...) Figure 6 Step S206 will be described in detail. The method includes steps S2061 to S2062.
[0132] In step S2061, the terminal calculates the target QP of the second P frame and the real-time bitrate of the IDR frame to obtain the target bitrate of the P frame.
[0133] For example, the terminal calculates the real-time average bitrate of the second P-frame based on the RC curve for the target QP and the real-time bitrate of the IDR frame. This real-time average bitrate of the second P-frame is the target bitrate of the P-frame.
[0134] Since each GOP has only one IDR frame, the real-time bitrate of the IDR frame can also be expressed as the real-time average bitrate of the IDR frame. Each QP corresponds to the real-time average bitrate of a P frame and the real-time bitrate or real-time average bitrate of an IDR frame.
[0135] In step S2062, the terminal calculates the real-time bitrate of the IDR frame and the target bitrate of the P frame to obtain the target IP ratio.
[0136] The target IP ratio obtained through the above embodiments corresponds to the minimum breathing effect in the target scene. That is, by encoding the subsequent P frames in the first GOP and subsequent GOPs with the target IP ratio, the stability of the bitrate allocation can be guaranteed to the greatest extent, thereby minimizing the breathing effect of encoding in the target scene.
[0137] Figure 7 This is a flowchart illustrating a second method for determining a target IP ratio based on a preset IP ratio, executed by a terminal according to an embodiment of this application. (Combined with...) Figure 7 A detailed description is provided of a method for determining a target IP ratio based on a preset IP ratio. This method includes steps S701 to S702.
[0138] In step S701, if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio meet the preset conditions, the terminal calculates the real-time bit rate of the second P frame and the QP of the second P frame to obtain the real-time bit rate of the IDR frame.
[0139] In step S702, the terminal calculates the real-time bitrate of the IDR frame and the real-time bitrate of the P frame to obtain the target IP ratio.
[0140] The above analysis shows that if the first peak signal-to-noise ratio (PSNR) and the second peak PSNR meet the preset conditions, there is no need to adjust the preset IP ratio. In other words, in this case, the preset IP ratio is the target IP ratio. Encoding subsequent P-frames and subsequent GOPs within the first GOP based on the preset IP ratio can effectively alleviate the breathing effect in the target scene.
[0141] Understandably, during encoding, the bitrate is minimized while maintaining a certain level of image quality. The encoder dynamically allocates the bitrate based on the complexity and intensity of motion in the video content. Therefore, even if a target bitrate (IP) is determined, a significant deviation between the real-time bitrate of a P-frame and its target bitrate may still occur during encoding. In embodiments of this application, when the real-time bitrate of an IP frame deviates significantly from the target bitrate of a P-frame, the QP of the next P-frame is adjusted, thereby adjusting the bitrate allocated to the next P-frame to ensure a relatively stable bitrate allocation and mitigate the breathing effect.
[0142] Figure 8 This is a flowchart illustrating a method for encoding the second P-frame in the first GOP performed by a terminal according to an embodiment of this application. (In conjunction with...) Figure 8The method for encoding the second P-frame in the first GOP is described in detail. The method includes steps S801 to S804.
[0143] In step S801, the terminal encodes the second P frame based on the target QP and target IP ratio of the second P frame to obtain the encoding result of the second P frame.
[0144] In step S802, the terminal obtains the real-time bitrate of the second P frame.
[0145] In step S803, the real-time bitrate of the second P-frame and the target bitrate of the P-frame are calculated to obtain the bitrate change rate of the P-frame.
[0146] In some examples, since the bitrate allocation is dynamic, in order to ensure the stability of the bitrate allocation, it is necessary to calculate the bitrate change rate of the P-frame to determine whether the real-time bitrate of the P-frame is too large or too small compared to the target bitrate of the P-frame.
[0147] For example, the bitrate change rate of P-frames =
[0148] |Real-time bitrate of the second P-frame - Target bitrate of the P-frame| ÷ Target bitrate of the P-frame × 100%
[0149] In step S804, if the bit rate change rate of the P frame is greater than a preset threshold, the terminal adjusts the QP of the third P frame to obtain the target QP of the third P frame.
[0150] In some examples, if the bitrate change rate of a P-frame is greater than a preset threshold, the QP of the third P-frame is adjusted based on the bitrate change rate of the P-frame to obtain the target QP of the third P-frame.
[0151] For example, if the bitrate change rate of a P-frame is greater than a preset threshold, and the real-time bitrate of the third P-frame is greater than the target bitrate of the P-frame, it indicates that too much bitrate is allocated to the second P-frame. Therefore, the QP of the third P-frame needs to be increased to reduce the bitrate allocated to the third P-frame.
[0152] For example, the preset threshold is 10%. When the real-time bitrate of the second P-frame increases by 20% relative to the target bitrate of the P-frame, the QP of the third P-frame is increased by 1 to obtain the target QP of the third P-frame.
[0153] It should be noted that this can be used as a reference. Figure 8 The method involves adjusting the QP of other P-frames in the first GOP and the QP of P-frames in other GOPs to ensure the stability of bitrate allocation during encoding, thereby effectively mitigating the breathing effect.
[0154] Figure 9This is a flowchart illustrating a method for a terminal to obtain the QP of the third P-frame of the first GOP, according to an embodiment of this application. Before executing step S804, the embodiment of this application also requires obtaining the QP of the third P-frame of the first GOP. Combined with... Figure 9 The method for obtaining the QP of the third P-frame of the first GOP is described in detail. The method includes steps S901 to S904.
[0155] In step S901, the terminal determines the target bitrate of the IDR frame based on the target IP ratio.
[0156] In some examples, after determining the target IP ratio, the IDR bitrate can be calculated based on the GOP bitrate. Since the bitrate of the IDR frame is relatively stable, embodiments of this application adjust the QP of the next P-frame based on the offset of the real-time bitrate of the previous P-frame relative to the target bitrate of the P-frame, thereby ensuring the stability of bitrate allocation.
[0157] For example, the target bitrate of an IDR frame can be calculated based on the number of IDR frames and P frames in a GOP, the target IP ratio, and the GOP's bitrate. Furthermore, since the target IP ratio is a range, the target bitrate of an IDR frame is also a range.
[0158] For example, if the target IP ratio is 30-40, a GOP includes one IDR frame and 49 P frames, and the bitrate of a GOP is 2Mbps, then the target bitrate of the IDR is (30-40)×1÷((30-40)×1+49×1)×2Mbps.
[0159] In step S902, the terminal calculates the real-time bitrate of the second P-frame to obtain the real-time average bitrate of the P-frame.
[0160] In some examples, the terminal calculates a weighted average of the real-time bitrate of the first P-frame and the real-time bitrate of the second P-frame to obtain the real-time average bitrate of the P-frame.
[0161] In step S903, the terminal calculates the target bit rate of the IDR frame and the real-time average bit rate of the P frame to obtain the predicted QP of the third P frame.
[0162] In some examples, the terminal calculates the target bitrate of the IDR frame and the real-time average bitrate of the P frame based on the RC curve to obtain the predicted QP of the third P frame.
[0163] In step S904, the terminal calculates the QP of the second P-frame and the predicted QP of the third P-frame to obtain the QP of the third P-frame.
[0164] Figure 10This is a flowchart illustrating a second method for determining a target IP ratio based on a preset IP ratio, executed by a terminal according to an embodiment of this application. (Combined with...) Figure 10 A detailed description is provided of a method for determining a target IP ratio based on a preset IP ratio. This method includes steps S1001 to S1007.
[0165] In step S1001, the terminal obtains the last P frame of the nth GOP, encodes the last P frame, and encodes the last P frame based on a preset IP ratio to obtain the encoding result of the last P frame.
[0166] Where n is an integer greater than 1.
[0167] In some examples, for target scenarios with relatively fixed backgrounds and low latency requirements, the target IP ratio can be determined during the encoding of subsequent GOPs, rather than during the encoding of the first GOP. For example, n is 2. That is, the terminal obtains the last P-frame of the second GOP, encodes the last P-frame, and encodes the last P-frame based on the preset IP ratio to obtain the encoded result of the last P-frame.
[0168] In step S1002, the terminal calculates the second peak signal-to-noise ratio based on the last P-frame and the encoding result of the last P-frame.
[0169] In step S1003, the terminal obtains the IDR frame of the (n+1)th GOP, and encodes the IDR frame based on the preset IP ratio to obtain the IDR frame encoding result.
[0170] In some examples, the terminal acquires the IDR frame of the third GOP, encodes the IDR frame based on a preset IP ratio, and obtains the IDR frame encoding result.
[0171] In step S1004, the terminal calculates the first peak signal-to-noise ratio based on the IDR frame and the IDR frame encoding result.
[0172] In step S1005, if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not meet the preset conditions, the terminal adjusts the QP of the first P frame of the (n+1)th GOP based on the first peak signal-to-noise ratio to obtain the target QP of the first P frame.
[0173] In step S1006, the terminal calculates the target QP of the first P frame and the real-time bitrate of the IDR frame to obtain the target bitrate of the P frame.
[0174] In step S1007, the terminal calculates the real-time bitrate of the IDR frame and the target bitrate of the P frame to obtain the target IP ratio.
[0175] In embodiments of this application, precoding is performed using preset GOPs (Group of Pictures) under multiple preset scenarios to obtain precoding results for each preset scenario. Based on each precoding result, a preset IP ratio (IP ratio) for the corresponding preset scenario is determined. The target scenario is one of the multiple preset scenarios; therefore, a preset IP ratio that is relatively well-matched to the target scenario can be directly obtained. Encoding the GOP under the target scenario based on the preset IP ratio can effectively alleviate the breathing effect of encoding under the target scenario. Furthermore, a target IP ratio that is even better matched to the target scenario can be determined based on the preset IP ratio. Encoding the GOP under the target scenario based on the target IP ratio can further alleviate the breathing effect of encoding under the target scenario, thereby improving the user experience.
[0176] Figure 11 This is a schematic diagram of a device 1100 for determining a target IP ratio based on a preset IP ratio, according to an embodiment of this application. The following is in conjunction with... Figure 11 A detailed description is provided for an apparatus 1100 that determines a target IP ratio based on a preset IP ratio. The apparatus includes:
[0177] The precoding module 1101 is used to precode a preset GOP under multiple preset scenarios to obtain the precoding result of each preset scenario;
[0178] The determination module 1102 is used to determine the preset IP ratio of the preset scenario corresponding to each precoding result based on each precoding result;
[0179] The first encoding module 1103 is used to obtain the IDR frame of the first GOP in the target scene, and encode the IDR frame based on the preset IP ratio of the IDR frame corresponding to the target scene to obtain the IDR frame encoding result; the target scene is a part of multiple preset scenes;
[0180] The second encoding module 1104 is used to obtain the first P frame of the first GOP, and encode the first P frame based on the preset IP ratio corresponding to the target scene to obtain the encoding result of the first P frame;
[0181] The adjustment module 1105 is used to adjust the QP of the second P frame based on the IDR frame encoding result and the first P frame encoding result to obtain the target QP of the second P frame.
[0182] The calculation module 1106 is used to calculate the target QP of the second P frame and the real-time bitrate of the IDR frame to obtain the target IP ratio.
[0183] In some embodiments, adjusting the QP of the second P-frame based on the IDR frame encoding result and the first P-frame encoding result to obtain the target QP of the second P-frame includes:
[0184] The first peak signal-to-noise ratio is obtained by calculating the IDR frame and the IDR frame encoding result;
[0185] The second peak signal-to-noise ratio is obtained by calculating the first P-frame and its encoding result.
[0186] If the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not meet the preset conditions, the QP of the second P frame is adjusted based on the first peak signal-to-noise ratio to obtain the target QP of the second P frame. The preset conditions include that the absolute value of the difference between the first peak signal-to-noise ratio and the second peak signal-to-noise ratio is less than the first quality threshold, and that both the first peak signal-to-noise ratio and the second peak signal-to-noise ratio are greater than the second quality threshold.
[0187] In some embodiments, the target QP of the second P-frame and the real-time bitrate of the IDR frame are calculated to obtain the target IP ratio, including:
[0188] The target QP of the second P-frame and the real-time bitrate of the IDR frame are calculated to obtain the target bitrate of the P-frame.
[0189] The target IP ratio is obtained by calculating the real-time bitrate of the IDR frame and the target bitrate of the P frame.
[0190] In some embodiments, the method further includes: if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio meet a preset condition, then calculating the real-time bitrate of the second P-frame and the QP of the second P-frame to obtain the real-time bitrate of the IDR frame.
[0191] The target IP ratio is obtained by calculating the real-time bitrate of the IDR frame and the real-time bitrate of the P frame.
[0192] In some embodiments, before adjusting the QP of the second P-frame based on the first peak signal-to-noise ratio to obtain the target QP of the second P-frame, the method further includes:
[0193] The real-time bitrate of the IDR frame is obtained by calculating the preset IP ratio and the real-time bitrate of the first P frame.
[0194] The real-time bitrate of the IDR and the real-time bitrate of the first P-frame are calculated to obtain the predicted QP of the second P-frame.
[0195] The predicted QP of the second P-frame and the preset QP of the first P-frame are calculated to obtain the QP of the second P-frame.
[0196] In some embodiments, adjusting the QP of the second P-frame based on the first peak signal-to-noise ratio to obtain the target QP of the second P-frame includes:
[0197] Obtain the difference between the second peak signal-to-noise ratio and the second quality threshold;
[0198] The QP of the second P-frame is adjusted based on the difference to obtain the target QP of the second P-frame.
[0199] In some embodiments, the method further includes:
[0200] Based on the target QP and target IP ratio of the second P-frame, the second P-frame is encoded to obtain the encoding result of the second P-frame;
[0201] Get the real-time bitrate of the second P-frame;
[0202] The real-time bitrate and target bitrate of the second P-frame are calculated to obtain the bitrate change rate of the P-frame.
[0203] If the bitrate change rate of a P-frame is greater than a preset threshold, the QP of the third P-frame is adjusted to obtain the target QP of the third P-frame.
[0204] In some embodiments, before adjusting the QP of the third P-frame to obtain the target QP of the third P-frame if the bitrate change rate of the P-frame is greater than a preset threshold, the method further includes:
[0205] Determine the target bitrate of the IDR frame based on the target IP ratio;
[0206] The real-time bitrate of the second P-frame is calculated to obtain the real-time average bitrate of the P-frame.
[0207] The target bitrate of the IDR frame and the real-time average bitrate of the P frame are calculated to obtain the predicted QP of the third P frame.
[0208] The QP of the second P-frame and the predicted QP of the third P-frame are calculated to obtain the QP of the third P-frame.
[0209] In some embodiments, if the bitrate change rate of a P-frame is greater than a preset threshold, the QP of the third P-frame is adjusted to obtain the target QP of the third P-frame, including:
[0210] Based on the bitrate change rate of the P-frame, the QP of the third P-frame is adjusted to obtain the target QP of the third P-frame.
[0211] In some embodiments, the method further includes:
[0212] Obtain the last P-frame of the nth GOP, encode the last P-frame, and encode the last P-frame based on the preset IP ratio to obtain the encoding result of the last P-frame; n is an integer greater than 1.
[0213] The second peak signal-to-noise ratio is calculated based on the last P-frame and the encoding result of the last P-frame.
[0214] Obtain the IDR frame of the (n+1)th GOP, and encode the IDR frame based on the preset IP ratio to obtain the IDR frame encoding result;
[0215] Calculate the first peak signal-to-noise ratio based on the IDR frame and the IDR frame encoding result;
[0216] If the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not meet the preset conditions, then the QP of the first P frame of the (n+1)th GOP is adjusted based on the first peak signal-to-noise ratio to obtain the target QP of the first P frame;
[0217] The target QP of the first P-frame and the real-time bitrate of the IDR frame are calculated to obtain the target bitrate of the P-frame.
[0218] The target IP ratio is obtained by calculating the real-time bitrate of the IDR frame and the target bitrate of the P frame.
[0219] It should be noted that the apparatus for determining the target IP ratio based on a preset IP ratio provided in the above embodiments is only illustrated by the division of the above functional modules when performing the corresponding steps. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus for determining the target IP ratio based on a preset IP ratio and the method embodiment for determining the target IP ratio based on a preset IP ratio provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiment, which will not be repeated here.
[0220] In embodiments of this application, precoding is performed using preset GOPs (Group of Pictures) under multiple preset scenarios to obtain precoding results for each preset scenario. Based on each precoding result, a preset IP ratio (IP ratio) for the corresponding preset scenario is determined. The target scenario is one of the multiple preset scenarios; therefore, a preset IP ratio that is relatively well-matched to the target scenario can be directly obtained. Encoding the GOP under the target scenario based on the preset IP ratio can effectively alleviate the breathing effect of encoding under the target scenario. Furthermore, a target IP ratio that is even better matched to the target scenario can be determined based on the preset IP ratio. Encoding the GOP under the target scenario based on the target IP ratio can further alleviate the breathing effect of encoding under the target scenario, thereby improving the user experience.
[0221] Embodiments of this application also provide a computer device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the method described above.
[0222] Taking computer devices as terminals as an example, Figure 12 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application. See also... Figure 12Terminal 1200 can be: a smartphone, tablet computer, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, or desktop computer. Terminal 1200 may also be referred to as user equipment, portable terminal, laptop terminal, desktop terminal, or other names.
[0223] Typically, terminal 1200 includes a processor 1201 and a memory 1202.
[0224] Processor 1201 may include one or more processing cores, such as a quad-core processor, a penta-core processor, etc. Processor 1201 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1201 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1201 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, processor 1201 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0225] The memory 1202 may include one or more computer-readable storage media, which may be non-transitory. The memory 1202 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1202 are used to store at least one program code, which is executed by the processor 1201 to implement the process of terminal execution in the method embodiments of this application.
[0226] In some embodiments, the terminal 1200 may also optionally include a peripheral device interface 1203 and at least one peripheral device. The processor 1201, memory 1202, and peripheral device interface 1203 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 1203 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of a display screen 1204, a camera assembly 1205, an audio circuit 1206, and a power supply 1207.
[0227] Peripheral device interface 1203 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 1201 and memory 1202. In some embodiments, processor 1201, memory 1202 and peripheral device interface 1203 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 1201, memory 1202 and peripheral device interface 1203 can be implemented on separate chips or circuit boards, and this application embodiment does not limit this.
[0228] Display screen 1204 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 1204 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 1201 for processing. In this case, display screen 1204 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 1204, disposed on the front panel of terminal 1200; in other embodiments, there may be at least two display screens, disposed on different surfaces of terminal 1200 or in a folded design; in still other embodiments, display screen 1204 may be a flexible display screen, disposed on a curved or folded surface of terminal 1200. Furthermore, display screen 1204 may be configured as a non-rectangular, irregular shape, i.e., a non-rectangular screen. The display screen 1204 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0229] The camera assembly 1205 is used to acquire images or videos. In some embodiments, the camera assembly 1205 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal, and the rear-facing camera is located on the back of the terminal. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 1205 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cool light flash, which can be used for light compensation at different color temperatures.
[0230] The audio circuit 1206 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals which are then input to the processor 1201 for processing. For stereo sound acquisition or noise reduction purposes, multiple microphones may be used, each positioned at a different location on the terminal 1200. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert the electrical signals from the processor 1201 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 1206 may also include a headphone jack.
[0231] Power supply 1207 is used to power the various components in terminal 1200. Power supply 1207 can be AC power, DC power, a disposable battery, or a rechargeable battery. When power supply 1207 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0232] Those skilled in the art will understand that Figure 12 The structure shown does not constitute a limitation on terminal 1200 and may include more or fewer components than shown, or combine certain components, or use different component arrangements.
[0233] Taking computer equipment as a server as an example, Figure 13This is a schematic diagram of a server structure provided in an embodiment of this application. The server 1300 can vary considerably due to different configurations or performance. It may include one or more processors 1301 (Central Processing Units, CPUs) and one or more memories 1302. The one or more memories 1302 store at least one computer program, which is loaded and executed by the one or more processors 1301 to implement the method described above for determining a target IP ratio based on a preset IP ratio. Of course, the server 1300 may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The server 1300 may also include other components for implementing device functions, which will not be elaborated here.
[0234] Embodiments of this application also provide a computer-readable storage medium, which includes a stored computer program, wherein the computer program, when running, controls the device where the computer-readable storage medium is located to perform the method described above. Optionally, the computer-readable storage medium may be read-only memory (ROM), random access memory (RAM), compact-disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device, etc.
[0235] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0236] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for determining a target IP ratio based on a preset IP ratio, characterized in that, The method comprises the following steps: pre-encoding preset GOPs under multiple preset scenes to obtain a pre-encoding result of each preset scene; determining a preset IP ratio of the preset scene corresponding to each pre-encoding result based on each pre-encoding result; encoding an IDR frame of a first GOP under a target scene based on the preset IP ratio of the IDR frame corresponding to the target scene to obtain an IDR frame encoding result; the target scene is part of the multiple preset scenes; encoding a first P frame of the first GOP based on the preset IP ratio corresponding to the target scene to obtain a first P frame encoding result; adjusting the QP of a second P frame based on the IDR frame encoding result and the first P frame encoding result to obtain a target QP of the second P frame; calculating the target QP of the second P frame and the real-time code rate of the IDR frame to obtain a target IP ratio.
2. The method of claim 1, wherein, The method further comprises the following steps: calculating the IDR frame and the IDR frame encoding result to obtain a first peak signal-to-noise ratio; calculating the first P frame and the first P frame encoding result to obtain a second peak signal-to-noise ratio; if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not satisfy a preset condition, adjusting the QP of the second P frame based on the first peak signal-to-noise ratio to obtain a target QP of the second P frame; the preset condition comprises that the absolute value of the difference between the first peak signal-to-noise ratio and the second peak signal-to-noise ratio is less than a first quality threshold, and both the first peak signal-to-noise ratio and the second peak signal-to-noise ratio are greater than a second quality threshold.
3. The method of claim 1, wherein, The method further comprises the following steps: calculating the target QP of the second P frame and the real-time code rate of the IDR frame to obtain a target code rate of the P frame; calculating the real-time code rate of the IDR frame and the target code rate of the P frame to obtain a target IP ratio.
4. The method of claim 1, wherein, The method further comprises the following steps: if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio satisfy a preset condition, calculating the real-time code rate of the second P frame and the QP of the second P frame to obtain the real-time code rate of the IDR frame; 5. The method of claim 2, wherein, calculating the real-time code rate of the IDR frame and the real-time code rate of the P frame to obtain the target IP ratio. The method further comprises the following steps: calculating the preset IP ratio and the real-time code rate of the first P frame to obtain the real-time code rate of the IDR frame; calculating the real-time code rate of the IDR and the real-time code rate of the first P frame to obtain a predicted QP of the second P frame; calculating a prediction QP of a second P frame and a preset QP of a first P frame to obtain a QP of the second P frame.
6. The method of claim 2, wherein, The method further comprises: calculating a difference between the second peak signal-to-noise ratio and the second quality threshold; adjusting the QP of the second P frame based on the difference to obtain a target QP of the second P frame.
7. The method of claim 1, wherein, The method further comprises: encoding the second P frame based on the target QP of the second P frame and the target IP ratio to obtain an encoding result of the second P frame; calculating a real-time code rate of the second P frame; calculating a code rate change rate of the P frame by calculating the real-time code rate of the second P frame and a target code rate of the P frame; adjusting a QP of a third P frame to obtain a target QP of the third P frame if the code rate change rate of the P frame is greater than a preset threshold.
8. The method of claim 7, wherein, The method further comprises: determining a target code rate of the IDR frame based on the target IP ratio; calculating a real-time average code rate of the P frame by calculating the real-time code rate of the second P frame; calculating a prediction QP of the third P frame by calculating the target code rate of the IDR frame and the real-time average code rate of the P frame; calculating a QP of the second P frame and the prediction QP of the third P frame to obtain a QP of the third P frame.
9. The method of claim 7, wherein, The method further comprises: adjusting the QP of the third P frame based on the code rate change rate of the P frame to obtain the target QP of the third P frame.
10. The method of claim 1, wherein, The method further comprises: obtaining a last P frame of an nth GOP, encoding the last P frame, and encoding the last P frame based on the preset IP ratio to obtain an encoding result of the last P frame; n is an integer greater than 1; calculating the second peak signal-to-noise ratio based on the last P frame and the encoding result of the last P frame; obtaining an IDR frame of an (n+1)th GOP, and encoding the IDR frame based on the preset IP ratio to obtain an encoding result of the IDR frame; calculating the first peak signal-to-noise ratio based on the IDR frame and the encoding result of the IDR frame; adjusting a QP of a first P frame of the (n+1)th GOP based on the first peak signal-to-noise ratio to obtain a target QP of the first P frame if the first peak signal-to-noise ratio and the second peak signal-to-noise ratio do not satisfy a preset condition; calculating a target code rate of the P frame by calculating the target QP of the first P frame and a real-time code rate of the IDR frame; calculating the target IP ratio by calculating the real-time code rate of the IDR frame and the target code rate of the P frame.
11. A device for determining a target IP ratio based on a preset IP ratio, characterized in that, The pre-encoding module is configured to pre-encode preset GOPs in multiple preset scenes to obtain a pre-encoding result of each preset scene. The determining module is configured to determine a preset IP ratio of the preset scene corresponding to each pre-encoding result based on each pre-encoding result. The first encoding module is configured to obtain an IDR frame of a first GOP in a target scene, encode the IDR frame based on the preset IP ratio of the IDR frame corresponding to the target scene, and obtain an IDR frame encoding result. The target scene is part of the multiple preset scenes. The second encoding module is configured to obtain a first P frame of the first GOP, encode the first P frame based on the preset IP ratio corresponding to the target scene, and obtain a first P frame encoding result. The adjusting module is configured to adjust a QP of a second P frame based on the IDR frame encoding result and the first P frame encoding result, and obtain a target QP of the second P frame. The calculating module is configured to calculate the target QP of the second P frame and a real-time code rate of the IDR frame, and obtain a target IP ratio.
12. A computer device, comprising: The computer device includes a processor and a memory, the memory is used to store at least one program, the at least one program is loaded and executed by the processor, and the method for determining a target IP ratio based on a preset IP ratio is executed as claimed in any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that, The computer readable storage medium stores at least one program, the at least one program is loaded and executed by the processor, and the method for determining a target IP ratio based on a preset IP ratio is executed as claimed in any one of claims 1 to 10.