A video decoding method based on acceleration module
By porting ffmpeg to the Linux platform and combining it with an acceleration module, the problem of low decoding efficiency of the Atlas 200AI acceleration module when the protocol frame does not fully conform to the decoding protocol was solved. This enabled the complete acquisition and hardware decoding of parameter frames, thus improving video decoding efficiency.
Patent Information
- Application Number
- CN202211084984.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-06
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-09-06
AI Technical Summary
On the Linux platform, the Atlas 200AI acceleration module has low decoding efficiency when the protocol frames do not fully conform to the decoding protocol or when there are many erroneous frames, and it cannot effectively decode image information with parameter frames.
Port ffmpeg to the HiSilicon development board, configure ffmpeg compilation properties, modify the source code to obtain parameter frame functions, create a network receiving thread to receive raw compressed image data, and use the ffmpeg decoding dynamic library to obtain complete compressed image data packets, and combine the acceleration module for hardware decoding.
It implements the filtering and hardware decoding of incomplete frames under the Linux system, which improves video decoding efficiency and ensures the complete acquisition of parameter frame information and the effective use of the decoder.
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of video decoding under Linux system, and specifically relates to a video decoding method based on an acceleration module. Background Art
[0002] The Atlas 200AI acceleration module integrates the Ascend 310AI processor, which can realize image recognition, image classification, etc. on the edge. It can realize various data analysis and reasoning calculations such as images and videos, and is widely used in edge AI scenarios such as smart cameras, robots, and drones.
[0003] However, Atlas 200AI belongs to the category of hard decoding. When the protocol frame does not fully comply with the decoding protocol or there are many error frames, the decoding efficiency is relatively low or decoding is impossible. In addition, for image information with parameter frames, the decoder cannot extract parameter information. Summary of the invention
[0004] 1. Technical issues to be resolved
[0005] The technical problem to be solved by the present invention is to solve the problem of video decoding under the Linux platform.
[0006] (II) Technical solution
[0007] In order to solve the above technical problems, the present invention provides a video decoding method based on an acceleration module, comprising the following steps:
[0008] Step 1: Port ffmpeg to HiSilicon development board
[0009] First, configure the ffmpeg compilation properties; then, modify the ffmpeg source code to enable it to have the function of returning parameter frames, cross-compile the ffmpeg source code, obtain the ffmpeg decoding dynamic library, and copy the ffmpeg decoding dynamic library to the HiSilicon development board, which is a platform for loading the acceleration module;
[0010] Step 2: Create a network receiving thread to receive the original compressed image data sent by the host
[0011] First, obtain the IP and port number information in the transmission according to the configuration file; then, create a network receiving thread to block the original compressed image data sent by the receiving host from the network;
[0012] Step 3: Use the ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing the parameter frame and complete the filtering of the incomplete frame data.
[0013] First, initialize the use environment of the ffmpeg decoding dynamic library; second, create a data packet acquisition thread, and use the ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing the parameter frame of the compressed image, that is, the complete image frame data packet;
[0014] Step 4: Complete the hard decoding process based on the acceleration module
[0015] Based on the acceleration module, the complete image frame data packet obtained after filtering using ffmpeg is hard decoded.
[0016] Preferably, step 1 specifically comprises:
[0017] ① First, configure the ffmpeg compilation properties, and configure parameters according to the platform type, CPU type, codec properties, format conversion properties, and cross-compilation properties;
[0018] ②Modify the acodec.h file, add the parameter frame length sei_len and array sei_buf, and determine its parameter frame size SEI_BUF_SIZE according to the application layer requirements;
[0019] ③ Add the function of obtaining the parameter frame in the decode_nal_sei_prefix function in the hevc_sei.c file: obtain the parameter size in the function, assign size to sei_len, and determine whether size is less than or equal to SEI_BUF_SIZE. If the condition is met, copy the data in the context parameter array gb to sei_buf. The length of the copy is size. The array subscript i of the copied sei_buf is the index index of the gb array divided by 8.
[0020] ④Then, execute the configure command to generate the decoding dynamic libraries libavcodec, libavformat, libavutil, and libswscale in the subfolder lib of the configuration folder.
[0021] ⑤Finally, copy the decoding dynamic library to the / usr / lib path of the HiSilicon development board;
[0022] Preferably, step 2 is specifically:
[0023] ①First, obtain the receiving IP and port number information in the configuration file;
[0024] ②Then, create a network socket;
[0025] ③Secondly, clear the receiving buffer and block the receiving host from sending the original compressed image data from the network;
[0026] ④ Determine whether the length of the data received this time is greater than zero. If it is greater than zero, execute the next step, otherwise return to step ③;
[0027] ⑤ Determine whether the protocol frame header meets the protocol requirements. If not, discard the frame, otherwise proceed to the next step.
[0028] Preferably, step 3 is specifically:
[0029] 1) Initialize the usage environment of ffmpeg decoding dynamic library
[0030] First, set the type of decoder in the acceleration module; then initialize the context of the decoder and dynamically apply for image frame storage space;
[0031] 2) Create a data packet acquisition thread and use the ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing the parameter frame of the compressed image, that is, the complete image frame data packet. The specific process is as follows:
[0032] Step 1: Get the image data array first address pointer bufPtr and data length bufLen read from the network;
[0033] Step 2: Determine whether the current data length bufLen is greater than 0. If so, proceed to the next step. If not, wait for the network to send data next time.
[0034] Step 3: Send the image data array first address pointer bufPtr and data length bufLen to the ffmpeg decoding dynamic library, and use the library function av_parser_parse2 to split the data array by frame. If a complete image frame data packet can be successfully obtained from the data array, record it and continue to the next step. If not, exit the decoding process;
[0035] Step 4: Save the data packet length ret of the image frame segmentation in this data array, remove the data packet length ret of the image frame segmentation this time from the data length bufLen, and move the first address pointer bufPtr forward by the number of moves ret;
[0036] Step 5: Put the complete image frame data packet obtained by this segmentation into the queue to be decoded.
[0037] Preferably, step 4 is specifically:
[0038] ① Initialize the acceleration module. The specific operations are as follows:
[0039] a. Create decoding channel properties. If the creation is successful, proceed to the next step, otherwise exit with an error;
[0040] b. Set the decoding channel ID number. If the setting is successful, proceed to the next step, otherwise an error will be reported and exit;
[0041] c. Set the decoding thread number;
[0042] d. Set the decoding channel callback function. If the setting is successful, proceed to the next step, otherwise exit with an error;
[0043] e. Set the decoding type of the decoding channel. If the setting is successful, proceed to the next step, otherwise an error will be reported and exit;
[0044] f. Set the output image format of the decoding channel. If the setting is successful, proceed to the next step, otherwise exit with an error;
[0045] g. Set the decoding channel output mode. If the setting is successful, proceed to the next step, otherwise exit with an error;
[0046] h. Create a decoding channel according to the decoding channel attributes;
[0047] ②Set the decoding callback function as follows:
[0048] a. Use the library function to obtain the normal frame output of decoding. If the result is 0, execute the next step, otherwise exit with an error;
[0049] b. Use library functions to obtain image attribute data output;
[0050] c. Use library functions to obtain the image size, width and height parameters from output;
[0051] d. Use library functions to send image data and parameter data to the host port;
[0052] ③ Obtaining a complete image frame data packet from the queue to be decoded;
[0053] ④ Send the complete image frame data packet to the decoder for decoding, as follows:
[0054] a. Use library functions to dynamically apply for image storage space;
[0055] b. Get the parameter data of the image frame from the ffmpeg decoding dynamic library;
[0056] c. Integrate the parameter data and the filtered complete image frame data into a complete frame;
[0057] d. Create an input image stream attribute object;
[0058] e. Set the input image stream attribute object;
[0059] f. Dynamically apply for image output memory space;
[0060] g. Create an output image stream attribute object;
[0061] h. Set output image properties according to image data, size and format;
[0062] i. Send the complete frame to the decoder using the library function with the decoding channel attributes, input image stream attributes, and output image stream attributes as parameters;
[0063] j. Release the requested image output memory space;
[0064] k. Destroy the input image stream attribute object resources.
[0065] Preferably, the HiSilicon development board is an atlas200AI chip.
[0066] Preferably, the decoder is a HEVC (h265) type decoder.
[0067] The present invention also provides a video decoding system for implementing the method.
[0068] Preferably, the decoder is a HEVC (h265) type decoder.
[0069] The invention also provides an application of the method in the technical field of video decoding under a Linux system.
[0070] Preferably, the decoder is a HEVC (h265) type decoder.
[0071] The invention also provides an application of the system in the technical field of video decoding under a Linux system.
[0072] (III) Beneficial effects
[0073] In the application scenario where the system is Linux, the present invention designs and implements a video decoding method based on an acceleration module in a Linux system, targeting the characteristics of the atlas200AI chip and combining the characteristics of hardware properties and soft decoding. In the Linux system, the present invention uses the ffmpeg soft decoding library for the first time to analyze the data received by the network, obtain the parameter frame information and data frame information in the original frame, obtain the complete image frame data packet, and transmit the decodable complete data packet to the decoder in the atlas200AI chip to complete the decoding function. DETAILED DESCRIPTION
[0074] In order to make the purpose, content, and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with embodiments.
[0075] In order to solve the video decoding problem under the Linux system, the present invention adopts a software-hardware combined decoding method based on an acceleration module. The content of the present invention is further described below. A video decoding method based on an acceleration module of the present invention comprises the following steps:
[0076] 1. Port ffmpeg to HiSilicon development board
[0077] ① First, configure the ffmpeg compilation properties, and configure parameters according to the platform type, CPU type, codec properties, format conversion properties, and cross-compilation properties;
[0078] ②Modify the acodec.h file, add the parameter frame length sei_len and array sei_buf, and determine its parameter frame size SEI_BUF_SIZE according to the application layer requirements;
[0079] ③ Add the function of obtaining the parameter frame in the decode_nal_sei_prefix function in the hevc_sei.c file: obtain the parameter size in the function, assign size to sei_len, and determine whether size is less than or equal to SEI_BUF_SIZE. If the condition is met, copy the data in the context parameter array gb to sei_buf. The length of the copy is size. The array subscript i of the copied sei_buf is the index index of the gb array divided by 8, that is, sei_buf[i]=gb_buf[index / 8];
[0080] ④Then, execute the configure command to generate the decoding dynamic libraries libavcodec, libavformat, libavutil, and libswscale in the subfolder lib of the configuration folder.
[0081] ⑤Finally, copy the decoding dynamic library to the / usr / lib path of the HiSilicon development board (decoding board). In this embodiment, the HiSilicon development board is the atlas200AI chip, which is a platform for loading the acceleration module;
[0082] 2. Create a network receiving thread to receive the original compressed image data sent by the host
[0083] ①First, obtain the receiving IP and port number information in the configuration file;
[0084] ②Then, create a network socket;
[0085] ③Secondly, clear the receiving buffer and block the receiving host from sending the original compressed image data from the network;
[0086] ④ Determine whether the length of the data received this time is greater than zero. If it is greater than zero, execute the next step, otherwise return to step 3;
[0087] ⑤ Determine whether the protocol frame header meets the protocol requirements. If not, discard the frame, otherwise proceed to the next step.
[0088] 3. Use ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing parameter frames and complete the filtering of incomplete frame data
[0089] 1) Initialize the usage environment of ffmpeg decoding dynamic library
[0090] First, the type of decoder in the acceleration module is set. In this embodiment, a HEVC (h265) type decoder is used. Then, the context of the decoder is initialized and image frame storage space is dynamically applied.
[0091] 2) Create a data packet acquisition thread and use the ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing the parameter frame of the compressed image, that is, the complete image frame data packet. The specific process is as follows:
[0092] Step 1: Get the image data array first address pointer bufPtr and data length bufLen read from the network;
[0093] Step 2: Determine whether the current data length bufLen is greater than 0. If so, proceed to the next step. If not, wait for the network to send data next time.
[0094] Step 3: Send the image data array first address pointer bufPtr and data length bufLen to the ffmpeg decoding dynamic library, and use the library function av_parser_parse2 to split the data array by frame. If a complete image frame data packet can be successfully obtained from the data array, record it and continue to the next step. If not, exit the decoding process;
[0095] Step 4: Save the data packet length ret of the image frame segmentation in the data array this time, and Array Total The length bufLen is subtracted from the length ret of the image frame data packet segmented this time, and the first address pointer bufPtr is moved forward by the number of times ret;
[0096] Step 5: Put the complete image frame data packet obtained by this segmentation into the queue to be decoded.
[0097] 4. Hard decoding based on acceleration module
[0098] Based on the acceleration module, the complete image frame data packet filtered by ffmpeg is hard decoded. The specific steps are as follows:
[0099] ① Initialize the acceleration module. The specific operations are as follows:
[0100] a. Create decoding channel properties. If the creation is successful, proceed to the next step, otherwise exit with an error;
[0101] b. Set the decoding channel ID number. If the setting is successful, proceed to the next step, otherwise an error will be reported and exit;
[0102] c. Set the decoding thread number;
[0103] d. Set the decoding channel callback function. If the setting is successful, proceed to the next step, otherwise exit with an error;
[0104] e. Set the decoding type of the decoding channel. If the setting is successful, proceed to the next step, otherwise an error will be reported and exit;
[0105] f. Set the output image format of the decoding channel. If the setting is successful, proceed to the next step, otherwise exit with an error;
[0106] g. Set the decoding channel output mode. If the setting is successful, proceed to the next step, otherwise exit with an error;
[0107] h. Create a decoding channel according to the decoding channel attributes;
[0108] ②Set the decoding callback function as follows:
[0109] a. Use the library function to obtain the normal frame output of decoding. If the result is 0, execute the next step, otherwise exit with an error;
[0110] b. Use library functions to obtain image attribute data output;
[0111] c. Use library functions to obtain the image size, width and height parameters from output;
[0112] d. Use library functions to send image data and parameter data to the host port.
[0113] ③ Obtaining a complete image frame data packet from the queue to be decoded;
[0114] ④ Send the complete image frame data packet to the decoder for decoding, as follows:
[0115] a. Use library functions to dynamically apply for image storage space;
[0116] b. Get the parameter data of the image frame from the ffmpeg decoding dynamic library (the data extracted from the parameter frame);
[0117] c. Integrate the parameter data and the filtered complete image frame data into a complete frame;
[0118] d. Create an input image stream attribute object;
[0119] e. Set the input image stream attribute object;
[0120] f. Dynamically apply for image output memory space;
[0121] g. Create an output image stream attribute object;
[0122] h. Set output image properties according to image data, size and format;
[0123] i. Send the complete frame to the decoder using the library function with the decoding channel attributes, input image stream attributes, and output image stream attributes as parameters;
[0124] j. Release the requested image output memory space;
[0125] k. Destroy the input image stream attribute object resources.
[0126] By using the above technical solution and the above operation steps, the present invention can solve the video decoding and transmission problems under the Linux system. The method has been verified by the algorithm and experimentally tested. The results show that the solution can solve the image decoding problem by using a soft decoding method to form a complete data packet containing image frames and parameter frames, and then using the chip decoder to complete the decoding process, effectively reducing the decoding time.
[0127] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A video decoding method based on an acceleration module, characterized in that: The following steps are involved: Step 1: Port ffmpeg to HiSilicon development board First, configure the ffmpeg compilation properties; then, modify the ffmpeg source code to enable it to have the function of returning parameter frames, cross-compile the ffmpeg source code, obtain the ffmpeg decoding dynamic library, and copy the ffmpeg decoding dynamic library to the HiSilicon development board, which is a platform for loading the acceleration module; Step 2: Create a network receiving thread to receive the original compressed image data sent by the host First, obtain the IP and port number information in the transmission according to the configuration file; then, create a network receiving thread to block the original compressed image data sent by the receiving host from the network; Step 3: Use the ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing the parameter frame and complete the filtering of the incomplete frame data. First, initialize the use environment of the ffmpeg decoding dynamic library; second, create a data packet acquisition thread, and use the ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing the parameter frame of the compressed image, that is, the complete image frame data packet; Step 4: Complete the hard decoding process based on the acceleration module Based on the acceleration module, the complete image frame data packet obtained after filtering using ffmpeg is hard decoded; Step 1 is as follows: ① First, configure the ffmpeg compilation properties, and configure parameters according to the platform type, CPU type, codec properties, format conversion properties, and cross-compilation properties; ②Modify the acodec.h file, add the parameter frame length sei_len and array sei_buf, and determine its parameter frame size SEI_BUF_SIZE according to the application layer requirements; ③ Add the function of obtaining the parameter frame in the decode_nal_sei_prefix function in the hevc_sei.c file: obtain the parameter size in the function, assign size to sei_len, and determine whether size is less than or equal to SEI_BUF_SIZE. If the condition is met, copy the data in the context parameter array gb to sei_buf. The length of the copy is size. The array subscript i of the copied sei_buf is the index index of the gb array divided by 8. ④Then, execute the configure command to generate the decoding dynamic libraries libavcodec, libavformat, libavutil, and libswscale in the subfolder lib of the configuration folder; ⑤Finally, copy the decoding dynamic library to the / usr / lib path of the HiSilicon development board; Step 2 is as follows: ①First, obtain the receiving IP and port number information in the configuration file; ②Then, create a network socket; ③Secondly, clear the receiving buffer and block the receiving host from sending the original compressed image data from the network; ④ Determine whether the length of the data received this time is greater than zero. If it is greater than zero, execute the next step, otherwise return to step ③; ⑤ Determine whether the protocol frame header meets the protocol requirements. If not, discard the frame, otherwise proceed to the next step; Step 3 is as follows: 1) Initialize the usage environment of ffmpeg decoding dynamic library First, set the type of decoder in the acceleration module; then initialize the context of the decoder and dynamically apply for image frame storage space; 2) Create a data packet acquisition thread and use the ffmpeg decoding dynamic library to obtain the complete compressed image data packet containing the parameter frame of the compressed image, that is, the complete image frame data packet. The specific process is as follows: Step 1: Get the image data array first address pointer bufPtr and data length bufLen read from the network; Step 2: Determine whether the current data length bufLen is greater than 0. If so, proceed to the next step. If not, wait for the network to send data next time. Step 3: Send the image data array first address pointer bufPtr and data length bufLen to the ffmpeg decoding dynamic library, and use the library function av_parser_parse2 to split the data array by frame. If a complete image frame data packet can be successfully obtained from the data array, record it and continue to the next step. If not, exit the decoding process; Step 4: Save the data packet length ret of the image frame segmentation in this data array, remove the data packet length ret of the image frame segmentation this time from the data length bufLen, and move the first address pointer bufPtr forward by the number of moves ret; Step 5: Put the complete image frame data packet obtained by this segmentation into the queue to be decoded; Step 4 is as follows: ① Initialize the acceleration module. The specific operations are as follows: a. Create the decoding channel properties. If the creation is successful, proceed to the next step. Otherwise, report an error and exit; b. Set the decoding channel ID number. If the setting is successful, proceed to the next step, otherwise an error will be reported and exit; c. Set the decoding thread number; d. Set the decoding channel callback function. If the setting is successful, proceed to the next step, otherwise exit with an error; e. Set the decoding type of the decoding channel. If the setting is successful, proceed to the next step, otherwise an error will be reported and exit; f. Set the output image format of the decoding channel. If the setting is successful, proceed to the next step, otherwise exit with an error; g. Set the decoding channel output mode. If the setting is successful, proceed to the next step, otherwise exit with an error; h. Create a decoding channel according to the decoding channel attributes; ②Set the decoding callback function as follows: a. Use the library function to obtain the normal frame output of decoding. If the result is 0, execute the next step, otherwise exit with an error; b. Use library functions to obtain image attribute data output; c. Use library functions to obtain the image size, width and height parameters from output; d. Use library functions to send image data and parameter data to the host port; ③ Obtaining a complete image frame data packet from the queue to be decoded; ④ Send the complete image frame data packet to the decoder for decoding, as follows: a. Use library functions to dynamically apply for image storage space; b. Get the parameter data of the image frame from the ffmpeg decoding dynamic library; c. Integrate the parameter data and the filtered complete image frame data into a complete frame; d. Create an input image stream attribute object; e. Set the input image stream attribute object; f. Dynamically apply for image output memory space; g. Create an output image stream attribute object; h. Set output image properties according to image data, size and format; i. Send the complete frame to the decoder using the library function with the decoding channel attributes, input image stream attributes, and output image stream attributes as parameters; j. Release the requested image output memory space; k. Destroy the input image stream attribute object resources.
2. The method according to claim 1, characterized in that The HiSilicon development board is the atlas200AI chip.
3. The method according to claim 1, characterized in that The decoder type is a HEVC (h265) type decoder.
