Coding and decoding resource allocation method and apparatus, and electronic device

The encoding-decoding resource allocation method addresses hardware saturation issues by determining resource needs and prompting for insufficiency, ensuring smooth operation through processor resource utilization.

GB2637847APending Publication Date: 2025-08-06HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
GB2024018807
Authority / Receiving Office
GB · GB
Patent Type
Applications
Current Assignee / Owner
Priority Date
2022-06-24
Filing Date
2023-06-25
Publication Date
2025-08-06

AI Technical Summary

Technical Problem

Existing video recorders face issues with encoding-decoding performance when hardware resources are saturated, leading to preview jams and data anomalies due to insufficient resource allocation.

Method used

A method and apparatus for encoding-decoding resource allocation that determines the required resources based on target protocols, resolutions, and frame rates, allocating idle resources when available and prompting for insufficiency, with fallback to processor resources when necessary.

Benefits of technology

Ensures smooth operation by reducing resource calculation errors and allowing efficient use of processor resources when encoding-decoding resources are insufficient, maintaining normal operation flow.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a coding and decoding resource allocation method and apparatus, and an electronic device. The method comprises: first, obtaining a first-type operation for a media stream to be processed; then determining a target protocol, a target resolution, and a target frame rate corresponding to the first-type operation; according to the target protocol, the target resolution, and the target frame rate, determining the quantity of coding and decoding resources to be consumed by the first-type operation, to obtain an allocation quantity; under the condition that the quantity of currently-idle coding and decoding resources is not smaller than the allocation quantity, allocating, from the currently-idle coding and decoding resources, coding and decoding resources of the allocation quantity to said media stream; and under the condition that the quantity of the currently-idle coding and decoding resources is smaller than the allocation quantity, generating prompt information indicating that the coding and decoding resources are insufficient. Corresponding coding and decoding resources are determined by combining the target protocol, the resolution, and the frame rate, so that resource calculation errors can be reduced, and reasonable control and allocation of the coding and decoding resources is realized.
Need to check novelty before this filing date? Find Prior Art

Description

The present application relates to the technical field of image processing, in particular to an encoding-decoding resource allocation method, apparatus and an electronic device. Background In the process of image encoding, decoding and transmitting, some video recorders, such as a NVR (Network Video Recorder), realize encoding and decoding functions by using the same VCP (Video Codec Processor, referred to as a hardware unit herein). When the hardware unit has reached a plateau, if preview and other operations still need to be realized by using the hardware unit, it will affect the encoding-decoding performance and processing effect of the ongoing operation, such as, it may result in preview jam, data abnormality, data loss, and the like. Summary The purpose of embodiments of the present application is to provide an encoding-decoding resource allocation method, apparatus and an electronic device, for reasonable control and allocation of encoding-decoding resources. The specific technical solutions are as follows: An embodiment of the present application provides an encoding-decoding resource allocation method, including: obtaining a first type of operation for a to-be-processed media stream; determining a target protocol, a target resolution and a target frame rate corresponding to the first type of operation, wherein the target protocol is a target encoding protocol or a target decoding protocol; based on the target protocol, the target resolution and the target frame rate, determining a quantity of encoding-decoding resources to be consumed by the first type of operation, and using the obtained quantity as a to-be-allocated quantity; when a quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, allocating the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; and / or, when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, generating prompt information indicating insufficient encoding-decoding resources. In a possible implementation, the method further includes: when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, not performing the first type of operation based on an encoding-decoding resource; performing a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. In a possible implementation, the method further includes: when the first type of operation does not require to consume an encoding-decoding resource or an electronic device does not support processing of the first type of operation, not performing the first type of operation based on an encoding-decoding resource; performing a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. In a possible implementation, the method further includes: quantifying a processing capacity of all encoding-decoding resources during an initialization process to obtain a total quantity of the all encoding-decoding resources. In a possible implementation, quantifying the processing capacity of the all encoding-decoding resources to obtain the total quantity of the all encoding-decoding resources includes: determining, based on a model of an encoding-decoding resource hardware, the number of channels of a reference media stream that are allowed to be processed simultaneously by the all encoding-decoding resources in case a preset reference encoding protocol or a preset reference decoding protocol is used, and using the obtained number of channels as the total quantity of the all encoding-decoding resources, wherein a resolution of the reference media stream is a preset reference resolution, and a frame rate of the reference media stream is a preset reference frame rate. In a possible implementation, determining, based on the target protocol, the target resolution and the target frame rate, the quantity of encoding-decoding resources to be consumed by the first type of operation to obtain the to-be-allocated quantity, includes: determining a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol based on a predetermined first correspondence to obtain a first weight, wherein the first correspondence includes weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol, and the preset reference encoding protocol or the preset reference decoding protocol is an encoding protocol or decoding protocol used when determining a total quantity of all encoding-decoding resources; determining a weight of the target resolution and the target frame rate relative to a reference media stream, and using the determined weight as a second weight, wherein a resolution of the reference media stream is a preset reference resolution, a frame rate of the reference media stream is a preset reference frame rate, and the reference media stream is a media stream used when determining the total quantity of all encoding-decoding resources; calculating the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight. In a possible implementation, determining, based on the target protocol, the target resolution and the target frame rate, the quantity of encoding-decoding resources to be consumed by the first type of operation to obtain the to-be-allocated quantity, includes: based on a predetermined first weight table, determining a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol to obtain a first weight; wherein weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol are recorded in the first weight table; determining whether there is a second weight of the target resolution and the target frame rate relative to a reference media stream in a predetermined second weight table, wherein weights of individual resolutions and frame rates relative to the reference media stream are recorded in the second weight table; if there is the second weight in the predetermined second weight table, determining the second weight of the target resolution and the target frame rate relative to the reference media stream based on the second weight table; and / or, if there is no second weight in a predetermined second weight table, dividing a product of the target resolution and the target frame rate by a product of a resolution of the reference media stream and a frame rate of the reference media stream to obtain a second weight; calculating the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight. In a possible implementation, determining the weight of the target resolution and the target frame rate relative to the reference media stream to obtain the second weight includes: calculating a product of the target resolution and the target frame rate to obtain a first product; calculating a product of the preset reference resolution and the preset reference frame rate to obtain a second product; calculating a ratio of the first product to the second product to obtain the second weight. In a possible implementation, the method further includes determining the first weight corresponding to the target protocol based on the number of video frames after Scalable Video Encoding SVC scaling and the number of video frames before the SVC scaling. An embodiment of the present application further provides an encoding-decoding resource allocation apparatus, including: an obtaining module, configured to obtain a first type of operation for a to-be-processed media stream; a first determining module, configured to determine a target protocol, a target resolution and a target frame rate corresponding to the first type of operation, wherein the target protocol is a target encoding protocol or a target decoding protocol; a second determining module, configured to determine a quantity of encoding-decoding resources to be consumed by the first type of operation based on the target protocol, the target resolution and the target frame rate, and use the obtained quantity as a to-be-allocated the quantity; an allocating module, configured to allocate, when a quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; and / or a generating module, configured to generate prompt information indicating insufficient encoding-decoding resources when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity. In a possible implementation, the apparatus further includes: a first processing module, configured to not perform the first type of operation based on an encoding-decoding resource when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity; perform a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. In a possible implementation, the apparatus further includes: a second processing module, configured to not perform the first type of operation based on an encoding-decoding resource when the first type of operation does not require to the consume an encoding-decoding resource or an electronic device does not support processing of the first type of operation; perform a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. In a possible implementation, the apparatus further includes: a quantifying module, configured to quantify a processing capacity of all encoding-decoding resources during an initialization process to obtain a total quantity of the all encoding-decoding resources. In a possible implementation, the quantifying module is specifically configured to: determine, based on a model of an encoding-decodingresource hardware, the number of channels of a reference media stream that are allowed to be processed simultaneously by the all encoding-decoding resources in case a preset reference encoding protocol or a preset reference decoding protocol is used, and use the obtained number of channels as the total quantity of the all encoding-decoding resources, wherein a resolution of the reference media stream is a preset reference resolution, and a frame rate of the reference media stream is a preset reference frame rate. In a possible implementation, the second determining module includes: a first determining sub-module, configured to determine a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol based on a predetermined first correspondence to obtain a first weight, wherein the first correspondence includes weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol, and the preset reference encoding protocol or the preset reference decoding protocol is an encoding protocol or decoding protocol used when determining a total quantity of all encoding-decoding resources; a second determining sub-module, configured to determine a weight of the target resolution and the target frame rate relative to a reference media stream, and use the determined weight as a second weight, wherein a resolution of the reference media stream is a preset reference resolution, a frame rate of the reference media stream is a preset reference frame rate, and the reference media stream is a media stream used when determining the total quantity of all encoding-decoding resources; a calculating sub-module, configured to calculate the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight. In a possible implementation, the second determining sub-module is specifically configured to: calculate a product of the target resolution and the target frame rate to obtain a first product; calculate a product of the preset reference resolution and the preset reference frame rate to obtain a second product; calculate a ratio of the first product to the second product to obtain the second weight. An embodiment of the present application further provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; the memory is configured to store a computer program; the processor is configured to carry out any of the encoding-decoding resource allocation method. An embodiment of the present application further provides a machine-readable storage medium having a computer program stored therein, wherein the computer program, when executed by a processor, implements any of the encoding-decoding resource allocation methods. An embodiment of the present application further provides a computer program product containing instructions, which when running on a computer, cause the computer to carry out any of the encoding-decoding resource allocation methods. Beneficial effects brought by embodiments of the present application: The embodiments of the present application provide the encoding-decoding resource allocation method and apparatus and an electronic device, including: first, obtaining a first type of operation for a to-be-processed media stream; then determining a target protocol, a target resolution and a target frame rate corresponding to the first type of operation; determining the quantity of encoding-decoding resources to be consumed by the first type of operation based on the target protocol, the target resolution and the target frame rate to obtain a to-be-allocated quantity; when the quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, allocating the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, generating prompt information indicating insufficient encoding-decoding resources. By determining the encoding-decoding resources required for performing an operation that requires an encoding-decoding resource on the to-be-processed code stream in combination with the target protocol, resolution and frame rate, the resource calculation error may be reduced and the reasonable control and allocation of the encoding-decoding resources is realized. Moreover, when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, the first type of operation is not performed, and at this time, the to-be-processed media stream is received, and an operation that does not requires the encoding-decoding resource is performed on the to-be-processed media stream by using the processor resource. Therefore, even if the operation that requires the encoding-decoding resource cannot be performed due to the current insufficient encoding-decoding resources, other operations that do not require the encoding-decoding resources can be performed normally, thus ensuring the operation flow related to encoding-decoding can be performed more smoothly. Of course, it is not necessary for any product or method implementing the present application to achieve all the advantages described above simultaneously. Brief Description of the Drawings Figure 1 is a first schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application; Figure 2 is a second schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application; Figure 3 is a third schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application; Figure 4 is a fourth schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application; Figure 5a is a fifth schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application; Figure 5b is a first schematic diagram of displaying prompt information indicating insufficient encoding-decoding resources in an encoding-decodingresource allocation method provided by an embodiment of the present application; Figure 5c is a second schematic diagram of displaying prompt information indicating insufficient encoding-decoding resources in an encoding-decoding resource allocation method provided by an embodiment of the present application; Figure 6 is a schematic structure diagram of an encoding-decoding resource allocation apparatus according to an embodiment of the present application; Figure 7 is schematic structure diagram of an electronic device provided by an embodiment of the present application. Detailed Description In order to realize reasonable control and allocation of encoding-decoding resources, the embodiments of the present application provides an encoding-decoding resource allocation method and apparatus, an electronic device, a storage medium and a computer program product containing instructions. In the following, firstly, the encoding-decoding resource allocation method provided by the embodiments of the present application is introduced. The method is applied to an electronic device. Specifically, the electronic device can be any electronic device that can provide an encoding-decoding resource allocation service for a media stream, such as a mobile a phone, a tablet, a personal computer, a server and the like. The encoding-decoding resource allocation method provided by the embodiments of the present application may be realized by at least one of software, hardware circuit and logic circuit arranged in the electronic device. As shown in Figure 1, Figure 1 is a first schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application. The method includes: SI 10, obtaining a first type of operation for a to-be-processed media stream; SI20, determining a target protocol, a target resolution and a target frame rate corresponding to the first type of operation, wherein the target protocol is a target encoding protocol or a target decoding protocol. For an encoding process, the target protocol (i.e„ the target encoding protocol) is an encoding standard that the first type of operation complies with, that is, the encoding standard that the data, on which the first type of operation has been performed, complies with; the target resolution is a resolution that the data after the first type of operation complies with; and the target frame rate is a frame rate that the data after the first type of operation complies with. For the decoding process, the target protocol (i.e. the target decoding protocol) is a decoding standard that the first type of operation complies with, that is, the decoding standard that the data before the first type of operation complies with; the target resolution is a resolution that the data before the first type of operation complies with; and the target frame rate is a frame rate that the data before the first type of operation complies with. SI30, based on the target protocol, the target resolution and the target frame rate, determining a quantity of encoding-decoding resources to be consumed by the first type of operation, and using the obtained quantity as a to-be-allocated quantity. The quantity of encoding-decoding resources to be consumed by the first type of operation refers to the quantity of encoding-decoding resources to be used in performing the first type of operation, that is, how many encoding-decoding resources are required to complete the first type of operation. S140, when the quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, allocating the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; SI50, when a quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, generating prompt information indicating insufficient encoding-decoding resources. The quantity of current idle encoding-decoding resources refers to the quantity of current remaining encoding-decoding resources in the electronic device, that is, the quantity of unoccupied encoding-decoding resources. The media stream may be a video or an audio, and some related operations for the media stream may be referred to as a second type of operation, such as parsing, storing and forwarding, etc. The second type of operation only needs to perform parsing, storing and forwarding of code stream, and does not need to perform previewing or playback, etc. Therefore, the second type of operation can be completed through a processor resource or an encoding-decoding resource. In this embodiment, the second type of operation is defined as an operation completed through a processor resource without requiring an encoding-decoding resource. In addition, some related operations for the media stream can be referred to as the first type of operation, such as previewing and playback, and the first type of operation is an operation to be completed with an encoding-decoding resource. Therefore, when the operation related to the encoding-decoding resource is started, it is first determined whether the operation for the to-be-processed media stream is the first type of operation or the second type of operation. If the operation for the to-be-processed media stream is the first type of operation that needs to consume the encoding-decoding resource, that is, the encoding-decoding resource will be consumed, it is necessary to calculate the quantity of encoding-decoding resources to be consumed by the first type of operation based on the target protocol, the target resolution and the target frame rate, and then determine whether a system has sufficient available encoding-decoding resources. If the system has sufficient available encoding-decoding resources, the encoding-decoding resources are allocated to the first type of operation. Further, after the encoding-decoding resources are allocated to the first type of operation, the current idle encoding-decoding resources need to be updated. If the system does not have sufficient available encoding-decoding resources, prompt information indicating insufficient encoding-decoding resources is generated. It should be noted that the quantity of encoding-decoding resources refers to a parameter obtained by quantifying an encoding-decoding ability, which is used to measure the encoding-decoding ability. Quantifying the encoding-decoding ability into a unit that can be calculated is helpful to determine a matching degree between resources and requirements. In addition, it should be noted that “encoding-decoding” herein is a synonym for “encoding or decoding”; in a decoding scenario, “encoding-decoding” means “decoding”; in an encoding scenario, “encoding-decoding” means “encoding”. For example, an encoding-decoding resource allocation method can be understood as an encoding resource allocation method or a decoding resource allocation method. Correspondingly, the embodiments provided in the present application and the solution to be protected can be correspondingly understood as a solution related to encoding or a solution related to decoding, and each complete solution is not repeated here. By determining the encoding-decoding resources required for an operation which is performed on the to-be-processed code stream and requires an encoding-decoding resource in combination with the target protocol, target resolution and target frame rate, a resource calculation error may be reduced and the reasonable control and allocation of the encoding-decoding resources may be realized. In a possible implementation, the above method further includes: when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, not performing the first type of operation (i.e., the first type of operation is not performed based on an encoding-decoding resource); receiving the to-be-processed media stream, and performing a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. When the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, it means that there are not sufficient available encoding-decoding resources at present, and although the operation for the media stream, such as analyzing, storing and forwarding and the like, needs to be completed with the encoding-decoding resources, the operation can also be completed through the processor resource. Therefore, since there are not sufficient available encoding-decoding resources, no encoding or decoding operation is performed at this point, and the to-be-processed media stream is received and an operation, such as parsing, storing and forwarding, is performed on the to-be-processed media stream by ^14^ using the processor resource. Therefore, when the encoding-decoding resources are insufficient, the processor resource can be reasonably used to maintain parsing, storing and forwarding of the code stream even if no encoding or decoding operation is performed. In a possible implementation, the above method further includes: when the above first type of operation does not require to consume an encoding-decoding resource or the electronic device does not support processing of the above first type of operation, not performing the above first type of operation (that is, the above first type of operation is not performed based on an encoding-decoding resource); receiving the to-be-processed media stream, and performing a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. When the first type of operation does not require to consume the encoding-decoding resource or when the electronic device does not support processing of the first type of operation, the first type of operation is not performed. Instead, after receiving the to-be-processed media stream, the second type of operation, such as parsing, storing, forwarding and the like, is performed on the to-be-processed media stream by using the processor resource. Alternatively, when the electronic device cannot support processing of the first type of operation, for example, the electronic device only supports processing of encoding and decoding under H.264 and H.265 protocols, and when the first type of operation is an encoding and decoding operation under other protocols except H.264 and H.265 protocols, the electronic device does not support processing of this first type of operation. After receiving the to-be-processed media stream, the electronic device performs an operation on the to-be-processed media stream by using the processor resource. In this way, when the first type of operation does not require to consume the encoding-decoding resource, or when the electronic device does not support processing of the first type of operation, the processor resource can be reasonably used to maintain parsing, storing and forwarding of the code stream even if no encoding or decoding operation is performed. In a possible implementation, the above method further includes: quantifying a processing capacity of all encoding-decoding resources during an initialization process to obtain a total quantity of the all encoding-decoding resources. After the initialization begins, it is necessary to quantify the processing capacity of all encoding-decoding resources to obtain the total quantity of the all encoding-decoding resources. When quantifying the processing capacity of the all encoding-decoding resources, a reference media stream can be set firstly, and the processing capacity of all the encoding-decoding resources is quantified based on the reference media stream. In order to make a solution clear and a layout clear, the following will be described in detail with another embodiment. In a possible implementation, quantifying the processing capacity of the all encoding-decoding resources during the initialization process to obtain the total quantity of the all encoding-decoding resources, includes: during the initialization process, determining, based on a model of an encoding-decoding resource hardware, the number of channels of a reference media stream that are allowed to be processed simultaneously by the all encoding-decoding resources in case a preset reference encoding protocol or a preset reference decoding protocol is used, to obtain the total quantity of the all encoding-decoding resources, wherein a resolution of the reference media stream is a preset reference resolution, and a frame rate of the reference media stream is a preset reference frame rate. During the initialization process, the reference media stream is set firstly, for example, the H.265 1080P@30FPS decoded media stream is used as the reference media stream, that is, the resource occupied by decoding one channel of H.265 1080P@30FPS is set as KP (K Proportionality), then it is determined, based on this reference media stream, that the number of channels of the reference media stream that are allowed to be processed simultaneously by the encoding-decoding resources, to obtain the total quantity of all encoding-decoding resources, for example the obtained total encoding-decoding capacity is x * KP. For example, if a total decoding capacity of one device VCP is 16 channels of H.265 1080P@30FPS video, the total encoding-decoding capacity is 16 * KP, which means that the 16 channels of 1080P @30FPS media stream can be decoded simultaneously. The reference media stream can be set based on the actual situation, which is not limited here. Based on the embodiment in Figure 1, referring to Figure 2, which is a second schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application, the above step SI30 can be implemented by the following steps: S131, based on the target protocol and a preset reference encoding protocol or a preset reference decoding protocol, determining a weight of the target protocol relative to the preset reference encoding protocol or the preset reference decoding protocol to obtain a first weight, wherein the preset reference encoding protocol or the preset reference decoding protocol is an encoding protocol or a decoding protocol used when determining the total quantity of all encoding-decoding resources; SI32, determining a weight of the target resolution and the target frame rate relative to a reference media stream to obtain a second weight, wherein the resolution of the reference media stream is a preset reference resolution, a frame rate of the reference media stream is a preset reference frame rate, and the reference media stream is a media stream used when determining the total quantity of all encoding-decoding resources; SI33, calculating the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation can be a product of the first weight and the second weight. After obtaining the to-be-processed media stream, if the first type of operation is performed on the to-be-processed media stream, the quantity of encoding-decoding resources to be consumed by the first type of operation is related to the target protocol, target resolution and target frame rate. After setting the preset reference encoding protocol or the preset reference decoding protocol, the weight of the target protocol relative to the preset reference encoding protocol or the preset reference decoding protocol can be determined. For example, if the H.265 1080P@30FPS decoded media stream is used as the reference media stream, that is, the H.265 protocol is set as the reference decoding protocol, then the weight of the target decoding protocol in the H.265 decoding scenarios is 1 relative to the H.265 protocol. Since performance consumption of encoding is higher than that of decoding, H.265 encoding may set a different weight based on the actually measured performance consumption. For H.264 encoding-decoding, since the performance consumption of H.264 will be higher than that of H.265 and the performance consumption of encoding will be higher than that of decoding, the weight corresponding to H.264 encoding or decoding can be obtained by means of performance test or theoretical calculation. For characteristic code stream processing, such as an SVC (Scalable Video Encoding) code stream, the SVC code stream mainly has temporal scalability and spatial scalability, mainly used for compressing the media stream. In the present application, the SVC code stream generally refers to temporal scalability, that is, some frames in the media stream may not be decoded, thereby reducing the decoding performance consumption. That is, the reduction of video frames mainly involved in encoding and decoding will not change the original data stream. The first weight corresponding to the target protocol is determined based on the number of video frames after SVC scaling. For example, if the number of video frames after SVC scaling is 1 / 2 of the number of original video frames (that is, the number of video frames involved in encoding-decoding is 1 / 2 of the number of original video frames), the first weight is 0.5; if the number of the video frames is 1 / 4 of the number of original video frames, the first weight is 0.25. The second weight corresponding to the to-be-processed media stream is determined based on the resolution of the reference media stream, the frame rate of the reference media stream, the target resolution and the target frame rate, wherein the second weight corresponding to the to-be-processed media stream can be calculated by dividing a product of the resolution and frame rate of the to-be-processed media stream by a product of the resolution of the reference media stream and the frame rate of the reference media stream. In a possible implementation, the above step SI32 can be implemented by the following steps: calculating a product of the target resolution and the target frame rate to obtain a first product; calculating a product of the preset reference resolution and the preset reference frame rate to obtain a second product; calculating a ratio of the first product to the second product to obtain the second weight. Similarly, the H.265 1080P@30FPS decoded media stream is taken as the reference media stream, and the resource occupied by decoding one channel of H.265 1080P@30FPS is set as KP. Then in the H.265 decoding scenario, for the to-be-processed media stream with a pixel of CIF lOw, a resolution of 352^288 and a frame rate of 30, the weight is 352 / 288 / 30 / (1920 / 1080 / 30)-0.05. The quantity of encoding-decoding resources to be consumed by the first type of operation is calculated based on the first weight and the second weight, to obtain the to-be-allocated quantity. Specifically, the quantity of encoding-decoding resources to be consumed by the first type of operation (that is, the to-be-allocated quantity) is the product of the first weight and the second weight. For example, the H.265 1080P@30FPS decoded media stream is taken as the reference media stream, and the resource occupied by decoding one channel of H.265 1080P@30FPS is set as KP, then for the typical H.265 decoding scenario: the decoding weight table (i.e. a table of the second weight) is shown in Table 1: Table 1 H.265 decoding weight table pixel resolution frame rate second weight occupied resource CTFlOw 352 x 288 30 0.05 0.05KP VGA30w 640 x 480 30 0.15 0.15KP DI40w 704 x 576 30 0.2 0.2KP XGASOw 1024 x 768 30 0.4 0.4KP HD720100w 1280 x 720 30 0.5 0.5KP HD1080200w 1920 x 1080 30 1 KP 300w 2048 x 1536 30 1.5 1.5KP 500w 2560 x 1920 30 2.5 2.5KP 600w 3072 x 2048 30 3 3KP 1200w 4000 x 3000 30 6 6KP For other H.265 decoding scenarios: for H.265 video with atypical resolution and frame rate, with 1080P as a reference, then after the linear calculation of diving the product of the resolution and the frame rate of the to-be-processed media stream by the product of the resolution of the reference media stream and the frame rate of the reference media stream, it is rounded. For example, for a 1000x1000@25FPS video, the second weight corresponding to the to-be-processed media stream is 1000 / 1000x25 / (1920x1080^30)-0.4. Therefore, the resources occupied by decoding the 1000 / 1000@25FPS video are 0.4 KP. For H.264 encoding and decoding: if the H.264 encoding or decoding complies with resolution and frame rate information in Table 1, the second weight in Table 1 can be directly multiplied by the first weight corresponding to the H.264 encoding or decoding. If the H.264 encoding or decoding does not comply with the resolution and frame rate information in Table 1, the product of the resolution and frame rate of the to-be-processed media stream is divide by the product of the resolution of the reference media stream and frame rate of the reference media stream to obtain the second weight, and then the second weight is multiplied by the first weight corresponding to the H.264 encoding or decoding. For example, the second weight corresponding to H.264 / JPG is kl, and m is the first weight corresponding to an H.264 encoding protocol, then the resource occupied by H.264 / JPG decoding is KP2=(mxKl)KP. The resource occupied by H.264 / JPG encoding is KP3=n*KP2, wherein n is a proportionality coefficient of encoding relative to decoding. In the present application, for the characteristics of the hardware unit, the encoding resources and decoding resources are in a unified management, the encoding-decoding resources are reasonably planed, and the weight is designed in combination with the target protocol, resolution, operating scenario, etc., so that the resource calculation error may be reduced, thus realizing the reasonable control and allocation of the encoding-decoding resources. Based on the embodiment of Figure 1, in a possible implementation, the above step S130 can be implemented by the following steps: determining a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol based on a predetermined first correspondence to obtain a first weight, wherein the first correspondence includes weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol, and the preset reference encoding protocol or the preset reference decoding protocol is an encoding protocol or decoding protocol used when determining a total quantity of all encoding-decoding resources. For example, for some encoding protocols or decoding protocols, not all of video frames need to be encoded or decoded, but some of the video frames are encoded or decoded. Therefore, for a certain type of encoding protocol or decoding protocol, the first weight is determined based on the proportionality relationship between the number of video frames corresponding to this type of encoding protocol or decoding protocol (that is, the number of video frames involved in encoding-decoding in a unit time, i.e., the number of all or some video frames in the total video frames) and the number of video frames corresponding to the preset reference encoding protocol or the preset reference decoding protocol (that is, the number of video frames involved in encoding-decoding in a unit time, i.e., the number of all or some video frames in the total video frames); or, the first weight is determined based on a relationship between a ratio of the number of video frames involved in encoding or decoding (or the number of video frames not involved in encoding or decoding) for this type of encoding protocol or decoding protocol to the number of all video frames, and a ratio of the number of video frames involved in encoding or decoding (or the number of video frames not involved in encoding or decoding) for the preset reference encoding protocol or the preset reference decoding protocol to the number of all video frames. For example, if the ratio of the number of video frames involved in encoding or decoding for a protocol of type A to the number of all video frames is 100%, and the ratio of the number of video frames involved in encoding or decoding for the preset reference encoding protocol or the preset reference decoding protocol to the number of all video frames is 50%, then the first weight is 2. For another example, if the ratio of the number of video frames involved in encoding or decoding for a protocol of type A to the number of all video frames is 25%, and the ratio of the number of video frames involved in encoding or decoding for the preset reference encoding protocol or the preset reference decoding protocol to the number of all video frames is 50%, then the first weight is 0.5. Wherein, the purpose of the first weight is to clearly determine the encoding-decoding resources occupied by frames that actually need to be involved in the encoding-decoding. For example, as shown in Table 2, which is an example of a first correspondence. Table 2 encoding protocol or decoding protocol type first weight relative to the preset reference encoding protocol or the preset reference encoding protocol protocol type A KI protocol type B K2 determining a weight of the target resolution and the target frame rate relative to a reference media stream to obtain a second weight, wherein a resolution of the reference media stream is a preset reference resolution, a frame rate of the reference media stream is a preset reference frame rate, and the reference media stream is a media stream used when determining a total quantity of all encoding-decoding ^22^ resources; calculating the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight. The first correspondence of the weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol can be pre-stored, so that the weight of the target protocol relative to the preset reference encoding protocol or the preset reference decoding protocol can be directly determined based on the predetermined first correspondence to obtain the first weight, thereby reducing the calculation amount. Specifically, the first correspondence may be stored as a first weight table (i.e., the first weight table and the first correspondence may be the same, as shown in Table 2), so that the weight of the target protocol relative to the preset reference encoding protocol or the preset reference decoding protocol can be directly determined based on the first weight table to obtain the first weight. Specifically, the weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol are recorded in the first weight table, and after the target protocol is obtained, the first weight corresponding to the target protocol is determined based on the matching of the target protocol type with a respective encoding protocol or decoding protocol type in the first weight table. Of course, the weight of the target resolution and the target frame rate relative to the reference media stream can also be determined based on the predetermined second correspondence to obtain the second weight. Specifically, the second correspondence can be stored as a second weight table, so that the second weight of the target resolution and the target frame rate relative to the reference media stream can be directly determined based on the second weight table. Specifically, the weights of individual resolutions and frame rates relative to the reference media stream are recorded in the second weight table, and after the target resolution and frame rate are obtained, the second weight of the target resolution and the target frame rate relative to the reference media stream is determined based on the matching of the target resolution and the target frame rate with the respective resolution and frame rate in the second weight table. Based on the embodiment of Figure 1, referring to Figure 3, which is a third schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application, the above step SI30 can be implemented by the following steps: S1310, based on a predetermined first weight table, determining a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol to obtain a first weight; S1320, determining whether there is a second weight of the target resolution and the target frame rate relative to a reference media stream in a predetermined second weight table; S1330, if there is the second weight in the predetermined second weight table, determining the second weight of the target resolution and the target frame rate relative to the reference media stream based on the second weight table; SI340, if there no second weight in a predetermined second weight table, dividing a product of the target media stream resolution and the target frame rate by a product of a resolution of the reference media stream and a frame rate of the reference media stream to obtain the second weight. The first and second weight tables may be different tables or the same table, which is not limited here. If there is the second weight of the target resolution and the target frame rate relative to the reference media stream in the second weight table, the second weight can be directly obtained from the second weight table. If the to-be-processed media stream is unconventional media stream, the second weight can be obtained by the linear calculation. In this way, the weight corresponding to the to-be-processed media stream with typical resolution and code stream can be directly obtained from the table, and the weight corresponding to the to-be-processed media stream with atypical resolution and code stream can be determined by calculation such as linear conversion, thereby the resource calculation error can be reduced and thus reasonable strategies are developed for resource management. In a possible implementation, determining, based on the target protocol, the target resolution and the target frame rate, the quantity of encoding-decoding resources to be consumed by the first type of operation to obtain the to-be-allocated quantity, includes: determining whether there is the quantity of encoding-decoding resources to be consumed by the first type of operation in a predetermined encoding-decoding resource table; if there is the quantity of encoding-decoding resources to be consumed by the first type of operation in a predetermined encoding-decoding resource table, determining the quantity of encoding-decoding resources to be consumed by the first type of operation based on the predetermined encoding-decoding resource table; if there is no quantity of encoding-decoding resources to be consumed by the first type of operation in a predetermined encoding-decoding resource table, determining the quantity of encoding-decoding resources to be consumed by the first type of operation based on the method described in any of the above embodiments. If the to-be-processed media stream is conventional media stream, the quantity of encoding-decoding resources to be consumed by the first type of operation can be directly obtained based on the predetermined encoding-decoding resource table, and if the to-be-processed media stream is unconventional media stream, the quantity of encoding-decoding resources to be consumed by the first type of operation can be determined by the linear calculation, thereby the resource calculation error can be reduced and thus reasonable strategies are developed for resource management. Based on the above embodiments, an embodiment of the present application provides an encoding-decoding resource allocation method, as shown in Figure 4, which is a fourth schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application. In this method, a decoding operation is taken as an example, and the method includes: S401, obtaining a decoding task for a to-be-processed media stream; S402, determining whether there is a preset situation, wherein the preset situation includes a special situation such as resolution being not supported, virtual decoding, etc., wherein the virtual decoding means that a decoding operation is not actually performed and no decoding resource is consumed; if there is the preset situation, performing step S408; if there is no preset situation, performing step S403; S403, determining the quantity of encoding-decoding resources to be consumed by the decoding task to obtain a to-be-allocated quantity; S404, determining whether the quantity of current idle encoding-decoding resources is not less than the to be allocated quantity; if the quantity of current idle encoding-decoding resources is not less than the to be allocated quantity, performing step S405; if the quantity of current idle encoding-decoding resources is less than the to be allocated quantity, performing step S408; S405, allocating the to-be-allocated quantity of encoding-decoding resources to the to-be-processed media stream; S406, updating the quantity of current idle encoding-decoding resources; S407, decoding; S408, performing an operation without requiring an encoding-decoding resource; In the above method, even if the operation requiring an encoding-decoding resource cannot be performed due to insufficient encoding-decoding resources in the current system, other operations that do not require a decoding resource can be performed normally, thus ensuring that the operation flow related to encoding-decoding can be performed more smoothly. In a possible implementation, when an instruction to stop performing a preset operation on the to-be-processed media stream is received, wherein the preset operation is an operation requiring an encoding-decoding resource, the method includes: determining whether the encoding-decoding resources have been allocated to the to-be-processed media stream; when the encoding-decoding resources have not been allocated to the to-be-processed media stream, performing a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is an operation that does not require an encoding-decoding resource; when the encoding-decoding resources have been allocated to the to-be-processed media stream, releasing the allocated encoding-decoding resources and updating the current idle encoding-decoding resources. Specifically, as shown in Figure 5, which is a fifth schematic flow diagram of an encoding-decoding resource allocation method provided by an embodiment of the present application, the method includes: S501, receiving an instruction to stop performing an decoding operation on the to-be-processed media stream; S502, determining whether an encoding-decoding resource is occupied; if the encoding-decoding resource is occupied, performing step S503; if the encoding-decoding resource is not occupied, performing step S5O5; S503, releasing the occupied encoding-decoding resource; S504, updating current idle encoding-decoding resources; S505, perform a second type of operation on the to-be-processed media stream by using a processor resource. When the operation with an encoding or decoding resource needs to be closed, it is first determined whether the current channel has occupied the encoding-decoding resource. If the current channel has occupied the encoding-decoding resource, the occupied encoding-decoding resource is released, and if the current channel has not occupied the encoding-decoding resource, the channel is directly closed. In a possible implementation, when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, after generating prompt information indicating insufficient encoding-decoding resources, the method includes: displaying the prompt information indicating insufficient encoding-decoding resources at a preview window corresponding to the to-be-processed media stream. NVR is connected with a digital camera through the network, receives video and audio data from the digital camera, and parses, stores, forwards, previews and plays back the video and audio data. During previewing, the preview screen of NVR is related to the number of split screens configured for the NVR. If the number of split screens is configured to be 4, then there are 4 preview screen windows which are distributed in 2*2. In addition, the preview screen of NVR is also related to a preview channel configured for the NVR. If a channel 3 is configured in a preview screen window 1, a media stream of the channel 3 is seen in the preview screen window 1. For example, there are currently 4 preview windows, wherein a window 1 corresponds to a media stream of a channel 1, a window 2 corresponds to a media stream of a channel 2, a window 3 corresponds to a media stream of a channel 3, and a window 4 corresponds to a media stream of a channel 4. When the media stream corresponding to the channel 3 is encoded or decoded, if the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, i.e., the current encoding-decoding resources cannot meet requirements of encoding or decoding the media stream corresponding to the channel 3, then the prompt information indicating insufficient encoding-decoding resources is displayed in the preview window corresponding to the channel 3. The prompt information can be any information that can characterize insufficient encoding-decoding resources, for example, the prompt information directly indicates insufficient decoding performance; further, the prompt information may also include information reminding to modify a parameter, as shown in Figure 5b. Of course, when one channel cannot be opened, the window indicating insufficient system resource can also be popped up directly on the NVR interface, as shown in Figure 5c. The specific form of the prompt information indicating insufficient encoding-decoding resource and how to display the prompt information indicating insufficient encoding-decoding resources may be set according to the actual needs, which are not limited here. Based on the above method embodiment, an embodiment of the present application provides an encoding-decoding resource allocation apparatus, as shown in Figure 6, which is a schematic structure diagram of an encoding-decoding resource allocation apparatus provided by an embodiment of the present application. The apparatus may include: an obtaining module 610, configured to obtain a first type of operation for a to-be-processed media stream; a first determining module 620, configured to determine a target protocol, a target resolution and a target frame rate corresponding to the first type of operation, wherein the target protocol is a target encoding protocol or a target decoding protocol; a second determining module 630, configured to determine a quantity of encoding-decoding resources to be consumed by the first type of operation based on the target protocol, the target resolution and the target frame rate, to obtain a to-be-allocated quantity; an allocating module 640, configured to allocate, when the quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; and / or a generating module 650, configured to generate prompt information indicating insufficient encoding-decoding resources when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity. In a possible implementation, the apparatus further includes: a first processing module, configured to not perform the first type of operation based on an encoding-decoding resource when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity; perform a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. In a possible implementation, the apparatus further includes: a second processing module, configured to not perform the first type of operation based on an encoding-decoding resource when the first type of operation does not require to the consume an encoding-decoding resource or an electronic device does not support processing of the first type of operation; perform a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources. In a possible implementation, the apparatus further includes: a quantifying module, configured to quantify a processing capacity of all encoding-decoding resources during an initialization process to obtain a total quantity of the all encoding-decoding resources. In a possible implementation, the quantifying module is specifically configured to: determine, based on a model of an encoding-decoding resource hardware, the number of channels of a reference media stream that are allowed to be processed simultaneously by the all encoding-decoding resources in case a preset reference encoding protocol or a preset reference decoding protocol is used, and use the obtained number of channels as the total quantity of the all encoding-decoding resources, wherein a resolution of the reference media stream is a preset reference resolution, and a frame rate of the reference media stream is a preset reference frame rate. In a possible implementation, the second determining module includes: a first determining sub-module, configured to determine a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol based on a predetermined first correspondence to obtain a first weight, wherein the first correspondence includes weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol, and the preset reference encoding protocol or the preset reference decoding protocol is an encoding protocol or decoding protocol used when determining the total quantity of all encoding-decoding resources; a second determining sub-module, configured to determine a weight of the target resolution and the target frame rate relative to a reference media stream, and use the determined weight as a second weight, wherein a resolution of the reference media stream is a preset reference resolution, a frame rate of the reference media stream is a preset reference frame rate, and the reference media stream is a media stream used when determining the total quantity of the all encoding-decoding resources; a calculating sub-module, configured to calculate the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight. In a possible implementation, the second determining sub-module is specifically configured to: calculate a product of the target resolution and the target frame rate to obtain a first product; calculate a product of the preset reference resolution and the preset reference frame rate to obtain a second product; calculate a ratio of the first product to the second product to obtain the second weight. With regard to the apparatus in the above embodiment, the specific way in which individual modules perform an operation has been described in detail in the embodiment of the method, which will not be described in detail here. An embodiment of the present application further provides an electronic device, as shown in Figure 7, including a processor 701, a communication interface 702, a memory 703 and a communication bus 704, wherein the processor 701, the communication interface 702 and the memory 703 communicate with each other through the communication bus 704, the memory 703 is configured to store a computer program; the processor 701 is configured to, when executing the program stored on the memory 703, implement the following steps: obtaining a first type of operation for a to-be-processed media stream; determining a target protocol, a target resolution and a target frame rate corresponding to the first type of operation; determining the quantity of encoding-decoding resources consumed by the first type of operation based on the target protocol, the target resolution and the target frame rate to obtain a to-be-allocated quantity; when the quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, allocating the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; and / or, when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, generating prompt information indicating insufficient encoding-decoding resources. Optionally, the processor 701 is configured to implement any of the above encoding-decoding resource allocation methods when executing the program stored on the memory 703. The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the electronic device and other devices. The memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk memory. In addition, the memory can also be at least one storage device located far away from the aforementioned processor. The processor may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc; it can also be a Digital Signal Processing (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components. In yet another embodiment provided by the present application, a machine-readable storage medium is further provided, having a computer program stored therein, wherein the computer program, when executed by a processor, implement any step of the above encoding-decoding resource allocation method. In yet another embodiment provided by the present application, a computer program product containing instructions is further provided, which when running on a computer, cause the computer to carry out any of the encoding-decoding resource allocation methods in the above embodiments.

Claims

1. An encoding-decoding resource allocation method, comprising:obtaining a first type of operation for a to-be-processed media stream;determining a target protocol, a target resolution and a target frame rate corresponding to the first type of operation, wherein the target protocol is a target encoding protocol or a target decoding protocol;based on the target protocol, the target resolution and the target frame rate, determining a quantity of encoding-decoding resources to be consumed by the first type of operation, and using the obtained quantity as a to-be-allocated quantity;when a quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, allocating the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; and / or,when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, generating prompt information indicating insufficient encoding-decoding resources.

2. The method according to claim 1, wherein the method further comprises:when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity, not performing the first type of operation based on an encoding-decoding resource;performing a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources.

3. The method according to claim 1, wherein the method further comprises:when the first type of operation does not require to consume an encoding-decoding resource or an electronic device does not support processing of the^34^first type of operation, not performing the first type of operation based on an encoding-decoding resource;performing a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources.

4. The method according to claim 1, wherein the method further comprises:quantifying a processing capacity of all encoding-decoding resources during an initialization process to obtain a total quantity of the all encoding-decoding resources.

5. The method according to claim 4, wherein quantifying the processing capacity of the all encoding-decoding resources to obtain the total quantity of the all encoding-decoding resources comprises:determining, based on a model of an encoding-decoding resource hardware, the number of channels of a reference media stream that are allowed to be processed simultaneously by the all encoding-decoding resources in case a preset reference encoding protocol or a preset reference decoding protocol is used, and using the obtained number of channels as the total quantity of the all encoding-decoding resources, wherein a resolution of the reference media stream is a preset reference resolution, and a frame rate of the reference media stream is a preset reference frame rate.

6. The method according to claim 1, wherein determining, based on the target protocol, the target resolution and the target frame rate, the quantity of encoding-decoding resources to be consumed by the first type of operation to obtain the to-be-allocated quantity, comprises:determining a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol based on a predetermined first correspondence to obtain a first weight, wherein the first correspondence comprises weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decodingprotocol, and the preset reference encoding protocol or the preset reference decoding protocol is an encoding protocol or decoding protocol used when determining a total quantity of all encoding-decoding resources;determining a weight of the target resolution and the target frame rate relative to a reference media stream, and using the determined weight as a second weight, wherein a resolution of the reference media stream is a preset reference resolution, a frame rate of the reference media stream is a preset reference frame rate, and the reference media stream is a media stream used when determining the total quantity of all encoding-decoding resources;calculating the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight.

7. The method according to claim 1, wherein determining, based on the target protocol, the target resolution and the target frame rate, the quantity of encoding-decoding resources to be consumed by the first type of operation to obtain the to-be-allocated quantity, comprises:based on a predetermined first weight table, determining a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol to obtain a first weight; wherein weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol are recorded in the first weight table;determining whether there is a second weight of the target resolution and the target frame rate relative to a reference media stream in a predetermined second weight table, wherein weights of individual resolutions and frame rates relative to the reference media stream are recorded in the second weight table; if there is the second weight in the predetermined second weight table, determining the second weight ofthe target resolution and the target frame rate relative to the reference media stream based on the second weight table; and / or, if there is no second weight in a predetermined second weight table, dividing a product of the target resolution and the target frame rate by a product of a resolution of the reference media stream and a frame rate of the reference media stream to obtain a second weight;calculating the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight.

8. The method according to claim 6 or 7, wherein determining the weight of the target resolution and the target frame rate relative to the reference media stream to obtain the second weight comprises:calculating a product of the target resolution and the target frame rate to obtain a first product;calculating a product of the preset reference resolution and the preset reference frame rate to obtain a second product;calculating a ratio of the first product to the second product to obtain the second weight.

9. The method according to claim 6 or 7, wherein the method further comprises determining the first weight corresponding to the target protocol based on the number of video frames after Scalable Video Encoding SVC scaling and the number of video frames before the SVC scaling.

10. An encoding-decoding resource allocation apparatus, comprising:an obtaining module, configured to obtain a first type of operation for a to-be-processed media stream;a first determining module, configured to determine a target protocol, a target resolution and a target frame rate corresponding to the first type of operation, whereinthe target protocol is a target encoding protocol or a target decoding protocol;a second determining module, configured to determine a quantity of encoding-decoding resources to be consumed by the first type of operation based on the target protocol, the target resolution and the target frame rate, and use the obtained quantity as a to-be-allocated the quantity;an allocating module, configured to allocate, when a quantity of current idle encoding-decoding resources is not less than the to-be-allocated quantity, the to-be-allocated quantity of encoding-decoding resources from the current idle encoding-decoding resources to the to-be-processed media stream; and / or a generating module, configured to generate prompt information indicating insufficient encoding-decoding resources when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity.

11. The apparatus according to claim 10, wherein the apparatus further comprises:a first processing module, configured to not perform the first type of operation based on an encoding-decoding resource when the quantity of current idle encoding-decoding resources is less than the to-be-allocated quantity; perform a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and the processor resource and the encoding-decoding resource are different data processing resources.

12. The apparatus according to claim 10, wherein the apparatus further comprises:a second processing module, configured to not perform the first type of operation based on an encoding-decoding resource when the first type of operation does not require to the consume an encoding-decoding resource or an electronic device does not support processing of the first type of operation; perform a second type of operation on the to-be-processed media stream by using a processor resource, wherein the second type of operation is different from the first type of operation, and theprocessor resource and the encoding-decoding resource are different data processing resources.

13. The apparatus according to claim 10, wherein the apparatus further comprises:a quantifying module, configured to quantify a processing capacity of all encoding-decoding resources during an initialization process to obtain a total quantity of the all encoding-decoding resources.

14. The apparatus according to claim 13, wherein the quantifying module is specifically configured to:determine, based on a model of an encoding-decoding resource hardware, the number of channels of a reference media stream that are allowed to be processed simultaneously by the all encoding-decoding resources in case a preset reference encoding protocol or a preset reference decoding protocol is used, and use the obtained number of channels as the total quantity of the all encoding-decoding resources, wherein a resolution of the reference media stream is a preset reference resolution, and a frame rate of the reference media stream is a preset reference frame rate.

15. The apparatus according to claim 10, wherein the second determining module comprises:a first determining sub-module, configured to determine a weight of the target protocol relative to a preset reference encoding protocol or a preset reference decoding protocol based on a predetermined first correspondence to obtain a first weight, wherein the first correspondence comprises weights of various types of encoding protocols or decoding protocols relative to the preset reference encoding protocol or the preset reference decoding protocol, and the preset reference encoding protocol or the preset reference decoding protocol is an encoding protocol or decoding protocol used when determining a total quantity of all encoding-decoding resources;a second determining sub-module, configured to determine a weight of the target resolution and the target frame rate relative to a reference media stream, and use thedetermined weight as a second weight, wherein a resolution of the reference media stream is a preset reference resolution, a frame rate of the reference media stream is a preset reference frame rate, and the reference media stream is a media stream used when determining the total quantity of all encoding-decoding resources;a calculating sub-module, configured to calculate the quantity of encoding-decoding resources to be consumed by the first type of operation based on the first weight and the second weight to obtain the to-be-allocated quantity; wherein, the to-be-allocated quantity of the encoding-decoding resources to be consumed by the first type of operation is a product of the first weight and the second weight.

16. The apparatus according to claim 15, wherein the second determining sub-module is specifically configured to:calculate a product of the target resolution and the target frame rate to obtain a first product;calculate a product of the preset reference resolution and the preset reference frame rate to obtain a second product;calculate a ratio of the first product to the second product to obtain the second weight.

17. An electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus;the memory is configured to store a computer program;the processor is configured to carry out the method according to any one of claims 1 to 9 when executing the program stored on the memory.

Citation Information

Patent Citations

  • Video preview method, device and equipment

    CN107155093A

  • Panoramic video transcoding method, apparatus and device

    CN108289228A

  • Soft and hard decoding control method and device and electronic equipment

    CN112399252A

  • Resource calling method and electronic equipment

    CN113722058A

  • Coding and decoding resource allocation method and device and electronic equipment

    CN115129470A