Video data encoding method, device and equipment

Through periodic target code rate adjustment and dynamic adjustment of quantization parameters, the shortcomings of CBR and VBR encoding methods are solved, and the precise encoding rate control of video data is realized, ensuring the predictable recording time of fixed storage space and the adaptive encoding quality of scenes.

CN115379210BActive Publication Date: 2025-08-22HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211112018.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2021-09-13
Filing Date
2022-09-13
Publication Date
2025-08-22
Estimated Expiration
2042-09-13

AI Technical Summary

Technical Problem

In the prior art, the CBR encoding method leads to low quality of complex scenarios, and the VBR encoding method cannot predict the storage space full time, resulting in inaccurate encoding rate control.

Method used

The cycle-based target code rate adjustment method is adopted, and the quantization parameters in the encoding process are dynamically adjusted by determining the fixed target code rate of the first cycle and the variable target code rate of multiple adjustment cycles, combined with the quantization parameter range, so as to achieve accurate control of the code rate.

Benefits of technology

It realizes predictable recording time for fixed storage space, avoids excessive quality of complex scenes or waste of code rates in simple scenes, and improves the accuracy and efficiency of coding rate control.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115379210B_ABST
    Figure CN115379210B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose a method, apparatus, and device for encoding video data, the method comprising: determining a second target bit rate corresponding to a plurality of adjustment cycles based on a first target bit rate corresponding to a first cycle; the first cycle includes the plurality of adjustment cycles, the first target bit rate is a fixed value, and the second target bit rates corresponding to different adjustment cycles are the same or different; for a current adjustment cycle among the plurality of adjustment cycles, determining a target quantization parameter for the current adjustment cycle based on a target quantization parameter range corresponding to the current adjustment cycle and the second target bit rate corresponding to the current adjustment cycle; the target quantization parameter range is used to constrain the maximum value and minimum value of the quantization parameter for the current adjustment cycle; and encoding the video data within the current adjustment cycle based on the target quantization parameter. The embodiments of the present application can control the bit rate based on scene adaptability and can also predict the recordable time in advance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of coding technology, and in particular to a method, apparatus, and device for encoding video data. Background Art

[0002] Video data encoding is the process of encoding video data using specific compression techniques to produce a bitstream, also known as video data. Since video data is much smaller than video data, storing it can improve storage space utilization.

[0003] When encoding video data, the related art typically uses CBR (Constant Bit Rate) or VBR (Variable Bit Rate) to control the encoding rate. When using CBR for encoding rate control, the encoded bit rate is fixed. Conversely, when using VBR for encoding rate control, the encoded bit rate is less than the target bit rate and fluctuates within a certain range of the target bit rate, which is the maximum bit rate for encoding rate control using VBR.

[0004] However, when using CBR encoding rate control, the bit rate is fixed, resulting in lower quality when encoding complex scenes and wasting some bit rate when encoding simple scenes. When using VBR encoding rate control, the bit rate fluctuates, making it impossible to predict how long it will take to fill a fixed amount of storage space. Summary of the Invention

[0005] The embodiments of the present application provide a method, apparatus, and device for encoding video data, which can solve the problems of related technologies. The technical solution is as follows:

[0006] In one aspect, a method for encoding video data is provided, the method comprising:

[0007] determining second target bit rates corresponding to a plurality of adjustment periods based on a first target bit rate corresponding to a first period; wherein the first period includes the plurality of adjustment periods, the first target bit rate is a fixed value, and second target bit rates corresponding to different adjustment periods are the same or different; wherein the first target bit rate represents an average bit rate expected within the first period, and the second target bit rate corresponding to each adjustment period represents an average bit rate expected within the adjustment period;

[0008] determining, for a current adjustment cycle among the multiple adjustment cycles, a target quantization parameter of the current adjustment cycle based on a target quantization parameter range corresponding to the current adjustment cycle and a second target bit rate corresponding to the current adjustment cycle; wherein the target quantization parameter range is used to constrain a maximum value and a minimum value of the quantization parameter of the current adjustment cycle, the second target bit rate is used to adjust the quantization parameter of the current adjustment cycle, and the quantization parameter is within the target quantization parameter range;

[0009] In the current adjustment period, video data is encoded based on the target quantization parameter.

[0010] Exemplarily, for each adjustment period, determining the second target bit rate corresponding to the adjustment period based on the first target bit rate corresponding to the first period includes: determining the maximum target bit rate corresponding to the adjustment period based on the first target bit rate corresponding to the first period; and determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate.

[0011] Exemplarily, determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate includes: determining the maximum target bit rate as the second target bit rate corresponding to the adjustment period; or determining the scene motion level corresponding to the adjustment period, and determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the scene motion level, the second target bit rate being less than or equal to the maximum target bit rate; wherein, when the scene motion level is greater, the second target bit rate is greater.

[0012] Exemplarily, after determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the scene motion level, the method further includes: when the scene motion level corresponding to the adjustment period changes, re-determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the changed scene motion level.

[0013] Exemplarily, determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the scene motion level includes: determining a configured proportional coefficient corresponding to the scene motion level; wherein the proportional coefficient is greater than 0 and less than or equal to 1, and when the scene motion level is greater, the proportional coefficient corresponding to the scene motion level is greater; and determining the second target bit rate based on the product of the proportional coefficient and the maximum target bit rate.

[0014] Exemplarily, determining the maximum target bit rate corresponding to the adjustment period based on the first target bit rate corresponding to the first period includes: if the adjustment period is the first adjustment period within the first period, determining the first target bit rate corresponding to the first period as the maximum target bit rate corresponding to the adjustment period; or, if the adjustment period is not the first adjustment period within the first period, determining the maximum target bit rate corresponding to the adjustment period based on the first target bit rate corresponding to the first period, the total duration corresponding to the first period, the total actual amount of coded bits in the first period before the adjustment period, and the remaining duration of the first period.

[0015] Exemplarily, determining the maximum target bit rate corresponding to the adjustment period based on the first target bit rate corresponding to the first period, the total duration corresponding to the first period, the actual total amount of coded bits within the first period before the adjustment period, and the remaining duration of the first period includes: determining the maximum target bit rate corresponding to the adjustment period based on the following formula: the maximum target bit rate = [the first target bit rate * the total duration corresponding to the first period - the actual total amount of coded bits] / the remaining duration of the first period.

[0016] Exemplarily, determining the target quantization parameter of the current adjustment cycle based on the target quantization parameter range corresponding to the current adjustment cycle and the second target bit rate corresponding to the current adjustment cycle includes: determining the actual encoding bit rate corresponding to the initial quantization parameter within the target quantization parameter range; if the actual encoding bit rate is greater than the second target bit rate corresponding to the current adjustment cycle, increasing the initial quantization parameter; if the increased quantization parameter is within the target quantization parameter range, determining the target quantization parameter based on the increased quantization parameter; if the increased quantization parameter is not within the target quantization parameter range, determining the target quantization parameter based on the maximum value of the quantization parameter corresponding to the target quantization parameter range; if the actual encoding bit rate is less than the second target bit rate corresponding to the current adjustment cycle, reducing the initial quantization parameter; if the reduced quantization parameter is within the target quantization parameter range, determining the target quantization parameter based on the reduced quantization parameter; if the reduced quantization parameter is not within the target quantization parameter range, determining the target quantization parameter based on the minimum value of the quantization parameter corresponding to the target quantization parameter range.

[0017] Exemplarily, before determining the target quantization parameter of the current adjustment cycle based on the target quantization parameter range corresponding to the current adjustment cycle and the second target bit rate corresponding to the current adjustment cycle, the method also includes: if the current adjustment cycle is the first adjustment cycle within the first cycle, determining the quantization parameter range corresponding to the first cycle, and determining the quantization parameter range as the target quantization parameter range corresponding to the current adjustment cycle; or, if the current adjustment cycle is not the first adjustment cycle within the first cycle, determining the quantization parameter range corresponding to the adjacent adjustment cycle before the current adjustment cycle, and determining the target quantization parameter range corresponding to the current adjustment cycle based on the quantization parameter range corresponding to the adjacent adjustment cycle.

[0018] Exemplarily, determining the target quantization parameter range corresponding to the current adjustment cycle based on the quantization parameter range corresponding to the adjacent adjustment cycle includes: determining the bit rate threshold of the adjacent adjustment cycle based on the maximum target bit rate corresponding to the adjacent adjustment cycle; wherein the bit rate threshold is the product of the maximum target bit rate and a preset multiplier value; if the actual bit rate corresponding to the adjacent adjustment cycle is greater than or equal to the bit rate threshold of the adjacent adjustment cycle, adjusting the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle upward to obtain the target quantization parameter range corresponding to the current adjustment cycle; if the actual bit rate corresponding to the adjacent adjustment cycle is less than the bit rate threshold of the adjacent adjustment cycle, determining the quantization parameter range corresponding to the adjacent adjustment cycle as the target quantization parameter range corresponding to the current adjustment cycle.

[0019] Exemplarily, the first cycle includes multiple second cycles, each second cycle includes multiple adjustment cycles, and determining the target quantization parameter range corresponding to the current adjustment cycle based on the quantization parameter ranges corresponding to the adjacent adjustment cycles includes: if the current adjustment cycle is the first adjustment cycle within the current second cycle, and the current second cycle is the first second cycle within the first cycle, determining a first bit quantity threshold and a second bit quantity threshold based on the first target bit rate corresponding to the first cycle; wherein the first bit quantity threshold is determined based on the product of the first target bit rate and a first multiplier value, and the second bit quantity threshold is determined based on the product of the first target bit rate and a second multiplier value, and the first multiplier value is greater than the second multiplier value; if the actual total amount of coded bits before the current adjustment cycle in the first cycle is greater than the first bit quantity threshold, upwardly adjusting the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycles to obtain the target quantization parameter range corresponding to the current adjustment cycle; if the actual total amount of coded bits before the current adjustment cycle in the first cycle is less than the second bit quantity threshold, downwardly adjusting the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycles to obtain the target quantization parameter range corresponding to the current adjustment cycle.

[0020] Exemplarily, the first cycle includes multiple second cycles, each second cycle includes multiple adjustment cycles, and the target quantization parameter range corresponding to the current adjustment cycle is determined based on the quantization parameter range corresponding to the adjacent adjustment cycles, including: if the current adjustment cycle is the first adjustment cycle in the current second cycle, and the current second cycle is not the first second cycle in the first cycle, then based on the first target bit rate corresponding to the first cycle and the total encoding time before the current adjustment cycle in the first cycle, a first bit number threshold and a second bit number threshold are determined, and based on the first target bit rate corresponding to the first cycle and the time length of the second cycle, a third bit number threshold and a fourth bit number threshold are determined; wherein, the first bit number threshold is greater than the second bit number threshold, and the third bit number threshold is greater than the fourth bit number threshold; if the If the total amount of actual coded bits before the current adjustment cycle within the first cycle is greater than the first bit quantity threshold, and the total amount of actual coded bits of the adjacent second cycle before the current second cycle is greater than the third bit quantity threshold, then the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle are adjusted upward to obtain the target quantization parameter range corresponding to the current adjustment cycle; if the total amount of actual coded bits before the current adjustment cycle within the first cycle is less than the second bit quantity threshold, and the total amount of actual coded bits of the adjacent second cycle before the current second cycle is less than the fourth bit quantity threshold, then the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle are adjusted downward to obtain the target quantization parameter range corresponding to the current adjustment cycle.

[0021] Exemplarily, the method further includes: determining the total bit rate of the analog channel based on the first target bit rate corresponding to the first period; determining the recordable time corresponding to the storage device based on the total bit rate of the analog channel; and displaying the recordable time through the target interface.

[0022] Exemplarily, determining the corresponding recordable time of the storage device based on the total bit rate of the analog channel includes: if the storage device is connected to multiple network camera IPCs, then counting the total bit rate of all IPC channels; determining the recordable time based on the total bit rate of the analog channel, the total bit rate of all IPC channels and the total hard disk space.

[0023] In another aspect, a method for displaying an interface is provided, the method comprising:

[0024] Determining a first target bit rate corresponding to a first period; wherein the first period includes multiple adjustment periods, and a second target bit rate corresponding to each adjustment period is determined based on the first target bit rate; the first target bit rate is a fixed value, and the second target bit rates corresponding to different adjustment periods are the same or different; the first target bit rate represents an average bit rate expected within the first period, and the second target bit rate corresponding to each adjustment period represents an average bit rate expected within the adjustment period; wherein, within each adjustment period, encoding the video data based on the second target bit rate corresponding to the adjustment period;

[0025] Determining a total bit rate of the analog channel based on a first target bit rate corresponding to the first period;

[0026] Determine the video recording time corresponding to the storage device based on the total bit rate of the analog channel;

[0027] The recordable time is displayed through the target interface.

[0028] Exemplarily, determining the recordable time corresponding to the storage device based on the total bit rate of the analog channel includes:

[0029] If the storage device is connected to multiple network camera IPCs, the total bit rate of all IPC channels is counted;

[0030] The available recording time is determined based on the total bit rate of the analog channels, the total bit rate of all IPC channels, and the total hard disk space.

[0031] In another aspect, a video data encoding apparatus is provided, the apparatus comprising:

[0032] a second target bit rate determination module, configured to determine second target bit rates corresponding to a plurality of adjustment periods based on a first target bit rate corresponding to a first period; wherein the first period includes the plurality of adjustment periods, the first target bit rate is a fixed value, and second target bit rates corresponding to different adjustment periods are the same or different; the first target bit rate represents an average bit rate expected within the first period, and the second target bit rate corresponding to each adjustment period represents an average bit rate expected within the adjustment period;

[0033] a quantization parameter determination module, configured to determine, for a current adjustment cycle among the multiple adjustment cycles, a target quantization parameter for the current adjustment cycle based on a target quantization parameter range corresponding to the current adjustment cycle and a second target bit rate corresponding to the current adjustment cycle; wherein the target quantization parameter range is used to constrain a maximum value and a minimum value of the quantization parameter for the current adjustment cycle, the second target bit rate is used to adjust the quantization parameter of the current adjustment cycle, and the quantization parameter is within the target quantization parameter range;

[0034] The encoding module is configured to encode the video data based on the target quantization parameter within the current adjustment period.

[0035] On the other hand, an electronic device is provided, which includes a memory and a processor, wherein the memory is used to store machine-executable instructions that can be executed by the processor, and the processor is used to execute the machine-executable instructions stored in the memory to implement the steps of the above-mentioned video data encoding method or the steps of the above-mentioned interface display method.

[0036] The technical solutions provided in the embodiments of the present application can at least bring the following beneficial effects:

[0037] Because the average bit rate corresponding to the number of encoding bits reaching the preset number of encoding bits within each first cycle is fixed and predictable, that is, the first target bit rate corresponding to the first cycle is a fixed value, the recordable time can be predicted in advance for a fixed-sized storage space. Moreover, within the adjustment period included in each first cycle, the quantization parameter can be adjusted based on the actual average bit rate during the encoding process (i.e., the second target bit rate), thereby controlling the actual average bit rate within each adjustment period. In this way, the encoding bit rate can be controlled according to the complexity of the actual scene, thereby preventing the encoding quality of complex scenes from being too low, or the encoding of simple scenes from wasting too much bit rate, thereby improving the bit rate control capability. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 is a schematic diagram showing an implementation environment according to an exemplary embodiment;

[0039] Figure 2 This is a flowchart of a method for encoding video data provided by an embodiment of the present application;

[0040] Figure 3 This is a schematic diagram of an encoding parameter setting interface provided in an embodiment of the present application;

[0041] Figure 4 1 is a schematic structural diagram of a video data encoding device provided in an embodiment of the present application;

[0042] Figure 5 This is a schematic diagram of the structure of a terminal provided in an embodiment of the present application. DETAILED DESCRIPTION

[0043] In an embodiment of the present application, a method for encoding video data is proposed, and the encoding process can be divided into a first cycle (the first cycle can also be called a long cycle), a second cycle (the second cycle can also be called a short cycle) and an adjustment cycle.

[0044] Exemplarily, the target bit rate corresponding to the first period is called the first target bit rate. The first target bit rate is a fixed value, that is, the first target bit rate corresponding to each first period is fixed. Since the first target bit rate is a fixed value, the confirmable recording space can be determined based on the first target bit rate, thereby confirming the number of days that can be recorded. For the specific determination process, please refer to the subsequent embodiments.

[0045] The first target bit rate represents the expected average bit rate in the first period, that is, the average bit rate in the first period is expected to be the first target bit rate. However, in the actual encoding process, the average bit rate in the first period may be greater than or less than the first target bit rate. The control goal of the first period is to try to make the average bit rate in the first period the first target bit rate.

[0046] Exemplarily, for each first cycle, the first cycle may include multiple second cycles, that is, the first cycle may be larger than the second cycle. For example, the first cycle may be set to several hours, and the second cycle may be set to several minutes, or the first cycle may be set to several days, and the second cycle may be set to several hours.

[0047] For example, for each first period, the first period may include multiple adjustment periods (also referred to as adjustment periods), that is, the first period may be greater than the adjustment period. In addition, for each second period within the first period, the second period may include multiple adjustment periods, that is, the second period may be greater than the adjustment period. For example, the first period may be set to several days, the second period may be set to several hours, and the adjustment period may be set to several minutes.

[0048] For example, the first cycle may include the second cycle 1, the second cycle 2, the second cycle 3 and the second cycle 4, the second cycle 1 may include the adjustment cycle 11, the adjustment cycle 12, the adjustment cycle 13 and the adjustment cycle 14, the second cycle 2 may include the adjustment cycle 21, the adjustment cycle 22, the adjustment cycle 23 and the adjustment cycle 24, and so on, that is, the first cycle includes 4 second cycles, each second cycle includes 4 adjustment cycles, and the first cycle includes 16 adjustment cycles.

[0049] Exemplarily, the target bit rate corresponding to the adjustment period is referred to as the second target bit rate. The second target bit rate is a variable value that can change dynamically. That is, within an adjustment period, the second target bit rate can be dynamically adjusted according to the actual motion of the scene. For example, when the actual motion of the scene is more complex, the second target bit rate increases, and when the actual motion of the scene is simpler, the second target bit rate decreases. Moreover, the second target bit rates corresponding to different adjustment periods can be the same or different. For example, when the actual motion of the scene in different adjustment periods is the same or similar, the second target bit rates corresponding to different adjustment periods can be the same or different. When the actual motion of the scene in different adjustment periods is different, the second target bit rates corresponding to different adjustment periods can be the same or different. Since the second target bit rate is a dynamically adjusted value, it is possible to control the actual average bit rate within each adjustment period, thereby controlling the encoding bit rate according to the complexity of the actual scene, thereby preventing the encoding quality of complex scenes from being too low or the encoding of simple scenes from being too much bit rate.

[0050] The second target bitrate corresponding to each adjustment period represents the desired average bitrate within that adjustment period. This means that the average bitrate within the adjustment period is the second target bitrate. However, during the actual encoding process, the average bitrate within the adjustment period may be greater than or less than the second target bitrate. The control goal of the adjustment period is to minimize the average bitrate within the adjustment period to the second target bitrate. Furthermore, the second target bitrate itself changes dynamically based on the actual motion conditions of the scene.

[0051] For example, for the second period and the adjustment period within the first period, a variable bit rate can be used for encoding, and the second target bit rate can be adjusted according to the actual motion of the scene. During the adjustment process, different second target bit rates can be set according to the degree of motion. Different code control adjustments can be made for the first period, the second period, and the adjustment period. For example, only the first target bit rate needs to be set for the first period, and the first target bit rate is a fixed value. The first target bit rate is restored to a fixed value in each first period. The first target bit rate can be configured based on experience, such as 400Kbps, that is, the first target bit rate is restored to 400Kbps in each first period. In each second period within the first period, the quantization parameter range can be dynamically adjusted. For example, the quantization parameter range can be increased or decreased, thereby providing rate compensation for complex and simple scenes during the second period. In each adjustment period within the first period, the second target bit rate can be adjusted according to the actual motion of the scene, and then encoding is performed based on the second target bit rate and the quantization parameter range.

[0052] In the above application scenario, the video data encoding method proposed in the embodiment of the present application may include the following steps:

[0053] In step S11, second target bit rates corresponding to multiple adjustment periods (ie, multiple adjustment periods within the first period) are determined based on the first target bit rate corresponding to the first period. The second target bit rates corresponding to different adjustment periods are the same or different.

[0054] In a possible implementation, for each adjustment period within the first period, based on the first target bit rate corresponding to the first period, the following steps may be used to determine the second target bit rate corresponding to the adjustment period:

[0055] Step S111: Determine a maximum target bit rate corresponding to the adjustment period based on the first target bit rate corresponding to the first period.

[0056] For example, for each adjustment period, after obtaining the maximum target bit rate corresponding to the adjustment period, the maximum target bit rate no longer changes, that is, the maximum target bit rate remains unchanged. During the encoding process of the adjustment period, a second target bit rate for the adjustment period can be determined based on the maximum target bit rate. The determination process is described in subsequent embodiments.

[0057] In one possible implementation, if the adjustment period is the first adjustment period within the first period, the first target bit rate corresponding to the first period is determined as the maximum target bit rate corresponding to the adjustment period. Alternatively, if the adjustment period is not the first adjustment period within the first period, the maximum target bit rate corresponding to the adjustment period is determined based on the first target bit rate corresponding to the first period, the total duration corresponding to the first period, the total actual amount of coded bits before the adjustment period within the first period, and the remaining duration of the first period. For example, the maximum target bit rate corresponding to the adjustment period can be determined based on the following formula: Maximum target bit rate = [first target bit rate * total duration corresponding to the first period - total actual amount of coded bits] / remaining duration of the first period.

[0058] For example, assuming that the first target bit rate corresponding to the first cycle is 400 Kbps, and the first cycle includes adjustment cycle 1-adjustment cycle 16 (that is, there are 16 adjustment cycles in total), then for adjustment cycle 1, the first target bit rate corresponding to the first cycle is determined as the maximum target bit rate corresponding to adjustment cycle 1, that is, the maximum target bit rate corresponding to adjustment cycle 1 is 400 Kbps.

[0059] For adjustment period 2, the maximum target bitrate corresponding to adjustment period 2 can be determined using the following formula: Maximum target bitrate = [400 Kbps * Long period duration - Total amount of past time coded bits (Kb)] / Remaining time. In the above formula, 400 Kbps represents the first target bitrate, Long period duration represents the total duration corresponding to the first period (i.e., the total duration of 16 adjustment periods), Total amount of past time coded bits represents the actual total amount of coded bits before adjustment period 2 (i.e., the actual total amount of coded bits in adjustment period 1), and Remaining time represents the remaining duration of the first period (i.e., the total duration of adjustment period 2 minus the total duration of adjustment period 16). Obviously, if the average bit rate corresponding to adjustment cycle 1 is greater than 400Kbps, the maximum target bit rate corresponding to adjustment cycle 2 is less than 400Kbps; if the average bit rate corresponding to adjustment cycle 1 is less than 400Kbps, the maximum target bit rate corresponding to adjustment cycle 2 is greater than 400Kbps. That is to say, when the average bit rate used in the adjustment cycle that has completed encoding is high (that is, the actual total amount of encoded bits is large), the maximum target bit rate corresponding to the remaining adjustment cycles is lowered; when the average bit rate used in the adjustment cycle that has completed encoding is low (that is, the actual total amount of encoded bits is small), the maximum target bit rate corresponding to the remaining adjustment cycles is increased.

[0060] For adjustment period 3, the maximum target bitrate corresponding to adjustment period 3 can be determined using the following formula: Maximum target bitrate = [400 Kbps * Long period duration - Total coded bits in the past (Kb)] / Remaining time. In the above formula, Total coded bits in the past represents the actual total number of coded bits before adjustment period 3 (i.e., the actual total number of coded bits in adjustment periods 1 and 2), and Remaining time represents the remaining duration of the first period (i.e., the total duration of adjustment period 3 minus adjustment period 16).

[0061] By analogy, the maximum target bit rate corresponding to each adjustment period in the first period can be obtained.

[0062] Step S112: Determine a second target bit rate corresponding to the adjustment period based on the maximum target bit rate corresponding to the adjustment period.

[0063] In a possible implementation, after obtaining the maximum target bit rate corresponding to the adjustment period, the maximum target bit rate may be determined as the second target bit rate corresponding to the adjustment period, that is, the second target bit rate is equal to the maximum target bit rate.

[0064] In another possible implementation, after obtaining the maximum target bit rate corresponding to the adjustment period, the scene motion level corresponding to the adjustment period can be determined, and a second target bit rate corresponding to the adjustment period can be determined based on the maximum target bit rate and the scene motion level, and the second target bit rate can be less than or equal to the maximum target bit rate.

[0065] The greater the scene motion level, the greater the motion degree of the current scene, and the higher the second target bit rate. Conversely, the smaller the scene motion level, the smaller the motion degree of the current scene, and the lower the second target bit rate.

[0066] Exemplarily, after determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the scene motion level, when the scene motion level corresponding to the adjustment period changes, the second target bit rate corresponding to the adjustment period can also be re-determined based on the maximum target bit rate and the changed scene motion level.

[0067] Exemplarily, determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the scene motion level may include, but is not limited to: determining a configured proportional coefficient corresponding to the scene motion level; wherein the proportional coefficient may be greater than 0 and less than or equal to 1, and when the scene motion level is greater, the proportional coefficient corresponding to the scene motion level is also greater; the second target bit rate may be determined based on the product of the proportional coefficient and the maximum target bit rate.

[0068] For example, K scene motion levels can be pre-divided, where K can be a positive integer greater than 1, such as 3 scene motion levels, 5 scene motion levels, 7 scene motion levels, etc. For the convenience of description, 7 scene motion levels are taken as an example, and these 7 scene motion levels are recorded as scene motion level 1-scene motion level 7. Among these 7 scene motion levels, scene motion level 1 corresponds to the smallest degree of motion, and scene motion level 7 corresponds to the largest degree of motion.

[0069] The mapping relationship between the scene motion level and the proportional coefficient can be pre-configured. The proportional coefficient can be a value between 0 and 1, that is, the proportional coefficient can be greater than 0, and the proportional coefficient can be less than or equal to 1. The smaller the degree of motion corresponding to the scene motion level, the smaller the proportional coefficient corresponding to the scene motion level. The greater the degree of motion corresponding to the scene motion level, the larger the proportional coefficient corresponding to the scene motion level. For example, the proportional coefficient corresponding to scene motion level 1 is smaller than the proportional coefficient corresponding to scene motion level 2, the proportional coefficient corresponding to scene motion level 2 is smaller than the proportional coefficient corresponding to scene motion level 3, and so on. The proportional coefficient corresponding to scene motion level 6 is smaller than the proportional coefficient corresponding to scene motion level 7.

[0070] See Table 1, which shows an example of a mapping relationship between scene motion levels and scale factors. Of course, this is just an example of a mapping relationship, and this embodiment does not limit this mapping relationship.

[0071] Table 1

[0072] Scene Motion Level Proportional coefficient Scene motion level 7 1 Scene motion level 6 0.875 Scene Motion Level 5 0.75 Scene Motion Level 4 0.625 Scene Motion Level 3 0.5 Scene Motion Level 2 0.375 Scene Motion Level 1 0.25

[0073] In Table 1, the scaling factor for scene motion level 7 is 1, indicating that the second target bitrate for the highest scene motion level is the maximum target bitrate. The scaling factor for scene motion level 1 is 0.25, indicating that the second target bitrate for the lowest scene motion level is the maximum target bitrate * 0.25. The lowest scene motion level can also be called a still scene. The scaling factor 0.25 represents the bitrate percentage for still scenes, meaning that the second target bitrate is a percentage of the maximum target bitrate.

[0074] For each adjustment cycle, the adjustment cycle can be divided into multiple sampling cycles. In each sampling cycle, the scene motion level of the current sampling cycle can be determined. The scene motion level is used to reflect the actual motion situation of the current sampling cycle, that is, the degree of motion of the current scene. For example, the scene motion level of the current sampling cycle is determined based on image analysis. There is no restriction on this process as long as the scene motion level can be obtained. After obtaining the scene motion level of the current sampling cycle, the mapping relationship shown in Table 1 can be queried to obtain the proportional coefficient corresponding to the scene motion level. Based on the product of the proportional coefficient and the maximum target bit rate corresponding to the adjustment cycle, the second target bit rate of the sampling cycle after the current sampling cycle is determined.

[0075] For example, the adjustment period can be divided into sampling period 1, sampling period 2, sampling period 3..., in sampling period 1, the scene motion level of sampling period 1 is determined, such as scene motion level 7, and the proportional coefficient corresponding to scene motion level 7 is 1. Assuming that the maximum target bit rate corresponding to the adjustment period is 400Kbps, the second target bit rate of sampling period 2 is 400Kbps.

[0076] In sampling period 2, the scene motion level of sampling period 2 is determined, such as scene motion level 6. The proportional coefficient corresponding to scene motion level 6 is 0.875, and the second target bit rate of sampling period 3 is 350 Kbps (400*0.875).

[0077] In sampling period 3, the scene motion level of sampling period 3 is determined, such as scene motion level 6. The proportional coefficient corresponding to scene motion level 6 is 0.875, and the second target bit rate of sampling period 4 is 350 Kbps, and so on.

[0078] In summary, for each sampling period of the adjustment period, a second target bitrate for that sampling period can be obtained. Obviously, the second target bitrate corresponding to the adjustment period is a variable value and can change dynamically. That is, the second target bitrate can be dynamically adjusted based on the actual motion conditions of the scene. The second target bitrates for different sampling periods can be the same or different. For example, when the actual motion conditions of the scene are more complex, the second target bitrate becomes larger, and when the actual motion conditions of the scene are relatively simple, the second target bitrate becomes smaller.

[0079] In step S12, for the current adjustment cycle among the multiple adjustment cycles, the target quantization parameter of the current adjustment cycle is determined based on the target quantization parameter range corresponding to the current adjustment cycle and the second target bit rate corresponding to the current adjustment cycle; wherein, the target quantization parameter range is used to constrain the maximum value and minimum value of the quantization parameter of the current adjustment cycle, the second target bit rate is used to adjust the quantization parameter of the current adjustment cycle, and the quantization parameter is within the target quantization parameter range.

[0080] In a possible implementation, for each adjustment period within the first period, when the adjustment period is used as the current adjustment period (i.e., the current time is in the adjustment period), based on the target quantization parameter range corresponding to the current adjustment period and the second target bit rate corresponding to the current adjustment period, the target quantization parameter of the current adjustment period may be determined using the following steps:

[0081] Step S121: Determine the target quantization parameter range corresponding to the current adjustment period.

[0082] In a possible implementation, if the current adjustment period is the first adjustment period within the first period, a quantization parameter range corresponding to the first period is determined, and the quantization parameter range is determined as a target quantization parameter range corresponding to the current adjustment period.

[0083] For example, the quantization parameter range corresponding to the first cycle can be pre-configured based on experience, and there is no restriction on this quantization parameter range. For example, the quantization parameter range corresponding to the first cycle can be [a, b], where a represents the minimum quantization parameter value (minQP) and b represents the maximum quantization parameter value (maxQP). The maximum quantization parameter value b is usually greater than the minimum quantization parameter value a.

[0084] On this basis, if the current adjustment cycle is the first adjustment cycle within the first cycle, the quantization parameter range [a, b] corresponding to the first cycle can be used as the target quantization parameter range corresponding to the current adjustment cycle (such as adjustment cycle 1).

[0085] In another possible implementation, if the current adjustment cycle is not the first adjustment cycle within the first cycle, the quantization parameter range corresponding to the adjacent adjustment cycle preceding the current adjustment cycle is determined, and the target quantization parameter range corresponding to the current adjustment cycle is determined based on the quantization parameter range corresponding to the adjacent adjustment cycle. For example, the rate threshold of the adjacent adjustment cycle can be determined based on the maximum target rate corresponding to the adjacent adjustment cycle, and the rate threshold can be the product of the maximum target rate and a preset multiplier value. If the actual rate corresponding to the adjacent adjustment cycle is greater than or equal to the rate threshold of the adjacent adjustment cycle, the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle are adjusted upward to obtain the target quantization parameter range corresponding to the current adjustment cycle; if the actual rate corresponding to the adjacent adjustment cycle is less than the rate threshold of the adjacent adjustment cycle, the quantization parameter range corresponding to the adjacent adjustment cycle is determined as the target quantization parameter range corresponding to the current adjustment cycle.

[0086] For example, assuming that the first cycle includes adjustment cycle 1-adjustment cycle 16, if the current adjustment cycle is adjustment cycle 2, then the adjacent adjustment cycle is adjustment cycle 1, if the current adjustment cycle is adjustment cycle 3, then the adjacent adjustment cycle is adjustment cycle 2, and so on. Taking the current adjustment cycle as an example, the quantization parameter range corresponding to adjustment cycle 1 is [a, b].

[0087] The bitrate threshold for adjustment period 1 can be determined based on the maximum target bitrate corresponding to adjustment period 1. The bitrate threshold can be the maximum target bitrate corresponding to adjustment period 1 * M, where M can be a preset multiple value that can be configured based on experience. Assuming that the maximum target bitrate corresponding to adjustment period 1 is 400 Kbps, the bitrate threshold can be (400 * M) Kbps. M can be a value greater than or equal to 1, such as 1.2, 1.5, 2, 2.2, etc., or a value less than 1, without limitation.

[0088] If the actual bit rate corresponding to adjustment period 1 (i.e., the actual average bit rate) is greater than or equal to the bit rate threshold of adjustment period 1 (e.g., 400*M), the quantization parameter maximum value and the quantization parameter minimum value in the quantization parameter range corresponding to adjustment period 1 can be adjusted upward. That is, based on the quantization parameter range corresponding to adjustment period 1 being [a, b], the quantization parameter maximum value b can be adjusted upward to obtain the quantization parameter maximum value b', and the quantization parameter minimum value a can be adjusted upward to obtain the quantization parameter minimum value a'. In this way, the target quantization parameter range corresponding to adjustment period 2 can be obtained, and the target quantization parameter range can be [a', b'].

[0089] If the actual bit rate corresponding to adjustment cycle 1 (i.e., the actual average bit rate) is less than the bit rate threshold of adjustment cycle 1, the quantization parameter range corresponding to adjustment cycle 1 is determined as the target quantization parameter range corresponding to adjustment cycle 2. That is to say, based on the quantization parameter range corresponding to adjustment cycle 1 being [a, b], the target quantization parameter range can be [a, b].

[0090] Step S122: Determine the actual encoding bit rate corresponding to the initial quantization parameter within the target quantization parameter range.

[0091] For example, after obtaining the target quantization parameter range corresponding to the current adjustment period, a quantization parameter can be selected from the target quantization parameter range as the initial quantization parameter. There is no restriction on this initial quantization parameter, as long as the initial quantization parameter is greater than or equal to the minimum value of the quantization parameter and the initial quantization parameter is less than or equal to the maximum value of the quantization parameter.

[0092] After obtaining the initial quantization parameters, the video data can be encoded based on the initial quantization parameters, and the actual encoding bit rate during the encoding process can be obtained. When the initial quantization parameters are used to encode the video data, if the actual motion of the scene is relatively complex, the actual encoding bit rate during the encoding process will be relatively high. Conversely, if the actual motion of the scene is relatively simple, the actual encoding bit rate during the encoding process will be relatively low. Obviously, during the encoding process of the video data, the actual encoding bit rate corresponding to the initial quantization parameters can be calculated, and then the initial quantization parameters can be adjusted based on the actual encoding bit rate.

[0093] Step S123: If the actual encoding bit rate is greater than the second target bit rate corresponding to the current adjustment period, the initial quantization parameter is increased; if the increased quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the increased quantization parameter, such as using the increased quantization parameter as the target quantization parameter; if the increased quantization parameter is not within the target quantization parameter range (that is, the increased quantization parameter is greater than the maximum quantization parameter value of the target quantization parameter range), the target quantization parameter is determined based on the maximum quantization parameter value corresponding to the target quantization parameter range, such as using the maximum quantization parameter value as the target quantization parameter.

[0094] Step S124: if the actual encoding bit rate is less than the second target bit rate corresponding to the current adjustment period, the initial quantization parameter is reduced; if the reduced quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the reduced quantization parameter, such as using the reduced quantization parameter as the target quantization parameter; if the reduced quantization parameter is not within the target quantization parameter range (that is, the reduced quantization parameter is less than the minimum quantization parameter of the target quantization parameter range), the target quantization parameter is determined based on the minimum quantization parameter corresponding to the target quantization parameter range, such as using the minimum quantization parameter as the target quantization parameter.

[0095] For example, in the process of encoding video data using the initial quantization parameter, the actual encoding bit rate can be compared with the second target bit rate (since the second target bit rate will change dynamically, the actual encoding bit rate can be compared with the second target bit rate at the current moment). If the actual encoding bit rate is greater than the second target bit rate, the initial quantization parameter (i.e., initial QP) is increased, and the increased quantization parameter is used as the target quantization parameter. If the actual encoding bit rate is less than the second target bit rate, the initial quantization parameter is decreased, and the decreased quantization parameter is used as the target quantization parameter. During the adjustment of the initial quantization parameter, if the adjusted quantization parameter is greater than the maximum quantization parameter, the maximum quantization parameter is used as the target quantization parameter. If the adjusted quantization parameter is less than the minimum quantization parameter, the minimum quantization parameter is used as the target quantization parameter. In other words, the initial quantization parameter needs to be adjusted within the target quantization parameter range [minQP, maxQP]. When the initial quantization parameter is adjusted to minQP or maxQP, the initial quantization parameter is no longer adjusted regardless of the relationship between the actual encoding bit rate and the second target bit rate.

[0096] After obtaining the target quantization parameter, the video data can be encoded based on the target quantization parameter, and the actual encoding bit rate during the encoding process can be obtained, and then the target quantization parameter can be adjusted based on the actual encoding bit rate. For example, if the actual encoding bit rate is greater than the second target bit rate, the target quantization parameter is increased; if the increased quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the increased quantization parameter; if the increased quantization parameter is not within the target quantization parameter range, the target quantization parameter is determined based on the maximum quantization parameter value corresponding to the target quantization parameter range. If the actual encoding bit rate is less than the second target bit rate, the target quantization parameter is decreased; if the decreased quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the decreased quantization parameter; if the decreased quantization parameter is not within the target quantization parameter range, the target quantization parameter is determined based on the minimum quantization parameter value corresponding to the target quantization parameter range.

[0097] Similarly, the target quantization parameter can be continuously adjusted, and the video data can be encoded based on the adjusted target quantization parameter, so that the actual encoding bit rate is close to the second target bit rate, that is, the quantization parameter QP is adjusted between minQP and maxQP, so that the actual encoding bit rate is close to the second target bit rate corresponding to the current scene motion level.

[0098] In summary, referring to steps S121 to S124 , the target quantization parameter of the current adjustment period may be determined based on the target quantization parameter range corresponding to the current adjustment period and the second target bit rate corresponding to the current adjustment period.

[0099] In step S13, the video data is encoded based on the target quantization parameter of the current adjustment period within the current adjustment period. During the encoding process of the video data, the target quantization parameter can be further adjusted based on the actual encoding bit rate during the encoding process and the second target bit rate corresponding to the current adjustment period, and so on, and the above process is continuously repeated.

[0100] In one possible implementation, a first cycle may include multiple second cycles, each of which may include multiple adjustment cycles. Based on the quantization parameter ranges corresponding to adjacent adjustment cycles, a target quantization parameter range corresponding to the current adjustment cycle may be determined in the following manner: if the current adjustment cycle is the first adjustment cycle within the current second cycle, and the current second cycle is the first second cycle within the first cycle, a first bit quantity threshold and a second bit quantity threshold may be determined based on the first target bit rate corresponding to the first cycle, the first bit quantity threshold being determined based on the product of the first target bit rate and a first multiplier value, and the second bit quantity threshold being determined based on the product of the first target bit rate and a second multiplier value, and the first multiplier value may be greater than the second multiplier value. Based on this, if the actual total amount of coded bits before the current adjustment cycle within the first cycle is greater than the first bit quantity threshold, the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle may be adjusted upward to obtain the target quantization parameter range corresponding to the current adjustment cycle. If the actual total amount of coded bits before the current adjustment cycle within the first cycle is less than the second bit quantity threshold, the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle may be adjusted downward to obtain the target quantization parameter range corresponding to the current adjustment cycle.

[0101] For example, a first multiple value and a second multiple value can be pre-configured, and both the first multiple value and the second multiple value can be configured based on experience, as long as the first multiple value is greater than the second multiple value. For example, the first multiple value can be a value greater than or equal to 1, such as (1+N1%), and N1 can be configured based on experience to represent the error range. The value range of N1 can be [0, 20], and there is no restriction on this. The second multiple value can be a value less than or equal to 1, such as (1-N2%), and N2 can be configured based on experience to represent the error range. The value range of N2 can be [0, 20], and there is no restriction on this.

[0102] The first bit quantity threshold can be determined based on the product of the first target bit rate (such as 400Kbps) and the first multiple value. For example, the first bit quantity threshold is the first target bit rate*the first multiple value*the total encoding time before the current adjustment period.

[0103] The second bit quantity threshold may be determined based on the product of the first target bit rate and the second multiplier value. For example, the second bit quantity threshold may be the first target bit rate*the second multiplier value*the total encoding time before the current adjustment period.

[0104] Assuming that the first cycle includes adjustment cycle 1 to adjustment cycle 16 and the current adjustment cycle is adjustment cycle 10, the total encoding duration before the current adjustment cycle may be the total duration of adjustment cycle 1 to adjustment cycle 9.

[0105] If the total amount of actual coded bits before the current adjustment period (e.g., the total amount of actual coded bits from adjustment period 1 to adjustment period 9, used to represent the actual coding space from the first period to the current period) is greater than a first bit quantity threshold (used to represent (1+N1%) times the coding space under the first target bit rate encoding), the maximum quantization parameter and the minimum quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period are adjusted upward. Assuming that the quantization parameter range corresponding to the adjacent adjustment period is [a, b], the maximum quantization parameter b is adjusted upward to obtain the maximum quantization parameter b', and the minimum quantization parameter a is adjusted upward to obtain the minimum quantization parameter a'. In this way, the target quantization parameter range corresponding to the current adjustment period is [a', b'].

[0106] When adjusting the maximum value and the minimum value of the quantization parameter in the quantization parameter range upward, if the maximum value and the minimum value have reached the adjustable threshold, it is prompted that the scene is too complex and the number of recording days cannot reach the expected number of days.

[0107] If the total amount of actual coded bits before the current adjustment period is less than a second bit quantity threshold (used to represent (1-N2%) times the coding space under the first target bit rate encoding), the maximum value of the quantization parameter and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period are adjusted downward. Assuming that the quantization parameter range corresponding to the adjacent adjustment period is [a, b], the maximum value of the quantization parameter b is adjusted downward to obtain the maximum value of the quantization parameter b", and the minimum value of the quantization parameter a is adjusted downward to obtain the minimum value of the quantization parameter a". In this way, the target quantization parameter range corresponding to the current adjustment period is [a", b".

[0108] In another possible embodiment, the first cycle may include multiple second cycles, each of which may include multiple adjustment cycles. Based on the quantization parameter ranges corresponding to adjacent adjustment cycles, the target quantization parameter range corresponding to the current adjustment cycle may be determined in the following manner: if the current adjustment cycle is the first adjustment cycle within the current second cycle, and the current second cycle is not the first second cycle within the first cycle, then a first bit quantity threshold and a second bit quantity threshold may be determined based on the first target bit rate corresponding to the first cycle and the total encoding duration before the current adjustment cycle within the first cycle, and a third bit quantity threshold and a fourth bit quantity threshold may be determined based on the first target bit rate corresponding to the first cycle and the duration of the second cycle; wherein the first bit quantity threshold may be greater than the second bit quantity threshold, and the third bit quantity threshold may be greater than the fourth bit quantity threshold. Based on this, if the actual total amount of coded bits before the current adjustment cycle within the first cycle is greater than the first bit quantity threshold, and the actual total amount of coded bits of the adjacent second cycle before the current second cycle is greater than the third bit quantity threshold, then the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle may be adjusted upward, thereby obtaining the target quantization parameter range corresponding to the current adjustment cycle. If the total amount of actual coded bits before the current adjustment cycle in the first cycle is less than the second bit quantity threshold, and the total amount of actual coded bits in the adjacent second cycle before the current second cycle is less than the fourth bit quantity threshold, the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle can be adjusted downward to obtain the target quantization parameter range corresponding to the current adjustment cycle.

[0109] For example, a first multiple value and a second multiple value can be pre-configured. Both the first multiple value and the second multiple value can be configured based on experience, and the first multiple value can be greater than the second multiple value. For example, the first multiple value can be a value greater than or equal to 1, such as (1+N1%), and the second multiple value can be a value less than or equal to 1, such as (1-N2%).

[0110] The first bit quantity threshold can be determined based on the first target bit rate (e.g., 400 Kbps), the first multiple value, and the total encoding duration before the current adjustment period within the first period. For example, the first bit quantity threshold can be the first target bit rate * the first multiple value * the total encoding duration before the current adjustment period. Furthermore, the second bit quantity threshold can be determined based on the second target bit rate, the second multiple value, and the total encoding duration before the current adjustment period within the first period. For example, the second bit quantity threshold can be the first target bit rate * the second multiple value * the total encoding duration before the current adjustment period.

[0111] For example, a third multiple value and a fourth multiple value can be pre-configured, and both the third multiple value and the fourth multiple value can be configured based on experience, and the third multiple value can be greater than the fourth multiple value. For example, the third multiple value can be a value greater than or equal to 1, such as (1+X1%), and X1 can be configured based on experience to represent the error range. The value range of X1 can be [0, 20], and there is no restriction on this. The fourth multiple value can be a value less than or equal to 1, such as (1-X2%), and X2 can be configured based on experience to represent the error range. The value range of X2 can be [0, 20], and there is no restriction on this.

[0112] The third bit quantity threshold can be determined based on the first target bit rate, the third multiple value, and the duration of the second cycle (i.e., the total duration of one second cycle. Assuming that one second cycle includes four adjustment cycles, the duration of the second cycle is the total duration of the four adjustment cycles). For example, the third bit quantity threshold can be the first target bit rate * the third multiple value * the duration of the second cycle. Furthermore, the fourth bit quantity threshold can be determined based on the first target bit rate, the fourth multiple value, and the duration of the second cycle. For example, the fourth bit quantity threshold can be the first target bit rate * the fourth multiple value * the duration of the second cycle.

[0113] If the total amount of actual coding bits before the current adjustment period (used to represent the actual coding space from the first period to the current period) is greater than the first bit quantity threshold (used to represent (1+N1%) times the coding space under the first target code rate coding), and the total amount of actual coding bits of the adjacent second period before the current second period (used to represent the actual coding space of the previous second period) is greater than the third bit quantity threshold (used to represent (1+X1%) times the coding space of the first target code rate at the corresponding time of the second period), then the maximum value and minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period can be adjusted upward. Assuming that the quantization parameter range corresponding to the adjacent adjustment period is [a, b], the maximum value of the quantization parameter b is adjusted upward to obtain the maximum value of the quantization parameter b', and the minimum value of the quantization parameter a is adjusted upward to obtain the minimum value of the quantization parameter a'. In this way, the target quantization parameter range corresponding to the current adjustment period can be obtained as [a', b'].

[0114] When adjusting the maximum value and the minimum value of the quantization parameter in the quantization parameter range upward, if the maximum value and the minimum value have reached the adjustable threshold, it is prompted that the scene is too complex and the number of recording days cannot reach the expected number of days.

[0115] If the total amount of actual coded bits before the current adjustment period is less than the second bit quantity threshold (used to represent (1-N2%) times the coding space under the first target code rate coding), and the total amount of actual coded bits in the adjacent second period before the current second period is less than the fourth bit quantity threshold (used to represent (1-X2%) times the coding space of the first target code rate at the corresponding time of the second period), then the maximum value and minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period can be adjusted downward. For example, assuming that the quantization parameter range corresponding to the adjacent adjustment period is [a, b], then the maximum value of the quantization parameter b is adjusted downward to obtain the maximum value of the quantization parameter b", and the minimum value of the quantization parameter a is adjusted downward to obtain the minimum value of the quantization parameter a", so that the target quantization parameter range corresponding to the current adjustment period is [a", b".

[0116] In one possible implementation, the total bit rate of the analog channel can be determined based on the first target bit rate (such as 400Kbps) corresponding to the first period. That is, since the first target bit rate is a fixed value, the first target bit rate will not change. Therefore, the total bit rate of the analog channel can be directly determined based on the first target bit rate. Then, the recordable time corresponding to the storage device is determined based on the total bit rate of the analog channel. For example, if the storage device is connected to multiple IPCs, the total bit rate of all IPC channels is counted, and the recordable time is determined based on the total bit rate of the analog channel, the total bit rate of all IPC channels and the total hard disk space. After obtaining the recordable time corresponding to the storage device, the recordable time can be displayed through the target interface.

[0117] Exemplarily, the calculation formula for the recordable time can be: Remaining recordable days = Space available for recording ÷ [(Total bit rate of analog channels + Total bit rate of IPC channels) ÷ 8 × 86400]. In the above formula, the unit of the space available for recording is KB, that is, the total hard disk space, and the space available for recording is a known value. The total bit rate of analog channels is the sum of the bit rates of all analog channels currently connected and encoded by the storage device, and the unit is Kbps. In this embodiment, for each analog channel currently connected and encoded by the storage device, the bit rate corresponding to the analog channel is the first target bit rate. Therefore, the sum of the first target bit rates of all analog channels can be used as the total bit rate of analog channels. The total bit rate of IPC channels is the sum of the bit rates of all IPC channels currently connected and recorded by the storage device, and the unit is Kbps. There is no restriction on the method of obtaining the total bit rate of IPC channels. Dividing by 8 is to convert the unit Kbps to KBps, that is, to convert bit to BYTE. 86400 is the number of seconds in a day, that is, the square brackets are the recording size of a day. Divide the total available recording space on the hard disk (i.e., the total hard disk space) by the size of one day's recording to get the number of days remaining for recording.

[0118] After obtaining the recordable time corresponding to the storage device (ie, the remaining recordable days), the recordable time can be displayed through the target interface, thereby simplifying the target interface to only display how many days can be recorded under the current hard disk space.

[0119] Based on the same application concept as the above method, an interface display method is also proposed in an embodiment of the present application, which can determine a first target bit rate corresponding to a first period; wherein the first period can include multiple adjustment periods, and the second target bit rate corresponding to each adjustment period can be determined based on the first target bit rate. The first target bit rate can be a fixed value, and the second target bit rates corresponding to different adjustment periods can be the same or different. The first target bit rate is used to represent the expected average bit rate within the first period, and the second target bit rate corresponding to each adjustment period is used to represent the expected average bit rate within the adjustment period. In each adjustment period, video data can be encoded based on the second target bit rate corresponding to the adjustment period.

[0120] On this basis, the total bit rate of the analog channel can be determined based on the first target bit rate corresponding to the first period, and the recordable time corresponding to the storage device can be determined based on the total bit rate of the analog channel, and the recordable time can be displayed through the target interface.

[0121] The above technical solution is described below in conjunction with specific application scenarios. Before explaining in detail the encoding method of video data provided in the embodiment of the present application, the implementation environment provided in the embodiment of the present application is first introduced.

[0122] Please refer to Figure 1 , Figure 1 This is a schematic diagram illustrating an implementation environment according to an exemplary embodiment. The implementation environment includes at least one camera 101 and a hard disk recorder 102. The camera 101 can be communicatively connected to the hard disk recorder 102. The communication connection can be a wired or wireless connection, which is not limited in this embodiment of the application.

[0123] In some embodiments, the camera 101 can capture an actual scene within a capture range to obtain video data, and send the video data to the hard disk recorder 102. Since the video data captured by the camera 101 is analog video data, the hard disk recorder 102 can encode the analog video data sent by the camera 101 according to the video data encoding method provided in the embodiment of the present application to obtain video data, thereby storing the video data.

[0124] It should be noted that when encoding the analog video data sent by the camera 101, it is necessary to first convert the analog video data into digital video data and then encode the digital video data. Similar contents involved below are similar and will not be elaborated on in detail in the embodiments of the present application.

[0125] In other embodiments, the camera 101 may capture an actual scene within a capture range to obtain video data, encode the video data according to the video data encoding method provided in the embodiments of the present application to obtain recording data, and then transmit the recording data to the hard disk recorder 102, which then stores the recording data.

[0126] The camera 101 may be any camera that can interact with a user through one or more methods such as a keyboard, a touchpad, a touch screen, a remote control, voice interaction, or a handwriting device to capture an actual scene, such as a PC (Personal Computer), a mobile phone, a smart phone, a PDA (Personal Digital Assistant), a Pocket PC (PPC), a tablet computer, a smart TV, etc.

[0127] The hard disk video recorder 102 may be an HVR (High Definition & Hybrid Digital Video Recorder), a DVR (Digital Video Recorder), an NVR (Network Video Recorder), or the like.

[0128] Those skilled in the art should understand that the above-mentioned camera 101 and hard disk recorder 102 are only examples. Other existing or future cameras or hard disk recorders that are applicable to the embodiments of the present application should also be included in the scope of protection of the embodiments of the present application and are included here by reference.

[0129] Next, the video data encoding method provided in the embodiment of the present application is explained in detail.

[0130] Figure 2 This is a flowchart of a video data encoding method provided in an embodiment of the present application. The method can be applied to a camera or a hard disk recorder. The following is a detailed explanation using the application of the video data encoding method provided in an embodiment of the present application to a hard disk recorder as an example.

[0131] The camera transmits analog video data to the hard disk recorder. When encoding the analog video data, the hard disk recorder can divide the encoding into multiple first cycles. Each first cycle corresponds to a target bit rate, which is the average bit rate corresponding to the number of encoding bits within the first cycle reaching a preset number of encoding bits. The first cycle includes multiple adjustment cycles, each adjustment cycle corresponds to a target bit rate, which is the maximum bit rate within the adjustment cycle.

[0132] Optionally, the first cycle may further include multiple second cycles, and the second cycle may include multiple adjustment cycles. Furthermore, the first cycle may have a length greater than the second cycle, and the second cycle may have a length greater than the adjustment cycle. For example, the first cycle may have a length of 4 hours, the second cycle may have a length of 30 minutes, and the adjustment cycle may have a length of 10 minutes.

[0133] Regardless of whether the first cycle includes the second cycle, the encoding method of video data provided in the embodiment of the present application divides the entire encoding process into multiple adjustment cycles, and the encoding method for each adjustment cycle is the same. Therefore, the following detailed description is given using one of the adjustment cycles as an example.

[0134] Please refer to Figure 2 , the method includes the following steps.

[0135] Step 201: Determine a first quantization parameter, where the first quantization parameter is an initial quantization parameter used to encode video data in a current adjustment period.

[0136] In some embodiments, a first quantization parameter range is determined, the first quantization parameter range being used to constrain the quantization parameter used to encode the video data in the current adjustment period. The first quantization parameter is determined based on the first quantization parameter range, and the first quantization parameter is within the first quantization parameter range.

[0137] When encoding video data, due to the varying image complexity and scene motion levels in different modulation cycles, it is necessary to determine corresponding quantization parameter ranges for each modulation cycle. This allows encoding within each modulation cycle to be performed based on quantization parameters within the quantization parameter range corresponding to each modulation cycle, thereby providing a certain degree of control over the actual average bitrate of each modulation cycle.

[0138] Taking the current adjustment period as an example, since the current adjustment period may be the first adjustment period within the current first period, or may be a non-first adjustment period within the current first period, and the current first period may be the first first period, or may be a non-first first period. In the case of different positions of the current adjustment period, the method of determining the quantization parameter range corresponding to the current adjustment period is different, that is, the method of determining the first quantization parameter range is different. Therefore, the following will be divided into the following three cases for explanation:

[0139] In the first case, if the current adjustment cycle is the first adjustment cycle within the current first cycle and the current first cycle is the first first cycle, that is, the start time of the current adjustment cycle is the start time of the first first cycle, the initial quantization parameter range is determined to be the first quantization parameter range.

[0140] When the start time of the current adjustment cycle is the start time of the first cycle, it indicates that the current adjustment cycle is the first adjustment cycle of the entire encoding process. At this time, the initial quantization parameter range can be directly determined as the first quantization parameter range.

[0141] The initial quantization parameter range may be a quantization parameter range set in advance. In addition, in the subsequent process of encoding the video data, the initial quantization parameter range may be adjusted according to different actual requirements.

[0142] In the second case, if the current adjustment cycle is not the first adjustment cycle within the current first cycle, that is, the start time of the current adjustment cycle is not the start time of the current first cycle, then the actual average bit rate of the previous adjustment cycle adjacent to the current adjustment cycle is determined. If the actual average bit rate of the previous adjustment cycle is greater than the bit rate threshold corresponding to the previous adjustment cycle, then the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle are increased to obtain the first quantization parameter range, and the bit rate threshold corresponding to the previous adjustment cycle is determined based on the target bit rate corresponding to the previous adjustment cycle.

[0143] In a case where the first cycle includes the second cycle, and the second cycle includes multiple adjustment cycles, if the current adjustment cycle is not the first adjustment cycle within the current first cycle and is not the first adjustment cycle within the current second cycle, that is, the start time of the current adjustment cycle is not the start time of the current first cycle and is not the start time of the current second cycle, then determine the actual average bit rate of the previous adjustment cycle adjacent to the current adjustment cycle. If the actual average bit rate of the previous adjustment cycle is greater than the bit rate threshold corresponding to the previous adjustment cycle, increase the upper limit and lower limit of the quantization parameter range corresponding to the previous adjustment cycle to obtain the first quantization parameter range, and the bit rate threshold corresponding to the previous adjustment cycle is determined based on the target bit rate corresponding to the previous adjustment cycle.

[0144] That is, when the current adjustment period is not the first adjustment period, no matter whether the first period includes the second period, the manner of determining the first quantization parameter range is the same.

[0145] The process of determining the actual average bit rate of the previous adjustment cycle includes: counting the number of encoded bits obtained by encoding the video data in the previous adjustment cycle, dividing the number of encoded bits by the period length of the previous adjustment cycle, and obtaining the actual average bit rate of the previous adjustment cycle.

[0146] The bitrate threshold corresponding to the previous adjustment period can be determined in a variety of ways based on the target bitrate corresponding to the previous adjustment period. For example, in some embodiments, the bitrate threshold corresponding to the previous adjustment period can be a multiple of the target bitrate corresponding to the previous adjustment period, and the multiple can be an integer or a decimal. In other embodiments, the bitrate threshold corresponding to the previous adjustment period can also be determined by adding a specific value to the target bitrate corresponding to the previous adjustment period.

[0147] When the actual average bit rate of the previous adjustment cycle is greater than the bit rate threshold corresponding to the previous adjustment cycle, it indicates that the number of encoded bits obtained after encoding the video data in the previous adjustment cycle is large. At this time, it is necessary to increase the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle to obtain a first quantization parameter range, so that when the video data is subsequently encoded, the bit rate can be reduced, thereby ensuring that the actual average bit rate corresponding to each first cycle tends to be fixed. Of course, if the actual average bit rate of the previous adjustment cycle is less than or equal to the bit rate threshold corresponding to the previous adjustment cycle, it indicates that the number of encoded bits obtained after encoding the video data in the previous adjustment cycle is more in line with the actual scene. At this time, the quantization parameter range corresponding to the previous adjustment cycle can be directly determined as the first quantization parameter range.

[0148] The quantization parameter range includes a lower limit and an upper limit. When increasing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle, the lower and upper limits of the quantization parameter range corresponding to the previous adjustment cycle may be increased simultaneously, and the increases in the lower and upper limits may be the same or different. For example, the lower and upper limits of the quantization parameter range corresponding to the previous adjustment cycle are denoted as minQP and maxQP, respectively. When increasing maxQP and minQP, the increase in minQP may be 2, and the increase in maxQP may be 1.

[0149] As an example, in the case where the first cycle includes multiple second cycles and the second cycle includes multiple adjustment cycles, if the current adjustment cycle is not the first adjustment cycle in the current first cycle and is the first adjustment cycle in the current second cycle, that is, the start time of the current adjustment cycle is not the start time of the current first cycle and is the start time of the current second cycle, then the first actual number of coding bits, the second actual number of coding bits, the first expected number of coding bits, and the second expected number of coding bits are determined. Based on the relationship between the first actual number of coding bits and the first expected number of coding bits, and the relationship between the second actual number of coding bits and the second expected number of coding bits, the upper limit and lower limit of the quantization parameter range corresponding to the previous adjustment cycle adjacent to the current adjustment cycle are adjusted to obtain the first quantization parameter range.

[0150] The first actual number of coded bits is the number of bits actually coded in the current first cycle, and the second actual number of coded bits is the number of bits actually coded in the current second cycle. The first expected number of coded bits is the number of bits expected to be coded in the current first cycle, determined based on the first target bit rate, and the second expected number of coded bits is the number of bits expected to be coded in the current second cycle, determined based on the first target bit rate.

[0151] That is, the first actual number of coded bits refers to the number of bits coded during the period starting from the start time of the current first cycle and ending at the start time of the current adjustment cycle. The second actual number of coded bits refers to the number of bits coded during the period starting from the start time of the current second cycle and ending at the start time of the current adjustment cycle.

[0152] The first expected number of encoded bits refers to the number of bits expected to be obtained by encoding at the first target bit rate during the period starting from the start time of the current first cycle and ending at the start time of the current adjustment cycle. In other words, the expected number of encoded bits can be obtained by determining the duration of the period starting from the start time of the current first cycle and ending at the start time of the current adjustment cycle, and multiplying the duration of this period by the first target bit rate.

[0153] The second expected number of coded bits refers to the number of bits expected to be obtained by encoding at the first target bit rate during the period starting from the start time of the current second cycle and ending at the start time of the current adjustment cycle. In other words, the expected number of coded bits can be obtained by determining the duration of the period starting from the start time of the current second cycle and ending at the start time of the current adjustment cycle, and multiplying the duration of this period by the first target bit rate.

[0154] In some embodiments, based on the relationship between the first actual number of coding bits and the first expected number of coding bits, and the relationship between the second actual number of coding bits and the second expected number of coding bits, the implementation process of adjusting the upper and lower limits of the quantization parameter range corresponding to the previous adjustment period adjacent to the current adjustment period includes: if the first actual number of coding bits is greater than the upper limit of the first expected number of coding bits, and the second actual number of coding bits is greater than the upper limit of the second expected number of coding bits, then increasing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment period adjacent to the current adjustment period to obtain the first quantization parameter range. If the first actual number of coding bits is less than the lower limit of the first expected number of coding bits, and the second actual number of coding bits is less than the lower limit of the second expected number of coding bits, then decreasing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment period to obtain the first quantization parameter range.

[0155] The first expected range of coding bits can be obtained by varying a certain range based on the first expected number of coding bits. The second expected range of coding bits can be obtained by varying a certain range based on the second expected number of coding bits. For example, the first expected range of coding bits can be obtained by varying ±N% based on the first expected number of coding bits, and the second expected range of coding bits can be obtained by varying ±N% based on the second expected number of coding bits. The value of N can be in the range [0, 20].

[0156] When the first actual number of coded bits is greater than the upper limit of the first expected number of coded bits, and the second actual number of coded bits is greater than the upper limit of the second expected number of coded bits, it indicates that the number of bits encoded in the current first cycle is relatively large, or that the quantization parameter used for the number of bits encoded in the current first cycle is relatively small. Therefore, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle adjacent to the current adjustment cycle can be increased, so that the actual number of coded bits is reduced in the subsequent encoding process, thereby ensuring that the actual average bit rate corresponding to the current first cycle approaches the first target bit rate. Conversely, when the first actual number of coded bits is less than the lower limit of the first expected number of coded bits, and the second actual number of coded bits is less than the lower limit of the second expected number of coded bits, it indicates that the number of bits encoded in the current first cycle is relatively small, or that the quantization parameter used for the number of bits encoded in the current first cycle is relatively large. Therefore, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle adjacent to the current adjustment cycle can be reduced, thereby increasing the actual number of coded bits in the subsequent encoding process, while ensuring that the actual average bit rate corresponding to the current first cycle approaches the first target bit rate, thereby improving image quality.

[0157] The implementation process of increasing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle can refer to the corresponding description in the second case above and will not be repeated here. Similarly, when reducing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle, the lower and upper limits of the quantization parameter range corresponding to the previous adjustment cycle can be reduced at the same time, and the reduction amounts of the lower and upper limits can be the same or different.

[0158] As another example, when a first cycle includes multiple second cycles, and the second cycle includes multiple adjustment cycles, if the current adjustment cycle is not the first adjustment cycle within the current first cycle and is the first adjustment cycle within the current second cycle, that is, the start time of the current adjustment cycle is not the start time of the current first cycle but is the start time of the current second cycle, then a first actual number of coding bits and a first expected number of coding bits are determined. Based on the relationship between the first actual number of coding bits and the first expected number of coding bits, the upper limit and lower limit of the quantization parameter range corresponding to the previous adjustment cycle adjacent to the current adjustment cycle are adjusted to obtain the first quantization parameter range.

[0159] The first actual number of coded bits is the number of bits actually coded in the current first period, and the first expected number of coded bits is the number of bits expected to be coded in the current first period determined based on the first target bit rate.

[0160] In some embodiments, based on the relationship between the first actual number of coding bits and the first expected number of coding bits, the implementation process of adjusting the upper limit and lower limit of the quantization parameter range corresponding to the previous adjustment period adjacent to the current adjustment period includes: if the first actual number of coding bits is greater than the upper limit of the first expected number of coding bits, increasing the upper limit and lower limit of the quantization parameter range corresponding to the previous adjustment period adjacent to the current adjustment period to obtain the first quantization parameter range. If the first actual number of coding bits is less than the lower limit of the first expected number of coding bits, decreasing the upper limit and lower limit of the quantization parameter range corresponding to the previous adjustment period to obtain the first quantization parameter range.

[0161] The first expected coding bit number range can be obtained by floating a certain range based on the first expected coding bit number. For example, the first expected coding bit number range can be obtained by floating ±N% based on the first expected coding bit number, and the value of N can be in the range of [0, 20].

[0162] When the first actual number of coded bits is greater than the upper limit of the first expected number of coded bits, it indicates that the number of bits coded in the current first cycle is relatively large, or that the quantization parameter used for the number of bits coded in the current first cycle is relatively small. Therefore, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle adjacent to the current adjustment cycle can be increased, so that the actual number of coded bits is reduced in the subsequent encoding process, thereby ensuring that the actual average bit rate corresponding to the current first cycle tends to the first target bit rate. Conversely, when the first actual number of coded bits is less than the lower limit of the first expected number of coded bits, it indicates that the number of bits coded in the current first cycle is relatively small, or that the quantization parameter used for the number of bits coded in the current first cycle is relatively large. Therefore, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle adjacent to the current adjustment cycle can be reduced, thereby increasing the actual number of coded bits in the subsequent encoding process, and improving image quality while ensuring that the actual average bit rate corresponding to the current first cycle tends to the first target bit rate.

[0163] Optionally, before increasing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle adjacent to the current adjustment cycle, it also includes: if the lower limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum lower limit quantization parameter and the upper limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum upper limit quantization parameter, a prompt message is displayed, and the prompt message is used to prompt that the recordable time cannot reach the expected time.

[0164] In some embodiments, the prompt information can be displayed in the form of a pop-up window, or in the form of a floating window. Of course, the prompt information can also be displayed in other ways, and the embodiment of the present application does not limit the display method of the prompt information.

[0165] When the lower limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum lower limit quantization parameter, and the upper limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum upper limit quantization parameter, it indicates that the lower limit of the quantization parameter range has reached the maximum adjustable threshold, and at the same time, the upper limit of the quantization parameter range has reached the maximum adjustable threshold. In other words, the quantization parameter range has reached its limit and the scene is too complex. In this case, the space occupied by the recorded data will be relatively large, and the recording time will not reach the expected time. The expected time refers to the theoretical recording time based on a certain amount of hard disk space.

[0166] Among them, when increasing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle, it can be determined whether the upper limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum upper limit parameter, and whether the lower limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum lower limit parameter. If the upper limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum upper limit parameter, and the lower limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum lower limit parameter, no further adjustment is made, and the quantization parameter range corresponding to the previous adjustment cycle is directly determined as the first quantization parameter range. Otherwise, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle are increased to obtain the first quantization parameter range, as long as the upper limit of the first quantization parameter range does not exceed the maximum upper limit parameter, and the lower limit of the first quantization parameter range does not exceed the maximum lower limit parameter.

[0167] Similarly, when reducing the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle, it can be determined whether the upper limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the minimum upper limit parameter, and whether the lower limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the minimum lower limit parameter. If the upper limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the minimum upper limit parameter, and the lower limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the minimum lower limit parameter, no further adjustment is made, and the quantization parameter range corresponding to the previous adjustment cycle is directly determined as the first quantization parameter range. Otherwise, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle are reduced to obtain the first quantization parameter range, as long as the upper limit of the first quantization parameter range is not less than the minimum upper limit parameter, and the lower limit of the first quantization parameter range is not less than the minimum lower limit parameter.

[0168] It should be noted that a maximum and minimum value can be set in advance for the lower limit of the quantization parameter range, that is, a maximum lower limit quantization parameter and a minimum lower limit quantization parameter. Similarly, a maximum and minimum value can also be set in advance for the upper limit of the quantization parameter range, that is, a maximum upper limit quantization parameter and a minimum upper limit quantization parameter. By setting maximum and minimum values ​​for the upper and lower limits of the quantization parameter range, it is possible to avoid problems such as image quality degradation caused by an excessively large quantization parameter, or the problem of video data occupying too much storage space due to an excessively small quantization parameter.

[0169] The third case: if the current adjustment cycle is the first adjustment cycle within the current first cycle and the current first cycle is not the first first cycle, that is, the start time of the current adjustment cycle is not the start time of the first first cycle, then the quantization parameter range corresponding to the last adjustment cycle included in the previous first cycle adjacent to the current first cycle is determined as the first quantization parameter range.

[0170] When the start time of the current adjustment cycle is not the start time of the first cycle, it indicates that the current adjustment cycle is the first adjustment cycle within the non-first first cycle. At this time, in order to achieve a smooth transition of the image between two adjacent first cycles, the quantization parameter range corresponding to the last adjustment cycle included in the previous first cycle adjacent to the current first cycle can be determined as the first quantization parameter range.

[0171] In some embodiments, the implementation process of determining the first quantization parameter based on the first quantization parameter range includes: if the current first cycle is not the first first cycle, or the current first cycle is the first first cycle and the current adjustment cycle is not the first adjustment cycle within the current first cycle, that is, the start time of the current adjustment cycle is not the start time of the first first cycle, then obtaining a second quantization parameter, the second quantization parameter being the quantization parameter used at the end of the previous adjustment cycle adjacent to the current adjustment cycle. If the second quantization parameter is within the first quantization parameter range, then determining the second quantization parameter as the first quantization parameter; otherwise, adjusting the second quantization parameter so that the adjusted second quantization parameter is within the first quantization parameter range, and determining the adjusted second quantization parameter as the first quantization parameter.

[0172] Normally, the scene motion levels of two adjacent adjustment cycles are not much different, so the second quantization parameter is usually also within the range of the first quantization parameter. In this case, the second quantization parameter can be directly determined as the first quantization parameter. However, in some cases, the scene motion levels of two adjacent adjustment cycles may differ greatly, resulting in the second quantization parameter not being within the range of the first quantization parameter. In this case, the second quantization parameter needs to be adjusted. When the second quantization parameter is greater than the upper limit of the first quantization parameter range, the second quantization parameter can be reduced. When the second quantization parameter is less than the lower limit of the first quantization parameter range, the second quantization parameter can be increased, as long as the adjusted second quantization parameter is within the range of the first quantization parameter.

[0173] Optionally, if the current adjustment cycle is the first adjustment cycle in the entire encoding process, that is, the start time of the current adjustment cycle is the start time of the first cycle, then the initial quantization parameter can be directly determined as the first quantization parameter.

[0174] The initial quantization parameter can be set in advance, and the initial quantization parameter can also be adjusted according to different requirements.

[0175] Step 202: Determine a second target bit rate. The second target bit rate is the maximum bit rate in the current adjustment period and is the average bit rate in the remaining time of the current first period determined based on the first target bit rate.

[0176] Based on the above description, the current adjustment period may be the first adjustment period within the current first period, or may be a non-first adjustment period within the current first period, and the current first period may be the first first period, or may be a non-first first period. In the case of different positions of the current adjustment period, the method for determining the target bit rate corresponding to the current adjustment period is different, that is, the method for determining the second target bit rate is different. The following will be divided into the following three cases for explanation:

[0177] In the first case, if the current adjustment period is the first adjustment period within the current first period, that is, the start time of the current adjustment period is the start time of the current first period, the first target bit rate is determined as the second target bit rate.

[0178] When the target bit rates corresponding to each first period are not equal, if the start time of the current adjustment period is the start time of the current first period, it indicates that the current adjustment period is the first adjustment period in the current first period and is an adjustment period encoded based on the first target bit rate. At this time, the first target bit rate can be directly determined as the second target bit rate.

[0179] If the number of coding bits in each first cycle reaches an average bit rate corresponding to a preset number of coding bits and is equal to the first target bit rate, and the current adjustment cycle is the first adjustment cycle within the current first cycle and the current first cycle is the first first cycle, that is, the start time of the current adjustment cycle is the start time of the first first cycle, then the first target bit rate is determined as the second target bit rate. In other words, if the number of coding bits in each first cycle reaches an average bit rate corresponding to a preset number of coding bits and is equal to the first target bit rate, for the first adjustment cycle of the entire encoding process, the first target bit rate can be directly determined as the second target bit rate.

[0180] In the case where the number of coding bits in each first cycle reaches the average bit rate corresponding to the preset number of coding bits and is equal to the first target bit rate, if the current adjustment cycle is the first adjustment cycle in the current first cycle and the current first cycle is not the first first cycle, that is, the start time of the current adjustment cycle is not the start time of the first first cycle, then the actual average bit rate of the first adjustment cycle in the previous first cycle adjacent to the current first cycle is determined as the second target bit rate, and the actual average bit rate of the first adjustment cycle in the previous first cycle is related to the first target bit rate. Alternatively, in the case where the first cycle includes multiple second cycles and the second cycle includes multiple adjustment cycles, the actual average bit rate of the first second cycle in the previous first cycle adjacent to the current first cycle is determined as the second target bit rate, and the actual average bit rate of the first second cycle in the previous first cycle is related to the first target bit rate.

[0181] If the start time of the current adjustment cycle is not the start time of the first first cycle, it indicates that the current adjustment cycle is the first adjustment cycle within the non-first first cycle. To achieve a better bit rate adjustment effect, the length of the first cycle should not be too long, and the number of adjustment cycles included in the first cycle should not be too large. Therefore, if the first cycle does not include the second cycle, the actual average bit rate of the first adjustment cycle within the previous first cycle is closer to the actual requirements of the encoding process. Therefore, the actual average bit rate of the first adjustment cycle within the previous first cycle can be directly determined as the second target bit rate.

[0182] When the first cycle includes the second cycle, the length of the second cycle will not be too short, and the number of second cycles included in the first cycle will not be too large. The length of the second cycle is greater than the length of the adjustment cycle. Therefore, compared with the adjustment cycle, the actual average bit rate of the first second cycle in the previous first cycle is closer to the actual requirements of the encoding process. Therefore, the actual average bit rate of the first second cycle in the previous first cycle can be directly determined as the second target bit rate.

[0183] It should be noted that the average bit rates corresponding to the number of coding bits reaching the preset number of coding bits in each first period are equal and are both the first target bit rates. For example, if the first target bit rate is set in advance to 400 Kbps, the target bit rates corresponding to each first period are equal, namely, 400 Kbps. In addition, the average bit rates corresponding to the number of coding bits reaching the preset number of coding bits in each first period may also be different, that is, the preset number of coding bits corresponding to each first period is different.

[0184] In the second case, if the current adjustment period is not the first adjustment period within the current first period, that is, the start time of the current adjustment period is not the start time of the current first period, then the first actual number of coded bits and the first expected number of coded bits are determined, where the first actual number of coded bits is the number of bits actually coded within the current first period, and the first expected number of coded bits is the number of bits expected to be coded within the current first period determined based on the first target bit rate. The remaining number of coded bits is determined, where the remaining number of coded bits is the difference between the first expected number of coded bits and the first actual number of coded bits. The remaining number of coded bits is divided by the remaining duration of the current first period to obtain the second target bit rate.

[0185] That is, based on the first target bit rate, the first actual number of coding bits, the first duration and the second duration, the second target bit rate is determined, the first duration is the total duration of the current first cycle, and the second duration is the remaining duration of the current first cycle.

[0186] When the start time of the current adjustment period is not the start time of the current first period, it indicates that the current adjustment period is not the first adjustment period within the current first period. At this time, in order to ensure that the actual average bit rate corresponding to the current first period tends to the first target bit rate, the first actual number of coding bits, the first expected number of coding bits, and the remaining number of coding bits can be determined, and then the second target bit rate is determined based on the first actual number of coding bits, the first expected number of coding bits, the remaining number of coding bits, the first duration, and the second duration.

[0187] As an example, based on the first target bit rate, the first actual number of coded bits, the first duration, and the second duration, the second target bit rate may be determined according to the following formula (1).

[0188] r=(R*t1-B) / t2 (1)

[0189] In the above formula (1), r is the second target bit rate, R is the first target bit rate, B is the first actual number of coded bits, t1 is the first duration, and t2 is the second duration.

[0190] Step 203: Based on the first quantization parameter, encode the video data within the current adjustment period, and during the encoding process, adjust the first quantization parameter based on the actual average bit rate of the video data per unit time, so that the actual average bit rate within the current adjustment period does not exceed the second target bit rate.

[0191] In some embodiments, a plurality of third target bit rates can be determined based on the second target bit rate, wherein the plurality of third target bit rates correspond one to one with a plurality of motion levels, the plurality of third target bit rates are different and the plurality of third target bit rates are less than or equal to the second target bit rate. During the encoding process, the actual motion level of the video data in a unit time is determined. When the actual average bit rate of the video data in a first unit time is not equal to the third target bit rate corresponding to the actual motion level of the video data in the first unit time, the first quantization parameter is adjusted so that the actual average bit rate of the video data in a second unit time tends to the third target bit rate corresponding to the actual motion level of the video data in the second unit time, the first unit time and the second unit time being any two adjacent unit times, and the first unit time being located before the second unit time.

[0192] That is, the third target bit rates corresponding to multiple motion levels in the current adjustment period are determined. In this way, in the process of encoding the video data in the current adjustment period, the first quantization parameter can be adjusted based on the different motion levels of the scene, so as to encode the video data so that the actual average bit rate per unit time is basically consistent with the third target bit rate corresponding to the actual motion level.

[0193] In some embodiments, the level ratios corresponding to the multiple motion levels may be obtained, and the second target bit rate may be multiplied by the level ratio corresponding to each motion level to obtain a third target bit rate corresponding to each motion level.

[0194] For the multiple motion levels, when the degree of motion is greater, a higher motion level may be set, and the level ratio corresponding to the motion level may be smaller, thereby increasing the third target bitrate corresponding to the motion level. When the degree of motion is smaller, a lower motion level may be set, and the level ratio corresponding to the motion level may be larger, thereby decreasing the third target bitrate corresponding to the motion level.

[0195] For example, the current scene's motion level is divided into seven motion levels, with the corresponding proportions from high to low being 100%, 80%, 75%, 60%, 50%, 35%, and 25%. Assuming the second target bitrate is 400Kbps, the third target bitrates are 400Kbps, 320Kbps, 300Kbps, 240Kbps, 200Kbps, 140Kbps, and 100Kbps.

[0196] Wherein, when the actual average bit rate of the video data in the first unit time is not equal to the third target bit rate corresponding to the actual motion level of the video data in the first unit time, the implementation process of adjusting the first quantization parameter includes: when the actual average bit rate of the video data in the first unit time is greater than the third target bit rate corresponding to the actual motion level of the video data in the first unit time, if the first quantization parameter is less than the upper limit of the first quantization parameter range, increasing the first quantization parameter so that the increased first quantization parameter is within the first quantization parameter range, the first quantization parameter range being used to constrain the quantization parameter used for encoding the video data in the current adjustment cycle. When the actual average bit rate of the video data in the first unit time is less than the third target bit rate corresponding to the actual motion level of the video data in the first unit time, if the first quantization parameter is greater than the lower limit of the first quantization parameter range, decreasing the first quantization parameter so that the decreased first quantization parameter is within the first quantization parameter range.

[0197] When the actual average bit rate of the video data in the first unit time is greater than the third target bit rate corresponding to the actual motion level of the video data in the first unit time, it indicates that the first quantization parameter is small. In order to control the actual average bit rate in the current adjustment period not to exceed the second target bit rate, the first quantization parameter needs to be increased. Similarly, when the actual average bit rate of the video data in the first unit time is less than the third target bit rate corresponding to the actual motion level of the video data in the first unit time, it indicates that the first quantization parameter is large. In order to control the actual average bit rate in the current adjustment period not to exceed the second target bit rate, the first quantization parameter needs to be reduced.

[0198] Optionally, when the actual average bit rate of the video data in the first unit time is greater than the third target bit rate corresponding to the actual motion level of the video data in the first unit time, if the first quantization parameter is equal to the upper limit of the first quantization parameter range, the first quantization parameter is no longer increased, and the video data continues to be encoded according to the first quantization parameter. Similarly, when the actual average bit rate of the video data in the first unit time is less than the third target bit rate corresponding to the actual motion level of the video data in the first unit time, if the first quantization parameter is equal to the lower limit of the first quantization parameter range, the first quantization parameter is no longer decreased, and encoding continues according to the first quantization parameter.

[0199] Since the target bitrate for each first cycle is fixed, encoding the video data using the above method allows the prediction of the available recording time. Specifically, the sum of the actual average bitrates of all connected analog channels during the previous first cycle is determined to obtain the total analog channel bitrate. The sum of the actual average bitrates of all connected IPC (IP Camera) channels during the previous first cycle is determined to obtain the total IPC channel bitrate. The total hard disk space is obtained. Based on the total analog channel bitrate, the total IPC channel bitrate, and the total hard disk space, the available recording time is determined. The available recording time is displayed.

[0200] An analog channel is a channel that transmits analog video data. That is, the video data transmitted by a camera connected to an analog channel is analog video data. An IPC channel is a channel that transmits digital video data. That is, the digital video data transmitted by a camera connected to an IPC channel is recorded data.

[0201] In some cases, a DVR may not always receive video data from a camera. For example, if the device malfunctions or a connection is damaged, the DVR may not receive video data from the camera for a certain period of time. Therefore, for any analog channel, the duration of the time period during which the analog channel received analog video data in the previous first cycle can be calculated to obtain a third duration. The first target bit rate is multiplied by the third duration and then divided by the duration of the first cycle to obtain the actual average bit rate for the analog channel in the previous first cycle. The actual average bit rate of each analog channel in the previous first cycle is then added together to obtain the total bit rate for the analog channel.

[0202] The same principle applies to IPC channels. That is, for any IPC channel, the duration of the time period in which the IPC channel receives video data in the previous first cycle can be calculated to obtain a fourth duration. The actual bit rate of the video data received by the IPC channel is multiplied by the fourth duration and then divided by the duration of the first cycle to obtain the actual average bit rate of the IPC channel in the previous first cycle. The actual average bit rate of each IPC channel in the previous first cycle is then added together to obtain the total bit rate of the IPC channel.

[0203] As an example, the recordable time may be determined according to the following formula (2) based on the total bit rate of the analog channels, the total bit rate of the IPC channels, and the total hard disk space.

[0204] T S =M / [(A+I) / 8*t] (2)

[0205] In the above formula (2), T S is the available recording time, M is the total hard disk space, A is the total bit rate of the analog channel, I is the total bit rate of the IPC channel, and t is the duration of the first cycle.

[0206] It should be noted that the unit of the total hard disk space is KB, and the unit of the total bit rate of the analog channel and the total bit rate of the IPC channel is Kbps. Dividing by 8 converts the unit Kbps to KBps, that is, converts bits to bytes. When the first cycle lasts for one day, t is 86400, which is the number of seconds in a day. That is, the brackets in the above formula (2) are the video size of the first cycle.

[0207] In the embodiment of the present application, the hard disk recorder can display the available recording time in the encoding parameter configuration interface in the form of a pop-up window, or in the form of a floating window. Of course, the available recording time can also be displayed in other ways, and the embodiment of the present application does not limit the display method of the available recording time.

[0208] It should be noted that the encoding parameter configuration interface of the hard disk recorder generally includes resolution, bit rate, image quality, frame rate, maximum bit rate setting mode, maximum bit rate, recommended bit rate (display only), encoding type, whether it is smart encoding, etc. The embodiment of the present application adjusts the encoding parameter setting interface to display the recordable time, but does not limit which encoding parameters to delete. For example, the encoding parameter configuration interface of the hard disk recorder is as follows: Figure 3 As shown, in Figure 3 The available recording time is displayed in the middle.

[0209] In the embodiment of the present application, since the target bit rate corresponding to each first cycle is fixed, that is, when encoding is performed using the method provided in the embodiment of the present application, the target bit rate corresponding to each first cycle can be predicted, so the recordable time can be predicted in advance. Moreover, in the encoding method provided in the embodiment of the present application, for one adjustment cycle, different target bit rates can be set according to different motion levels based on the different degrees of motion in the actual scene, thereby adopting variable bit rate encoding. In this way, the image quality of the video data after encoding can be guaranteed and bit rate waste can be reduced. Moreover, by comparing the actual bit rate with the target bit rate and continuously adjusting the quantization parameter range, the bit rate control capability can be improved.

[0210] Figure 4 This is a schematic diagram of the structure of a video data encoding device provided by an embodiment of the present application. The video data encoding device can be implemented by software, hardware, or a combination of both to become part or all of a video data encoding device. The video data encoding device can be Figure 1 The video data encoding device shown. Figure 4 The device includes: a quantization parameter determination module 401, a second target bit rate determination module 402, an encoding module 403 and an adjustment module 404.

[0211] The quantization parameter determination module 401 is configured to determine a first quantization parameter, where the first quantization parameter is an initial quantization parameter used to encode video data in a current adjustment period.

[0212] A second target bit rate determination module 402 is configured to determine a second target bit rate, where the second target bit rate is the maximum bit rate within the current adjustment period and is an average bit rate for the remaining duration of the current first period determined based on the first target bit rate. The first target bit rate is the average bit rate corresponding to the number of coded bits within the current first period reaching a preset number of coded bits, where the current first period includes multiple adjustment periods.

[0213] The encoding module 403 is configured to encode the video data within a current adjustment period based on the first quantization parameter;

[0214] The adjustment module 404 is configured to adjust the first quantization parameter based on the actual average bit rate of the video data in a unit time during the encoding process, so that the actual average bit rate in a current adjustment period does not exceed the second target bit rate.

[0215] Optionally, the quantization parameter determination module 401 includes:

[0216] a quantization parameter range determining unit, configured to determine a first quantization parameter range, the first quantization parameter range being used to constrain the quantization parameter used for encoding the video data within a current adjustment period;

[0217] The quantization parameter determining unit is configured to determine a first quantization parameter based on a first quantization parameter range, wherein the first quantization parameter is within the first quantization parameter range.

[0218] Optionally, the quantization parameter range determining unit is specifically configured to:

[0219] If the current adjustment cycle is the first adjustment cycle within the current first cycle and the current first cycle is the first first cycle, the initial quantization parameter range is determined to be the first quantization parameter range.

[0220] Optionally, the quantization parameter range determining unit is specifically configured to:

[0221] If the current adjustment period is not the first adjustment period within the current first period, determining the actual average bit rate of the previous adjustment period adjacent to the current adjustment period;

[0222] If the actual average bit rate in the previous adjustment cycle is greater than the bit rate threshold corresponding to the previous adjustment cycle, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle are increased to obtain a first quantization parameter range, and the bit rate threshold is determined based on the target bit rate corresponding to the previous adjustment cycle.

[0223] Optionally, the first period includes multiple second periods, and the second period includes multiple adjustment periods; and the quantization parameter range determining unit is specifically configured to:

[0224] If the current adjustment period is not the first adjustment period in the current first period and is not the first adjustment period in the current second period, the actual average bit rate of the previous adjustment period adjacent to the current adjustment period is determined.

[0225] Optionally, the first period includes multiple second periods, and the second period includes multiple adjustment periods; and the quantization parameter range determining unit is specifically configured to:

[0226] If the current adjustment period is not the first adjustment period within the current first period and is the first adjustment period within the current second period, determining a first actual number of coded bits, a second actual number of coded bits, a first expected number of coded bits, and a second expected number of coded bits;

[0227] The first actual number of coded bits is the number of bits actually coded in the current first cycle, the second actual number of coded bits is the number of bits actually coded in the current second cycle, the first expected number of coded bits is the number of bits expected to be coded in the current first cycle determined based on the first target bit rate, and the second expected number of coded bits is the number of bits expected to be coded in the current second cycle determined based on the first target bit rate;

[0228] Based on the relationship between the first actual number of coding bits and the first expected number of coding bits, and the relationship between the second actual number of coding bits and the second expected number of coding bits, the upper and lower limits of the quantization parameter range corresponding to the previous adjustment period adjacent to the current adjustment period are adjusted to obtain the first quantization parameter range.

[0229] Optionally, the quantization parameter range determining unit is specifically configured to:

[0230] Determining a first expected range of coding bits based on the first expected number of coding bits, and determining a second expected range of coding bits based on the second expected number of coding bits;

[0231] If the first actual number of coded bits is greater than an upper limit of the first expected range of coded bits, and the second actual number of coded bits is greater than an upper limit of the second expected range of coded bits, increasing the upper limit and the lower limit of the quantization parameter range corresponding to a previous adjustment period adjacent to the current adjustment period to obtain the first quantization parameter range;

[0232] If the first actual number of coding bits is less than the lower limit of the first expected number of coding bits, and the second actual number of coding bits is less than the lower limit of the second expected number of coding bits, then the upper and lower limits of the quantization parameter range corresponding to the previous adjustment cycle are reduced to obtain the first quantization parameter range.

[0233] Optionally, the first period includes multiple second periods, and the second period includes multiple adjustment periods; and the quantization parameter range determining unit is specifically configured to:

[0234] If the current adjustment period is not the first adjustment period within the current first period and is the first adjustment period within the current second period, determining a first actual number of coded bits and a first expected number of coded bits;

[0235] The first actual number of coded bits is the number of bits actually coded in the current first period, and the first expected number of coded bits is the number of bits expected to be coded in the current first period determined based on the first target bit rate;

[0236] Based on the relationship between the first actual number of coded bits and the first expected number of coded bits, the upper limit and the lower limit of the quantization parameter range corresponding to the previous adjustment period adjacent to the current adjustment period are adjusted to obtain a first quantization parameter range.

[0237] Optionally, the quantization parameter range determining unit is specifically configured to:

[0238] Determining a first expected number of coding bits range based on the first expected number of coding bits;

[0239] If the first actual number of coded bits is greater than the upper limit of the first expected range of coded bits, increasing the upper limit and the lower limit of the quantization parameter range corresponding to the previous adjustment period adjacent to the current adjustment period to obtain the first quantization parameter range;

[0240] If the first actual number of coded bits is less than the lower limit of the first expected number of coded bits, the upper limit and the lower limit of the quantization parameter range corresponding to the previous adjustment cycle are reduced to obtain the first quantization parameter range.

[0241] Optionally, the device further comprises:

[0242] The prompt information display module is used to display a prompt information if the lower limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum lower limit quantization parameter and the upper limit of the quantization parameter range corresponding to the previous adjustment cycle reaches the maximum upper limit quantization parameter. The prompt information is used to indicate that the recordable time cannot reach the expected time.

[0243] Optionally, the quantization parameter range determining unit is specifically configured to:

[0244] If the current adjustment cycle is the first adjustment cycle within the current first cycle and the current first cycle is not the first first cycle, the quantization parameter range corresponding to the last adjustment cycle included in the previous first cycle adjacent to the current first cycle is determined as the first quantization parameter range.

[0245] Optionally, the quantization parameter determination unit is specifically configured to:

[0246] If the current first cycle is not the first first cycle, or the current first cycle is the first first cycle and the current adjustment cycle is not the first adjustment cycle within the current first cycle, obtaining a second quantization parameter, where the second quantization parameter is the quantization parameter used at the end of a previous adjustment cycle adjacent to the current adjustment cycle;

[0247] If the second quantization parameter is within the range of the first quantization parameter, the second quantization parameter is determined as the first quantization parameter; otherwise, the second quantization parameter is adjusted so that the adjusted second quantization parameter is within the range of the first quantization parameter, and the adjusted second quantization parameter is determined as the first quantization parameter.

[0248] Optionally, the second target bit rate determination module 402 is specifically configured to:

[0249] If the current adjustment period is the first adjustment period within the current first period, the first target bit rate is determined as the second target bit rate.

[0250] Optionally, the average bit rates corresponding to the number of coded bits in each first period reaching the preset number of coded bits are equal and both are the first target bit rates; the second target bit rate determination module 402 is specifically configured to:

[0251] If the current adjustment period is the first adjustment period within the current first period and the current first period is the first first period, the first target bit rate is determined as the second target bit rate.

[0252] Optionally, the average bit rates corresponding to the number of coded bits in each first period reaching the preset number of coded bits are equal and both are the first target bit rates; the second target bit rate determination module 402 is specifically configured to:

[0253] If the current adjustment period is the first adjustment period within the current first period and the current first period is not the first first period, the actual average bit rate of the first adjustment period within the previous first period adjacent to the current first period is determined as the second target bit rate.

[0254] Optionally, the average bit rates corresponding to the number of coded bits in each first period reaching a preset number of coded bits are equal and are all the first target bit rates; the first period includes multiple second periods, and the second period includes multiple adjustment periods; the second target bit rate determination module 402 is specifically configured to:

[0255] If the current adjustment period is the first adjustment period within the current first period and the current first period is not the first first period, the actual average bit rate of the first second period within the previous first period adjacent to the current first period is determined as the second target bit rate.

[0256] Optionally, the second target bit rate determination module 402 is specifically configured to:

[0257] If the current adjustment period is not the first adjustment period within the current first period, determining a first actual number of coded bits and a first expected number of coded bits, where the first actual number of coded bits is the number of bits actually coded within the current first period, and the first expected number of coded bits is the number of bits expected to be coded within the current first period determined based on the first target bit rate;

[0258] Determining a remaining number of coding bits, where the remaining number of coding bits is a difference between the first expected number of coding bits and the first actual number of coding bits;

[0259] The remaining number of coded bits is divided by the remaining duration of the current first cycle to obtain a second target bit rate.

[0260] Optionally, the device further comprises:

[0261] a third target bit rate determination module, configured to determine a plurality of third target bit rates based on the second target bit rate, the plurality of third target bit rates corresponding one-to-one to a plurality of motion levels, the plurality of third target bit rates being different and less than or equal to the second target bit rate;

[0262] A motion level determination module is used to determine the actual motion level of the video data per unit time during the encoding process;

[0263] The adjustment module 404 is specifically used for:

[0264] Whenever the actual average bit rate of the video data in the first unit time is not equal to the third target bit rate corresponding to the actual motion level of the video data in the first unit time, the first quantization parameter is adjusted so that the actual average bit rate of the video data in the second unit time tends to the third target bit rate corresponding to the actual motion level of the video data in the second unit time, the first unit time and the second unit time are any two adjacent unit times, and the first unit time is located before the second unit time.

[0265] Optionally, the adjustment module 404 is specifically configured to:

[0266] When the actual average bit rate in the first unit time is greater than a third target bit rate corresponding to the actual motion level in the first unit time, if the first quantization parameter is less than an upper limit of the first quantization parameter range, increasing the first quantization parameter so that the increased first quantization parameter is within the first quantization parameter range, the first quantization parameter range being used to constrain a quantization parameter used for encoding the video data in the current adjustment period;

[0267] When the actual average bit rate in the first unit time is less than the third target bit rate corresponding to the actual motion level in the first unit time, if the first quantization parameter is greater than the lower limit of the first quantization parameter range, the first quantization parameter is reduced, and the reduced first quantization parameter is within the first quantization parameter range.

[0268] Optionally, the device further comprises:

[0269] A first bit rate determination module is used to determine the sum of actual average bit rates of all connected analog channels in the previous first period to obtain a total bit rate of the analog channels;

[0270] The second bit rate determination module is used to determine the sum of the actual average bit rates of all connected network camera IPC channels in the previous first period to obtain the total bit rate of the IPC channels;

[0271] Acquisition module, used to obtain the total hard disk space;

[0272] The recordable time determination module is used to determine the recordable time based on the total bit rate of the analog channel, the total bit rate of the IPC channel and the total hard disk space;

[0273] The recording time display module is used to display the available recording time.

[0274] In the embodiment of the present application, since the target bit rate corresponding to each first cycle is fixed, that is, when encoding is performed using the method provided in the embodiment of the present application, the target bit rate corresponding to each first cycle can be predicted, so the recordable time can be predicted in advance. Moreover, in the encoding method provided in the embodiment of the present application, for one adjustment cycle, different target bit rates can be set according to different motion levels based on the different degrees of motion in the actual scene, thereby adopting variable bit rate encoding. In this way, the image quality of the video data after encoding can be guaranteed and bit rate waste can be reduced. Moreover, by comparing the actual bit rate with the target bit rate and continuously adjusting the quantization parameter range, the bit rate control capability can be improved.

[0275] It should be noted that the video data encoding device provided in the above embodiment only uses the division of the above functional modules as an example to illustrate the encoding of video data. In actual 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 video data encoding device provided in the above embodiment and the video data encoding method embodiment are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0276] Figure 5 This is a block diagram of the structure of a terminal 500 provided in an embodiment of the present application. This terminal can function as the aforementioned camera or hard disk recorder. This terminal 500 can be a portable mobile terminal, such as a smartphone, tablet computer, laptop computer, or desktop computer. Terminal 500 may also be referred to as user equipment, portable terminal, laptop terminal, desktop terminal, or other names.

[0277] Typically, the terminal 500 includes a processor 501 and a memory 502 .

[0278] The processor 501 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 501 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor 501 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 501 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 501 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0279] The memory 502 may include one or more computer-readable storage media, which may be non-transitory. The memory 502 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 502 is used to store at least one instruction, which is executed by the processor 501 to implement the video data encoding method provided in the method embodiment of the present application.

[0280] In some embodiments, terminal 500 may optionally include a peripheral device interface 503 and at least one peripheral device. Processor 501, memory 502, and peripheral device interface 503 may be connected via a bus or signal lines. Each peripheral device may be connected to peripheral device interface 503 via a bus, signal lines, or circuit boards. Specifically, the peripheral device may include at least one of a radio frequency circuit 504, a touchscreen display 505, a camera 506, and a power supply 507.

[0281] The peripheral device interface 503 can be used to connect at least one I / O (Input / Output)-related peripheral device to the processor 501 and the memory 502. In some embodiments, the processor 501, the memory 502, and the peripheral device interface 503 are integrated on the same circuit board; in some other embodiments, any one or two of the processor 501, the memory 502, and the peripheral device interface 503 can be implemented on separate circuit boards, which is not limited in this embodiment.

[0282] The radio frequency circuit 504 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 504 communicates with communication networks and other communication devices via electromagnetic signals. The radio frequency circuit 504 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the radio frequency circuit 504 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a user identity module card, etc. The radio frequency circuit 504 can communicate with other terminals via at least one wireless communication protocol. Such wireless communication protocols include, but are not limited to, the World Wide Web, a metropolitan area network, an intranet, various generations of mobile communication networks (2G, 3G, 4G, and 5G), a wireless local area network, and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 504 may also include circuits related to NFC (Near Field Communication), which is not limited in this embodiment of the present application.

[0283] Display screen 505 is used to display a user interface (UI). This UI may include graphics, text, icons, videos, or any combination thereof. When display screen 505 is a touchscreen display, it is also capable of collecting touch signals on or above the surface of display screen 505. These touch signals can be input as control signals to processor 501 for processing. In this case, display screen 505 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 can be a single display screen 505, located on the front panel of terminal 500. In other embodiments, there can be at least two display screens 505, located on different surfaces of terminal 500 or in a foldable design. In still other embodiments, display screen 505 can be a flexible display screen, located on a curved or foldable surface of terminal 500. Furthermore, display screen 505 can be configured as a non-rectangular, irregular shape, i.e., a special-shaped screen. Display screen 505 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).

[0284] The camera assembly 506 is used to capture images or videos. Optionally, the camera assembly 506 includes a front camera and a rear camera. Typically, the front camera is set on the front panel of the terminal, and the rear camera is set on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 506 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.

[0285] Power supply 507 is used to power various components in terminal 500. Power supply 507 can be AC ​​power, DC power, a disposable battery, or a rechargeable battery. When power supply 507 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged via a wired line, while a wireless rechargeable battery is a battery that is charged via a wireless coil. The rechargeable battery can also be used to support fast charging technology.

[0286] Those skilled in the art will understand that Figure 5The structure shown in the figure does not constitute a limitation on the terminal 500, and the terminal 500 may include more or fewer components than shown in the figure, or combine certain components, or adopt a different component arrangement.

[0287] In some embodiments, a computer-readable storage medium is further provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of the video data encoding method in the above embodiment are implemented.

[0288] In some embodiments, a computer program product comprising instructions is further provided, which, when executed on a computer, enables the computer to perform the steps of the above-mentioned method for encoding video data.

[0289] It should be understood that the "at least one" mentioned herein refers to one or more, and "a plurality of" refers to two or more. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is merely a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate a clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. Those skilled in the art will understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.

[0290] The above description is an embodiment provided for this application and is not intended to limit this application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this application should be included in the scope of protection of this application.

Claims

1. A method for encoding video data, characterized in that: The method comprises: determining second target bit rates corresponding to a plurality of adjustment periods based on a first target bit rate corresponding to a first period; wherein the first period includes the plurality of adjustment periods, the first target bit rate is a fixed value, and second target bit rates corresponding to different adjustment periods are the same or different; wherein the first target bit rate represents an average bit rate expected within the first period, and the second target bit rate corresponding to each adjustment period represents an average bit rate expected within the adjustment period; For a current adjustment cycle among the multiple adjustment cycles, determining a target quantization parameter for the current adjustment cycle based on a target quantization parameter range corresponding to the current adjustment cycle and a second target bit rate corresponding to the current adjustment cycle; wherein the target quantization parameter range is used to constrain a maximum value and a minimum value of the quantization parameter for the current adjustment cycle, the second target bit rate is used to adjust the quantization parameter for the current adjustment cycle, and the quantization parameter is within the target quantization parameter range; wherein if an actual encoding bit rate corresponding to an initial quantization parameter within the target quantization parameter range is greater than the second target bit rate, increasing the initial quantization parameter; if the increased quantization parameter is within the target quantization parameter range, determining the target quantization parameter based on the increased quantization parameter; if the increased quantization parameter is not within the target quantization parameter range, determining the target quantization parameter based on the maximum value of the quantization parameter; if the actual encoding bit rate is less than the second target bit rate, decreasing the initial quantization parameter; if the decreased quantization parameter is within the target quantization parameter range, determining the target quantization parameter based on the decreased quantization parameter; and if the decreased quantization parameter is not within the target quantization parameter range, determining the target quantization parameter based on the minimum value of the quantization parameter. In the current adjustment period, video data is encoded based on the target quantization parameter.

2. The method according to claim 1, characterized in that For each adjustment period, determining the second target bit rate corresponding to the adjustment period based on the first target bit rate corresponding to the first period includes: Determining a maximum target bit rate corresponding to the adjustment period based on a first target bit rate corresponding to the first period; A second target bit rate corresponding to the adjustment period is determined based on the maximum target bit rate.

3. The method according to claim 2, characterized in that The determining, based on the maximum target bit rate, a second target bit rate corresponding to the adjustment period includes: Determine the maximum target bit rate as the second target bit rate corresponding to the adjustment period; or, determining a scene motion level corresponding to the adjustment period, and determining a second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the scene motion level, wherein the second target bit rate is less than or equal to the maximum target bit rate; Wherein, when the scene motion level is greater, the second target bit rate is greater.

4. The method according to claim 3, characterized in that After determining the second target bit rate corresponding to the adjustment period based on the maximum target bit rate and the scene motion level, the method further includes: When the scene motion level corresponding to the adjustment period changes, the second target bit rate corresponding to the adjustment period is re-determined based on the maximum target bit rate and the changed scene motion level.

5. The method according to claim 3 or 4, characterized in that The determining, based on the maximum target bit rate and the scene motion level, a second target bit rate corresponding to the adjustment period includes: Determining a configured scaling factor corresponding to the scene motion level; wherein the scaling factor is greater than 0 and less than or equal to 1, and the greater the scene motion level, the greater the scaling factor corresponding to the scene motion level; The second target bit rate is determined based on a product of the scaling factor and the maximum target bit rate.

6. The method according to claim 2, characterized in that The determining, based on the first target bit rate corresponding to the first period, the maximum target bit rate corresponding to the adjustment period includes: If the adjustment period is the first adjustment period within the first period, the first target bit rate corresponding to the first period is determined as the maximum target bit rate corresponding to the adjustment period; or If the adjustment period is not the first adjustment period within the first period, the maximum target bit rate corresponding to the adjustment period is determined based on the first target bit rate corresponding to the first period, the total duration corresponding to the first period, the total actual amount of coded bits before the adjustment period within the first period, and the remaining duration of the first period.

7. The method according to claim 6, characterized in that The determining, based on the first target bit rate corresponding to the first period, the total duration corresponding to the first period, the total actual amount of coded bits in the first period before the adjustment period, and the remaining duration of the first period, the maximum target bit rate corresponding to the adjustment period includes: The maximum target bit rate corresponding to the adjustment period is determined based on the following formula: the maximum target bit rate = [the first target bit rate * the total duration corresponding to the first period - the total actual coding bits] / the remaining duration of the first period.

8. The method according to claim 1 or 7, characterized in that Before determining the target quantization parameter of the current adjustment period based on the target quantization parameter range corresponding to the current adjustment period and the second target bit rate corresponding to the current adjustment period, the method further includes: If the current adjustment period is the first adjustment period within the first period, determining a quantization parameter range corresponding to the first period, and determining the quantization parameter range as a target quantization parameter range corresponding to the current adjustment period; Alternatively, if the current adjustment cycle is not the first adjustment cycle within the first cycle, the quantization parameter range corresponding to the adjacent adjustment cycle before the current adjustment cycle is determined, and the target quantization parameter range corresponding to the current adjustment cycle is determined based on the quantization parameter range corresponding to the adjacent adjustment cycle.

9. The method according to claim 8, characterized in that The determining the target quantization parameter range corresponding to the current adjustment period based on the quantization parameter ranges corresponding to the adjacent adjustment periods includes: Determining a bit rate threshold of the adjacent adjustment period based on the maximum target bit rate corresponding to the adjacent adjustment period; wherein the bit rate threshold is the product of the maximum target bit rate and a preset multiplier value; If the actual bit rate corresponding to the adjacent adjustment period is greater than or equal to the bit rate threshold of the adjacent adjustment period, the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period are adjusted upward to obtain the target quantization parameter range corresponding to the current adjustment period; If the actual bit rate corresponding to the adjacent adjustment period is less than the bit rate threshold of the adjacent adjustment period, the quantization parameter range corresponding to the adjacent adjustment period is determined as the target quantization parameter range corresponding to the current adjustment period.

10. The method according to claim 8, characterized in that The first cycle includes a plurality of second cycles, each second cycle includes a plurality of adjustment cycles, and determining the target quantization parameter range corresponding to the current adjustment cycle based on the quantization parameter ranges corresponding to the adjacent adjustment cycles includes: If the current adjustment period is the first adjustment period within the current second period, and the current second period is the first second period within the first period, determining a first bit quantity threshold and a second bit quantity threshold based on a first target bit rate corresponding to the first period; wherein the first bit quantity threshold is determined based on a product of the first target bit rate and a first multiplier value, and the second bit quantity threshold is determined based on a product of the first target bit rate and a second multiplier value, and the first multiplier value is greater than the second multiplier value; If the total amount of actual coded bits before the current adjustment period in the first period is greater than the first bit quantity threshold, upwardly adjusting the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period to obtain a target quantization parameter range corresponding to the current adjustment period; If the total amount of actual coded bits before the current adjustment period in the first period is less than the second bit quantity threshold, the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period are adjusted downward to obtain the target quantization parameter range corresponding to the current adjustment period.

11. The method according to claim 8, characterized in that The first cycle includes a plurality of second cycles, each second cycle includes a plurality of adjustment cycles, and determining the target quantization parameter range corresponding to the current adjustment cycle based on the quantization parameter ranges corresponding to the adjacent adjustment cycles includes: If the current adjustment cycle is the first adjustment cycle within the current second cycle, and the current second cycle is not the first second cycle within the first cycle, then determining a first bit quantity threshold and a second bit quantity threshold based on a first target bit rate corresponding to the first cycle and a total encoding duration before the current adjustment cycle within the first cycle, and determining a third bit quantity threshold and a fourth bit quantity threshold based on the first target bit rate corresponding to the first cycle and the duration of the second cycle; wherein the first bit quantity threshold is greater than the second bit quantity threshold, and the third bit quantity threshold is greater than the fourth bit quantity threshold; If the total amount of actual coded bits before the current adjustment period in the first period is greater than the first bit quantity threshold, and the total amount of actual coded bits in the adjacent second period before the current second period is greater than the third bit quantity threshold, then upwardly adjusting the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment period to obtain a target quantization parameter range corresponding to the current adjustment period; If the total amount of actual coded bits before the current adjustment cycle in the first cycle is less than the second bit quantity threshold, and the total amount of actual coded bits in the adjacent second cycle before the current second cycle is less than the fourth bit quantity threshold, then the maximum value and the minimum value of the quantization parameter in the quantization parameter range corresponding to the adjacent adjustment cycle are adjusted downward to obtain the target quantization parameter range corresponding to the current adjustment cycle.

12. The method according to claim 1, characterized in that The method further comprises: Determining a total bit rate of the analog channel based on a first target bit rate corresponding to the first period; Determine the video recording time corresponding to the storage device based on the total bit rate of the analog channel; The recordable time is displayed through the target interface.

13. The method according to claim 12, characterized in that The determining of the recordable time corresponding to the storage device based on the total bit rate of the analog channel includes: If the storage device is connected to multiple network camera IPCs, the total bit rate of all IPC channels is counted; The available recording time is determined based on the total bit rate of the analog channels, the total bit rate of all IPC channels, and the total hard disk space.

14. An interface display method, characterized in that: The method comprises: Determine a first target bit rate corresponding to a first period; wherein the first period includes multiple adjustment periods, and the second target bit rate corresponding to each adjustment period is determined based on the first target bit rate; the first target bit rate is a fixed value, and the second target bit rates corresponding to different adjustment periods are the same or different; the first target bit rate represents the average bit rate expected in the first period, and the second target bit rate corresponding to each adjustment period represents the average bit rate expected in the adjustment period; wherein, in each adjustment period, the target quantization parameter of the adjustment period is determined based on the second target bit rate corresponding to the adjustment period and the target quantization parameter range, and the video data is encoded based on the target quantization parameter of the adjustment period; wherein the target quantization parameter range is used to constrain the maximum value and the minimum value of the quantization parameter of the adjustment period. wherein, if the actual encoding bit rate corresponding to the initial quantization parameter within the target quantization parameter range is greater than the second target bit rate, the initial quantization parameter is increased; if the increased quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the increased quantization parameter; if the increased quantization parameter is not within the target quantization parameter range, the target quantization parameter is determined based on the maximum value of the quantization parameter; if the actual encoding bit rate is less than the second target bit rate, the initial quantization parameter is decreased; if the decreased quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the decreased quantization parameter; if the decreased quantization parameter is not within the target quantization parameter range, the target quantization parameter is determined based on the minimum value of the quantization parameter; Determining a total bit rate of the analog channel based on a first target bit rate corresponding to the first period; Determine the video recording time corresponding to the storage device based on the total bit rate of the analog channel; The recordable time is displayed through the target interface.

15. The method according to claim 14, characterized in that The determining of the recordable time corresponding to the storage device based on the total bit rate of the analog channel includes: If the storage device is connected to multiple network camera IPCs, the total bit rate of all IPC channels is counted; The available recording time is determined based on the total bit rate of the analog channels, the total bit rate of all IPC channels, and the total hard disk space.

16. A video data encoding device, characterized in that: The device comprises: a second target bit rate determination module, configured to determine second target bit rates corresponding to a plurality of adjustment periods based on a first target bit rate corresponding to a first period; wherein the first period includes the plurality of adjustment periods, the first target bit rate is a fixed value, and second target bit rates corresponding to different adjustment periods are the same or different; the first target bit rate represents an average bit rate expected within the first period, and the second target bit rate corresponding to each adjustment period represents an average bit rate expected within the adjustment period; a quantization parameter determination module, configured to determine, for a current adjustment cycle among the multiple adjustment cycles, a target quantization parameter for the current adjustment cycle based on a target quantization parameter range corresponding to the current adjustment cycle and a second target bit rate corresponding to the current adjustment cycle; wherein the target quantization parameter range is used to constrain a maximum value and a minimum value of the quantization parameter for the current adjustment cycle, the second target bit rate is used to adjust the quantization parameter for the current adjustment cycle, and the quantization parameter is within the target quantization parameter range; wherein if an actual encoding bit rate corresponding to an initial quantization parameter within the target quantization parameter range is greater than the second target bit rate, the initial quantization parameter is increased; if the increased quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the increased quantization parameter; if the increased quantization parameter is not within the target quantization parameter range, the target quantization parameter is determined based on the maximum value of the quantization parameter; if the actual encoding bit rate is less than the second target bit rate, the initial quantization parameter is decreased; if the decreased quantization parameter is within the target quantization parameter range, the target quantization parameter is determined based on the decreased quantization parameter; if the decreased quantization parameter is not within the target quantization parameter range, the target quantization parameter is determined based on the minimum value of the quantization parameter; The encoding module is configured to encode the video data based on the target quantization parameter within the current adjustment period.

17. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory is used to store machine-executable instructions that can be executed by the processor, and the processor is used to execute the machine-executable instructions stored in the memory to implement the steps of any of the methods described in claims 1-15 above.

Citation Information

Patent Citations

  • Code rate control method and code rate control device

    CN108235016A