Method, apparatus, and device for scheduling an encoder

By scheduling the number of threads of the encoder based on the unit encoding time of each type of encoder and the number of macroblocks of each type in the current frame image, and monitoring the encoder status allocation threads, the problem of low encoding efficiency in the image encoding process is solved, and the image encoding time is shortened and the encoding efficiency is improved.

CN113014921BActive Publication Date: 2025-06-13XIAN WANXIANG ELECTRONICS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110148303.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-03
Publication Date
2025-06-13
Estimated Expiration
2041-02-03

AI Technical Summary

Technical Problem

During the image encoding process, due to the differences in macroblock types and the complexity of the encoder algorithm, the encoding efficiency is low, and each encoder cannot basically complete encoding synchronously, wasting the ability of multi-core and multi-tasks.

Method used

By obtaining the unit encoding time of each type of encoder and the number of macroblocks of each type in the current frame image, the number of threads of each type of encoder is determined, and the corresponding encoder is started according to the number of threads. In addition, by monitoring the status of the encoder, the threads occupied by the encoder that has completed encoding are allocated to the encoder with the highest total operational volume to improve the processor occupancy rate and encoding efficiency.

Benefits of technology

By scheduling the encoder, each encoder can complete the work as simultaneously as possible, thereby shortening the image encoding time and improving the encoding efficiency in the image encoding process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113014921B_ABST
    Figure CN113014921B_ABST
Patent Text Reader

Abstract

The present application provides a method, device and equipment for scheduling encoders, relating to the field of image processing, and capable of solving the problem of low coding efficiency in the process of image coding. The specific technical solution is as follows: obtain the unit coding time of each type of encoder; count the number of macroblocks of each type in the current frame image; determine the number of threads of each type of encoder according to the unit coding time of each type of encoder and the number of macroblocks of each type in the current frame image; start the corresponding encoder according to the number of threads of each type of encoder. The present invention is used for the scheduling of encoders.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing, and particularly to a method, apparatus, and device for scheduling encoders. Background Art

[0002] During the image encoding process, it is usually necessary to first perform segmentation processing on each frame of the image. For example, the image can be first horizontally cut into several strips, each strip being called a slice; then each slice is vertically cut into several blocks, each block being called a macroblock. A macroblock is the basic unit of image compression. Within a macroblock, the features of the image are easier to summarize. For example, a macroblock can consist of 16×16 = 256 pixels. Through an image recognition algorithm, macroblocks can be classified into text blocks, picture blocks, video blocks, etc. In addition, there are also macroblocks that are the same as a certain block in the previous frame of the image or a certain block in the current frame of the image. After the macroblock recognition and classification are completed, targeted encoding is performed for different macroblock types. For example, Huffman coding is used for text blocks, jpeg or png coding is used for picture blocks, and H.264 coding is used for video blocks, etc.

[0003] In the specific implementation process of image encoding, different encoders are usually implemented according to the adopted encoding algorithm. After the macroblock division and recognition are completed, the corresponding encoder is called according to different macroblock types for encoding, and then the bitstreams encoded by each encoder are spliced to complete the encoding of one frame of the image.

[0004] Currently, most mainstream CPUs are multi-core, and the operating system can also support multi-tasks. To improve the encoding efficiency, when implementing a software encoding program, all encoders can be run simultaneously in a multi-tasking manner to parallelly implement the encoding operations of different macroblocks. However, this method has the following limitations:

[0005] First, since images are highly diverse, after being divided into macroblocks, the distribution of the number of each type of macroblock in the total number of macroblocks will also vary greatly. Even an entire frame of the image may only contain one type of macroblock. For example, when playing a video full screen, all macroblocks are video blocks, and there are no text and picture macroblocks; another example is that when a text file is displayed on the screen, there are almost only text blocks, and almost no picture blocks or video blocks. Therefore, the workload of each encoder is dynamically changing. Thus, for the complete encoding of one frame of the image, the respective time consumption of each encoder is also necessarily dynamically changing.

[0006] Second, since the complexity of each encoder algorithm is different, the time required for each encoder to calculate one macroblock is also different. For example, the complexity of binary arithmetic coding (CABAC) is higher than that of adaptive variable length coding (CAVLC), and the corresponding time consumption is also longer than the latter.

[0007] In actual coding design, the bitstream of a frame of image needs to be spliced after all encoders have completed encoding. However, due to the above limitations, during the encoding process, there will be a situation where some encoders have completed encoding while others are still encoding. The encoders cannot complete encoding basically synchronously, which will waste the capabilities of multi-core and multi-tasking, resulting in low encoding efficiency. Summary of the Invention

[0008] An embodiment of the present application provides a method, device and equipment for scheduling encoders, which can solve the problem of low encoding efficiency during image encoding. The technical solutions are as follows:

[0009] According to the first aspect of the embodiments of the present application, a method for scheduling encoders is provided. The method includes:

[0010] Obtain the unit encoding time of each type of encoder, where the unit encoding time is the time for encoding a macroblock in an image;

[0011] Count the number of each type of macroblock in the current frame of image;

[0012] Determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame of image;

[0013] Start the corresponding encoder according to the number of threads of each type of encoder.

[0014] The method for scheduling encoders provided by the embodiments of the present application can determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame of image, and schedule each encoder accordingly. Since the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame of image are comprehensively considered during the encoder scheduling process, each encoder can complete its work as much as possible at the same time, thereby shortening the image encoding time and improving the encoding efficiency during the image encoding process.

[0015] In one embodiment, the determining the number of threads for starting each type of encoder according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame of image includes:

[0016] Calculate the total operation amount of each type of encoder according to the number of each type of macroblock and the unit encoding time of each type of encoder;

[0017] Sort the total operation amounts of each type of encoder to obtain the sorting result of the total operation amounts;

[0018] Based on the sorting result of the total operation amounts, determine the number of threads of each type of encoder according to a preset rule.

[0019] In one embodiment, determining the number of threads of each type of encoder according to the sorting result based on the total amount of operations includes:

[0020] According to the sorting result of the total amount of operations, determine the number of threads of the encoder with the smallest total amount of operations as R1, where R1 is a preset minimum number of threads and R1 is a positive integer;

[0021] For the other total amounts of operations other than the smallest total amount of operations, use the first formula to determine the number of threads of the corresponding type of encoder;

[0022] The first formula is: R i =[T i / T min *R1;

[0023] Wherein, R i represents the number of threads of the encoder corresponding to the i-th total amount of operations among the other total amounts of operations, T i represents the value of the i-th total amount of operations among the other total amounts of operations, T min represents the smallest total amount of operations, [T i / T min represents taking the integer of the value of T i / T min .

[0024] In one embodiment, after starting the corresponding encoder according to the number of threads of each type of encoder, the method further includes:

[0025] Monitor the started encoder;

[0026] When it is monitored that any one encoder has completed encoding and there are still other encoders performing encoding tasks, allocate the threads occupied by the encoder that has completed encoding to the encoder with the highest total amount of operations among the currently executing encoding tasks.

[0027] During the image encoding process, by monitoring the started encoder, the threads occupied by the encoder that has completed encoding can be allocated to the encoder with the corresponding highest total amount of operations among the currently executing encoding tasks to complete the remaining encoding tasks, further improving the occupancy rate of the processor and the efficiency of image encoding.

[0028] In one embodiment, before obtaining the unit encoding time of each type of encoder, the method further includes:

[0029] Calculate the unit encoding time of each type of encoder;

[0030] Save the unit encoding time of each type of encoder.

[0031] In one embodiment, the unit encoding time of each type of encoder is represented in a time complexity manner; calculating the unit encoding time of each type of encoder includes:

[0032] Taking a macroblock as a calculation unit, statistically calculating the calculation time of a reference type encoder and the calculation time of each other type of encoder other than the reference type encoder;

[0033] Taking the time complexity of the reference type encoder as m, and calculating the time complexity of each other type of encoder other than the reference type encoder by using a second formula;

[0034] The second formula is: m * o x = t x / t b ;

[0035] wherein, o x represents the time complexity of the x type encoder, the x type encoder being any one type of encoder among other types of encoders other than the reference type encoder, t x represents the calculation time of the x type encoder, and t b represents the calculation time of the reference type encoder.

[0036] By performing normalization processing on the calculation time of each type of encoder to obtain the time complexity of each type of encoder, it is possible to facilitate sorting and comparison of the total operation amounts of each type of macroblock.

[0037] According to a second aspect of the embodiments of the present application, there is provided a device for scheduling encoders, including:

[0038] An acquisition module, configured to acquire the unit encoding time of each type of encoder, where the unit encoding time is the time for encoding a macroblock in an image;

[0039] A statistics module, configured to statistically calculate the number of each type of macroblock in a current frame image;

[0040] A scheduling module, configured to determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image;

[0041] A start module, configured to start corresponding encoders according to the number of threads of each type of encoder.

[0042] The device of the scheduling encoder provided by the embodiment of the present application can determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image, and schedule each encoder accordingly. Since the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image are comprehensively considered during the scheduling process of the encoder, each encoder can complete its work as much as possible at the same time, thereby shortening the image encoding time and improving the encoding efficiency during the image encoding process.

[0043] In one embodiment, the scheduling module includes:

[0044] An operation amount calculation unit, configured to calculate the total operation amount of each type of encoder according to the number of each type of macroblock and the unit encoding time of each type of encoder;

[0045] A sorting unit, configured to sort the total operation amounts of each type of encoder to obtain a sorting result of the total operation amounts;

[0046] A thread determination unit, configured to determine the number of threads of each type of encoder based on the sorting result of the total operation amounts according to a preset rule.

[0047] In one embodiment, the device further includes:

[0048] A monitoring module, configured to monitor the started encoders;

[0049] An allocation module, configured to, when it is monitored that any one encoder has completed encoding and there are still other encoders performing encoding tasks, allocate the threads occupied by the encoder that has completed encoding to the encoder with the highest total operation amount among the encoders currently performing encoding tasks.

[0050] The device of the scheduling encoder provided by the embodiment of the present application can, through monitoring the started encoders, allocate the threads occupied by the encoder that has completed encoding to the encoder with the corresponding highest total operation amount among the encoders currently performing encoding tasks to complete the remaining encoding tasks, further improving the occupancy rate of the processor and the efficiency of image encoding.

[0051] According to the third aspect of the embodiment of the present application, there is provided a device for scheduling an encoder, where the device for scheduling an encoder includes a processor and a memory, and at least one computer instruction is stored in the memory, and the instruction is loaded and executed by the processor to implement the steps performed in the above method for scheduling an encoder.

[0052] It should be understood that the above general description and subsequent detailed description are only exemplary and explanatory, and cannot limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] The accompanying drawings here are incorporated into the specification and form a part of this specification, showing embodiments consistent with this application, and are used together with the specification to explain the principles of this application.

[0054] Figure 1 is a flowchart of a method for scheduling an encoder provided by an embodiment of this application;

[0055] Figure 2 is a flowchart of another method for scheduling an encoder provided by an embodiment of this application;

[0056] Figure 3 is a schematic structural diagram of a device for scheduling an encoder provided by an embodiment of this application;

[0057] Figure 4 is a schematic structural diagram of another device for scheduling an encoder provided by an embodiment of this application;

[0058] Figure 5 is a schematic structural diagram of yet another device for scheduling an encoder provided by an embodiment of this application;

[0059] Figure 6 is a schematic structural diagram of still another device for scheduling an encoder provided by an embodiment of this application;

[0060] Figure 7 is a schematic structural diagram of a device for scheduling an encoder provided by an embodiment of this application. Detailed implementation manners

[0061] Exemplary embodiments will be described in detail here, and the examples are shown in the accompanying drawings. When the following description refers to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with this application. On the contrary, they are merely examples of devices and methods consistent with some aspects of this application as detailed in the appended claims.

[0062] An embodiment of this application provides a method for scheduling an encoder, as Figure 1 shown, the method for scheduling an encoder includes the following steps:

[0063] Step 101: Obtain the unit encoding time of each type of encoder.

[0064] Obtain the unit encoding time of each type of encoder provided by the current encoding platform, where the unit encoding time is the time for encoding a macroblock in an image.

[0065] In one embodiment, the unit encoding time of each type of encoder can be pre-computed and the computed unit encoding time of each type of encoder can be saved, and the unit encoding time of each type of encoder can be directly used when encoding an image.

[0066] Step 102: Count the number of each type of macroblock in the current frame image.

[0067] When encoding a frame of image, count the number of each type of macroblock in the current frame image. For the current frame image, the divided macroblocks can include multiple types, such as at least one of text macroblocks, video macroblocks, image macroblocks, etc. Each type of macroblock can be encoded using at least one type of encoder. For example, a text macroblock is encoded using an encoder of type A, a video macroblock is encoded using an encoder of type B, and an image macroblock is encoded using an encoder of type C, etc.

[0068] Specifically, the count of each type of macroblock can be directly calculated as a percentage according to the ratio of the count of each type of macroblock to the total number of macroblocks in the entire frame image, and the statistical value of the number of each type of macroblock can be obtained, which can be respectively recorded as: p txt (Statistical value of the number of text macroblocks), p pct (Statistical value of the number of picture macroblocks), p mov (Statistical value of the number of video macroblocks), etc.

[0069] Step 103: Determine the number of threads of each type of encoder.

[0070] After the number of each type of macroblock in the current frame image is determined, the number of threads of each type of encoder is determined according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image.

[0071] Specifically, the total computation amount of each type of encoder can be calculated first according to the number of each type of macroblock and the unit encoding time of each type of encoder, and then the total computation amounts of each type of encoder are sorted to obtain the sorting result of the total computation amounts. Then, based on the sorting result of the total computation amounts, the number of threads of each type of encoder is determined according to a preset rule.

[0072] Among them, the method for determining the number of threads of each type of encoder according to the preset rule can be: determining the number of threads of the encoder with the smallest total computation amount as R1, where R1 is a positive integer representing the preset minimum number of threads, such as 1; for the other total computation amounts other than the smallest total computation amount, use the first formula R i =[T i / T min *R1 to determine the number of threads of the corresponding type of encoder; where R iRepresents the number of threads of the encoder corresponding to the i-th (i is an integer) total amount of operations among other total amounts of operations, T i Represents the value of the i-th total amount of operations among other total amounts of operations, T min Represents the minimum total amount of operations, [T i / T min represents rounding the value of T i / T min to an integer.

[0073] In this step, usually, the number of threads of each type of encoder used for encoding the current frame image is determined. The encoder used for encoding the current frame image can be determined according to various types of macroblocks in the current frame image.

[0074] Step 104: Start the corresponding encoder according to the number of threads of each type of encoder.

[0075] After determining the number of threads of each type of encoder, start the corresponding encoder according to the number of threads of each type of encoder. For example, if the current frame image includes text macroblocks and image macroblocks, the text macroblocks are encoded using type A encoders, and the image macroblocks are encoded using type C encoders. According to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image, it is determined that the number of threads of type A encoder is M1, and the number of threads of type C encoder is M2. Then, start M1 channels of type A encoders to encode the text macroblocks, and start M2 channels of type C encoders to encode the image macroblocks.

[0076] The method for scheduling encoders provided by the embodiments of the present application can determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image, and schedule each encoder accordingly. Since the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image are comprehensively considered during the encoder scheduling process, each encoder can complete the work as much as possible at the same time, thereby shortening the image encoding time and improving the encoding efficiency during the image encoding process.

[0077] Based on the above Figure 1 corresponding method for scheduling encoders provided by the embodiments, another embodiment of the present application provides a method for scheduling encoders, and this method can be applied to image encoding platforms such as image encoding devices and image encoding equipment. Referring to Figure 2 as shown, the method for scheduling encoders provided by this embodiment can include the following steps:

[0078] Step 201: Calculate the unit encoding time of each type of encoder.

[0079] Before determining the number of threads for each type of encoder, the unit encoding time of each type of encoder provided by the current encoding platform can be determined first. The unit encoding time of each type of encoder can be measured once initially and then directly used later. This unit encoding time is the time for encoding a macroblock in an image.

[0080] Specifically, the unit encoding time of each type of encoder can be expressed in terms of time complexity. The unit encoding time of each type of encoder can be calculated by the following method: First, taking the macroblock as the calculation unit, count the calculation time of the reference type encoder and the calculation time of each other type of encoder other than the reference type encoder; then take the time complexity of the reference type encoder as m. For example, m can be taken as 1, and use the second formula m * o x = t x / t b to calculate the time complexity of each other type of encoder other than the reference type encoder, where o x represents the time complexity of the x-type encoder, and the x-type encoder is any one type of encoder among the other types of encoders other than the reference type encoder, and t x represents the calculation time of the x-type encoder, and t b represents the calculation time of the reference type encoder.

[0081] To facilitate sorting and comparison, an encoder can be selected from each type of encoder provided by the current encoding platform as the reference type encoder. For example, the current encoding platform provides Huffman encoder, Context Adaptive Variable-Length Coding (CAVLC), Discrete Cosine Transform (DCT) encoder, Inverse Discrete Cosine Transform (iDCT) encoder, and Context Adaptive Binary Arithmetic Coding (CABAC), etc. The Huffman encoder can be used as the reference type encoder. Based on the calculation time of the Huffman encoder, the time complexities of encoders such as CAVLC, iDCT, and CABAC are obtained through normalization processing.

[0082] Specifically, in this step, taking the normalization with the calculation time of the Huffman encoder as an example, its normalization process can include the following steps a1 to d1:

[0083] Step a1: Taking the macroblock as the calculation unit, count the calculation time of the Huffman encoder, denoted as t b ;

[0084] Step b1: Record the time for each other encoder algorithm (such as CAVLC, DCT, iDCT, and CABAC, etc.) other than the Huffman encoder to complete a macroblock respectively. Taking DCT as an example, it is denoted as t DCT ;

[0085] Step c1: Assume the time complexity of the Huffman encoder is 1, then the time complexity of the DCT encoder can be calculated as: o DCT = t DCT / t b ;

[0086] Step d1: Calculate the complexities of encoder algorithms such as iDCT, CAVLC, and CABAC respectively in the same way as the DCT encoder, and obtain o iDCT , o CAVLC and o CABAC .

[0087] Step 202: Save the unit encoding time of each type of encoder.

[0088] After calculating the unit encoding time of each type of encoder, the unit encoding time of each type of encoder can be saved and directly used later when determining the number of threads for each type of encoder.

[0089] Step 203: Obtain the unit encoding time of each type of encoder.

[0090] When determining the number of threads for each type of encoder, obtain the unit encoding time of each type of encoder. Specifically, the saved unit encoding time of each type of encoder can be read from the memory.

[0091] Step 204: Count the number of each type of macroblock in the current frame image.

[0092] Before determining the number of threads for each type of encoder for the current frame image, first count the number of each type of macroblock in the current frame image. Specifically, the count of each type of macroblock can be directly calculated as a percentage based on the ratio of the count of each type of macroblock to the total number of macroblocks in the entire frame, and the statistical value of the number of each type of macroblock can be obtained.

[0093] Generally, one type of encoder can correspond to at least one type of macroblock. For example, the A-type encoder can be used for text macroblock encoding or image macroblock encoding; for another example, the image macroblock can be encoded using the A-type encoder or the B-type encoder. In practical applications, after counting the number of each type of macroblock in the current frame image, a suitable encoder can be selected for each type of macroblock according to the statistical results to further improve the encoding efficiency.

[0094] For example, a minimum number of macroblocks X can be preset. When the number of a certain type of macroblock is counted to be less than the minimum number of macroblocks X, if this type of macroblock can be encoded by more than one type of encoder, the encoder with the fastest encoding speed can be selected to encode this type of macroblock. For example, picture macroblocks can be encoded by an encoder of type A or an encoder of type B, and text macroblocks are encoded by an encoder of type C; when encoding the current frame of the image, it is counted that the current frame of the image includes X1 picture macroblocks and X2 text macroblocks. Assuming that the encoder of type A has a faster encoding speed than the encoder of type B, and the encoder of type B is the default encoder for encoding picture macroblocks; if X1 is greater than the preset minimum number of macroblocks X, the default encoder of type B is used to encode the picture macroblocks; if X1 is less than the preset minimum number of macroblocks X, then at this time, the encoder for the picture macroblocks can be adjusted to the encoder of type A.

[0095] Step 205: Calculate the total operation amounts of each type of encoder.

[0096] After the number of each type of macroblock in the current frame of the image is determined, the total operation amounts of each type of encoder can be calculated according to the number of each type of macroblock and the unit encoding time of each type of encoder. Among them, the number of each type of macroblock can be represented in the form of the statistical value described in step 102. Specifically, the total operation amounts of each type of encoder can be calculated by weighting the unit encoding time of each type of encoder.

[0097] Specifically, taking the DCT encoder as an example, the DCT encoder is respectively used in jpeg encoding and H264 encoding. Jpeg encoding is mainly for picture macroblocks, and H264 encoding is mainly for video macroblocks. Therefore, the total operation amount T DCT of the DCT encoder can be calculated by the following formula:

[0098] T DCT = o DCT × (p pct + p mov );

[0099] Among them, o DCT represents the time complexity of the DCT encoder, p pct represents the statistical value of the number of picture macroblocks, and p mov represents the statistical value of the number of video macroblocks.

[0100] Similarly, the total operation amounts of other encoders can be determined in a similar manner, such as the total operation amount T iDCT of the iDCT encoder, the total operation amount T CAVLC of the CAVLC encoder, the total operation amount T CABAC of the CABAC encoder, etc.

[0101] Step 206: Sort the total computing amounts of each type of encoder.

[0102] After calculating the total computing amounts of each type of encoder, sort the total computing amounts of each type of encoder to obtain the sorting result of the total computing amounts. For example, it can be sorted in descending order or ascending order.

[0103] Step 207: Determine the number of threads for each type of encoder.

[0104] After obtaining the sorting result of the total computing amounts of each type of encoder, based on the sorting result of the total computing amounts, determine the number of threads for each type of encoder according to the preset rules. Specifically, it can be determined in the following way: When starting encoding, determine the number of threads of the encoder with the smallest total computing amount as R1, where R1 is the preset minimum number of threads. For example, R1 can be taken as 1; for other total computing amounts, use the first formula R i =[T i / T min *R1 to determine the number of threads of the corresponding type of encoder, where R i represents the number of threads of the encoder corresponding to the i-th total computing amount among other total computing amounts, T i represents the value of the i-th total computing amount among other total computing amounts, T min represents the minimum total computing amount, [T i / T min represents taking the integer of the value of T i / T min , that is, the largest integer not exceeding T i / T min .

[0105] In practical applications, there should be a limit to the total number of threads created for all encoders, so as to avoid the processor (such as the central processing unit CPU) being frequently in the thread switching state and reducing the encoding efficiency. Generally, the total number of threads should not exceed 3 times the number of current processor cores. In the case where the thread limit has been reached, only R1 channels of the encoder corresponding to the largest total computing amount are started.

[0106] In practical applications, the current encoding platform can provide multiple types of encoders, and the current frame image to be encoded may only require some of these encoders. At this time, only the unit encoding time of these encoders can be obtained, and the number of threads of these encoders can be determined through the above method.

[0107] Step 208: Start the corresponding encoder according to the number of threads of each type of encoder.

[0108] Step 209: Monitor the started encoders.

[0109] Step 210: When it is monitored that any one encoder has completed encoding and there are still other encoders performing encoding tasks, adjust the encoder threads according to a preset allocation rule.

[0110] Specifically, during the encoding process, the status of each started encoder can be monitored. When it is monitored that any one encoder has completed encoding and there are still other encoders performing encoding tasks, the thread occupied by the encoder that has completed encoding is allocated to the encoder with the highest total computing amount among the encoders currently performing encoding tasks to complete the remaining encoding tasks, thereby improving the processor occupancy rate and image encoding efficiency.

[0111] In the above solution, on the one hand, the distribution of various types of macroblocks is considered. For the type with fewer macroblocks, since the number of such macroblocks is small and has little impact on the size of the bitstream, a faster encoder algorithm can be used to improve the encoding efficiency. On the other hand, since the content of each frame of the image is different, it is possible to count every N (N is a positive integer) frames of images and adjust the allocation of the encoder based on the statistical results; for example, dynamic statistics can be performed for each frame of the image and the allocation of the encoder can be adjusted based on the statistical results.

[0112] The method for scheduling an encoder provided in the embodiments of the present application, by obtaining the unit encoding time of each type of encoder, counting the number of various types of macroblocks in the current frame of the image, determining the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of various types of macroblocks in the current frame of the image, starting the corresponding encoder according to the number of threads of each type of encoder, comprehensively considering the calculation time of each type of encoder and the distribution quantity of different types of macroblocks in the current frame of the image, enables each encoder to complete the work as simultaneously as possible, shortens the image encoding time from the perspective of the statistics of the complete frame; moreover, according to the distribution of each macroblock in the current frame of the image, a suitable encoder algorithm can be selected, thereby balancing the conflict between the size of the bitstream and the encoding time.

[0113] Based on the method for scheduling an encoder described in the above embodiments, the following is an embodiment of the device of the present application, which can be used to execute the method embodiments of the present application.

[0114] The embodiments of the present application provide a device for scheduling an encoder, as Figure 3 shown. The device 30 for scheduling an encoder includes: an acquisition module 301, a statistics module 302, a scheduling module 303, and a start module 304;

[0115] Among them, the acquisition module 301 is used to obtain the unit encoding time of each type of encoder, and the unit encoding time is the time for encoding a macroblock in the image;

[0116] The statistical module 302 is used to count the number of macroblocks of each type in the current frame image;

[0117] The scheduling module 303 is used to determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of macroblocks of each type in the current frame image;

[0118] The startup module 304 is used to start the corresponding encoder according to the number of threads of each type of encoder.

[0119] As Figure 4 shown, the scheduling module 303 may include an operation amount calculation unit 3031, a sorting unit 3032, and a thread determination unit 3033;

[0120] Among them, the operation amount calculation unit 3031 is used to calculate the total operation amount of each type of encoder according to the number of macroblocks of each type and the unit encoding time of each type of encoder;

[0121] The sorting unit 3032 is used to sort the total operation amounts of each type of encoder to obtain the sorting result of the total operation amounts;

[0122] The thread determination unit 3033 determines the number of threads of each type of encoder based on the sorting result of the total operation amounts obtained by the sorting unit 3032 according to a preset rule. Specifically, the thread determination unit 3033 determines the number of threads of the encoder with the smallest total operation amount as R1 (R1 is a positive integer) according to the sorting result of the total operation amounts obtained by the sorting unit 3032, and this R1 is the preset minimum number of threads; for other total operation amounts other than the minimum total operation amount, use the first formula R i = [T i / T min *R1 to determine the number of threads of the corresponding type of encoder; where R i represents the number of threads of the encoder corresponding to the i-th total operation amount among other total operation amounts, T i represents the value of the i-th total operation amount among other total operation amounts, T min represents the minimum total operation amount, [T i / T min represents rounding the value of T i / T min .

[0123] In one embodiment, as Figure 5 shown, the device 30 for scheduling the encoder further includes a monitoring module 305 and an allocation module 306.

[0124] Among them, the monitoring module 305 is used to monitor the started encoder;

[0125] The allocation module 306 is configured to allocate the thread occupied by the encoder that has completed encoding to the encoder with the highest total computing workload among the encoders currently performing the encoding task when it is monitored that any one encoder has completed encoding and there are still other encoders performing the encoding task.

[0126] In one embodiment, as Figure 6 shown, the device 30 for scheduling encoders further includes a calculation module 307 and a storage module 308.

[0127] Among them, the calculation module 307 is configured to calculate the unit encoding time of each type of encoder;

[0128] The storage module 308 is configured to save the unit encoding time of each type of encoder calculated by the calculation module 307.

[0129] Specifically, the unit encoding time of each type of encoder can be represented in the form of time complexity. The calculation module 307 may include a statistics unit 3071 and a time complexity calculation unit 3072.

[0130] The statistics unit 3071 is configured to take macroblocks as the calculation unit and statistically calculate the calculation time of the reference type encoder and the calculation time of each other type of encoder other than the reference type encoder;

[0131] The time complexity calculation unit 3072 is configured to take the time complexity of the reference type encoder as m and calculate the time complexity of each other type of encoder other than the reference type encoder by using the second formula; the second formula is: m*o x =t x / t b ; where, o x represents the time complexity of the x type encoder, and the x type encoder is any one type of encoder among the other types of encoders other than the reference type encoder, t x represents the calculation time of the x type encoder, and t b represents the calculation time of the reference type encoder.

[0132] The device for scheduling encoders provided by the embodiment of the present application can determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image, and schedule each encoder accordingly. Since the unit encoding time of each type of encoder and the number of each type of macroblock in the current frame image are comprehensively considered in the process of scheduling the encoders, each encoder can complete the work as much as possible at the same time, thereby shortening the image encoding time and improving the encoding efficiency in the image encoding process.

[0133] Refer to Figure 7As shown in the figure, the embodiment of the present application further provides a device 70 for scheduling an encoder. The device for scheduling the encoder includes a processor 701 and a memory 702. At least one computer instruction is stored in the memory 702, and the computer instruction is loaded and executed by the processor 701 to implement the above Figure 1 or Figure 2 the method for scheduling the encoder described in the corresponding embodiment.

[0134] Based on the above Figure 1 and Figure 2 the method for scheduling the encoder described in the corresponding embodiment, the embodiment of the present application further provides a computer-readable storage medium. For example, a non-transitory computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc. Computer instructions are stored on the storage medium for executing the above Figure 1 and Figure 2 the method for scheduling the encoder described in the corresponding embodiment, which will not be elaborated here.

[0135] After considering the specification and practicing the content disclosed herein, those skilled in the art will readily think of other implementation schemes of the present application. The present application aims to cover any variations, uses, or adaptive changes of the present application. These variations, uses, or adaptive changes follow the general principles of the present application and include the common general knowledge or conventional technical means in the technical field not disclosed in the present application. The specification and the embodiments are only regarded as exemplary, and the true scope and spirit of the present application are pointed out by the appended claims.

[0136] It should be understood that the present application is not limited to the exact structure already described and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present application is only limited by the appended claims.

Claims

1. A method for scheduling encoders, characterized in that, the method includes: Obtaining the unit encoding time of each type of encoder, where the unit encoding time is the time for encoding a macroblock in an image; Counting the number of macroblocks of each type in the current frame image; Determining the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of macroblocks of each type in the current frame image; Starting the corresponding encoder according to the number of threads of each type of encoder; Among them, the determining the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of macroblocks of each type in the current frame image includes: calculating the total operation amount of each type of encoder according to the number of macroblocks of each type and the unit encoding time of each type of encoder; sorting the total operation amounts of each type of encoder to obtain the sorting result of the total operation amounts; based on the sorting result of the total operation amounts, determining the number of threads of each type of encoder according to a preset rule; Determining the number of threads for each type of encoder according to the sorting result based on the total amount of operations includes: according to the sorting result of the total amount of operations, determining the number of threads of the encoder with the smallest total amount of operations as R1, where R1 is a preset minimum number of threads and R1 is a positive integer; for the other total amounts of operations other than the smallest total amount of operations, using the first formula to determine the number of threads of the corresponding type of encoder; the first formula is: R i =[[T i / T min *R1; where R i represents the number of threads of the encoder corresponding to the i-th total amount of operations among the other total amounts of operations, T i represents the value of the i-th total amount of operations among the other total amounts of operations, T min represents the smallest total amount of operations, [T i / T min represents taking the integer of the value of T i / T min .

2. The method according to claim 1, characterized in that, after starting the corresponding encoder according to the number of threads of each type of encoder, the method further includes: Monitoring the started encoder; When it is monitored that any one of the encoders has completed encoding and there are still other encoders performing encoding tasks, allocating the threads occupied by the encoder that has completed encoding to the encoder with the highest total operation amount among the encoders currently performing encoding tasks.

3. The method according to claim 1, characterized in that, before obtaining the unit encoding time of each type of encoder, the method further includes: Calculating the unit encoding time of each type of encoder; Saving the unit encoding time of each type of encoder.

4. The method according to claim 3, characterized in that, the unit encoding time of each type of encoder is represented in the form of time complexity; the calculating the unit encoding time of each type of encoder includes: Taking the macroblock as the calculation unit, counting the calculation time of the reference type encoder and the calculation time of other types of encoders other than the reference type encoder; Taking the time complexity of the reference type encoder as m, and calculating the time complexity of other types of encoders other than the reference type encoder by using the second formula; The second formula is: m*ο x = t x / t b ; Among them, ο x represents the time complexity of the x-type encoder, and the x-type encoder is any one of the other various types of encoders other than the reference type encoder, t x represents the calculation time of the x-type encoder, t b represents the calculation time of the reference type encoder.

5. A device for scheduling encoders, characterized in that, including: An obtaining module, configured to obtain the unit encoding time of each type of encoder, where the unit encoding time is the time for encoding a macroblock in an image; A statistics module, configured to count the number of macroblocks of each type in the current frame image; A scheduling module, configured to determine the number of threads of each type of encoder according to the unit encoding time of each type of encoder and the number of macroblocks of each type in the current frame image; A starting module, configured to start the corresponding encoder according to the number of threads of each type of encoder; The scheduling module includes: An operation amount calculation unit, configured to calculate the total operation amount of each type of encoder according to the number of macroblocks of each type and the unit encoding time of each type of encoder; A sorting unit, configured to sort the total operation amounts of each type of encoder to obtain the sorting result of the total operation amounts; A thread determination unit, configured to determine the number of threads of each type of encoder according to a preset rule based on the sorting result of the total amount of operations; Among them, the thread determination unit is configured to determine the number of threads of the encoder with the smallest total amount of computation as R1 according to the sorting result of the total amount of computation, where R1 is a preset minimum number of threads and R1 is a positive integer; for the total amount of computation other than the smallest total amount of computation, the number of threads of the corresponding type of encoder is determined using the first formula; the first formula is: R i = i / min *R1; where R i represents the number of threads of the encoder corresponding to the i-th total amount of computation among the other total amounts of computation, T i represents the value of the i-th total amount of computation among the other total amounts of computation, T min represents the smallest total amount of computation, i / min represents rounding the value of T i / min .

6. The apparatus according to claim 5, wherein, the apparatus further comprises: a monitoring module, configured to monitor the started encoders; an allocation module, configured to, when it is monitored that any one encoder has completed encoding and there are still other encoders performing encoding tasks, allocate the threads occupied by the encoder that has completed encoding to the encoder with the highest total amount of operations among the encoders currently performing encoding tasks.

7. A device for scheduling encoders, wherein, the device for scheduling encoders comprises a processor and a memory, and at least one computer instruction is stored in the memory, and the computer instruction is loaded and executed by the processor to implement the steps performed in the method for scheduling encoders according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Full exploitation of parallel processors for data processing

    US20130198753A1

  • Image coding method and apparatus

    WO2021004126A1