Video coding method
By calculating the bit rate budget trend value and historical trend value, the frame discarding period is determined, and the video encoding is optimized, which solves the problem of quality, delay and accuracy in the video encoding method, improves the encoding performance and stability, and reduces the cost. Delay.
Patent Information
- Application Number
- CN202410795587.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-06-19
AI Technical Summary
Existing video encoding methods are difficult to balance between quality, delay and accuracy, resulting in low coding performance versatility, and in-depth coupling of encoder implementation methods, video encoding protocols and business scenarios, resulting in system performance deterioration.
By obtaining the target bit rate, number of encoded frames and bit rate budget value of the target video, calculate the current bit rate budget trend value and historical trend value, obtain the continuous downward and upward trend coefficients, determine the frame discarding period, and encode the unencoded frames in sequence , ensuring the actuality and stability of the bit rate budget value and reducing latency.
It is possible to reserve spare budget while meeting the target bit rate, improve the quality and stability of video encoding, reduce encoding output speed, avoid output congestion, reduce delay, and ensure the accuracy of video encoding.
Smart Images

Figure CN118714320A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of video encoding, and in particular to a video encoding method. Background Art
[0002] The real-time audio and video communication system (RTC) mainly uses packet-based transmission protocols to transmit audio and video data. From the acquisition at the sender to the decoding and rendering at the receiver, the audio and video data must pass through multiple network nodes, and each network node has a corresponding bandwidth bottleneck. When RTC transmits audio data, it estimates the bandwidth of the link in real time and controls the end-to-end audio and video data volume based on the bandwidth estimation results.
[0003] The bit rate control of RTC video data transmission usually consists of two parts: one is the bit rate control of the video encoding process, and the other is the bit rate control when the video is sent. The bit rate control of video encoding mainly aims to improve encoding quality, reduce latency, and improve the accuracy of encoding rate control. The characteristics of video encoding technology make these goals contradictory. In actual engineering applications, customized strategies are usually designed by combining multiple factors.
[0004] The technical solution of finely controlling the encoding process to improve the encoding accuracy will increase the difference in encoding quality in the spatial domain and the temporal domain, thereby degrading the final encoding quality.
[0005] In the technical solution of fine-grained control of the encoding process to improve the encoding quality, there are usually special encoding parameter designs for special types of frames (key frames, motion frames, screen switching frames, etc.). Such designs will produce obvious bit rate peaks when encoding special frames, thereby reducing the accuracy of encoding control.
[0006] At the same time, the more refined the bit rate control scheme design is, the more it can strike a balance between quality, delay, and accuracy, and the deeper the coupling with encoder implementation methods, video encoding protocols, and business scenarios. Once the encoding parameters, usage scenarios, encoder implementation, and other factors change, the method will deteriorate the performance of the system and have very low versatility. It can be seen that the existing video encoding methods have the problem of not being able to balance the quality, delay, and accuracy of video encoding. Summary of the invention
[0007] The present application provides a video encoding method, which can solve the problem that the quality, delay and accuracy of video encoding cannot be taken into account at the same time.
[0008] In a first aspect, an embodiment of the present application provides a video encoding method, the video encoding method comprising:
[0009] Obtain the target bit rate of the target video, the number of coded frames and the bit rate budget value at the N-1 moments before the Nth moment, multiple uncoded frames at the Nth moment, and the coding state at the N-1th moment; the Nth moment is the current moment, the target bit rate is the preset coding bit rate of the target video, the bit rate budget value is the maximum coding bit rate, the bit rate budget value is greater than or equal to the target bit rate, and the coding state is used to describe the state of the bit rate budget value of the target video;
[0010] Calculate the current bit rate budget value at the current moment according to the target bit rate and the bit rate budget value at the N-1th moment;
[0011] Based on the number of coded frames and the bit rate budget value at the previous N-1 moments, the current bit rate budget value and the number of uncoded frames, calculate the current bit rate budget trend value at the current moment and the historical bit rate budget trend value at the N-1th moment;
[0012] According to the current bitrate budget trend value and the historical bitrate budget trend value, a continuous downward trend coefficient and a continuous upward trend coefficient of the bitrate budget value at the current moment are obtained; the continuous downward trend coefficient is used to describe the decrease of the bitrate budget value between the current moment and the N-1th moment, and the continuous upward trend coefficient is used to describe the increase of the bitrate budget value between the current moment and the N-1th moment;
[0013] Based on the encoding state of the target video at the N-1th moment, the continuous downward trend coefficient, the continuous upward trend coefficient, and the current bit rate budget value, the frame discarding period at the current moment is obtained; the frame discarding period is used to describe the interval for discarding unencoded frames;
[0014] All uncoded frames at the current moment are encoded in sequence according to the current bit rate budget value and the frame discarding period.
[0015] Optionally, the current bit rate budget value at the current moment is calculated according to the target bit rate and the bit rate budget value at the N-1th moment, including:
[0016] By formula:
[0017] B N =B N-1 +(T N -T N-1 )×R×RF
[0018] Calculate the current bitrate budget value B at the current moment N ;
[0019] Among them, B N-1 represents the bit rate budget value at the N-1th moment, T N Indicates the system time corresponding to the current moment, T N-1represents the system time corresponding to the N-1th moment, R represents the target bit rate, and RF represents the bit rate control strength coefficient.
[0020] Optionally, based on the number of coded frames and the bit rate budget value at the previous N-1 moments, the current bit rate budget value, and the number of uncoded frames, a current bit rate budget trend value at the current moment and a historical bit rate budget trend value at the N-1th moment are calculated, including:
[0021] Calculate the bitrate budget average value based on the bitrate budget values at the previous N-1 moments and the current bitrate budget value;
[0022] Calculate the average number of coded frames based on the number of coded frames and the number of uncoded frames at the previous N-1 moments;
[0023] Calculate the current rate budget trend value at the current moment according to the rate budget average value, the average number of coded frames, the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value, and the number of uncoded frames;
[0024] The historical rate budget trend value at the N-1th moment is calculated based on the rate budget average value, the average number of uncoded frames, the number of coded frames at the previous N-1 moments, and the rate budget value.
[0025] Optionally, the bit rate budget average is calculated based on the bit rate budget values at the previous N-1 moments and the current bit rate budget value, including:
[0026] By formula:
[0027]
[0028] Calculate the bitrate budget average value B avg ;
[0029] Among them, B t represents the code rate budget value at the tth moment. When t = N, B N represents the current bit rate budget value, and N represents the current time;
[0030] The average number of coded frames is calculated based on the number of coded frames and the number of uncoded frames at the previous N-1 moments, including:
[0031] By formula:
[0032]
[0033] Calculate the average number of uncoded frames C avg ;
[0034] Among them, C t Indicates the number of coded frames at the tth moment. When t = N, C NIndicates the number of uncoded frames.
[0035] Optionally, the current rate budget trend value at the current moment is calculated according to the rate budget average value, the average number of coded frames, the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value, and the number of uncoded frames, including:
[0036] By formula:
[0037]
[0038] Calculate the current bitrate budget trend value Q at the current moment N ;
[0039] According to the bitrate budget average value, the average number of uncoded frames, the number of coded frames in the previous N-1 moments, and the bitrate budget value, the historical bitrate budget trend value at the N-1th moment is calculated, including:
[0040] By formula:
[0041]
[0042] Calculate the historical bitrate budget trend value Q at the N-1th moment N-1 .
[0043] Optionally, according to the current bitrate budget trend value and the historical bitrate budget trend value, a continuous downward trend coefficient and a continuous upward trend coefficient of the bitrate budget value at the current moment are obtained, including:
[0044] If the historical bitrate budget trend value is less than -Q th , and the current bitrate budget trend value is less than -Q th , then the continuous downward trend coefficient at the current moment is set to the continuous downward trend coefficient at the N-1th moment plus 1, and the continuous upward trend coefficient at the current moment is set to 0; where Q th Indicates the bitrate budget trend threshold;
[0045] If the historical bitrate budget trend value is greater than Q th , and the current bitrate budget trend value is greater than Q th , then the continuous rising trend coefficient at the current moment is set to the continuous rising trend coefficient at the N-1th moment plus 1, and the continuous falling trend coefficient at the current moment is set to 0;
[0046] If the historical bitrate budget trend value is less than -Q th , and the current bitrate budget trend value is greater than Q th , then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both set to 0;
[0047] If the historical bitrate budget trend value is greater than Qth , and the current bitrate budget trend value is less than -Q th , then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both set to 0.
[0048] Optionally, the encoding state is one of a budget sufficient state, a budget decreasing state, a budget increasing state, and a budget deficit state;
[0049] The frame discarding period at the current moment is obtained based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value, including:
[0050] When the encoding state of the target video at the N-1th moment is a sufficient budget state, if the continuous decreasing trend coefficient at the current moment is greater than or equal to the decreasing coefficient threshold, the encoding state of the target video at the current moment is a decreasing budget state, the frame discarding period is set to the upper limit of the frame discarding period, and the continuous decreasing trend coefficient is set to 0;
[0051] If the continuous downward trend coefficient at the current moment is less than the downward coefficient threshold, the encoding state of the target video at the current moment is a sufficient budget state, and the frame discarding period is the frame discarding period at the N-1th moment.
[0052] Optionally, obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value, further includes:
[0053] When the encoding state of the target video at the N-1th moment is a budget reduction state, if the bit rate budget value at the current moment is greater than the bit rate budget lower limit value, the encoding state of the target video at the current moment is a budget reduction state, and the frame discarding period is set to the frame discarding period upper limit value minus one;
[0054] If the continuous rising trend coefficient at the current moment is greater than or equal to the rising coefficient threshold, the encoding state of the target video at the current moment is the budget rising state, the continuous rising trend coefficient is set to 0, and it is determined whether the frame discarding period at the N-1th moment is less than the upper limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the upper limit of the frame discarding period;
[0055] If the bitrate budget value at the current moment is less than or equal to the bitrate budget lower limit, the encoding state of the target video at the current moment is a budget deficit state, and it is determined whether the frame discarding period at the N-1th moment is greater than the frame discarding period lower limit. If so, the frame discarding period is set to the frame discarding period at the N-1th moment minus 1, otherwise, the frame discarding period is set to the frame discarding period lower limit.
[0056] Optionally, obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value, further includes:
[0057] When the encoding state of the target video at the N-1th moment is the budget rising state, if the bit rate budget value at the current moment is less than the bit rate budget upper limit value, the encoding state of the target video at the current moment is the budget rising state, and it is determined whether the frame discarding period at the N-1th moment is less than the frame discarding period upper limit value, if so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the frame discarding period upper limit value;
[0058] If the bitrate budget value at the current moment is greater than or equal to the bitrate budget upper limit value, the encoding state of the target video at the current moment is a sufficient budget state, and the frame discard period is 0;
[0059] If the continuous downward trend coefficient at the current moment is greater than or equal to the downward coefficient threshold, the encoding state of the target video at the current moment is a budget reduction state, the continuous downward trend coefficient is set to 0, and the frame discarding period is the frame discarding period at the N-1th moment.
[0060] Optionally, obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value, further includes:
[0061] When the encoding state of the target video at the N-1th moment is a budget deficit state, if the continuous rising trend coefficient at the current moment is less than the rising coefficient threshold, the encoding state of the target video at the current moment is a budget deficit state, and it is determined whether the frame discarding period at the N-1th moment is greater than the lower limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment minus 1, otherwise, the frame discarding period is set to the lower limit of the frame discarding period;
[0062] If the continuous rising trend coefficient at the current moment is greater than or equal to the rising coefficient threshold, the encoding state of the target video at the current moment is a budget rising state, and it is determined whether the frame discarding period at the N-1th moment is less than the upper limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the upper limit of the frame discarding period.
[0063] In a second aspect, an embodiment of the present application provides a video encoding device, including:
[0064] The first acquisition module acquires the target bit rate of the target video, the number of coded frames and the bit rate budget value at the N-1 moments before the Nth moment, multiple uncoded frames at the Nth moment, and the encoding state at the N-1th moment; the Nth moment is the current moment, the target bit rate is the preset encoding bit rate of the target video, the bit rate budget value is the maximum value of the encoding bit rate, the bit rate budget value is greater than or equal to the target bit rate, and the encoding state is used to describe the state of the bit rate budget value of the target video;
[0065] A first calculation module calculates a current bit rate budget value at a current moment according to a target bit rate and a bit rate budget value at an N-1th moment;
[0066] A second calculation module calculates a current rate budget trend value at a current moment and a historical rate budget trend value at an N-1th moment based on the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value, and the number of uncoded frames;
[0067] The second acquisition module acquires a continuous downward trend coefficient and a continuous upward trend coefficient of the bit rate budget value at the current moment according to the current bit rate budget trend value and the historical bit rate budget trend value; the continuous downward trend coefficient is used to describe the decrease of the bit rate budget value between the current moment and the N-1th moment, and the continuous upward trend coefficient is used to describe the increase of the bit rate budget value between the current moment and the N-1th moment;
[0068] The frame discarding period acquisition module obtains the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value; the frame discarding period is used to describe the interval for discarding unencoded frames;
[0069] The encoding module encodes all unencoded frames at the current moment in sequence according to the current bit rate budget value and the frame discarding period.
[0070] In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned video encoding method when executing the above-mentioned computer program.
[0071] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program implements the above-mentioned video encoding method when executed by a processor.
[0072] The above solution of the present application has the following beneficial effects:
[0073] In an embodiment of the present application, a target bit rate of a target video, the number of coded frames and a bit rate budget value at the N-1th moment before the Nth moment, a plurality of uncoded frames at the Nth moment, and a coding state at the N-1th moment are obtained, and then a current bit rate budget value at the current moment is calculated according to the target bit rate and the bit rate budget value at the N-1th moment, and then a current bit rate budget trend value at the current moment and a historical bit rate budget trend value at the N-1th moment are calculated based on the number of coded frames and the bit rate budget value at the N-1th moment before the N-1th moment, the current bit rate budget value, and the number of uncoded frames, and then a continuous decreasing trend coefficient and a continuous increasing trend coefficient of the bit rate budget value at the current moment are obtained according to the current bit rate budget trend value and the historical bit rate budget trend value, and then a frame discarding period at the current moment is obtained based on the coding state, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value of the target video at the N-1th moment, and finally all uncoded frames at the current moment are encoded in sequence according to the current bit rate budget value and the frame discarding period. Among them, the bit rate budget value is calculated based on the target bit rate, and the actual bit rate target of the target video is taken into consideration, so that the bit rate budget value is practical. The subsequent video encoding steps are performed according to the practical bit rate budget value, which can ensure the accuracy of video encoding. At the same time, by using the bit rate budget value for video encoding, it is possible to reserve a spare budget while meeting the target bit rate, which is convenient for special processing of special unencoded frames, improving the quality and stability of video encoding, and introducing a frame discarding period for video encoding, so that the number of unencoded frames encoded at the current moment is reduced, the output speed of encoding is reduced, the situation of output congestion caused by too fast encoding is avoided, and the delay is reduced.
[0074] Other beneficial effects of the present application will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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 application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0076] Figure 1 A flowchart of a video encoding method provided by an embodiment of the present application;
[0077] Figure 2 A schematic diagram of an encoding state provided by an embodiment of the present application;
[0078] Figure 3 A quantization parameter curve diagram provided in an embodiment of the present application;
[0079] Figure 4A transmission delay curve diagram provided in an embodiment of the present application;
[0080] Figure 5 A coding rate curve diagram provided by an embodiment of the present application;
[0081] Figure 6 A code rate budget curve diagram provided by an embodiment of the present application;
[0082] Figure 7 An encoder input skip rate curve diagram provided by an embodiment of the present application;
[0083] Figure 8 A schematic diagram of the structure of a video encoding device provided in one embodiment of the present application;
[0084] Fig. 9 A schematic diagram of the structure of a terminal device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0085] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0086] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0087] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0088] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0089] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0090] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0091] In order to solve the problem that the quality, delay and accuracy of video encoding cannot be taken into account at the same time, an embodiment of the present application provides a video encoding method, which obtains the target bit rate of the target video, the number of encoded frames and the bit rate budget value at the N-1 moments before the Nth moment, multiple unencoded frames at the Nth moment, and the encoding state at the N-1th moment, and then calculates the current bit rate budget value at the current moment according to the target bit rate and the bit rate budget value at the N-1th moment, and then calculates the current bit rate budget value based on the number of encoded frames and the bit rate budget value at the N-1th moment, the current bit rate budget value and the unencoded frames. The number of bitrate budget trends at the current moment and the historical bitrate budget trend values at the N-1th moment are calculated, and then the continuous decreasing trend coefficient and the continuous increasing trend coefficient of the bitrate budget value at the current moment are obtained according to the current bitrate budget trend value and the historical bitrate budget trend value. Then, based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bitrate budget value, the frame discarding period at the current moment is obtained. Finally, all unencoded frames at the current moment are encoded in sequence according to the current bitrate budget value and the frame discarding period. Among them, the bit rate budget value is calculated based on the target bit rate, and the actual bit rate target of the target video is taken into consideration, so that the bit rate budget value is practical. The subsequent video encoding steps are performed according to the practical bit rate budget value, which can ensure the accuracy of video encoding. At the same time, by using the bit rate budget value for video encoding, it is possible to reserve a spare budget while meeting the target bit rate, which is convenient for special processing of special unencoded frames, improving the quality and stability of video encoding, and introducing a frame discarding period for video encoding, so that the number of unencoded frames encoded at the current moment is reduced, the output speed of encoding is reduced, the situation of output congestion caused by too fast encoding is avoided, and the delay is reduced.
[0092] Next, the video encoding method provided by this application is exemplified.
[0093] like Figure 1 As shown, the video encoding method provided by the present application includes the following steps:
[0094] Step 11, obtain the target bit rate of the target video, the number of encoded frames and the bit rate budget value at the N-1 moments before the Nth moment, multiple unencoded frames at the Nth moment, and the encoding state at the N-1th moment.
[0095] The Nth moment is the current moment, the target bit rate is the preset encoding bit rate of the target video, the bit rate budget value is the maximum value of the encoding bit rate, the bit rate budget value is greater than or equal to the target bit rate, such as if the target bit rate is 20, the bit rate budget value can be 25, and the encoding status is used to describe the status of the bit rate budget value of the target video.
[0096] It should be noted that the target video is the video to be encoded, the Nth moment may be the 5th moment, and the N-1 moments before the Nth moment are the 1st moment, the 2nd moment, the 3rd moment, and the 4th moment respectively.
[0097] In some embodiments of the present application, video encoders such as H264 and AV1 can be used to obtain the number of encoded frames (i.e., the number of encoded frames) and the bit rate budget value of the target video at N-1 moments before the Nth moment, multiple unencoded frames at the Nth moment, and the encoding status at the N-1th moment, and the target bit rate can be preset according to the bit rate requirement of the target video.
[0098] Step 12: Calculate the current bit rate budget value at the current moment according to the target bit rate and the bit rate budget value at the N-1th moment.
[0099] Specifically, through the formula:
[0100] B N =B N-1 +(T N -T N-1 )×R×RF
[0101] Calculate the current bitrate budget value B at the current moment N .
[0102] Among them, B N-1 represents the bit rate budget value at the N-1th moment, T N Indicates the system time corresponding to the current moment, T N-1 It represents the system time corresponding to the N-1th moment, R represents the target bit rate, and RF represents the bit rate control strength coefficient, which can be a value from 1 to 1.33.
[0103] Exemplarily, the above formula can be run using computer software for mathematical calculations such as Mathematica to obtain the current bit rate budget value.
[0104] It is worth mentioning that in order to ensure that special situations can be adapted while meeting the target bit rate (such as a frame being a key frame, a still switching motion frame, a screen switching frame, and other special frames that require a high encoding bit rate), a bit rate budget value slightly larger than the target bit rate is calculated to improve the stability of encoding the target video.
[0105] Step 13, based on the number of coded frames and the bit rate budget value at the previous N-1 moments, the current bit rate budget value and the number of uncoded frames, calculate the current bit rate budget trend value at the current moment and the historical bit rate budget trend value at the N-1th moment.
[0106] The above bitrate budget trend value is used to describe the change of the bitrate budget value over a period of time.
[0107] In some embodiments of the present application, the current rate budget trend value at the current moment and the historical rate budget trend value at the N-1th moment are calculated based on the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value and the number of uncoded frames as follows:
[0108] In the first step, the bit rate budget average value is calculated based on the bit rate budget values at the previous N-1 moments and the current bit rate budget value.
[0109] By formula:
[0110]
[0111] Calculate the bitrate budget average value B avg .
[0112] Among them, B t represents the code rate budget value at the tth moment. When t = N, B N represents the current bit rate budget value, and N represents the current time.
[0113] In the second step, the average number of coded frames is calculated based on the number of coded frames and the number of uncoded frames at the previous N-1 moments.
[0114] By formula:
[0115]
[0116] Calculate the average number of uncoded frames C avg .
[0117] Among them, C t Indicates the number of coded frames at the tth moment. When t = N, C NIndicates the number of uncoded frames.
[0118] The third step is to calculate the current rate budget trend value at the current moment based on the rate budget average value, the average number of coded frames, the number of coded frames and rate budget value at the previous N-1 moments, the current rate budget value, and the number of uncoded frames.
[0119] By formula:
[0120]
[0121] Calculate the current bitrate budget trend value Q at the current moment N .
[0122] The fourth step is to calculate the historical bit rate budget trend value at the N-1th moment according to the bit rate budget average value, the average number of uncoded frames, the number of coded frames at the previous N-1 moments, and the bit rate budget value.
[0123] Specifically, through the formula:
[0124]
[0125] Calculate the historical bitrate budget trend value Q at the N-1th moment N-1 .
[0126] It should be noted that the rate budget trend value can be compared with the rate budget trend threshold to analyze the change of the rate budget value over a period of time, and the larger the absolute value of the rate budget trend value, the larger the change of the rate budget value.
[0127] Exemplarily, the current bit rate budget trend value is 3, which is greater than the bit rate budget trend value threshold 2, indicating that the bit rate budget value shows an increasing trend in the time period from the first moment to the current moment. If the bit rate budget trend value is -3, which is less than -2, it means that the bit rate budget value shows a decreasing trend in this time period.
[0128] It is worth mentioning that by calculating the current bit rate budget trend value and the historical bit rate budget trend value, the change status of the bit rate budget value in the time period from the first moment to the current moment and in the time period from the first moment to the N-1th moment can be analyzed.
[0129] Step 14: Obtain a continuous decreasing trend coefficient and a continuous increasing trend coefficient of the bit rate budget value at the current moment according to the current bit rate budget trend value and the historical bit rate budget trend value.
[0130] The above continuous downward trend coefficient is used to describe the decrease of the bit rate budget value between the current moment and the N-1th moment, and the continuous upward trend coefficient is used to describe the increase of the bit rate budget value between the current moment and the N-1th moment.
[0131] Specifically, if the historical bitrate budget trend value is less than -Q th , and the current bitrate budget trend value is less than -Q th , then the continuous downward trend coefficient at the current moment is set to the continuous downward trend coefficient at the N-1th moment plus 1, and the continuous upward trend coefficient at the current moment is set to 0. th Indicates the bitrate budget trend threshold.
[0132] If the historical bitrate budget trend value is greater than Q th , and the current bitrate budget trend value is greater than Q th , then the continuous rising trend coefficient at the current moment is set to the continuous rising trend coefficient at the N-1th moment plus 1, and the continuous falling trend coefficient at the current moment is set to 0.
[0133] If the historical bitrate budget trend value is less than -Q th , and the current bitrate budget trend value is greater than Q th , then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both set to 0.
[0134] If the historical bitrate budget trend value is greater than Q th , and the current bitrate budget trend value is less than -Q th , then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both set to 0.
[0135] Exemplarily, the continuous downward trend coefficient at the N-1th moment is 1, and the continuous upward trend coefficient at the N-1th moment is 3. If the historical rate budget trend value and the current rate budget trend value are both less than the negative value of the rate budget trend threshold 5, the continuous downward trend coefficient at the current moment is 2, and the continuous upward trend coefficient is 0; if the historical rate budget trend value and the current rate budget trend value are both greater than 5, the continuous upward trend coefficient at the current moment is 4, and the continuous downward trend coefficient is 0; if the historical rate budget trend value is less than -5, and the current rate budget trend value is greater than 5, then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both 0; if the historical rate budget trend value is greater than 5, and the current rate budget trend value is less than -5, then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both 0.
[0136] It is worth mentioning that by obtaining the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment, the upward and downward conditions of the bit rate budget value can be described, providing the change information of the bit rate budget value for subsequent steps.
[0137] Step 15, obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value.
[0138] The frame discarding period is used to describe the interval of discarding uncoded frames. For example, if the frame discarding period is 5, one uncoded frame is discarded every 5 uncoded frames during the encoding process. The encoding state is one of the budget sufficient state, budget decreasing state, budget increasing state, and budget deficit state. The budget sufficient state indicates that the bitrate budget value tends to be stable and can meet the encoding requirements of the target video; the budget decreasing state indicates that the bitrate budget value is in a decreasing state, the budget increasing state indicates that the bitrate budget value is in an increasing state, and the budget deficit state indicates that the bitrate budget value is less than the bitrate budget lower limit.
[0139] It should be noted that, before the target video starts to be encoded, the encoding state of the target video is recorded as the startup state. At this time, each unencoded frame of the target video is loaded in sequence. When the number of unencoded frames that have been loaded reaches the unencoded frame number threshold, the budget is sufficient state is entered, and the target video is started to be encoded. At this time, the frame discarding period is set to 0, indicating that the unencoded frames are not discarded, and the continuous rising trend coefficient and the continuous falling trend coefficient are both set to 0, that is, when the target video is encoded, the initial values of the frame discarding period, the continuous rising trend coefficient, and the continuous falling trend coefficient are all 0.
[0140] In some embodiments of the present application, the step of obtaining the frame discarding period at the current moment based on the encoding state, the continuous downward trend coefficient, the continuous upward trend coefficient, and the current bit rate budget value of the target video at the N-1th moment includes:
[0141] When the encoding state of the target video at the N-1th moment is a sufficient budget state, if the continuous downward trend coefficient at the current moment is greater than or equal to the downward coefficient threshold, the encoding state of the target video at the current moment is a downward budget state, the frame discarding period is set to the upper limit of the frame discarding period, and the continuous downward trend coefficient is set to 0.
[0142] If the continuous downward trend coefficient at the current moment is less than the downward coefficient threshold, the encoding state of the target video at the current moment is a sufficient budget state, and the frame discarding period is the frame discarding period at the N-1th moment.
[0143] When the encoding state of the target video at the N-1th moment is a budget reduction state, if the bit rate budget value at the current moment is greater than the bit rate budget lower limit value, the encoding state of the target video at the current moment is a budget reduction state, and the frame discarding period is set to the frame discarding period upper limit value minus one.
[0144] If the continuous rising trend coefficient at the current moment is greater than or equal to the rising coefficient threshold, the encoding state of the target video at the current moment is the budget rising state, the continuous rising trend coefficient is set to 0, and it is determined whether the frame discarding period at the N-1th moment is less than the upper limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the upper limit of the frame discarding period.
[0145] If the bitrate budget value at the current moment is less than or equal to the bitrate budget lower limit, the encoding state of the target video at the current moment is a budget deficit state, and it is determined whether the frame discarding period at the N-1th moment is greater than the frame discarding period lower limit. If so, the frame discarding period is set to the frame discarding period at the N-1th moment minus 1, otherwise, the frame discarding period is set to the frame discarding period lower limit.
[0146] When the encoding state of the target video at the N-1th moment is the budget increasing state, if the bit rate budget value at the current moment is less than the bit rate budget upper limit value, the encoding state of the target video at the current moment is the budget increasing state, and it is determined whether the frame discarding period at the N-1th moment is less than the frame discarding period upper limit value. If so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the frame discarding period upper limit value.
[0147] If the bitrate budget value at the current moment is greater than or equal to the bitrate budget upper limit value, the encoding state of the target video at the current moment is a sufficient budget state, and the frame discarding period is 0.
[0148] If the continuous downward trend coefficient at the current moment is greater than or equal to the downward coefficient threshold, the encoding state of the target video at the current moment is a budget reduction state, the continuous downward trend coefficient is set to 0, and the frame discarding period is the frame discarding period at the N-1th moment.
[0149] When the encoding state of the target video at the N-1th moment is a budget deficit state, if the continuous rising trend coefficient at the current moment is less than the rising coefficient threshold, the encoding state of the target video at the current moment is a budget deficit state, and it is determined whether the frame discarding period at the N-1th moment is greater than the lower limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment minus 1, otherwise, the frame discarding period is set to the lower limit of the frame discarding period.
[0150] If the continuous rising trend coefficient at the current moment is greater than or equal to the rising coefficient threshold, the encoding state of the target video at the current moment is a budget rising state, and it is determined whether the frame discarding period at the N-1th moment is less than the upper limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the upper limit of the frame discarding period.
[0151] Exemplarily, before encoding the target video, it is in a startup state, which can be recorded as the 0th moment. When the startup state becomes a sufficient budget state, encoding of the target video begins, which is recorded as the 1st moment. At the 1st moment, multiple unencoded frames of the target video are encoded, and the encoding state and frame discarding period of the second moment are obtained according to the above steps. At the second moment, multiple unencoded frames are encoded according to the frame discarding period, and so on, until the encoding of the target video is completed.
[0152] It should be noted that in the above steps, after obtaining the encoding state of the target video at the current moment, the continuous rising trend coefficient or the continuous falling trend coefficient is set to 0 in order to facilitate the calculation of the continuous rising trend coefficient or the continuous falling trend coefficient at the next moment after the current moment.
[0153] It is worth mentioning that the encoding status at the current moment and the frame discard period are obtained according to the encoding status of the target video at the previous moment, the continuous downward trend coefficient, the continuous upward trend coefficient, and the current bit rate budget value. The encoding status at the previous moment, the changing trend of the encoding budget value, and the value of the encoding budget value are taken into consideration, thereby improving the accuracy of the frame discard period.
[0154] The above encoding state is exemplarily described below with reference to a specific example.
[0155] like Figure 2 As shown, the target video enters the budget sufficient state after the startup phase (i.e., the startup state mentioned above) ends. The budget sufficient state can be switched to the budget decreasing state and the budget sufficient state. The budget decreasing state can be switched to the budget deficit state, the budget increasing state, and the budget decreasing state. The budget deficit state can be switched to the budget increasing state and the budget deficit state. The budget increasing state can be switched to the budget sufficient state, the budget decreasing state, and the budget increasing state. The line with an arrow in the figure indicates the state switching direction.
[0156] Step 16: Encode all unencoded frames at the current moment in sequence according to the current bit rate budget value and the frame discarding period.
[0157] Specifically, all uncoded frames are discarded according to a frame discarding period, and each uncoded frame that is not discarded is encoded in turn according to a target bit rate. If the uncoded frame is a special frame, the uncoded frame is not discarded, and without exceeding a current bit rate budget value, the encoding bit rate parameters of the uncoded frame are adjusted to improve the clarity of the special frame.
[0158] It should be noted that after the encoding of all uncoded frames at the current moment is completed, the average encoding bit rates of all coded uncoded frames are calculated, and the current bit rate budget value minus the average value is used as the bit rate budget value at the current moment, so as to calculate the bit rate budget value at the next moment. When the transmission rate of the coded frames is less than the encoding rate, video encoding is performed according to the frame discarding period, which can reduce the number of uncoded frames to be encoded, empty the coded frames as soon as possible, and prevent congestion.
[0159] It is worth mentioning that the bit rate budget value is calculated based on the target bit rate, and the actual bit rate target of the target video is taken into account, so that the bit rate budget value is practical. The subsequent video encoding steps are performed according to the practical bit rate budget value, which can ensure the accuracy of video encoding. At the same time, using the bit rate budget value for video encoding can reserve spare budget while meeting the target bit rate, which is convenient for special processing of special unencoded frames, improving the quality and stability of video encoding, and introducing a frame discarding period for video encoding, so that the number of unencoded frames encoded at the current moment is reduced, the output speed of encoding is reduced, and the situation of output congestion caused by too fast encoding is avoided, thereby reducing delays.
[0160] The video encoding method of the present application is exemplarily described below with reference to a specific example.
[0161] A video is encoded using the video encoding method of the present application.
[0162] In terms of coding quality, the quantization parameter QP curve in the encoding process is as follows Figure 3 As shown in the figure, the horizontal axis represents time, the vertical axis represents the QP value, the dotted line with diamonds represents the maximum coding QP change curve, the solid line with diamonds represents the average coding QP change curve, and the solid line with triangles represents the minimum coding QP change curve.
[0163] In terms of latency, the sending latency curve is as follows Figure 4 As shown in the figure, the horizontal axis represents time, the vertical axis represents the transmission delay, the unit is milliseconds (ms), the solid line with triangles is the transmission delay change curve; the coding rate change curve is as follows Figure 5 As shown in the figure, the horizontal axis represents time, the vertical axis represents the bit rate, and the unit is kilobits per second (kbps). The curve with a triangle represents the change curve of the bit rate water level, the curve with a diamond represents the change curve of the actual bit rate, and the dotted line with a diamond represents the change curve of the encoding parameter.
[0164] Figure 3 In the video, between 17:22:35 and 17:22:40, the encoding QP is limited to 43 to ensure the minimum definition of the target video after encoding. Figure 4 and Figure 5In the process, the encoding bit rate drops rapidly in a short time, and a large transmission delay occurs at the sending end. The video encoding method of the present application can quickly reduce the transmission delay to less than 30ms in a short time.
[0165] The bitrate budget changes as follows: Figure 6 As shown in the figure, the horizontal axis represents time, the vertical axis represents the bit rate budget, the solid line with triangles represents the change curve of the real-time bit rate budget, the solid line with diamonds represents the change curve of the minimum bit rate budget, and the encoder input skip rate (i.e., the frame discard period mentioned above) is shown in Figure 7 As shown in the figure, the horizontal axis represents time, the vertical axis represents frame rate, and the unit is frames per second. The solid line with triangles represents the frame rate change curve, and the solid line with dots represents the frame skipping rate.
[0166] It can be seen that the video encoding method of the present application can improve the accuracy of video encoding while ensuring the quality of video encoding, while reducing the transmission delay of the sending end.
[0167] The video encoding device provided in this application is exemplarily described below.
[0168] like Figure 8 As shown, the embodiment of the present application provides a video encoding device, and the video encoding device 800 includes:
[0169] The first acquisition module 801 acquires the target bit rate of the target video, the number of coded frames and the bit rate budget value at the N-1 moments before the Nth moment, multiple uncoded frames at the Nth moment, and the encoding state at the N-1th moment; the Nth moment is the current moment, the target bit rate is the preset encoding bit rate of the target video, the bit rate budget value is the maximum value of the encoding bit rate, the bit rate budget value is greater than or equal to the target bit rate, and the encoding state is used to describe the state of the bit rate budget value of the target video;
[0170] A first calculation module 802 calculates a current bit rate budget value at a current moment according to a target bit rate and a bit rate budget value at an N-1th moment;
[0171] The second calculation module 803 calculates the current rate budget trend value at the current moment and the historical rate budget trend value at the N-1th moment based on the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value and the number of uncoded frames;
[0172] The second acquisition module 804 acquires a continuous decreasing trend coefficient and a continuous increasing trend coefficient of the rate budget value at the current moment according to the current rate budget trend value and the historical rate budget trend value; the continuous decreasing trend coefficient is used to describe the decreasing condition of the rate budget value between the current moment and the N-1th moment, and the continuous increasing trend coefficient is used to describe the increasing condition of the rate budget value between the current moment and the N-1th moment;
[0173] The frame discarding period acquisition module 805 acquires the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value; the frame discarding period is used to describe the interval for discarding unencoded frames;
[0174] The encoding module 806 encodes all unencoded frames at the current moment in sequence according to the current bit rate budget value and the frame discarding period.
[0175] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0176] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0177] like Fig. 9 As shown, an embodiment of the present application provides a terminal device. The terminal device D10 of this embodiment includes: at least one processor D100 ( Fig. 9 Only one processor is shown in the figure), a memory D101, and a computer program D102 stored in the memory D101 and executable on the at least one processor D100, wherein the processor D100 implements the steps of any of the above-mentioned method embodiments when executing the computer program D102.
[0178] Specifically, when the processor D100 executes the computer program D102, the target bit rate of the target video, the number of coded frames and the bit rate budget value at the N-1th moment before the Nth moment, multiple uncoded frames at the Nth moment, and the coding state at the N-1th moment are obtained, and then the current bit rate budget value at the current moment is calculated according to the target bit rate and the bit rate budget value at the N-1th moment, and then the current bit rate budget trend value at the current moment and the historical bit rate budget trend value at the N-1th moment are calculated based on the number of coded frames and the bit rate budget value at the N-1th moment before the N-1th moment, the current bit rate budget value, and the number of uncoded frames, and then the continuous downward trend coefficient and the continuous upward trend coefficient of the bit rate budget value at the current moment are obtained according to the current bit rate budget trend value and the historical bit rate budget trend value, and then the frame discarding period at the current moment is obtained based on the coding state of the target video at the N-1th moment, the continuous downward trend coefficient, the continuous upward trend coefficient, and the current bit rate budget value, and finally all the uncoded frames at the current moment are encoded in sequence according to the current bit rate budget value and the frame discarding period. Among them, the bit rate budget value is calculated based on the target bit rate, and the actual bit rate target of the target video is taken into consideration, so that the bit rate budget value is practical. The subsequent video encoding steps are performed according to the practical bit rate budget value, which can ensure the accuracy of video encoding. At the same time, by using the bit rate budget value for video encoding, it is possible to reserve a spare budget while meeting the target bit rate, which is convenient for special processing of special unencoded frames, improving the quality and stability of video encoding, and introducing a frame discarding period for video encoding, so that the number of unencoded frames encoded at the current moment is reduced, the output speed of encoding is reduced, the situation of output congestion caused by too fast encoding is avoided, and the delay is reduced.
[0179] The processor D100 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0180] In some embodiments, the memory D101 may be an internal storage unit of the terminal device D10, such as a hard disk or memory of the terminal device D10. In other embodiments, the memory D101 may also be an external storage device of the terminal device D10, such as a plug-in hard disk, a smart memory card (SMC, SmartMedia Card), a secure digital (SD, Secure Digital) card, a flash card (Flash Card), etc. equipped on the terminal device D10. Further, the memory D101 may also include both an internal storage unit of the terminal device D10 and an external storage device. The memory D101 is used to store an operating system, an application program, a boot loader (BootLoader), data and other programs, such as the program code of the computer program, etc. The memory D101 may also be used to temporarily store data that has been output or is to be output.
[0181] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0182] An embodiment of the present application provides a computer program product. When the computer program product runs on a terminal device, the terminal device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0183] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the video encoding method device / terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0184] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0185] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0186] The above is a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles described in the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A video encoding method, characterized in that: include: Obtaining a target bit rate of a target video, the number of coded frames and a bit rate budget value at the N-1 moments before the Nth moment, a plurality of uncoded frames at the Nth moment, and a coding state at the N-1th moment; the Nth moment is the current moment, the target bit rate is a preset coding bit rate of the target video, the bit rate budget value is a maximum coding bit rate, the bit rate budget value is greater than or equal to the target bit rate, and the coding state is used to describe a state of the bit rate budget value of the target video; Calculate the current bit rate budget value at the current moment according to the target bit rate and the bit rate budget value at the N-1th moment; Calculate a current rate budget trend value at the current moment and a historical rate budget trend value at the N-1th moment based on the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value and the number of uncoded frames; According to the current bit rate budget trend value and the historical bit rate budget trend value, obtaining a continuous downward trend coefficient and a continuous upward trend coefficient of the bit rate budget value at the current moment; the continuous downward trend coefficient is used to describe a decrease in the bit rate budget value between the current moment and the N-1th moment, and the continuous upward trend coefficient is used to describe an increase in the bit rate budget value between the current moment and the N-1th moment; Acquire a frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value; the frame discarding period is used to describe the interval for discarding unencoded frames; All uncoded frames at the current moment are encoded in sequence according to the current code rate budget value and the frame discarding period.
2. The video encoding method according to claim 1, characterized in that: The calculating the current bit rate budget value at the current moment according to the target bit rate and the bit rate budget value at the N-1th moment includes: By formula: B N =B N-1 +(T N -T N-1 )×R×RF Calculate the current bitrate budget value B at the current moment N ; Among them, B N-1 represents the bit rate budget value at the N-1th moment, T N Indicates the system time corresponding to the current moment, T N-1 represents the system time corresponding to the N-1th moment, R represents the target bit rate, and RF represents the bit rate control strength coefficient.
3. The video encoding method according to claim 1, characterized in that: The calculating, based on the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value and the number of uncoded frames, the current rate budget value and the number of uncoded frames, the current rate budget trend value at the current moment and the historical rate budget trend value at the N-1th moment includes: Calculate a bit rate budget average value based on the bit rate budget values at the previous N-1 moments and the current bit rate budget value; Calculate the average number of coded frames based on the number of coded frames and the number of uncoded frames at the first N-1 moments; Calculate a current rate budget trend value at a current moment according to the rate budget average value, the average number of coded frames, the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value, and the number of uncoded frames; The historical rate budget trend value at the N-1th moment is calculated according to the rate budget average value, the average number of uncoded frames, the number of coded frames at the previous N-1 moments, and the rate budget value.
4. The video encoding method according to claim 3, characterized in that: The calculating the bit rate budget average value based on the bit rate budget values at the previous N-1 moments and the current bit rate budget value includes: By formula: Calculate the bitrate budget average value B avg ; Among them, B t represents the code rate budget value at the tth moment. When t = N, B N represents the current bit rate budget value, and N represents the current time; The calculating the average number of coded frames based on the number of coded frames and the number of uncoded frames at the first N-1 moments includes: By formula: Calculate the average number of uncoded frames C avg ; Among them, C t represents the number of coded frames at the t-th moment. When t=N, C N Indicates the number of uncoded frames.
5. The video encoding method according to claim 3, characterized in that: The calculating the current rate budget trend value at the current moment according to the rate budget average value, the average number of coded frames, the number of coded frames and the rate budget value at the previous N-1 moments, the current rate budget value, and the number of uncoded frames includes: By formula: Calculate the current bitrate budget trend value Q at the current moment N ; The calculating the historical rate budget trend value at the N-1th moment according to the rate budget average value, the average number of uncoded frames, the number of coded frames at the previous N-1 moments, and the rate budget value includes: By formula: Calculate the historical bitrate budget trend value Q at the N-1th moment N-1 .
6. The video encoding method according to claim 1, characterized in that: The step of obtaining a continuous decreasing trend coefficient and a continuous increasing trend coefficient of the bit rate budget value at the current moment according to the current bit rate budget trend value and the historical bit rate budget trend value includes: If the historical bitrate budget trend value is less than -Q th , and the current bitrate budget trend value is less than -Q th , then the continuous downward trend coefficient at the current moment is set to the continuous downward trend coefficient at the N-1th moment plus 1, and the continuous upward trend coefficient at the current moment is set to 0; where Q th Indicates the bitrate budget trend threshold; If the historical bit rate budget trend value is greater than Q th , and the current bitrate budget trend value is greater than Q th , then the continuous rising trend coefficient at the current moment is set to the continuous rising trend coefficient at the N-1th moment plus 1, and the continuous falling trend coefficient at the current moment is set to 0; If the historical bitrate budget trend value is less than -Q th , and the current bitrate budget trend value is greater than Q th , then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both set to 0; If the historical bit rate budget trend value is greater than Q th , and the current bitrate budget trend value is less than -Q th , then the continuous downward trend coefficient and the continuous upward trend coefficient at the current moment are both set to 0.
7. The video encoding method according to claim 1, characterized in that: The coding state is one of a budget sufficient state, a budget decreasing state, a budget increasing state, and a budget deficit state; The obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value includes: When the encoding state of the target video at the N-1th moment is the budget sufficient state, if the continuous downward trend coefficient at the current moment is greater than or equal to the downward coefficient threshold, the encoding state of the target video at the current moment is the budget downward state, the frame discarding period is set to the frame discarding period upper limit value, and the continuous downward trend coefficient is set to 0; If the continuous downward trend coefficient at the current moment is less than the downward coefficient threshold, the encoding state of the target video at the current moment is a sufficient budget state, and the frame discarding period is the frame discarding period at the N-1th moment.
8. The video encoding method according to claim 7, characterized in that: The step of obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value further includes: When the encoding state of the target video at the N-1th moment is the budget reduction state, if the bit rate budget value at the current moment is greater than the bit rate budget lower limit value, the encoding state of the target video at the current moment is the budget reduction state, and the frame discarding period is set to the frame discarding period upper limit value minus one; If the continuous rising trend coefficient at the current moment is greater than or equal to the rising coefficient threshold, the encoding state of the target video at the current moment is a budget rising state, the continuous rising trend coefficient is set to 0, and it is determined whether the frame discarding period at the N-1th moment is less than the upper limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the upper limit of the frame discarding period; If the bit rate budget value at the current moment is less than or equal to the bit rate budget lower limit value, the encoding state of the target video at the current moment is the budget deficit state, and it is determined whether the frame discarding period at the N-1th moment is greater than the frame discarding period lower limit value. If so, the frame discarding period is set to the frame discarding period at the N-1th moment minus 1; otherwise, the frame discarding period is set to the frame discarding period lower limit value.
9. The video encoding method according to claim 7, characterized in that: The step of obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value further includes: When the encoding state of the target video at the N-1th moment is the budget rising state, if the bit rate budget value at the current moment is less than the bit rate budget upper limit value, the encoding state of the target video at the current moment is the budget rising state, and it is determined whether the frame discarding period at the N-1th moment is less than the frame discarding period upper limit value, and if so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the frame discarding period upper limit value; If the bit rate budget value at the current moment is greater than or equal to the bit rate budget upper limit value, the encoding state of the target video at the current moment is the budget sufficient state, and the frame discarding period is 0; If the continuous downward trend coefficient at the current moment is greater than or equal to the downward coefficient threshold, the encoding state of the target video at the current moment is the budget reduction state, the continuous downward trend coefficient is set to 0, and the frame discarding period is the frame discarding period at the N-1th moment.
10. The video encoding method according to claim 7, characterized in that: The step of obtaining the frame discarding period at the current moment based on the encoding state of the target video at the N-1th moment, the continuous decreasing trend coefficient, the continuous increasing trend coefficient, and the current bit rate budget value further includes: When the encoding state of the target video at the N-1th moment is a budget deficit state, if the continuous rising trend coefficient at the current moment is less than the rising coefficient threshold, the encoding state of the target video at the current moment is the budget deficit state, and it is determined whether the frame discarding period at the N-1th moment is greater than the lower limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment minus 1, otherwise, the frame discarding period is set to the lower limit of the frame discarding period; If the continuous rising trend coefficient at the current moment is greater than or equal to the rising coefficient threshold, the encoding state of the target video at the current moment is the budget rising state, and it is determined whether the frame discarding period at the N-1th moment is less than the upper limit of the frame discarding period. If so, the frame discarding period is set to the frame discarding period at the N-1th moment plus 1, otherwise, the frame discarding period is set to the upper limit of the frame discarding period.
Citation Information
Patent Citations
Video coding method and device
CN108495142A
Frame extracting method, device, apparatus and computer-readable storage medium
CN109168013A
Video code stream transmission method and device
CN111836079A
Frame rate control method and device and storage medium
CN111953978A
Video stream transmission method and system, server and storage medium
CN115209189A
Cited By
Video coding control method and related equipment
CN121217919A
A video encoding control method and related device
CN121217919B
