Video encoding method, electronic device, and computer-readable storage medium
By calculating the dynamic detection proportion allocating matching encoding load to multi-channel video encoding, the problem of unreasonable encoding frame rate in multi-channel video encoding is solved, and more efficient video data encoding is achieved.
Patent Information
- Application Number
- CN202210730293.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-24
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2042-06-24
AI Technical Summary
In the multi-channel video encoding process, the rationality of the encoding frame rate of each channel in the prior art is difficult to ensure, especially when the total load of available encoding is limited, the encoding frame rate of some channels may be ignored, resulting in unreasonable encoding.
By calculating the dynamic detection proportion (dynamic detection proportion) of each channel, the matching encoding load is allocated to each channel based on the dynamic detection proportion and the encoding load to be used, and the encoding frame rate is determined based on the matching encoding load, ensuring that channels with high importance allocate higher encoding frame rate.
The rationality of the encoding frame rate of each channel during multi-channel video encoding is improved, ensuring that channels with a high proportion of motion targets can obtain higher encoding frame rate, and improving the effectiveness and accuracy of encoding.
Smart Images

Figure CN115348452B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and in particular, to a video encoding method, an electronic device, and a computer-readable storage medium. Background Art
[0002] Since the amount of video data is relatively large, it is usually necessary to encode the video data to reduce the amount of video data. However, the encoding ability of the backend to encode video data is limited, that is, the total available encoding load is usually limited. When video data of multiple channels needs to be encoded, in the prior art, a fixed frame rate is usually set for each channel to allocate the total available encoding load. However, the targets in the video data collected by each channel are constantly changing. When the encoding frame rate is specified, the probability that the targets in some channels with lower frame rates are ignored will increase, resulting in a decrease in the rationality of the encoding frame rate of some channels. In view of this, how to improve the rationality of the encoding frame rate of each channel during multi-channel video encoding when the total available encoding load is limited has become an urgent problem to be solved. Summary of the Invention
[0003] The main technical problem to be solved by this application is to provide a video encoding method, an electronic device, and a computer-readable storage medium, which can improve the rationality of the encoding frame rate of each channel during multi-channel video encoding.
[0004] To solve the above technical problem, in the first aspect of this application, a video encoding method is provided. The method includes: obtaining the total available encoding load and the encoding loads to be used corresponding to multiple channels respectively; the encoding load to be used is determined based on the resolution and frame rate of the video data in the channel; obtaining the motion detection ratio corresponding to each channel; the motion detection ratio is determined based on the proportion of moving targets in the current frame of the video data in each channel; based on the motion detection ratio corresponding to each channel and the encoding load to be used, allocating the total available encoding load to each channel to obtain the matching encoding load corresponding to each channel; the matching encoding load is positively correlated with the motion detection ratio; based on the matching encoding load corresponding to each channel, determining the encoding frame rate corresponding to each channel, and encoding the video data in the channel according to the encoding frame rate corresponding to each channel.
[0005] To solve the above technical problem, in the second aspect of this application, an electronic device is provided. The electronic device includes: a memory and a processor coupled to each other, wherein the memory stores program data, and the processor calls the program data to execute the method described in the first aspect above.
[0006] To solve the above technical problem, in the third aspect of this application, a computer storage medium is provided, on which program data is stored, and when the program data is executed by a processor, the method described in the first aspect above is implemented.
[0007] In the above solution, the total available coding load and the coding loads to be used corresponding to multiple channels are obtained. When the total available coding load is difficult to meet the coding loads to be used corresponding to multiple channels, the dynamic detection ratio corresponding to each channel is obtained, where the dynamic detection ratio is determined based on the ratio of moving targets in the current frame of video data in each channel, and the moving targets are often the key objects that need to be concerned in the video data. That is to say, the dynamic detection ratio can be used as an index to measure the importance degree of the video data in each channel. Then, based on the dynamic detection ratio and the coding loads to be used corresponding to each channel, the total available coding load is allocated to each channel to obtain the matching coding load corresponding to each channel, and the matching coding load is positively correlated with the dynamic detection ratio. Therefore, when the importance degree of the video data in the channel is higher, the higher the matching coding load that can be obtained. The coding frame rate is determined based on the matching coding load, and a higher coding frame rate can be allocated to the channel with a higher importance degree. The video data in the channel is encoded according to the coding frame rate corresponding to each channel, thereby effectively improving the rationality of the coding frame rates of each channel during multi-channel video coding. Description of the Drawings
[0008] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts. Among them:
[0009] Figure 1 is a schematic flowchart of an embodiment of the video coding method of the present application;
[0010] Figure 2 is a schematic flowchart of another embodiment of the video coding method of the present application;
[0011] Figure 3 is a schematic flowchart of yet another embodiment of the video coding method of the present application;
[0012] Figure 4 is a schematic structural diagram of an embodiment of the electronic device of the present application;
[0013] Figure 5 is a schematic structural diagram of an embodiment of the computer-readable storage medium of the present application. Detailed Embodiments
[0014] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without creative efforts belong to the scope of protection of the present application.
[0015] The terms "system" and "network" are often used interchangeably herein. The term "and / or" in this article is merely a description of the association relationship between associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in this article generally represents an "or" relationship between the associated objects before and after. In addition, "multiple" in this article means two or more than two.
[0016] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of an implementation manner of the video encoding method of the present application. The method includes:
[0017] S101: Obtain the total available encoding load and the encoding loads to be used corresponding to multiple channels respectively. The encoding loads to be used are determined based on the resolution and frame rate of the video data in the channels.
[0018] Specifically, the total available encoding load is determined based on the maximum encoding area of the backend encoding device within a unit time. Among them, the maximum encoding area corresponds to the available encoding frames and the available encoding area within a unit time, and the product of the available encoding frames and the available encoding area is the maximum encoding area.
[0019] Furthermore, video data is collected in each of the multiple channels. The video data corresponds to encoding parameters including resolution and frame rate. The encoding loads to be used corresponding to each channel are determined based on the resolution and frame rate of the video data in the channel. Among them, the video data in the channel corresponds to the original data collected by the channel. The original data includes, but is not limited to, video streams or consecutive image frames. The original data corresponds to resolution and frame rate, which are the encoding parameters of the video data.
[0020] In an application mode, obtain the total available encoding load of the backend encoding device, obtain the encoding parameters corresponding to the video data in each channel, and determine the encoding loads to be used corresponding to each channel.
[0021] S102: Obtain the moving detection ratio corresponding to each channel. The moving detection ratio is determined based on the ratio of the moving targets in the current frame of the video data in each channel.
[0022] Specifically, when the condition for obtaining the dynamic detection ratio is triggered, the dynamic detection ratios corresponding to each channel are obtained. Among them, the dynamic detection ratio can be uploaded after being detected by each channel or detected by the backend encoding device before encoding.
[0023] In one application mode, the current frame of the video data in each channel is obtained, and the current frame is compared with the historical frame to determine the moving object in the current frame. Among them, the historical frame is the video frame before the current frame, and the dynamic detection ratio is determined based on the proportion of the moving object in the current frame.
[0024] In another application mode, the moving object in the current frame relative to the historical frame is detected in real time in each channel, and the dynamic detection ratio is determined based on the proportion of the moving object in the current frame. Among them, the historical frame is the video frame before the current frame, and in response to the condition for triggering the acquisition of the dynamic detection ratio, the current dynamic detection ratio is obtained from each channel.
[0025] In a specific application scenario, the moving object in the current frame relative to the historical frame is detected in real time in each channel, a motion detection box is set for the moving object, and the dynamic detection ratio is determined based on the proportion of the union area of all the motion detection boxes in the current frame. Each motion in the current frame corresponds to its own motion detection box.
[0026] It can be understood that the moving object is often the key object that needs to be concerned in the video data, that is to say, the dynamic detection ratio can be used as an index to measure the importance degree of the video data in each channel.
[0027] S103: Based on the dynamic detection ratios corresponding to each channel and the encoding load to be used, allocate the total available encoding load to each channel to obtain the matching encoding load corresponding to each channel. The matching encoding load is positively correlated with the dynamic detection ratio.
[0028] Specifically, divide the total available encoding load based on the dynamic detection ratios corresponding to each channel, compare the encoding load that each channel can obtain with the encoding load to be used. If the encoding load that all channels can obtain is less than the encoding load to be used, then adaptively round the encoding load that each channel can obtain, and set the matching encoding load for each channel.
[0029] Further, if there is at least one channel that can be allocated a coding load greater than or equal to the coding load to be used, the coding load that can be allocated to the corresponding channel can meet the use of the coding load to be used. Among the remaining loads of the total available coding load, set the matching coding load for the corresponding channel to the value of the coding load to be used for the corresponding channel. Then, divide the remaining load based on the motion detection ratio corresponding to the channels without allocated matching coding loads, and repeat the above comparison process until the coding load that can be allocated to the remaining channels without allocated matching coding loads is less than the coding load to be used. Then, perform adaptive rounding on the coding load that can be allocated to the remaining channels and set the matching coding load for the corresponding channels.
[0030] In an application scenario, assume that the total available coding load is video frames with a resolution of 1080P at 60 frames per second. The coding parameters of all four channels are 30 frames per second and a resolution of 1080P. That is to say, the coding load to be used for multiple channels is 120 video frames with a resolution of 1080P. Therefore, the total available coding load cannot meet the coding of all channels according to the coding load to be used. When the motion detection ratios of the four channels are 70%, 40%, 50%, and 60% respectively, divide the total available coding load based on the motion detection ratio of each channel. The coding loads that can be allocated to the four channels are 19.09 video frames with a resolution of 1080P per second, 10.9 video frames with a resolution of 1080P per second, 13.63 video frames with a resolution of 1080P per second, and 16.36 video frames with a resolution of 1080P per second. Therefore, the coding loads that can be allocated to all channels are less than the coding load to be used. Perform adaptive rounding on the coding loads that can be allocated to all channels so that the total available coding load is fully utilized, and obtain the corresponding matching coding loads for the four channels as 19 video frames with a resolution of 1080P per second, 11 video frames with a resolution of 1080P per second, 14 video frames with a resolution of 1080P per second, and 16 video frames with a resolution of 1080P per second.
[0031] In another application scenario, still taking the conditions in the previous application scenario as an example, when the dynamic inspection ratios of the four channels are 70%, 30%, 10%, and 10% respectively, the total available coding load is divided based on the dynamic inspection ratios of each channel. The coding loads that the four channels can obtain in sequence are 35 1080P video frames per second, 15 1080P video frames per second, 5 1080P video frames per second, and 5 1080P video frames per second. Therefore, since the coding load that one channel can obtain exceeds the coding load to be used, the matching coding load of the corresponding channel is set to the coding load to be used, that is, 30 1080P video frames per second. At this time, the remaining load is 30 1080P video frames per second. The remaining load is divided based on the dynamic inspection ratios of the channels without allocated matching coding loads, and the coding loads that the remaining channels can obtain are 18 1080P video frames per second, 6 1080P video frames per second, and 6 1080P video frames per second. At this time, the coding loads that all the remaining channels can obtain are less than the coding load to be used. After adaptive rounding, the corresponding matching coding loads of the remaining channels are 18 1080P video frames per second, 6 1080P video frames per second, and 6 1080P video frames per second in sequence.
[0032] It can be understood that the matching coding load corresponding to each channel is positively correlated with the dynamic inspection ratio. The higher the importance of the video data in the channel, the higher the matching coding load that can be obtained.
[0033] S104: Based on the matching coding load corresponding to each channel, determine the coding frame rate corresponding to each channel, and encode the video data in the channel according to the coding frame rate corresponding to each channel.
[0034] Specifically, based on the matching coding load corresponding to each channel, determine the coding frame rate corresponding to each channel, and then encode the video data in each channel according to the respective corresponding coding frame rates.
[0035] In an application scenario, when determining the matching coding load, the coding frame rate corresponding to the matching coding load can be obtained. Determining the coding frame rate based on the matching coding load can allocate a higher coding frame rate to the channel with higher importance. When the total available coding load is not sufficient to ensure that all channels are encoded according to the coding load to be used, the channel with a larger dynamic inspection ratio has a higher coding frame rate, so as to make full use of the total coding load and configure a higher coding frame rate for the channel with a higher proportion of moving targets, improve the accuracy of capturing moving targets, and then effectively improve the rationality of the coding frame rates of each channel during multi-channel video coding.
[0036] Optionally, before determining the encoding frame rate corresponding to each channel based on the matching encoding payload corresponding to each channel and encoding the video data within the channel according to the encoding frame rate corresponding to each channel, it further includes: encoding the video data within each channel using the matching encoding payload within a preset time interval; and in response to exceeding the preset time interval, returning to the step of obtaining the motion detection ratio corresponding to each channel.
[0037] Specifically, when a new matching encoding payload is determined, the current matching encoding payload is maintained, the encoding frame rate is determined according to the current matching encoding payload, and thus the preset time interval is encoded according to the encoding frame rate. When the preset time interval arrives, the condition for obtaining the motion detection ratio is triggered again. Among them, the video data within the preset time interval is encoded based on the encoding frame rate corresponding to each channel. When the preset time interval has passed, the motion detection ratio corresponding to each channel is obtained again to adjust the encoding frame rate again, so as to adapt to the change process of the moving targets in the video data collected within each channel, and at the same time avoid frequently obtaining the motion detection ratio so that the encoding frame rate is continuously adjusted.
[0038] In the above solution, the total available encoding payload and the encoding payloads to be used corresponding to each of the multiple channels are obtained. When the total available encoding payload is difficult to meet the encoding payloads to be used corresponding to each of the multiple channels, the motion detection ratio corresponding to each channel is obtained, where the motion detection ratio is determined based on the proportion of moving targets in the current frame of the video data within each channel, and the moving targets are often the key objects to be concerned about in the video data. That is to say, the motion detection ratio can be used as an index to measure the importance degree of the video data within each channel. Furthermore, based on the motion detection ratio and the encoding payloads to be used corresponding to each channel, the total available encoding payload is allocated to each channel to obtain the matching encoding payload corresponding to each channel, and the matching encoding payload is positively correlated with the motion detection ratio. Therefore, when the importance degree of the video data within the channel is higher, the higher the matching encoding payload that can be allocated. Determining the encoding frame rate based on the matching encoding payload can allocate a higher encoding frame rate to the channel with a higher importance degree, and encoding the video data within the channel according to the encoding frame rate corresponding to each channel, thereby effectively improving the rationality of the encoding frame rate of each channel during multi-channel video encoding.
[0039] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of another embodiment of the video encoding method of the present application. The method includes:
[0040] S201: Obtain the total available encoding payload and the encoding payloads to be used corresponding to each of the multiple channels, where the encoding payloads to be used are determined based on the resolution and frame rate of the video data within the channel.
[0041] Specifically, the available encoding total load is determined based on the maximum encoding area of the backend encoding device, and the encoding load to be used corresponding to each channel is determined based on the resolution and frame rate of the video data within the channel.
[0042] In an application mode, video data collected by each channel is obtained, the resolution and frame rate of the video data are determined to obtain the encoding frame rate to be used corresponding to each channel, and the available encoding total load is determined based on the maximum encoding area per unit time of the backend encoding device.
[0043] S202: Obtain the moving detection ratio corresponding to each channel, where the moving detection ratio is determined based on the ratio of moving targets in the current frame of the video data within each channel.
[0044] Specifically, moving targets in the current frame within each channel are detected in real time, the current frame is compared with the previous video frame or the previous key frame before the current frame to determine the moving targets in the current frame, and thus the moving detection ratio corresponding to each channel is determined based on the proportion of the moving targets in the current frame.
[0045] S203: Divide the available encoding total load based on the moving detection ratio corresponding to each channel to obtain the allocable encoding load corresponding to each channel, where the allocable encoding load is positively correlated with the moving detection ratio.
[0046] Specifically, a preliminary division of the available encoding total load is performed based on the moving detection ratio corresponding to each channel, that is, the available encoding total load is divided only with reference to one parameter of the moving detection ratio to obtain the allocable encoding load corresponding to each channel. At this time, the allocable encoding load is a theoretical value completely based on the moving detection ratio.
[0047] Furthermore, when dividing the available encoding total load, first obtain the sum of the moving detection ratios corresponding to all channels, divide the moving detection ratio corresponding to each channel by the sum and then multiply by the available encoding total load to obtain the allocable encoding load corresponding to each channel, so that the allocable encoding load is in a direct proportional relationship with the moving detection ratio.
[0048] Optionally, before dividing the available encoding total load based on the moving detection ratio corresponding to each channel to obtain the allocable encoding load corresponding to each channel, it further includes: determining the moving detection level corresponding to each channel based on the moving detection ratio corresponding to each channel; where the moving detection level is related to the value of the moving detection ratio, the value of the moving detection ratio corresponding to the highest level is greater than the first value, and the value of the moving detection ratio corresponding to the lowest level is less than or equal to the second value; in response to obtaining a channel with the moving detection level being the lowest level, set a lower limit encoding load for at least one channel with the moving detection level being the lowest level, and use the channel with the lower limit encoding load set as the divided channel; the lower limit encoding load is determined based on the resolution of the video data within the channel and a video frame.
[0049] Specifically, the dynamic detection ratio corresponds to at least two levels, where the value of the dynamic detection ratio corresponding to the highest level is greater than the first value, and the value of the dynamic detection ratio corresponding to the lowest level is less than or equal to the second value. Here, the first value is greater than the second value, and the value of the second value is extremely small. When the value of the dynamic detection ratio is less than the second value, it indicates that the change amplitude of the moving target in the video data of the corresponding channel is extremely small.
[0050] Optionally, the second value is zero. When the dynamic detection level corresponding to the dynamic detection ratio of any channel is the lowest level, it means that there is currently no moving target in the video data of the corresponding channel, and it is in a completely static state.
[0051] Furthermore, when a channel with the lowest dynamic detection level is obtained, it indicates that the video data in at least one channel is in a state of almost static or completely static. Set a lower limit coding load for at least one channel with the lowest dynamic detection level, and use the channel with the set lower limit coding load as the divided channel. The lower limit coding load is determined based on the resolution of the video data in the channel and a video frame, that is, only one video frame is encoded per second in the corresponding channel. On the basis of maintaining the timing of the video data, the coding load consumption in the corresponding channel is reduced and adapted to the static state in the channel.
[0052] Optionally, intermediate levels are also set for the dynamic detection levels in addition to the lowest and highest levels, so as to perform a more accurate division of the dynamic detection ratio.
[0053] In an application scenario, the total available coding load is divided based on the dynamic detection ratios corresponding to each channel to obtain the allocable coding loads corresponding to each channel, including: in response to obtaining the divided channels, using the lower limit coding load as the allocable coding load of the divided channels, and dividing the remaining divided coding load based on the dynamic detection ratios corresponding to each undivided channel different from the divided channels to obtain the allocable coding loads corresponding to each undivided channel; where the remaining divided coding load is determined based on the difference between the total available coding load and the lower limit coding loads of all divided channels; in response to not obtaining the divided channels, dividing the total available coding load based on the ratio between the dynamic detection ratio corresponding to each channel and the sum of the dynamic detection ratios corresponding to all channels to obtain the allocable coding loads corresponding to each channel.
[0054] Specifically, when the divided channels are obtained, the lower limit coding load is used as the allocable coding load of the divided channels, and the difference between the total available coding load and the lower limit coding loads of all divided channels is calculated as the remaining divided coding load. Then, based on the dynamic detection ratios corresponding to each undivided channel, the remaining divided coding load is divided to obtain the allocable coding loads corresponding to each undivided channel, where the undivided channels are different from the divided channels.
[0055] Further, when the divided channels are not obtained, divide the total available coding load based on the ratio between the dynamic inspection ratio corresponding to each channel and the sum of the dynamic inspection ratios corresponding to all channels, to obtain the allocable coding load corresponding to each channel.
[0056] That is to say, if there is no dynamic inspection ratio at the lowest level, there are no divided channels, and it is only necessary to divide the total available coding load based on the ratio between the dynamic inspection ratio corresponding to each channel and the sum of the dynamic inspection ratios corresponding to all channels. If there is a dynamic inspection ratio at the lowest level, set a lower limit coding load for at least one channel with the dynamic inspection level being the lowest level, and use the channel with the set lower limit coding load as the divided channel, and divide the remaining divided coding load according to the dynamic inspection ratio for the remaining undivided channels, to obtain the allocable coding load corresponding to each undivided channel. By specifying a lower limit coding load for the channel corresponding to the dynamic inspection ratio at the lowest level, the continuity of the video data of each channel is maintained, and the consumption of the coding load by the channel corresponding to the dynamic inspection ratio at the lowest level is reduced.
[0057] In a specific application scenario, assume that the total available coding load is video frames with a resolution of 1080P at 60 frames per second. The coding parameters of all four channels are 30 frames per second and a resolution of 1080P. The dynamic inspection levels are pre-divided into four levels. Among them, the dynamic inspection ratio corresponding to the highest level is greater than or equal to 60%, the dynamic inspection ratio corresponding to the second level is 30% - 60%, the dynamic inspection ratio corresponding to the third level is 1% - 30%, and the dynamic inspection ratio corresponding to the lowest level is less than or equal to 1%. When the dynamic inspection ratios of the four channels are 70%, 40%, 10%, and 0% respectively, there is one channel with the dynamic inspection level of the dynamic inspection ratio being the lowest level. Set a lower limit coding load for the channel with the dynamic inspection level being the lowest level. The lower limit coding load corresponds to 1 video frame of 1080P per second, and use the channel with the set lower limit coding load as the divided channel. At this time, the remaining divided coding load corresponds to video frames with a resolution of 1080P at 59 frames per second. Divide the remaining divided coding load according to the dynamic inspection ratio for the remaining undivided channels, to obtain the allocable coding load corresponding to each undivided channel, that is, divide the remaining divided coding load according to the dynamic inspection ratio for the channels with dynamic inspection ratios of 70%, 40%, and 10%, to obtain the allocable coding load corresponding to each undivided channel. Among them, the calculation method for dividing the remaining divided coding load is to first calculate the percentage of the dynamic inspection ratio in the total, and then divide the percentage corresponding to each channel by the remaining divided coding load, to obtain the allocable coding loads corresponding to each undivided channel as 34.22 video frames of 1080P per second, 19.6 video frames of 1080P per second, and 4.8 video frames of 1080P per second respectively.
[0058] S204: Based on the size relationship between the allocable coding load and the coding load to be used, and the dynamic inspection ratio corresponding to each channel, allocate the total available coding load to each channel to obtain the matching coding load corresponding to each channel.
[0059] Specifically, compare the size relationship between the allocable coding load and the coding load to be used. If the allocable coding load corresponding to all channels is less than the coding load to be used, perform adaptive rounding on the coding load that each channel can obtain, and set the matching coding load for each channel. If there is at least one channel whose allocable coding load is greater than or equal to the coding load to be used, use the value of the coding load to be used for the corresponding channel as the matching coding load.
[0060] In an application mode, in response to the allocable coding load corresponding to at least one channel being greater than or equal to the coding load to be used for the channel, use the coding load to be used as the matching coding load for the corresponding channel, and use the channel allocated with the coding load to be used as the matched channel; and, based on the dynamic inspection ratio corresponding to each unmatched channel different from the matched channel, allocate the remaining available coding load to obtain the matching coding load corresponding to each unmatched channel; where the remaining available coding load is determined based on the difference between the total available coding load and the coding loads to be used for all matched channels; in response to the allocable coding load of all channels being less than the coding loads to be used for their respective channels, use the allocable coding load corresponding to each channel as the matching coding load corresponding to each channel.
[0061] Specifically, the above application mode can be applied to any application scenario in the above step S204. When the allocable coding load corresponding to at least one channel is greater than or equal to the coding load to be used for the channel, use the coding load to be used as the matching coding load for the corresponding channel, and use the channel allocated with the coding load to be used as the matched channel, then the channels different from the matched channels are used as unmatched channels, calculate the difference between the total available coding load and the coding loads to be used for all matched channels as the remaining available coding load, and then based on the dynamic inspection ratio corresponding to each unmatched channel, allocate the remaining available coding load to obtain the matching coding load corresponding to each unmatched channel. It can be understood that when re - dividing the remaining available coding load, still compare the size relationship between the allocable coding load and the coding load to be used until the allocable coding load corresponding to the unmatched channels is less than the coding load to be used, perform adaptive rounding on the allocable coding load, and use the rounded value as the matching coding load corresponding to each unmatched channel, so that the channels that can meet the coding load to be used are encoded according to the full amount of the load to be used, and the part exceeding the coding load to be used is released as the remaining available coding load, increasing the value of the matching coding load corresponding to the unmatched channels, thereby overall improving the rationality of the coding frame rate of each channel.
[0062] Further, when the allocable coding loads of all channels are less than their respective coding loads to be used, the allocable coding loads corresponding to each channel are adaptively rounded, and the rounded values are used as the matching coding loads corresponding to each channel, and the sum of the matching coding loads corresponding to all channels is less than or equal to the total available coding load.
[0063] It should be noted that when there is a dynamic inspection level corresponding to the dynamic inspection ratio, if a channel with the lowest dynamic inspection level is included, the matching coding load of the corresponding channel is directly set to the allocable coding load, and the allocable coding load of this channel is the lower limit coding load.
[0064] In a specific application scenario, assume that the total available coding load is video frames with a resolution of 1080P at 60 frames per second, and the coding parameters of all four channels are 30 frames per second and a resolution of 1080P. When the dynamic inspection ratio of channel 1 is 70%, the dynamic inspection ratio of channel 2 is 35%, the dynamic inspection ratio of channel 3 is 10%, and the dynamic inspection ratio of channel 4 is 5%. The allocable coding loads corresponding to each channel are 35 frames of 1080P video frames per second, 17.5 frames of 1080P video frames per second, 5 frames of 1080P video frames per second, and 2.5 frames of 1080P video frames per second respectively. The coding load that channel 1 can obtain exceeds the coding load to be used, so the matching coding load of channel 1 is set to the coding load to be used, that is, 30 frames of 1080P video frames per second. At this time, channel 1 is a matched channel, and channels 2, 3, and 4 are unmatched channels. The remaining available coding load is 30 frames of 1080P video frames per second. Based on the dynamic inspection ratios corresponding to the unmatched channels, the remaining available coding load is allocated, and the allocable coding loads corresponding to the unallocated channels are 21 frames of 1080P video frames per second, 6 frames of 1080P video frames per second, and 3 frames of 1080P video frames per second respectively. At this time, the allocable coding loads are all less than the coding loads to be used, and the allocable coding loads are adaptively rounded to obtain the matching coding loads.
[0065] In another specific application scenario, assume that the total available encoding payload is video frames with a resolution of 1080P at 60 frames per second. The encoding parameters of Channel 1 are a frame rate of 30 frames per second and a resolution of 540P. The encoding parameters of Channels 2, 3, and 4 are all a frame rate of 30 frames per second and a resolution of 1080P. Among them, the motion detection ratios of Channels 1 to 4 are 40%, 70%, 10%, and 0% respectively. Among them, the motion detection level of Channel 4 is the lowest level, and the corresponding allocable encoding payload is the lower limit encoding payload, that is, 1 video frame of 1080P per second. The allocable encoding payload corresponding to Channel 1 is 19.6 video frames of 1080P per second, 34.22 video frames of 1080P per second, and 4.8 video frames of 1080P per second. Among them, the allocable encoding payload corresponding to Channel 1 is 19.6 video frames of 1080P per second. The encoding payload to be used corresponding to Channel 1 is 30 video frames of 540P per second. The encoding payload to be used corresponding to Channel 1 is equivalent to 15 video frames of 1080P per second. At this time, the allocable encoding payloads of Channels 1 and 2 both exceed the encoding payload to be used. Then, the matching encoding payloads of Channels 1 and 2 are set to the encoding payload to be used. At this time, Channels 1 and 2 are the matched channels, and the encoding payloads consumed are 15 video frames of 1080P per second and 30 video frames of 1080P per second respectively. Channels 3 and 4 are the unallocated channels. At this time, the remaining available encoding payload is 15 video frames of 1080P per second. Based on the motion detection ratios of the allocated channels, the remaining available encoding payload is allocated. Since the motion detection ratio corresponding to Channel 4 is at the lowest level, the matching encoding payload of Channel 4 is set to the lower limit encoding payload, that is, 1 video frame of 1080P per second. At this time, the allocable encoding payload corresponding to Channel 3 is 14 video frames of 1080P per second, which is less than the encoding payload to be used. Therefore, the allocable encoding payload corresponding to Channel 3 is adaptively rounded to obtain a matching encoding payload of 14 video frames of 1080P per second.
[0066] S205: Based on the matching encoding payloads corresponding to each channel, determine the encoding frame rates corresponding to each channel, and encode the video data in the channel according to the encoding frame rates corresponding to each channel.
[0067] Specifically, based on the matching encoding payloads corresponding to each channel, parse out the encoding frame rates corresponding to each channel, and encode the video data in the channel according to the encoding frame rates corresponding to each channel.
[0068] In an application mode, based on the matching encoding payloads corresponding to each channel, determine the matching encoding parameters corresponding to each channel. Among them, the matching encoding parameters include the encoding frame rate and the resolution, and the matching encoding parameters correspond to the matching encoding payload.
[0069] In this embodiment, the dynamic detection levels can be divided based on the dynamic detection ratios corresponding to each channel. When there is a channel with the lowest dynamic detection level, a lower-limit coded load is set for at least one channel with the lowest dynamic detection level. On the basis of maintaining the timing of the video data, the coded load consumption within the corresponding channel is reduced and the static state within the channel is adapted. The total available coded load is divided based on the dynamic detection ratios to obtain the allocable coded load corresponding to each channel, so that the allocable coded load is in a direct proportional relationship with the dynamic detection ratio. The relationship between the allocable coded load and the coded load to be used is compared to determine the matching coded load corresponding to each channel, enabling the channels that can meet the coded load to be used to be coded at the full amount of the load to be used, and releasing the part exceeding the coded load to be used as the remaining available coded load, increasing the value of the matching coded load corresponding to the unmatched channels, thereby overall improving the rationality of the coding frame rate of each channel.
[0070] Please refer to Figure 3 , Figure 3 which is a schematic flowchart of another embodiment of the video coding method of the present application. The method includes:
[0071] S301: Obtain the total available coded load and the coded load to be used corresponding to each of the multiple channels. The coded load to be used is determined based on the resolution and frame rate of the video data within the channel.
[0072] S302: Obtain the dynamic detection ratio corresponding to each channel. The dynamic detection ratio is determined based on the proportion of moving targets in the current frame of the video data within each channel.
[0073] Specifically, steps S301 and S302 are the same as those in any of the above embodiments. Please refer to any of the above embodiments, and the present application will not elaborate on this.
[0074] S303: Based on the dynamic detection ratio corresponding to each channel, determine the dynamic detection level corresponding to each channel. Among them, the dynamic detection level is related to the value of the dynamic detection ratio. The value of the dynamic detection ratio corresponding to the highest level is greater than the first value, and the value of the dynamic detection ratio corresponding to the lowest level is less than or equal to the second value.
[0075] Specifically, there are at least two levels corresponding to the dynamic detection ratio. The value of the dynamic detection ratio corresponding to the highest level is greater than the first value, and the value of the dynamic detection ratio corresponding to the lowest level is less than or equal to the second value. Among them, the first value is greater than the second value, and the value of the second value is extremely small. When the value of the dynamic detection ratio is less than the second value, it indicates that the change amplitude of the moving targets in the video data within the corresponding channel is extremely small. When the value of the dynamic detection ratio is greater than the first value, it indicates that the change amplitude of the moving targets in the video data within the corresponding channel is relatively large, and it is video data with a relatively high degree of importance.
[0076] S304: In response to obtaining channels with the lowest dynamic inspection level, set a lower limit coding payload for at least one channel with the lowest dynamic inspection level, and use the channel with the set lower limit coding payload as the divided channel. The lower limit coding payload is determined based on the resolution of the video data in the channel and a video frame.
[0077] Specifically, when obtaining channels with the lowest dynamic inspection level, it indicates that the video data in at least one channel is in a state of almost static or completely static. Set a lower limit coding payload for at least one channel with the lowest dynamic inspection level, and use the channel with the set lower limit coding payload as the divided channel. Among them, the lower limit coding payload is determined based on the resolution of the video data in the channel and a video frame, that is, only one video frame is encoded per second in the corresponding channel. On the basis of maintaining the timing of the video data, reduce the coding payload consumption in the corresponding channel and adapt to the static state in the channel.
[0078] S305: Divide the total available coding payload based on the dynamic inspection ratios corresponding to each channel to obtain the allocable coding payloads corresponding to each channel. The allocable coding payload is positively correlated with the dynamic inspection ratio.
[0079] Specifically, obtain the sum of the dynamic inspection ratios corresponding to all channels, divide the dynamic inspection ratio corresponding to each channel by the sum and then multiply by the total available coding payload to obtain the allocable coding payloads corresponding to each channel, so that the allocable coding payload is in a direct proportional relationship with the dynamic inspection ratio.
[0080] In an application scenario, dividing the total available coding payload based on the dynamic inspection ratios corresponding to each channel to obtain the allocable coding payloads corresponding to each channel includes: in response to obtaining the divided channels, use the lower limit coding payload as the allocable coding payload of the divided channels, and divide the remaining divided coding payload based on the dynamic inspection ratios corresponding to each undivided channel different from the divided channels to obtain the allocable coding payloads corresponding to each undivided channel; among them, the remaining divided coding payload is determined based on the difference between the total available coding payload and the lower limit coding payloads of all divided channels; in response to not obtaining the divided channels, divide the total available coding payload based on the ratio between the dynamic inspection ratio corresponding to each channel and the sum of the dynamic inspection ratios corresponding to all channels to obtain the allocable coding payloads corresponding to each channel.
[0081] Specifically, when obtaining the divided channels, use the lower limit coding payload as the allocable coding payload of the divided channels, calculate the difference between the total available coding payload and the lower limit coding payloads of all divided channels as the remaining divided coding payload. Furthermore, divide the remaining divided coding payload based on the dynamic inspection ratios corresponding to each undivided channel to obtain the allocable coding payloads corresponding to each undivided channel, where the undivided channels are different from the divided channels.
[0082] Further, when the divided channels are not obtained, based on the ratio between the dynamic inspection ratio corresponding to each channel and the total sum of the dynamic inspection ratios corresponding to all channels, divide the total available coding load to obtain the allocable coding load corresponding to each channel.
[0083] That is to say, if there is no dynamic inspection ratio at the lowest level, there are no divided channels, and it is only necessary to divide the total available coding load based on the ratio between the dynamic inspection ratio corresponding to each channel and the total sum of the dynamic inspection ratios corresponding to all channels. If there is a dynamic inspection ratio at the lowest level, set a lower limit coding load for at least one channel whose dynamic inspection level is the lowest level, and use the channel with the set lower limit coding load as the divided channel, and divide the remaining divided coding load according to the dynamic inspection ratio for the remaining undivided channels to obtain the allocable coding load corresponding to each undivided channel. By specifying a lower limit coding load for the channel corresponding to the dynamic inspection ratio at the lowest level, the continuity of the video data of each channel is maintained, and the consumption of the coding load by the channel corresponding to the dynamic inspection ratio at the lowest level is reduced.
[0084] S306: In response to obtaining a channel with the highest dynamic inspection level, use at least one channel with the highest dynamic inspection level as the designated channel, use the coding load to be used corresponding to the designated channel as the matching coding load corresponding to the designated channel, and use the channels different from the designated channel as the undesignated channels.
[0085] Specifically, when at least one channel with the highest dynamic inspection level is obtained, select at least one channel with the highest dynamic inspection level as the designated channel, and directly set the matching coding load corresponding to the designated channel as the coding load to be used, so that the designated channel is encoded according to the full amount of the coding load to be used, so as to ensure that at least one of the designated channels can be encoded with the coding load to be used preferentially when the dynamic inspection ratios of multiple channels are all relatively high.
[0086] In an application scenario, if the dynamic inspection ratios of multiple channels all reach the highest level, determine the number of designated channels based on the coding load to be used corresponding to all channels with the highest dynamic inspection level and the total available coding load, so that the sum of the coding loads to be used corresponding to all designated channels is less than the difference between the total available coding load and the lower limit coding load corresponding to all undesignated channels, so as to satisfy as many channels as possible to be encoded with the coding load to be used while enabling the undesignated channels to still have allocable coding load.
[0087] In another application scenario, if the motion detection ratios of multiple channels all reach the highest level, one of the channels is designated as the designated channel, wherein the channel that the user focuses on is pre-set with a priority flag. When the motion detection ratio of the channel including the priority flag reaches the highest level, the channel including the priority flag is selected as the designated channel, thereby improving the rationality of the encoding frame rate corresponding to the channel of focus, thereby satisfying the encoding of a channel of focus as much as possible according to the encoding load to be used, while ensuring that more encoding loads can be allocated to the undesignated channel.
[0088] S307: In response to not obtaining a channel with the highest level of the dynamic inspection level, treating each channel as an undesignated channel different from the designated channels.
[0089] Specifically, when a channel whose dynamic inspection level is the highest level is not obtained, all channels are regarded as undesignated channels different from designated channels.
[0090] S308: Based on the relationship between the allocatable coding load and the coding load to be used corresponding to each unspecified channel, and the dynamic detection ratio corresponding to each unspecified channel, the unspecified coding load is allocated to obtain the matching coding load corresponding to each unspecified channel, wherein the unspecified coding load is determined based on the difference between the total available coding load and the coding load to be used of all designated channels.
[0091] Specifically, when there is a designated channel, the difference between the total available coding load and the coding load to be used of all designated channels is the undesignated coding load. When all channels are undesignated channels, the undesignated coding load is the total available coding load.
[0092] Furthermore, the size relationship between the allocable coding load corresponding to the unspecified channels and the coding load to be used is compared. If the allocable coding load corresponding to all channels is smaller than the coding load to be used, the allocable coding load of each unspecified channel is adaptively rounded, and a matching coding load is set for each unspecified channel. If there is at least one unspecified channel whose allocable coding load is greater than or equal to the coding load to be used, the value of the coding load to be used of the corresponding channel is used as the matching coding load, and the remaining available loads are further allocated to other unspecified channels based on the dynamic detection ratio until the allocable coding loads corresponding to the remaining unspecified channels are smaller than the coding load to be used, thereby adaptively rounding the allocable coding loads of the remaining unspecified channels, and finally determining the matching coding loads corresponding to all unspecified channels. While satisfying the encoding of the designated channels according to the coding load to be used, the matching coding loads of the unspecified channels are reasonably allocated, thereby improving the rationality of the matching coding loads corresponding to the unspecified channels.
[0093] S309: Determine the encoding frame rate corresponding to each channel based on the matching encoding payload corresponding to each channel, and encode the video data within the channel according to the encoding frame rate corresponding to each channel.
[0094] Specifically, parse the encoding frame rate corresponding to each channel based on the matching encoding payload corresponding to each channel, and encode the video data within the channel according to the encoding frame rate corresponding to each channel.
[0095] In this embodiment, the dynamic detection levels can be divided based on the dynamic detection ratios corresponding to each channel. When there is a channel with the highest dynamic detection level, at least one channel with the highest dynamic detection level is used as the designated channel, and priority is given to ensuring that at least one of the designated channels can be encoded with the encoding payload to be used. While satisfying the encoding of the designated channels with the encoding payload to be used, the matching encoding payloads of the un-designated channels are reasonably allocated to improve the rationality of the matching encoding payloads corresponding to the un-designated channels, thereby improving the rationality of the encoding frame rates of each channel.
[0096] Please refer to Figure 4 , Figure 4 , which is a schematic structural diagram of an embodiment of the electronic device of the present application. The electronic device 40 includes a mutually coupled memory 401 and a processor 402. Among them, the memory 401 stores program data (not shown in the figure), and the processor 402 calls the program data to implement the method in any of the above embodiments. For the description of related content, please refer to the detailed description of the above method embodiments and will not be repeated here.
[0097] Please refer to Figure 5 , Figure 5 , which is a schematic structural diagram of an embodiment of the computer-readable storage medium of the present application. The computer-readable storage medium 50 stores program data 500, and when the program data 500 is executed by the processor, it implements the method in any of the above embodiments. For the description of related content, please refer to the detailed description of the above method embodiments and will not be repeated here.
[0098] It should be noted that the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0099] In addition, in each embodiment of the present application, the functional units can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or in the form of software functional units.
[0100] When the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods in various embodiments of this application. The foregoing storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs.
[0101] The above is only the embodiment of this application, and does not limit the patent scope of this application. Any equivalent structure or equivalent process transformation made by using the content of the specification and drawings of this application, or directly or indirectly applied in other related technical fields, shall be equally included in the patent protection scope of this application.
Claims
1. A video encoding method, characterized in that, The method includes: Obtaining the total available encoding payload and the encoding payloads to be used corresponding to multiple channels respectively; the encoding payloads to be used are determined based on the resolution and frame rate of the video data in the channels; Obtaining the motion detection ratio corresponding to each of the channels; the motion detection ratio is determined based on the ratio of moving targets in the current frame of the video data in each of the channels; Based on the motion detection ratio and the encoding payloads to be used corresponding to each of the channels, allocating the total available encoding payload to each of the channels to obtain the matching encoding payloads corresponding to each of the channels; specifically including: dividing the total available encoding payload based on the motion detection ratio corresponding to each of the channels to obtain the allocable encoding payloads corresponding to each of the channels; the allocable encoding payloads are positively correlated with the motion detection ratio; based on the size relationship between the allocable encoding payloads and the encoding payloads to be used and the motion detection ratio corresponding to each channel, allocating the total available encoding payload to each of the channels to obtain the matching encoding payloads corresponding to each of the channels; the matching encoding payloads are positively correlated with the motion detection ratio; Based on the matching encoding payloads corresponding to each of the channels, determining the encoding frame rate corresponding to each of the channels, and encoding the video data in the channels according to the encoding frame rate corresponding to each of the channels.
2. The video encoding method according to claim 1, wherein Before dividing the total available encoding payload based on the motion detection ratio corresponding to each of the channels to obtain the allocable encoding payloads corresponding to each of the channels, it further includes: Based on the motion detection ratio corresponding to each of the channels, determining the motion detection level corresponding to each of the channels; wherein, the motion detection level is related to the value of the motion detection ratio, the value of the motion detection ratio corresponding to the highest level is greater than a first value, and the value of the motion detection ratio corresponding to the lowest level is less than or equal to a second value; In response to obtaining a channel with the motion detection level being the lowest level, setting a lower limit encoding payload for at least one channel with the motion detection level being the lowest level, and taking the channel for which the lower limit encoding payload has been set as the divided channel; the lower limit encoding payload is determined based on the resolution of the video data in the channel and a video frame.
3. The video encoding method according to claim 2, wherein Dividing the total available encoding payload based on the motion detection ratio corresponding to each of the channels to obtain the allocable encoding payloads corresponding to each of the channels, includes: In response to obtaining the divided channel, taking the lower limit encoding payload as the allocable encoding payload of the divided channel, and dividing the remaining divided encoding payload based on the motion detection ratio corresponding to each undivided channel different from the divided channel to obtain the allocable encoding payloads corresponding to each undivided channel; wherein, the remaining divided encoding payload is determined based on the difference between the total available encoding payload and the lower limit encoding payloads of all the divided channels; In response to not obtaining the divided channel, dividing the total available encoding payload based on the ratio between the motion detection ratio corresponding to each of the channels and the sum of the motion detection ratios corresponding to all the channels to obtain the allocable encoding payloads corresponding to each of the channels.
4. The video encoding method according to any one of claims 1 to 3, characterized in that, Allocating the total available encoding load to each of the channels based on the size relationship between the allocable encoding load and the encoding load to be used, and the dynamic inspection ratio corresponding to each channel, to obtain the matching encoding load corresponding to each channel, includes: In response to the allocable encoding load corresponding to at least one of the channels being greater than or equal to the encoding load to be used for the channel, using the encoding load to be used as the matching encoding load for the corresponding channel, and using the channel allocated with the encoding load to be used as the matched channel; and, Allocating the remaining available encoding load based on the dynamic inspection ratios corresponding to each of the unmatched channels that are different from the matched channels, to obtain the matching encoding load corresponding to each of the unmatched channels; wherein, the remaining available encoding load is determined based on the difference between the total available encoding load and the encoding loads to be used for all the matched channels; In response to the allocable encoding load of all the channels being less than the encoding loads to be used for their respective channels, using the allocable encoding load corresponding to each of the channels as the matching encoding load corresponding to each of the channels.
5. The video encoding method according to any one of claims 2-3, characterized in that, Before allocating the total available encoding load to each of the channels based on the size relationship between the allocable encoding load and the encoding load to be used, and the dynamic inspection ratio corresponding to each channel, to obtain the matching encoding load corresponding to each channel, further includes: In response to obtaining a channel with the highest dynamic inspection level, using at least one channel with the highest dynamic inspection level as the designated channel, using the encoding load to be used corresponding to the designated channel as the matching encoding load corresponding to the designated channel, and using the channels different from the designated channel as the undesignated channels; In response to not obtaining a channel with the highest dynamic inspection level, using each of the channels as the undesignated channels different from the designated channel.
6. The video encoding method according to claim 5, wherein Allocating the total available encoding load to each of the channels based on the size relationship between the allocable encoding load and the encoding load to be used, and the dynamic inspection ratio corresponding to each channel, to obtain the matching encoding load corresponding to each channel, includes: Allocating the undesignated encoding load based on the size relationship between the allocable encoding load and the encoding load to be used corresponding to each of the undesignated channels, and the dynamic inspection ratios corresponding to each of the undesignated channels, to obtain the matching encoding load corresponding to each of the undesignated channels; wherein, the undesignated encoding load is determined based on the difference between the total available encoding load and the encoding loads to be used for all the designated channels.
7. The video encoding method according to claim 1, wherein Before determining the encoding frame rate corresponding to each of the channels based on the matching encoding load corresponding to each of the channels, and encoding the video data in the channel at the encoding frame rate corresponding to each of the channels, further includes: Encoding the video data in each of the channels using the matching encoding load within a preset time interval; In response to exceeding the preset time interval, returning to the step of obtaining the dynamic inspection ratio corresponding to each of the channels.
8. An electronic device, characterized in that, Includes: A mutually coupled memory and processor, wherein the memory stores program data, and the processor calls the program data to execute the method according to any one of claims 1-7.
9. A computer-readable storage medium having program data stored thereon, characterized in that, When the program data is executed by the processor, the method according to any one of claims 1-7 is implemented.
Citation Information
Patent Citations
Method and system for dynamically adjusting load of multiple graphics processors
CN103268263A
Video coding method, video coding device and computer storage medium
CN110662044A