Video stream processing method and device, electronic equipment and storage medium
By jumping to find effective frame headers in the video stream and splicing the complete frame data, the problems of data blocking and frame loss in video stream processing in the prior art are solved, and the data processing speed and picture quality are improved.
Patent Information
- Application Number
- CN202411130416.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-11-01
AI Technical Summary
When processing high-definition video data, existing video stream processing solutions are prone to data transmission delay, data blockage, frame loss and picture quality degradation, especially when the transmission channel is unstable or data backlog.
By jumping to find valid frame headers in the video stream, quickly locate decoded video frames, reduce invalid data processing, splicing complete frame data and sending it to the decoding layer, ensuring the integrity of the data frame and the receiver can reconstruct the complete video flow.
It avoids data blocking and frame loss, improves data processing speed and frame detection accuracy, and ensures picture quality stability and video stream integrity.
Smart Images

Figure CN118890508A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the computer field, and more specifically, to a video stream processing method, device, electronic device and storage medium in the computer field. Background Art
[0002] In the current vehicle computer system, there is a core component that is used for processing and displaying real-time video streams. Usually, the video stream is captured by the vehicle camera and previewed in real time through the terminal device. The processing of video data involves splitting the video stream and transmitting the video stream to the application layer for further processing.
[0003] However, the common video stream processing solutions currently have extremely high requirements for transmission bandwidth and cache, which can easily cause data transmission delays and data blockage when processing high-definition video data. In addition, when the transmission channel is unstable or data is backlogged, it is also easy to cause frame loss and image quality degradation. Summary of the invention
[0004] The present application provides a method, device, electronic device and storage medium for processing a video stream, which can avoid problems such as data blocking, frame loss and picture quality degradation.
[0005] In a first aspect, a method for processing a video stream is provided, the method comprising: obtaining a video stream to be processed; searching for a valid frame header in the video stream to be processed in a jumpy manner; wherein the valid frame header is a frame header whose data format conforms to a preset format; in each jumpy search process, when the valid frame header is found, if it is determined that cached data exists in a data cache area, then the cached data and the data before the valid frame header are spliced into complete frame data, and the complete frame data is sent to a decoding layer for decoding and playback by the decoding layer.
[0006] The above technical solution obtains the video stream to be processed, and jumps to search for a valid frame header in the video stream to be processed. By processing the video stream to be processed in a jump search manner, it is possible to quickly locate the decodable video frame, avoid the processing of invalid data, reduce unnecessary computing resource consumption, improve the data processing speed and the accuracy of frame detection, and avoid data blocking. In the case where the valid frame header is found during each jump search, if it is determined that there is cached data in the data buffer area, the cached data and the data before the valid frame header are spliced into complete frame data, and the complete frame data is sent to the decoding layer. In the case of finding a valid frame header, the cached data and the data before the valid frame header are spliced to ensure the integrity of the data frame, and ensure that the receiving end can reconstruct a complete video stream, which can avoid frame loss and picture quality degradation. By sending the complete frame data to the decoding layer, it is convenient for the decoding layer to decode and play.
[0007] In combination with the first aspect, in certain implementations of the first aspect, jump searching for a valid frame header in the video stream to be processed includes: identifying a valid frame header in the video stream to be processed; determining a frame type corresponding to the valid frame header each time the valid frame header is identified; based on the frame type, determining a jump interval for the jump search; and according to the jump interval, jump searching for a valid frame header located after the valid frame header in the video stream to be processed.
[0008] In combination with the first aspect and the above-mentioned implementation methods, in some implementation methods of the first aspect, based on the frame type, the jump interval of the jump search is determined, including: determining the minimum frame length of the complete frame data corresponding to the frame type; and determining a preset proportion of the minimum frame length as the jump interval of the jump search.
[0009] In combination with the first aspect and the above-mentioned implementation methods, in some implementation methods of the first aspect, according to the jump interval, a valid frame header located after the valid frame header is jumped in the video stream to be processed, including: judging whether the data length of the data frame located after the valid frame header in the video stream to be processed is greater than the jump interval; if it is determined that the data length of the data frame located after the valid frame header is greater than the jump interval, then according to the determined jump interval, a valid frame header located after the valid frame header is jumped in the data frame located after the valid frame header.
[0010] In combination with the first aspect and the above-mentioned implementation methods, in certain implementation methods of the first aspect, sending the complete frame data to the decoding layer includes: determining whether the data length of the complete frame data is greater than a preset length threshold; when it is determined that the data length of the complete frame data is greater than the preset length threshold, performing secondary framing on the complete frame data to obtain at least two data frames; if the data lengths of the at least two data frames are both less than or equal to the preset length threshold, sending the at least two data frames to the decoding layer respectively.
[0011] In combination with the first aspect and the above-mentioned implementation methods, in some implementation methods of the first aspect, the complete frame data is divided into two frames to obtain at least two data frames, including: searching for a valid frame header in the complete frame data, and determining the number of frame headers corresponding to the found valid frame header; when the number of frame headers is greater than one, dividing the complete frame data into at least two data frames according to the number of frame headers.
[0012] In combination with the first aspect and the above-mentioned implementation methods, in certain implementation methods of the first aspect, after the jump search for the valid frame header in the video stream to be processed, the method also includes: if the valid frame header is not found during each jump search, if it is determined that the cache data exists in the data cache area, the data frame in the video stream to be processed that has been jump-searched is stored in the data cache area; if it is determined that the cache data does not exist in the data cache area, the data frame in the video stream to be processed that has been jump-searched is discarded; if the valid frame header is found during each jump search, if it is determined that the cache data does not exist in the data cache area, the valid frame header is stored in the data cache area.
[0013] In a second aspect, a video stream processing device is provided, which includes: an acquisition module for acquiring a video stream to be processed; a search module for jumping to search for a valid frame header in the video stream to be processed; wherein the valid frame header is a frame header whose data format conforms to a preset format; and a splicing module for finding the valid frame header during each jumping search. If it is determined that cached data exists in a data cache area, the cached data and the data before the valid frame header are spliced into complete frame data, and the complete frame data is sent to a decoding layer for decoding and playback by the decoding layer.
[0014] In combination with the second aspect, in certain implementations of the second aspect, the search module is specifically used to: identify a valid frame header in the video stream to be processed; determine the frame type corresponding to the valid frame header each time the valid frame header is identified; based on the frame type, determine a jump interval for a jump search; and according to the jump interval, jump search for a valid frame header located after the valid frame header in the video stream to be processed.
[0015] In combination with the second aspect and the above-mentioned implementation methods, in some implementation methods of the second aspect, the search unit includes a determination unit, which is specifically used to: determine the jump interval of the jump search based on the frame type, including: determining the minimum frame length of the complete frame data corresponding to the frame type; determining a preset proportion of the minimum frame length as the jump interval of the jump search.
[0016] In combination with the second aspect and the above-mentioned implementation methods, in certain implementation methods of the second aspect, the search unit is also specifically used to: determine whether the data length of the data frame located after the valid frame header in the video stream to be processed is greater than the jump interval; if it is determined that the data length of the data frame located after the valid frame header is greater than the jump interval, then according to the determined jump interval, jump-search for the valid frame header located after the valid frame header in the data frame located after the valid frame header.
[0017] In combination with the second aspect and the above-mentioned implementation methods, in some implementation methods of the second aspect, the splicing module includes a sending unit, which is specifically used to: determine whether the data length of the complete frame data is greater than a preset length threshold; when it is determined that the data length of the complete frame data is greater than the preset length threshold, perform secondary framing on the complete frame data to obtain at least two data frames; if the data lengths of the at least two data frames are both less than or equal to the preset length threshold, send the at least two data frames to the decoding layer respectively.
[0018] In combination with the second aspect and the above-mentioned implementation methods, in some implementation methods of the second aspect, the storage unit includes a frame division unit, which is specifically used to: search for a valid frame header in the complete frame data, and determine the number of frame headers corresponding to the found valid frame header; when the number of frame headers is greater than one, divide the complete frame data into at least two data frames according to the number of frame headers.
[0019] In combination with the second aspect and the above-mentioned implementation methods, in some implementation methods of the second aspect, the device also includes a second storage module, which is specifically used to: in the case where the valid frame header is not found during each jump search process, if it is determined that the cached data exists in the data cache area, then the data frame that has been jump-searched in the video stream to be processed is stored in the data cache area; if it is determined that the cached data does not exist in the data cache area, then the data frame that has been jump-searched in the video stream to be processed is discarded; in the case where the valid frame header is found during each jump search process, if it is determined that the cached data does not exist in the data cache area, then the valid frame header is stored in the data cache area.
[0020] In a third aspect, an electronic device is provided, comprising a memory and a processor. The memory is used to store executable program code, and the processor is used to call and run the executable program code from the memory, so that the electronic device executes the video stream processing method in the first aspect and any possible implementation of the first aspect.
[0021] In a fourth aspect, a computer program product is provided, comprising: a computer program code, which, when executed on a computer, enables the computer to execute the video stream processing method in the above-mentioned first aspect and any possible implementation of the first aspect.
[0022] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the video stream processing method in the above-mentioned first aspect and any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a schematic flow chart of a method for processing a video stream provided in an embodiment of the present application;
[0024] Figure 2 It is a schematic diagram of a jump search for a valid frame header provided by an embodiment of the present application;
[0025] Figure 3 It is a schematic flow chart of a method for jumping to find a valid frame header provided in an embodiment of the present application;
[0026] Figure 4 is a schematic flow chart of a method for performing secondary framing on complete frame data provided by an embodiment of the present application;
[0027] Figure 5 is a schematic flow chart of another method for processing a video stream provided in an embodiment of the present application;
[0028] Figure 6 It is a structural schematic diagram of a video stream processing device provided in an embodiment of the present application;
[0029] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0031] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0032] In the current vehicle computer system, there is a core component that is used for processing and displaying real-time video streams. Usually, the video stream is captured by the vehicle camera and previewed in real time through the terminal device. The processing of video data involves splitting the video stream and transmitting the video stream to the application layer for further processing.
[0033] However, the common video stream processing solutions currently have extremely high requirements for transmission bandwidth and cache, which can easily cause data transmission delays and data blockage when processing high-definition video data. In addition, when the transmission channel is unstable or data is backlogged, it is also easy to cause frame loss and image quality degradation.
[0034] Specifically, in the prior art, common video stream processing solutions are:
[0035] (1) Each frame is unpacked and transmitted separately: Each frame of data in the video stream is split into data packets for transmission. Each packet can be relatively small, which is easy to manage and control. In the absence of data loss or error, since the information carried by each packet is complete, the receiving end can quickly process and present it. Therefore, under the condition of "clear frame boundaries", that is, the video stream structure is orderly and there are no major network problems, this solution can efficiently utilize network resources and quickly transmit video content. However, because each frame is processed and transmitted separately, especially high-definition video, the amount of data in each frame is very large, which requires the network to have a high bandwidth to ensure real-time data transmission. Therefore, each frame of high-definition video may contain a large amount of pixel information, and the data packets split into are also large, which will not only occupy more bandwidth, but also may cause network congestion. If the data packet cannot be delivered in time, it will cause playback delays or even data blockage, affecting the continuity and viewing experience of the video.
[0036] (2) Using the frame header as the unpacking standard: When processing video or data streams, the continuous data stream is segmented according to the start identifier (i.e., frame header) of each video frame or data packet, which serves as the basis for data splitting and reassembly. Because the data is split directly based on the clear frame header information, there is no need to check the entire data stream byte by byte or bit by bit to determine the frame boundary, thereby reducing the search and verification operations when processing data and improving processing efficiency. In particular, when processing a large amount of data streams, the beginning of each independent frame can be located more quickly, making the data processing process more direct and efficient. However, in the case of an unstable network environment, data packets may not arrive at the receiving end in order, or there may be delays, disorder, packet loss, etc. If unpacking is based solely on the frame header without an additional mechanism to deal with network errors, then in the case of data packet disorder or missing frame headers, it is difficult for the receiving end to correctly identify the frame boundary, which can easily lead to data mixing. The data of adjacent frames may be mistakenly merged together, resulting in frame loss. When network congestion causes the data transmission rate to drop, and the data processing speed of the receiving end cannot keep up with the sending speed, unprocessed data will accumulate in the buffer. In a system that uses frame headers as the depacketization standard, backlogs may cause subsequent frame headers to be recognized late, further increasing the difficulty of decoding. In this case, not only will the processing delay increase, but the picture quality may also be reduced due to improper reorganization of data packets, such as screen distortion, freezes, or image distortion.
[0037] In order to solve the above technical problems, the embodiment of the present application provides a method for processing a video stream. The execution subject of the method is an electronic device, which can be used to process the video stream. For example, the electronic device can be a mobile phone, a computer, a smart TV, a vehicle computer, etc. The following is an example of applying the method for processing a video stream to a vehicle computer:
[0038] Figure 1 It is a schematic flowchart of a video stream processing method provided in an embodiment of the present application.
[0039] For example, Figure 1 As shown, the method 100 includes:
[0040] S101, obtaining a video stream to be processed.
[0041] S102, jump-searching for a valid frame header in the video stream to be processed.
[0042] The valid frame header is a frame header whose data format complies with a preset format.
[0043] S103, when the valid frame header is found during each jump search process, if it is determined that there is cached data in the data cache area, the cached data and the data before the valid frame header are spliced into complete frame data, and the complete frame data is sent to the decoding layer for decoding and playback by the decoding layer.
[0044] In an embodiment of the present application, a video stream to be processed is obtained, and a valid frame header is searched in the video stream to be processed in a jump-type manner. By processing the video stream to be processed in a jump-type search manner, it is possible to quickly locate the decodable video frame, avoid the processing of invalid data, reduce unnecessary computing resource consumption, improve the data processing speed and the accuracy of frame detection, and avoid data blocking. In the case where the valid frame header is found during each jump-type search, if it is determined that there is cached data in the data buffer area, the cached data and the data before the valid frame header are spliced into complete frame data, and the complete frame data is sent to the decoding layer. In the case where a valid frame header is found, the cached data and the data before the valid frame header are spliced, which can ensure the integrity of the data frame and ensure that the receiving end can reconstruct a complete video stream, which can avoid frame loss and picture quality degradation. By sending the complete frame data to the decoding layer, it is convenient for the decoding layer to decode and play.
[0045] Below Figure 1 The implementation method of each step in the embodiment shown is specifically described:
[0046] As for S101, it can be understood that the above-mentioned video stream to be processed can be a video stream obtained from an input buffer, wherein the input buffer is used to temporarily store a video stream received from an external source (such as a vehicle-mounted camera), which helps to smooth the input rate of the video stream and plays a buffering role.
[0047] Furthermore, after obtaining the video stream to be processed from the input buffer, relevant operations such as searching for frame headers and splicing data can be performed on the video stream to be processed, and then the data to be spliced (incomplete frame data) and valid frame headers in the video stream to be processed are temporarily stored in the data buffer area as cache data. The data buffer area is used to store the data to be spliced and valid frame headers in the video stream to be processed.
[0048] Specifically, the video stream in the input buffer may be a video stream regularly acquired from an onboard camera of the vehicle, and may include real-time road conditions during the driving of the vehicle, including road conditions ahead, traffic signs, other vehicles, pedestrians, etc.
[0049] Furthermore, the vehicle's onboard camera usually continuously outputs video streams in a specific encoding format (such as H.264, H.265). Among them, H.264 and H.265 are two widely used video encoding standards, which are mainly used to efficiently compress video data and reduce the size of video files while maintaining the quality of the video as much as possible.
[0050] Since a video stream is composed of a series of continuous image frames, each image frame is equipped with one or more frame headers when encoded. The frame header can contain metadata of the image frame, such as frame type, timestamp, resolution, and encoding parameters.
[0051] Among them, the frame type can characterize whether the frame is a key frame (I frame), a predicted frame (P frame), or a bidirectional predicted frame (B frame), which is crucial for the decoder to correctly decode and reconstruct the video sequence.
[0052] The timestamp can be used to indicate the time position of the image frame in the video stream, which helps to synchronize audio and video to achieve smooth video playback.
[0053] The resolution and encoding parameters may specifically include the width, height, bit rate, etc. of the image frame, and the decoder may correctly decode the image frame based on this information.
[0054] It is understandable that during video streaming or data reception, data usually does not arrive all at once, but flows into the input buffer in batches or continuously. As a temporary storage space, the input buffer can help smooth the data flow, avoid network delays or uneven data arrival problems, and ensure the continuity and stability of data processing.
[0055] However, the data received by the input buffer is usually an unprocessed, mixed video stream, including valid video frame data and possible noise, invalid data fragments, etc. In order to reduce the subsequent processing burden, the data entering the input buffer can be initially screened, that is, quickly identifying and filtering out those data segments that obviously do not contain valid information or do not conform to the expected format.
[0056] Exemplarily, the video stream acquired in real time from the vehicle-mounted camera is received. Since these video streams adopt a specific encapsulation format (such as H.264 and H.265 mentioned above), the acquired video stream can be decomposed into a series of frames (including I frames, P frames, B frames, etc.) through the decapsulation module. Then, each frame of data is preliminarily screened, specifically, it can be checked whether there is a valid frame header for each frame of data, and the integrity of the data frame, the timing logic of the data frame, and whether there is severe noise in the data frame can be verified. According to the above screening conditions, the data frames that do not meet the requirements (such as data frames that do not contain valid frame headers, damaged data frames, disordered or repeated data frames, and data frames with severe noise) are directly discarded or marked as invalid frames to avoid occupying storage resources and subsequent processing time.
[0057] Furthermore, after the video stream obtained in real time from the vehicle-mounted camera is preliminarily screened, the video stream after the preliminarily screening can be stored in an input buffer, and the video stream to be processed can be obtained from the input buffer later.
[0058] As for the above S102, it can be understood that, as mentioned above, each image frame is equipped with a frame header when being encoded, and the above valid frame header specifically refers to a data segment in the video stream whose structure and content conform to a pre-defined specification or standard, that is, a frame header whose data format conforms to a preset format. By screening out the valid frame header, it can be ensured that the receiving end correctly identifies and processes the subsequent data of the image frame.
[0059] The above preset format can be set according to actual needs. For example, in H.264, the start of a NAL unit (network abstraction layer unit) may be identified by a specific byte sequence such as 0x00 0x00 0x000x01, and the above preset format can be set to "0x00 0x00 0x00 0x01". If the preset format is "0x00 0x00 0x00 0x01", the frame header with the format of "0x00 0x00 0x00 0x01" in the video stream to be processed is a valid frame header.
[0060] The above-mentioned "jump search for valid frame headers" means that when processing the video stream to be processed, according to a predetermined jump interval, the current position is directly jumped to the end position of the jump search, that is, the checkpoint position, and the valid frame headers in the video stream to be processed are traversed from the checkpoint position. The distance between the current position and the checkpoint position is the above-mentioned jump interval.
[0061] Since a video stream is composed of a large number of image frames, which may contain multiple types of image frames, it would be very time-consuming to directly traverse each byte or image frame one by one. Based on this, a valid frame header can be searched in a jump manner in the video stream to be processed.
[0062] Furthermore, the jump search for valid frame headers usually requires first determining the jump interval, which can usually be determined based on the data length of the complete frame data. The jump interval defines starting from the currently known valid frame header position, skipping a preset length of data (the preset length is equal to the jump interval), and directly starting from the jump end position to search for the valid frame header in the video stream to be processed.
[0063] Data frames of different frame types also have greatly different data lengths. For example, the data length of an I frame is usually longer than that of a P frame and a B frame.
[0064] Based on this, when a valid frame header is identified, the frame type of the valid frame header can be determined, and based on the frame type, the jump interval of the jump search can be determined.
[0065] In one possible implementation, a jump search for a valid frame header in the video stream to be processed includes: identifying a valid frame header in the video stream to be processed; determining a frame type corresponding to the valid frame header each time the valid frame header is identified; determining a jump interval for the jump search based on the frame type; and jumping searching for a valid frame header located after the valid frame header in the video stream to be processed according to the jump interval.
[0066] It is understandable that after obtaining the video stream to be processed, a valid frame header may be first identified in the video stream to be processed, that is, a deep traversal is performed in order to search for the valid frame header.
[0067] When the valid frame header is identified, the frame type corresponding to the valid frame header may be determined based on the frame header data.
[0068] Exemplarily, the frame header data corresponding to the I frame is: 0x00 0x00 0x00 0x01 0x65; the frame header data corresponding to the P frame is: 0x00 0x00 0x00 0x01 0x21; the frame header data corresponding to the PPS frame is: 0x00 0x00 0x000x01 0x68; the frame header data corresponding to the SPS frame is: 0x00 0x00 0x00 0x01 0x67.
[0069] It can be understood that the frame type of the data frame can be determined based on the sixth byte of the data frame.
[0070] Furthermore, after determining the frame type corresponding to the valid frame header through the frame header data, the jump interval for jumping backward from the valid frame header position can be determined based on the frame type, and then the data frame with a preset data length (the preset data length is equal to the jump interval) can be skipped according to the jump interval, and the search for other valid frame headers can be started at the end position of the jump.
[0071] It can be understood that according to the determined jump interval, it moves directly to the vicinity of the checkpoint position and starts to find and process the valid frame header from there. Doing so can significantly reduce the time for processing a large amount of useless data and improve the processing speed, especially when processing long videos or high frame rate videos.
[0072] In some embodiments, there are some frame types whose corresponding complete frame data lengths are relatively short. If the frame type corresponding to the identified valid frame header belongs to the above frame types, there is no need to jump to search for the valid frame header, and the valid frame headers after the valid frame header in the video stream to be processed can be directly traversed in sequence.
[0073] For example, for PPS frames (Picture Parameter Set) and SPS frames (Sequence Parameter Set), since the frame length of PPS frames and SPS frames is usually very small and may not exceed 30 bits, they usually do not cause a significant burden on data processing. Therefore, the processing speed of these frames is very fast, and there is no need to perform a jump search for valid frame headers. If it is determined that the frame type corresponding to the currently identified valid frame header is a PPS frame or an SPS frame, the valid frame headers located after the valid frame header in the video stream to be processed can be directly traversed in order.
[0074] In some embodiments, after determining the frame type of the valid frame header, it can be determined whether the complete frame data corresponding to the frame type has been obtained. If the complete frame data corresponding to the frame type has been obtained, then based on the data length of the complete frame data corresponding to the frame type, the jump interval for searching for the valid frame header backward from the valid frame header is determined, and based on the jump interval, the valid frame header located after the valid frame header is searched in the video stream to be processed in a jump manner; if the complete frame data corresponding to the frame type has not been obtained, then the valid frame header is searched for in depth from the valid frame header in order.
[0075] It is understandable that the complete frame data corresponding to the frame type of the above-mentioned valid frame header can be the complete frame data of the frame type obtained in the video stream to be processed before the current jump search for the valid frame header. Among them, the data between the current valid frame header and the next valid frame header can constitute a complete frame data.
[0076] The above method determines the frame type corresponding to the valid frame header each time a valid frame header is identified in the video stream to be processed. If the complete frame data of the frame type has been obtained before the valid frame header is identified, a jump interval can be determined according to the data length of the complete frame data of the frame type, so as to jump to search for the valid frame header located after the valid frame header in the video stream to be processed. By jumping to search, the number of traversals of the video stream can be reduced, especially for data with basic length information of the known frame type, which can significantly improve the processing efficiency. For frame types that have not been processed, a sequential traversal method is used to search for the valid frame header after the valid frame header, which can ensure that no frame data is missed, thereby ensuring the integrity of the data.
[0077] Exemplarily, if complete frame data corresponding to the frame type has been obtained, the data length of the complete frame data corresponding to the frame type can be obtained, the average frame length of the complete frame data corresponding to the frame type can be determined, and the jump interval of the jump search can be determined based on the average frame length.
[0078] For example, if it is determined that the average frame length of the complete frame data corresponding to the frame type is 1500 bytes, half of the average frame length may be determined as the jump interval, that is, 750 bytes may be used as the jump interval.
[0079] In order to find as many valid frame headers as possible during the jump search process, the jump interval of the jump search can also be determined according to the minimum frame length of the complete frame data corresponding to the frame type.
[0080] In a possible implementation, based on the frame type, determining the jump interval of the jump search includes: determining the minimum frame length of the complete frame data corresponding to the frame type; and determining a preset ratio of the minimum frame length as the jump interval of the jump search.
[0081] It can be understood that, as mentioned above, the complete frame data corresponding to the above frame type can be the complete frame data belonging to the frame type obtained in the video stream to be processed before the current jump search for the valid frame header is performed.
[0082] In some embodiments, during processing of the video stream to be processed, after each splicing to obtain complete frame data, the frame type corresponding to the complete frame data and the frame length corresponding to the complete frame data can be counted, and statistical information related to the frame type and frame length can be stored.
[0083] Furthermore, when a valid frame header is identified, the frame type corresponding to the valid frame header can be determined, and based on the stored statistical information, the minimum frame length of the complete frame data corresponding to the frame type can be determined, and a preset proportion of the minimum frame length can be determined as the jump interval of the jump search.
[0084] The preset ratio may be set according to actual needs. For example, in order to find as many valid frame headers as possible, the preset ratio may be set to 75%, and 75% of the minimum frame length may be determined as the jump interval.
[0085] Exemplarily, when a valid frame header is identified, the frame type corresponding to the valid frame header is obtained. If the frame type is an I frame, the minimum frame length corresponding to the I frame is determined to be 1000 bytes. If the preset ratio is 75%, the data length of 750 bytes can be determined as the jump interval for searching for the valid frame header backward from the valid frame header.
[0086] In order to reduce storage space, only the minimum frame length and average frame length of the complete frame data corresponding to the frame type may be stored.
[0087] It can be understood that since the above-mentioned jump interval is determined based on the minimum frame length of the complete frame data corresponding to the frame type, when the minimum frame length of the complete frame data corresponding to the frame type changes, the jump interval determined based on the frame type may also change, that is, the above-mentioned jump interval changes dynamically.
[0088] Exemplarily, if the frame length of the complete frame data corresponding to the I frame obtained for the first time is 1000 bytes, it is determined that the minimum frame length corresponding to the I frame is 1000 bytes and the average frame length is 1000 bytes, and the minimum frame length and the average frame length are stored. If the frame length of the complete frame data corresponding to the I frame obtained for the second time is 800 bytes, since the frame length of the complete frame data corresponding to the I frame obtained for the second time is smaller than the previously stored minimum frame length, the average frame length of the complete frame data has also changed, and the current minimum frame length and average frame length can be updated, that is, the minimum frame length corresponding to the updated I frame is determined to be 800 bytes and the average frame length is 900 bytes. In the case of identifying a valid frame header of the frame type as an I frame, the jump interval can be determined based on the minimum frame length corresponding to the current I frame.
[0089] The above method can dynamically determine the jump interval, especially when a valid frame header is identified, the frame type corresponding to the valid frame header can be determined, and based on the specific information of the complete frame data corresponding to the frame type that has been obtained (such as the minimum frame length), the jump interval of the current jump search for the valid frame header from the valid frame header can be determined, which can more accurately skip unnecessary data checks and directly locate the next possible frame header position to start searching for the valid frame header. Compared with the method of indiscriminate traversal or fixed jump length, this method significantly improves the efficiency of video stream processing, especially when processing large amounts of video data, reducing processing time and resource consumption.
[0090] In one possible case, the stored statistical information does not include the minimum frame length corresponding to the frame type of a certain valid frame header, indicating that the complete frame data corresponding to the frame type has not been obtained before, and the minimum frame length corresponding to the frame type cannot be determined. The minimum frame length corresponding to the frame type is 0, and then it can be determined that the jump interval of the jump search from the valid frame header backward is 0. In other words, no jump search is performed backward from the valid frame header, but the valid frame headers located after the valid frame header in the video stream to be processed are traversed in order.
[0091] In some embodiments, a valid frame header is identified in the video stream to be processed. If the identified frame header is the first valid frame header in the video stream to be processed, it means that the valid frame header has not been found before and the complete frame data has not been obtained before. In this case, the jump interval of the jump search is determined to be 0, that is, the jump search is not performed, and the valid frame headers after the first valid frame header in the video stream to be processed are traversed in sequence.
[0092] Furthermore, if the identified frame header is the first valid frame header in the video stream to be processed, the first valid frame header can be stored in the data cache area, and the second valid frame header in the video stream to be processed can be traversed in depth. When the second valid frame header is identified, the data between the first valid frame header and the second valid frame header are spliced into complete frame data, and the frame type, minimum frame length and average frame length corresponding to the complete frame data are counted, and the frame type, minimum frame length and average frame length are saved as statistical information.
[0093] It can be understood that the complete frame data obtained by splicing the data between the first valid frame header and the second valid frame header is the complete frame data corresponding to the first valid frame header, and the frame type corresponding to the complete frame data is consistent with the frame type corresponding to the first valid frame header. For example, if the frame type corresponding to the first valid frame header is an I frame, after obtaining the complete frame data corresponding to the first frame header, the minimum length and average length of the complete frame data corresponding to the I frame can be counted, and the minimum length and average length of the complete frame data corresponding to the I frame can be saved as statistical information.
[0094] Furthermore, when the second valid frame header is identified, the frame type corresponding to the second valid frame header may be determined, and based on the frame type, the jump interval of the jump search may be determined.
[0095] Exemplarily, if the frame type corresponding to the second valid frame header is an I frame, since the complete frame data corresponding to the I frame has been obtained as mentioned above, the minimum frame length of the complete frame data corresponding to the I frame can be determined, and the minimum frame length of a preset proportion can be determined as the jump interval of the jump search.
[0096] If the frame type corresponding to the second valid frame header is a P frame, and the complete frame data corresponding to the P frame has not been obtained before, it can be determined that the jump interval of the jump search is 0, that is, the jump search is not performed, and the valid frame headers located after the first valid frame header in the video stream to be processed are traversed in order.
[0097] By analogy, each time a valid frame header is identified, the frame type corresponding to the valid frame header can be determined first, and then based on the frame type, the jump interval of the jump search can be determined.
[0098] Specifically, if the complete frame data corresponding to the frame type has not been obtained before, the jump interval for jumping backward from the valid frame header is determined to be 0; if the complete frame data corresponding to the frame type has been obtained before, the minimum frame length of the complete frame data corresponding to the frame type is obtained, and the minimum frame length of a preset proportion is determined as the jump interval for jumping backward from the valid frame header.
[0099] For example, Figure 2As shown, a valid frame header is identified in the video stream 200 to be processed (obtained from the input buffer). If the first valid frame header is identified at position X, it is determined that the frame type corresponding to the first valid frame header is an I frame. As described above, since the first valid frame header in the video stream to be processed is identified, it means that no valid frame header has been found before, and no complete frame data has been obtained before. Therefore, it can be determined that the jump interval of the jump search is 0, that is, the jump search is not performed, and the valid frame headers after the first valid frame header in the video stream to be processed are traversed in order.
[0100] Furthermore, when the first valid frame header is identified, the first valid frame header can be stored in the data buffer area, and then the valid frame header is continuously searched in the to-be-processed video stream 200 starting from the position X where the first valid frame header is located. If the second valid frame header is found at position A, the data between position X and position A are spliced into complete frame data (the complete frame data is the complete frame data corresponding to the first frame header), the frame type, minimum frame length and average frame length of the complete frame data are counted, and the frame type, minimum frame length and average frame length are saved as statistical information. Specifically, the saved statistical information can be: the minimum frame length corresponding to the I frame is 1000 bytes, and the average frame length is 1000 bytes.
[0101] Since the second valid frame header is found at position A, the frame type corresponding to the second valid frame header can be determined. If it is determined that the frame type corresponding to the second valid frame header is a P frame, since the complete frame data corresponding to the P frame has not been obtained before, it can be determined that the jump interval of this jump search is 0, that is, the jump search is not performed, and the valid frame headers located after the second valid frame header in the video stream to be processed are traversed in order.
[0102] Starting from position A where the second valid frame header is located, continue searching for a valid frame header in the video stream 200 to be processed. If the third valid frame header is found at position B, the data between position A and position B are spliced into complete frame data (the complete frame data is the complete frame data corresponding to the second valid frame header), and the frame type, minimum frame length and average frame length of the complete frame data are counted. The frame type, minimum frame length and average frame length are saved as statistical information. The saved statistical information may specifically be: the minimum frame length corresponding to the P frame is 500 bytes, and the average frame length is 500 bytes.
[0103] Since the third valid frame header is found at position B, the frame type corresponding to the third valid frame header can be determined. If the frame type corresponding to the third valid frame header is determined to be a P frame, the minimum frame length of the complete frame data corresponding to the frame type can be determined to be 500 bytes. If the preset ratio is 75%, 375 bytes are used as the jump interval for searching for valid frame headers backward from position B, that is, the jump interval 1 corresponding to the P frame is determined to be 375 bytes.
[0104] Then, starting from position B, a valid frame header is searched in a jump manner in the video stream 200 to be processed according to a jump interval of 1. Specifically, the video stream 200 can be directly jumped to position C, and a valid frame header is searched in the video stream 200 to be processed from position C. The data between position B and position C can be temporarily stored in the data buffer as data to be spliced.
[0105] If the fourth valid frame header is identified at position D in the video stream 200 to be processed, it is determined whether there is cached data in the data cache area. If there is cached data in the data cache area, the cached data is spliced with the data before the fourth valid frame header (i.e., the data between position B and position D) to obtain complete frame data (the complete frame data is the complete frame data corresponding to the third valid frame header). Then, the frame type, minimum frame length, and average frame length of the complete frame data are counted.
[0106] Since the frame type corresponding to the third valid frame header is also a P frame, which is consistent with the frame type corresponding to the second valid frame header, if it is determined that the data length of the complete frame data corresponding to the third valid frame header is 400 bytes, it means that the data length of the complete frame data corresponding to the P frame obtained for the second time is smaller than the minimum frame length corresponding to the previously stored P frame, and the average frame length of the complete frame data corresponding to the P frame has also changed. The currently stored statistical information can be updated and the updated statistical information can be saved. Specifically, the updated statistical information can be: the minimum frame length corresponding to the P frame is 400 bytes, and the average frame length is 450 bytes.
[0107] Furthermore, since the fourth valid frame header is found at position D, the frame type corresponding to the fourth valid frame header can be determined. If the frame type corresponding to the fourth valid frame header is an I frame, the minimum frame length of the complete frame data corresponding to the frame type can be determined to be 1000 bytes. If the preset ratio is 75%, 750 bytes are used as the jump interval for searching for valid frame headers backward from position A, that is, the jump interval 2 corresponding to the I frame is determined to be 750 bytes.
[0108] Then, starting from position D, a valid frame header is searched in a jump manner in the video stream 200 to be processed according to a jump interval of 2. Specifically, the video stream 200 can be directly jumped to position E, and a valid frame header is searched in the video stream 200 to be processed from position E. The data between position D and position E can be temporarily stored in the data buffer as data to be spliced.
[0109] If the fifth valid frame header is identified at position F in the video stream to be processed 200, it is determined whether there is cached data in the data cache area. If there is cached data in the data cache area, the cached data is spliced with the data before the fifth valid frame header (i.e., the data between position D and position F) to obtain complete frame data (the complete frame data is the complete frame data corresponding to the fourth valid frame header). Then, the frame type, minimum frame length, and average frame length of the complete frame data are counted.
[0110] Since the frame type corresponding to the fourth valid frame header is also an I frame, which is consistent with the frame type corresponding to the first valid frame header, if it is determined that the data length of the complete frame data corresponding to the fourth valid frame header is 800 bytes, it means that the data length of the complete frame data corresponding to the I frame obtained for the second time is smaller than the minimum frame length corresponding to the previously stored I frame, and the average frame length of the complete frame data corresponding to the I frame has also changed. The currently stored statistical information can be updated and the updated statistical information can be saved. The updated statistical information saved can specifically be: the minimum frame length corresponding to the I frame is 800 bytes, and the average frame length is 900 bytes.
[0111] Furthermore, since the fifth valid frame header is found at position F, the frame type corresponding to the fifth valid frame header can be determined. If the frame type corresponding to the fifth valid frame header is a P frame, the minimum frame length of the complete frame data corresponding to the frame type can be determined to be 400 bytes. If the preset ratio is 75%, 300 bytes are used as the jump interval for searching for valid frame headers backward from position F, that is, the jump interval 3 corresponding to the P frame is determined to be 300 bytes.
[0112] With position F as the jump starting point of the jump search, the valid frame header located after position F is jumped in the video stream 200 to be processed according to the jump interval 3. If the data length between position F and the end position of the video stream to be processed is less than the jump interval 3, the jump search cannot be performed, and the data frame that cannot be jumped can be temporarily stored in the data buffer area.
[0113] In the above process, each time a complete frame of data is obtained, the obtained complete frame of data can be sent to the decoding layer for decoding and playback by the decoding layer, and the data in the data buffer area is cleared, and only the valid frame header found this time is stored.
[0114] Furthermore, after the frame type of the valid frame header is determined and the jump interval is determined based on the frame type, the valid frame header following the valid frame header can be searched in a jump manner in the video stream to be processed according to the determined jump interval.
[0115] In one possible implementation, according to the jump interval, a jump search is performed in the video stream to be processed for a valid frame header that follows the valid frame header, including: determining whether the data length of the data frame that follows the valid frame header in the video stream to be processed is greater than the jump interval; if it is determined that the data length of the data frame that follows the valid frame header is greater than the jump interval, then according to the determined jump interval, a jump search is performed in the data frames that follow the valid frame header for a valid frame header that follows the valid frame header.
[0116] It can be understood that when performing a jump search for a valid frame header in the data frame located after the valid frame header, if the data length of the data frame located after the valid frame header is greater than the jump interval, it means that the data frame located after the valid frame header may contain data from multiple frames. In this case, a jump search can be adopted starting from the currently known frame header position, skipping part of the data according to the length of the jump interval, and directly starting from the end position of the jump and searching backward for the next valid frame header.
[0117] If the data length of the data frame after the valid frame header is less than or equal to the jump interval, it means that the remaining data length of the video stream to be processed is not enough to be processed by the jump search. In this case, the data frame after the valid frame header can be directly stored in the data buffer area, waiting to splice the data frame after the valid frame header with the valid frame header in the next segment of the video stream to be processed into a complete frame data.
[0118] Since the video stream to be processed is obtained from the input buffer, the storage capacity of the input buffer is limited. The length of the unprocessed data frames in the video stream to be processed, i.e., the remaining data length, can be determined based on the storage capacity of the input buffer and the length of the processed data frames.
[0119] For example, Figure 2 As shown, the data length of the data frame from position F in the video stream to be processed to the end position of the video stream to be processed is less than the jump interval, and it is determined that the segment of data frames cannot be searched by jumping, so the segment of data frames that cannot be searched by jumping is directly stored in the data buffer area.
[0120] Exemplarily, in combination with the above embodiment, the implementation method of jumping to find the valid frame header can be as follows: Figure 3 As shown:
[0121] S301, obtaining a video stream to be processed.
[0122] It is understandable that this step is Figure 1 S101 in the description will not be described in detail here.
[0123] S302, determining whether there is cached data in the data cache area.
[0124] It is understandable that, as described above, after obtaining the video stream to be processed, the video stream to be processed will be deeply traversed to find a valid frame header, and when a valid frame header is found in the video stream to be processed, the valid frame header will be temporarily stored in the data buffer area.
[0125] Based on this, if there is no cached data in the data cache area, it means that no valid frame header was found during the in-depth traversal in the video stream to be processed, resulting in no cached data in the cache area, that is, there is no valid frame header in the video stream to be processed, then the video stream to be processed can be discarded, that is, execute S303; and if there is cached data in the data cache area, it means that a valid frame header was found before, and a valid frame header is stored in the data cache area, then the valid frame header can continue to be identified, and when a valid frame header is identified, the frame type corresponding to the valid frame header is determined, and based on the frame type, the jump interval of the jump search is determined, that is, execute S304.
[0126] S303: discard the data.
[0127] S304, identifying a valid frame header, and when a valid frame header is identified, determining a frame type corresponding to the valid frame header, and determining a jump interval based on the frame type.
[0128] It is understandable that, as described above, the frame type of the valid frame header is first determined, then the minimum data length of the complete frame data corresponding to the frame type, i.e. the minimum frame length, is determined, and the preset proportion of the minimum data length is determined as the jump interval of the jump search.
[0129] S305, determining whether the data length of the data frame following the valid frame header in the video stream to be processed is greater than the jump interval.
[0130] It can be understood that, as described above, if the data length of the data frame located after the valid frame header in the video stream to be processed is greater than the jump interval, it means that the valid frame header can continue to be searched in the segment of data frames in a jump manner, that is, S306 is executed; if the data length of the data frame located after the valid frame header in the video stream to be processed is less than or equal to the jump interval, it means that the data length of the segment of data frames is insufficient for jump search, and the segment of data frames can be directly stored in the data buffer area, that is, S307 is executed.
[0131] S306: Search for a valid frame header in a jump manner in the data frame following the valid frame header according to the jump interval.
[0132] S307, storing the data frame after the valid frame header into the data buffer area.
[0133] Furthermore, in the case that the data length of the data frame following the valid frame header is greater than the jump interval, the valid frame header may be searched for in a jump manner in the data frame following the valid frame header according to the jump interval.
[0134] In one possible situation, when performing a jump search in a data frame after the valid frame header based on the jump interval, the valid frame header may be skipped due to an excessively large jump range, resulting in failure to find the valid frame header in this jump search.
[0135] Furthermore, for the data for which no valid frame header is found, it can be determined whether to retain the data or discard the data according to the cache status in the data cache area.
[0136] In one possible implementation, after the jump search for a valid frame header in the video stream to be processed, the method further includes: if the valid frame header is not found during each jump search, if it is determined that the cache data exists in the data cache area, then the data frame in the video stream to be processed that has been jump-searched is stored in the data cache area; if it is determined that the cache data does not exist in the data cache area, then the data frame in the video stream to be processed that has been jump-searched is discarded.
[0137] It can be understood that the data frame subjected to the jump search refers to the data frame located between the starting position of the jump search and the end position of the video stream to be processed during the jump search.
[0138] If there is previously stored data in the data buffer, it means that a valid frame header may have been found and stored before this processing process, and this data frame, that is, the data frame that has been searched in the above-mentioned video stream to be processed, can be temporarily stored in the data buffer. Since this data frame may be a continuation of an incomplete frame or the beginning of the next valid frame header, storing this data frame in the data buffer can further analyze the cached data through subsequent processing to try to recover or locate the valid frame header.
[0139] If there is no cached data in the data buffer, it means that no valid frame header or data fragment has been cached before, and the currently processed data frame may be at the beginning of the video stream, or the previous processing has completed the search for valid frame headers in the video stream to be processed and the data buffer has been cleared. In this case, you can choose to discard the current part of the data frame to avoid useless data occupying resources.
[0140] Furthermore, when it is determined that a valid frame header is found, it is also possible to determine how to perform subsequent processing based on the cache status in the data cache area.
[0141] In one possible implementation, after the jump search for a valid frame header in the video stream to be processed, the method further includes: when the valid frame header is found during each jump search, if it is determined that the cached data does not exist in the data cache, then the valid frame header is stored in the data cache.
[0142] It can be understood that if a valid frame header is found, it is possible to check whether there is cached data in the data cache area. If there is no cached data, the valid frame header can be stored in the data cache area first, so that the key data frame start information can be retained, which is convenient for subsequent combination with other data to form a complete frame data.
[0143] If there is cached data in the data cache area, the cached data can be spliced with the data before the valid frame header to obtain complete frame data.
[0144] For the above S103, it can be understood that "jump search each time" means that when processing the video stream to be processed, each time according to a predetermined jump interval, it jumps from the current position to the next checkpoint position, and starts to search for a valid frame header from the checkpoint position (for example, Figure 2 In the example, the video stream jumps from position B to position C, and searches for a valid frame header backward from position C), until the end of the video stream to be processed is found or a valid frame header is found. As mentioned above, the jump interval changes dynamically, and the jump interval corresponding to each jump search may be different.
[0145] As mentioned above, the end point position of each jump search is specifically the checkpoint position during the jump search in the video stream to be processed, that is, the search for the valid frame header starts from the checkpoint position.
[0146] "Finding a valid frame header" can be understood as jumping from the current position to the next checkpoint position according to the predetermined jump interval, and finding a valid frame header in the process of searching backward from the next checkpoint position. Figure 2 According to the predetermined jump interval 1, it jumps from position B to position C, starts to search backward from position C for a valid frame header, and finds a valid frame header at position D, then it can be considered that a valid frame header is found at position D.
[0147] When searching for a valid frame header in a video stream to be processed in a jump manner, a portion of the video data may have been processed before, and a portion of the video data that failed to form a complete frame may be stored in the data buffer.
[0148] Based on this, when a valid frame header is found in the video stream to be processed, if there is cached data in the data buffer area, the cached data can be spliced with the data before the found valid frame header to form complete frame data.
[0149] It can be understood that the data before the valid frame header may specifically be data between the starting position of the jump search and the position where the valid frame header is located.
[0150] Further, after obtaining the complete frame data, the complete frame data can be sent to the decoding layer for the decoding layer to decode and play the complete frame data. Then the data buffer area can be cleared, and the valid frame header found this time can be stored in the data buffer area, so as to facilitate the subsequent use of the valid frame header to splice the complete frame data.
[0151] In some embodiments, as described above, after obtaining the complete frame data, statistical information of the complete frame data may also be determined, such as the frame type of the complete frame data, the minimum frame length corresponding to the frame type, and the average frame length, etc. Then, the currently stored statistical information is replaced with the statistical information determined this time, so that during the next jump search, the jump interval of the next jump search is determined according to the statistical information determined this time.
[0152] Since the valid frame header is found by jumping search, there may be a situation where there are multiple valid frame headers in the obtained complete frame data. If there are multiple valid frame headers in a certain section of complete frame data, the data length of the complete frame data may be longer. Based on this, the data length of the complete frame data can be obtained, and it can be determined whether the complete frame data needs to be reframed.
[0153] In one possible implementation, the complete frame data is sent to the decoding layer, including: determining whether the data length of the complete frame data is greater than a preset length threshold; if it is determined that the data length of the complete frame data is greater than the preset length threshold, performing secondary framing on the complete frame data to obtain at least two data frames; if the data lengths of the at least two data frames are both less than or equal to the preset length threshold, sending the at least two data frames to the decoding layer respectively.
[0154] Exemplarily, the above-mentioned preset length threshold can be set according to actual needs. For example, the frame type of the complete frame data can be determined, and based on the stored statistical information, the maximum length of the complete frame data corresponding to the frame type can be determined, and the maximum length can be used as the preset length threshold.
[0155] In some embodiments, the frame type of the complete frame data may be determined, and then based on the stored statistical information corresponding to the frame type, the average length corresponding to the frame type may be determined, and a preset proportion of the average frame length may be determined as a preset length threshold.
[0156] It is understandable that the above preset ratio can be set according to actual needs. In order to avoid missing a valid frame header, the preset ratio can be set to 150%, and the preset length threshold can be determined to be 150% of the average length.
[0157] Furthermore, if it is determined that the data length of the complete frame data is less than or equal to a preset length threshold, it means that the complete frame data may not have multiple valid frame headers, and the complete frame data can be directly sent to the decoding layer.
[0158] On the contrary, if it is determined that the data length of the complete frame data is greater than the preset length threshold, it means that there may be multiple valid frame headers in the complete frame data. If the complete frame data is directly transmitted, it may cause the loss of frame data. Based on this, the complete frame data can be divided into two frames to obtain at least two data frames.
[0159] It can be understood that the secondary framing is equivalent to continuing to search for a valid frame header in the complete frame data and dividing the complete frame data at the position of the valid frame header to obtain at least two data frames.
[0160] Furthermore, it is possible to continue to determine whether the data length of the at least two data frames obtained is less than or equal to a preset length threshold. If it is determined that the data length of the at least two data frames is less than or equal to the preset length threshold, the at least two data frames can be stored in the data buffer area.
[0161] If the data lengths of the at least two data frames are still greater than the preset length threshold, the at least two data frames may continue to be divided into frames until the data lengths of the divided data frames are less than or equal to the preset length threshold.
[0162] As mentioned above, if the data length of the complete frame data is greater than the preset length threshold, there may be multiple valid frame headers in the complete frame data. The valid frame header can be further searched in the complete frame data, and when a valid frame header is found, the complete frame data can be framed.
[0163] In one possible implementation, the complete frame data is divided into two frames to obtain at least two data frames, including: searching for a valid frame header in the complete frame data, and determining the number of frame headers corresponding to the found valid frame header; when the number of frame headers is greater than one, dividing the complete frame data into at least two data frames according to the number of frame headers.
[0164] It is understandable that, as described above, if it is determined that the complete frame data needs to be reframed, it means that there may be multiple valid frame headers in the complete frame data. Then, the valid frame headers can be searched in the complete frame data, and the number of frame headers corresponding to the found valid frame headers can be counted.
[0165] In some embodiments, a valid frame header may be searched in the complete frame data by binary search.
[0166] It can be understood that the above-mentioned dichotomy method refers to searching for the target value by continuously halving the search range until the target value is found or it is determined that the target value does not exist.
[0167] Specifically, searching for a valid frame header in the complete frame data by binary search may be to first find the middle position of the complete frame data, that is, the position of half the data length of the complete frame data, and then check whether there is a valid frame header at the middle position. If there is no valid frame header at the middle position, continue to reduce the search range by half until a valid frame header is found or the search interval cannot be reduced.
[0168] Furthermore, if the number of frame headers corresponding to the found valid frame header is 1, it means that there is only one valid frame header in the complete frame data, and there is no need to perform secondary framing on the complete frame data.
[0169] If the number of frame headers exceeds 1, it means that there are multiple valid frame headers in the complete frame data, and the complete frame data can be divided into frames according to the number of frame headers.
[0170] Specifically, when it is determined that there are multiple valid frame headers, the complete frame data is divided into at least two independent data frames according to the position of each valid frame header. Each divided data frame starts from a valid frame header and ends before another valid frame header, so that each divided data frame can be guaranteed to be an independent and decodable video frame unit.
[0171] It is understandable that, according to the number of frame headers, the complete frame data can be divided into data frames whose number is the same as the number of frame headers. For example, if the number of frame headers is n, the complete frame data can be divided into n data frames, where n is a positive integer.
[0172] Exemplarily, if two valid frame headers are found in the complete frame data, the complete frame data may be divided into two data frames according to the two valid frame headers.
[0173] Exemplarily, in combination with the above embodiment, the implementation method of performing secondary framing on the complete frame data can be as follows: Figure 4 As shown:
[0174] S401, obtaining the data length of the complete frame data.
[0175] S402, determining whether the data length of the complete frame data is greater than 1.5 times the average frame length.
[0176] It is understandable that 1.5 times of the above average frame length is the preset length threshold mentioned above. The above average frame length is the average data length of the frame type corresponding to the complete frame data determined based on the stored statistical information.
[0177] For example, if the data length is greater than 1.5 times the average frame length, it means that there may be multiple valid frame headers in the complete data frame, and the complete frame data needs to be divided into two frames, that is, execute S403; if the data length is less than or equal to 1.5 times the average frame length, the complete frame data can be stored in the data cache area, that is, execute S406.
[0178] S403, searching for a valid frame header in the complete frame data by using a binary search method.
[0179] It is understandable that the method of searching for a valid frame header in the complete frame data by binary division can refer to the content described above, and will not be described in detail here.
[0180] S404, determining whether the number of found valid frame headers is greater than 1;
[0181] Exemplarily, if the number of frame headers is greater than 1, it means that there are multiple valid frame headers in the complete frame data, and the complete frame data can be framed according to the frame header data, that is, executing S405; if the number of frame headers is equal to 1, it means that there is only 1 valid frame header in the complete frame data, and there is no need to frame the complete frame data, that is, executing S406.
[0182] S405, splitting the complete frame data into frame data whose number is the same as the number of frame headers.
[0183] It is understandable that if the number of frame headers is n, the complete frame data can be divided into n data frames, where n is a positive integer. After the complete frame data is divided into data frames whose number is consistent with the number of frame headers, the divided data frames are sent to the decoding layer, that is, S406 is executed.
[0184] S406, sending to the decoding layer.
[0185] The above method can quickly filter out complete frame data that is too long and perform secondary framing on the complete frame data by presetting a length threshold (for example, setting it to 1.5 times the average frame length of the cached data). By performing secondary framing on complete frame data that is too long, the problem of missing valid frame headers due to excessive jump intervals can be effectively avoided, and the continuity and integrity of the video stream can be ensured. It can also avoid the memory or processing resource pressure that may be caused by the one-time processing of large frame data, especially when processing high-resolution or high-frame rate video streams, which can significantly improve the system processing efficiency and response speed.
[0186] Figure 5It is a schematic flowchart of another video stream processing method provided in an embodiment of the present application.
[0187] For example, Figure 5 As shown, the method 500 includes:
[0188] S501, obtaining a video stream to be processed.
[0189] It is understandable that this step is Figure 1 S101 in the description will not be described in detail here.
[0190] S502: searching for a valid frame header in the video stream to be processed, and determining a frame type corresponding to the valid frame header when a valid frame header is identified.
[0191] It is understandable that, as described above, after obtaining the video stream to be processed, a valid frame header can be searched in the video stream to be processed. When a valid frame header is found, the frame type corresponding to the valid frame header can be further determined.
[0192] S503: Determine a jump interval of jump search based on the frame type, and jump search for a valid frame header in the video stream to be processed according to the jump interval.
[0193] It is understandable that, as described above, the minimum frame length of the complete frame data corresponding to the stored frame type can be obtained, and a preset proportion of the minimum frame length is determined as the jump interval of the jump search, such as 75% of the minimum length is determined as the jump interval. If the minimum frame length of the complete frame data corresponding to the frame type is not stored, the jump interval of the jump search is determined to be 0. After the jump interval is determined, the valid frame header located after the valid frame header can be searched backward in the video stream to be processed according to the jump interval starting from the position of the valid frame header.
[0194] S504: Determine whether a valid frame header is found.
[0195] Exemplarily, as described above, if a valid frame header is found, it is possible to further determine whether there is cached data in the data cache area, and determine different processing strategies based on the data storage situation in the data cache area, that is, execute S505; if no valid frame header is found, it is also possible to further determine whether there is cached data in the data cache area, and determine different processing strategies based on the data storage situation in the data cache area, that is, execute S508.
[0196] S505, determining whether there is cached data in the data cache area.
[0197] Exemplarily, as described above, when a valid frame header is found, if it is determined that cached data exists in the data cache area, the cached data and the data before the valid frame header can be spliced into complete frame data, that is, executing S506; if it is determined that no cached data exists in the data cache area, the valid frame header can be written into the data cache area, that is, executing S507.
[0198] S506: splice the buffered data and the data before the valid frame header into complete frame data.
[0199] It can be understood that, as mentioned above, when a valid frame header is found in the video stream to be processed, if there is cached data in the data buffer area, it means that part of the video data may have been processed before, and part of the video data may have been stored in the data buffer area that failed to form a complete frame. In this case, the cached data can be spliced with the data before the found valid frame header to form a complete frame data.
[0200] S507, writing the valid frame header into the data buffer area.
[0201] It is understandable that, as mentioned above, when a valid frame header is found, if there is no cached data in the data cache area, the valid frame header can be stored in the data cache area first, so as to retain the key data frame start information and facilitate the subsequent formation of complete frame data with other data.
[0202] S508, determining whether there is cached data in the data cache area.
[0203] Exemplarily, as described above, when no valid frame header is found, if it is determined that there is cached data in the data cache area, it means that a valid frame header may have been encountered before this processing process and the relevant data of the valid frame header has been stored, then this segment of data can be temporarily stored in the data cache area, that is, execute S509; if it is determined that there is no cached data in the data cache area, it means that no valid frame header or data fragment has been cached before, the data currently being processed may be located at the beginning of the video stream, or the previous processing has been completed and the data cache area has been cleared, then you can choose to discard the current part of the video stream data, that is, execute S510.
[0204] S509, storing the data after the jump search into the data buffer area.
[0205] S510, discard the data after the jump search.
[0206] It is understandable that after discarding the data that has been searched in a jump manner, the valid frame header may continue to be searched in a jump manner in the video stream to be processed, that is, S503 is executed.
[0207] S511, determining whether the data length of the complete frame data is greater than 1.5 times the average frame length.
[0208] It is understandable that this step is Figure 4 S402 in the description will not be described in detail here.
[0209] For example, if the data length is greater than 1.5 times the average frame length, it means that there may be multiple valid frame headers in the complete data frame, and the complete frame data needs to be divided into two frames, that is, execute S512; if the data length is less than or equal to 1.5 times the average frame length, the complete frame data can be sent to the decoding layer, that is, execute S513.
[0210] S512, performing secondary framing on the complete frame data.
[0211] It is understandable that how to perform secondary framing on the complete frame data can be found in Figure 3 After the framing is completed, if the data length of the data frame after framing is less than or equal to 1.5 times the average value, the data after framing is stored in the data buffer area.
[0212] S513: Send the complete frame data to the decoding layer.
[0213] It can be understood that after obtaining the complete frame data, the decoding layer can be notified to decode the complete frame data and wait for the decoding layer to complete the decoding task. When it is determined that the decoding task is complete, the data cache area is cleared and the valid frame header found this time is stored in the data cache area so as to form a complete frame data with subsequent data frames.
[0214] S514, recording the minimum frame length and average frame length of the complete frame data according to the frame type.
[0215] It can be understood that after obtaining the complete frame data, the frame type corresponding to the complete frame data can be determined, and the minimum frame length and average frame length of the complete frame data can be recorded according to the frame type to update the statistical information of the data frame in real time, thereby optimizing the jumping search strategy.
[0216] The above method processes the video stream to be processed by a jump search method, can quickly locate the decodable video frame, avoids the processing of invalid data, reduces unnecessary computing resource consumption, improves the data processing speed and the accuracy of frame detection, and can avoid data blocking. When a valid frame header is found, the cached data and the data before the valid frame header are spliced to ensure the integrity of the data frame and ensure that the receiving end can reconstruct a complete video stream, which can avoid frame loss and picture quality degradation.
[0217] Figure 6It is a structural diagram of a video stream processing device provided in an embodiment of the present application.
[0218] For example, Figure 6 As shown, the device 600 includes:
[0219] The acquisition module 601 is used to acquire the video stream to be processed.
[0220] The search module 602 is used to jump-search for a valid frame header in the video stream to be processed.
[0221] The valid frame header is a frame header whose data format complies with a preset format.
[0222] The splicing module 603 is used to splice the cached data and the data before the valid frame header into complete frame data when the valid frame header is found during each jump search process. The complete frame data is sent to the decoding layer for decoding and playback by the decoding layer.
[0223] In one possible implementation, the search module is specifically used to: identify a valid frame header in the video stream to be processed; determine the frame type corresponding to the valid frame header each time the valid frame header is identified; determine a jump interval for a jump search based on the frame type; and jump search for a valid frame header located after the valid frame header in the video stream to be processed according to the jump interval.
[0224] In a possible implementation, the search unit includes a determination unit, which is specifically used to: determine a minimum frame length of complete frame data corresponding to the frame type; and determine a preset proportion of the minimum frame length as a jump interval for the jump search.
[0225] In one possible implementation, the search unit is also specifically used to: determine whether the data length of the data frame located after the valid frame header in the video stream to be processed is greater than the jump interval; if it is determined that the data length of the data frame located after the valid frame header is greater than the jump interval, then according to the determined jump interval, jump-search for the valid frame header located after the valid frame header in the data frame located after the valid frame header.
[0226] In one possible implementation, the splicing module includes a storage unit, which is specifically used to: determine whether the data length of the complete frame data is greater than a preset length threshold; when it is determined that the data length of the complete frame data is greater than the preset length threshold, perform secondary framing on the complete frame data to obtain at least two data frames; if the data lengths of the at least two data frames are both less than or equal to the preset length threshold, send the at least two data frames to the decoding layer respectively.
[0227] In one possible implementation, the storage unit includes a frame division unit, which is specifically used to: search for a valid frame header in the complete frame data, and determine the number of frame headers corresponding to the found valid frame header; when the number of frame headers is greater than one, divide the complete frame data into at least two data frames according to the number of frame headers.
[0228] Optionally, the device also includes a second storage module, which is specifically used to: in the case where the valid frame header is not found during each jump search process, if it is determined that the cached data exists in the data cache area, then the data frame in the video stream to be processed that has undergone jump search is stored in the data cache area; if it is determined that the cached data does not exist in the data cache area, then the data frame in the video stream to be processed that has undergone jump search is discarded; in the case where the valid frame header is found during each jump search process, if it is determined that the cached data does not exist in the data cache area, then the valid frame header is stored in the data cache area.
[0229] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.
[0230] For example, Figure 7 As shown, the electronic device 700 includes: a memory 701 and a processor 702, wherein the memory 701 stores an executable program code 7011, and the processor 702 is used to call and execute the executable program code 7011 to perform a method for processing a video stream.
[0231] In addition, an embodiment of the present application also protects a device, which may include a memory and a processor, wherein the memory stores an executable program code, and the processor is used to call and execute the executable program code to perform a video stream processing method provided by an embodiment of the present application.
[0232] In this embodiment, the functional modules of the device can be divided according to the above method example. For example, each functional module can be corresponded, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0233] In the case of dividing each functional module according to each function, the device may also include an acquisition module, a search module, a splicing module, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, which will not be repeated here.
[0234] It should be understood that the device provided in this embodiment is used to execute the above-mentioned method for processing a video stream, and thus can achieve the same effect as the above-mentioned implementation method.
[0235] In the case of an integrated unit, the device may include a processing module and a storage module. When the device is applied to an electronic device, the processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device in executing relevant program codes and data.
[0236] The processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules and circuits shown in conjunction with the disclosure of the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.
[0237] In addition, the device provided in the embodiments of the present application may specifically be a chip, a component or a module, and the chip may include a connected processor and a memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute a video stream processing method provided in the above embodiments.
[0238] This embodiment further provides a computer-readable storage medium, in which a computer program code is stored. When the computer program code is executed on a computer, the computer executes the above-mentioned related method steps to implement a video stream processing method provided in the above embodiment.
[0239] This embodiment further provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement a video stream processing method provided in the above embodiment.
[0240] Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.
[0241] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0242] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0243] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for processing a video stream, characterized in that: The method comprises: Get the video stream to be processed; Searching for a valid frame header in the video stream to be processed in a jump manner; wherein the valid frame header is a frame header whose data format conforms to a preset format; When the valid frame header is found during each jump search, if it is determined that there is cached data in the data cache area, the cached data and the data before the valid frame header are spliced into complete frame data, and the complete frame data is sent to the decoding layer for decoding and playback by the decoding layer.
2. The method according to claim 1, characterized in that The step of searching for a valid frame header in the video stream to be processed in a jump manner includes: Identifying a valid frame header in the video stream to be processed; In each case where the valid frame header is identified, determining the frame type corresponding to the valid frame header; Based on the frame type, determining a jump interval of a jump search; According to the jump interval, the valid frame header located after the valid frame header is jumped in the video stream to be processed.
3. The method according to claim 2, characterized in that The step of determining a jump interval of a jump search based on the frame type comprises: Determine the minimum frame length of the complete frame data corresponding to the frame type; A minimum frame length of a preset ratio is determined as a jump interval of the jump search.
4. The method according to claim 2, characterized in that: The step of searching for a valid frame header located after the valid frame header in the video stream to be processed in a jump manner according to the jump interval includes: Determine whether the data length of the data frame after the valid frame header in the video stream to be processed is greater than the jump interval; If it is determined that the data length of the data frame following the valid frame header is greater than the jump interval, then the valid frame header following the valid frame header is jumped-searched in the data frame following the valid frame header according to the determined jump interval.
5. The method according to claim 1, characterized in that The sending the complete frame data to the decoding layer comprises: Determine whether the data length of the complete frame data is greater than a preset length threshold; When it is determined that the data length of the complete frame data is greater than the preset length threshold, performing secondary framing on the complete frame data to obtain at least two data frames; If the data lengths of the at least two data frames are both less than or equal to the preset length threshold, the at least two data frames are sent to the decoding layer respectively.
6. The method according to claim 5, characterized in that The secondary framing of the complete frame data to obtain at least two data frames includes: Searching for a valid frame header in the complete frame data, and determining the number of frame headers corresponding to the found valid frame header; When the number of the frame headers is greater than one, the complete frame data is divided into at least two data frames according to the number of the frame headers.
7. The method according to claim 1, characterized in that After searching for a valid frame header in the video stream to be processed in a jump manner, the method further includes: In the case where the valid frame header is not found during each jump search, if it is determined that the cached data exists in the data cache, the data frame in the video stream to be processed that has undergone the jump search is stored in the data cache; If it is determined that the cached data does not exist in the data cache area, discarding the data frame in the video stream to be processed that has undergone the jump search; In the case where the valid frame header is found during each jump search process, if it is determined that the cached data does not exist in the data cache area, the valid frame header is stored in the data cache area.
8. A video stream processing device, characterized in that: The device comprises: An acquisition module, used to acquire the video stream to be processed; A search module, used for searching for a valid frame header in the video stream to be processed in a jump manner; wherein the valid frame header is a frame header whose data format conforms to a preset format; The splicing module is used to splice the cached data and the data before the valid frame header into complete frame data when the valid frame header is found in each jump search process, if it is determined that there is cached data in the data cache area, and send the complete frame data to the decoding layer for decoding and playback by the decoding layer.
9. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable program codes; A processor, configured to call and run the executable program code from the memory, so that the electronic device executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 7 is implemented.
