Decoding method, device, and computer-readable storage medium

By caching and parsing audio stream segments and decoding after obtaining header information, the problem of FFmpeg tools being unable to perform real-time decoding in AI customer service scenarios is solved, and real-time decoding of audio streams is achieved.

CN114093375BActive Publication Date: 2025-09-12BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110229441.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-02
Publication Date
2025-09-12
Estimated Expiration
2041-03-02

AI Technical Summary

Technical Problem

In AI customer service scenarios, when using the FFmpeg tool to decode audio streams, most stream segments do not contain header information, resulting in real-time decoding failure and failure to meet the requirements of real-time audio streams.

Method used

The received data stream segments are cached until the header information is parsed and the audio stream segments are decoded according to the header information, including determining the preset frame length, updating the preset frame length, waiting to receive the next stream segment, calling FFmpeg methods to parse and separate other data streams, until the decoding of the audio stream is completed.

Benefits of technology

It realizes real-time decoding of audio streams, meets the needs of real-time decoding in artificial intelligence customer service scenarios, and solves the decoding error problem caused by the FFmpeg tool because the stream fragment does not contain header information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114093375B_ABST
    Figure CN114093375B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a decoding method, apparatus, and computer-readable storage medium, and relates to the field of computer technology. The method includes: caching stream segments of a received data stream, wherein the data stream includes an audio stream; parsing the cached stream segments until header information is obtained; saving the header information; and decoding the audio stream segments of each received stream segment based on the header information until the audio stream is completely decoded.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a decoding method, device, and computer-readable storage medium. Background Art

[0002] With the rapid development of artificial intelligence, the application of AI customer service robots is becoming increasingly widespread. This involves speech recognition technology, which in turn relies on real-time audio stream input as a prerequisite. In the field of AI customer service, it is often necessary to recognize what the user is saying to the robot. The user's speech is transmitted into the system in real time as an audio stream, so real-time decoding of the audio stream becomes a challenge.

[0003] Real-time decoding of audio streams requires obtaining the audio format, parameters, etc., which are generally contained in the header information. Summary of the Invention

[0004] The inventors discovered that in actual AI customer service call scenarios, audio needs to be streamed, meaning the audio file is divided into audio stream segments for transmission. In this case, the first stream segment or the first few stream segments contain header information generated during audio encoding. Subsequent stream segments do not contain this header information. In particular, when using the FFmpeg tool to decode different stream segments, most stream segments cannot be decoded because they do not contain header information, resulting in error messages. This fails to meet the requirements for real-time audio streaming decoding in AI customer service scenarios.

[0005] A technical problem to be solved by the present disclosure is: how to achieve real-time decoding of audio streams.

[0006] According to some embodiments of the present disclosure, a decoding method is provided, comprising: caching stream segments of a received data stream, wherein the data stream includes an audio stream; parsing the cached stream segments until header information is obtained; saving the header information; and decoding the stream segments of the audio stream in each received stream segment according to the header information until the decoding of the audio stream is completed.

[0007] In some embodiments, parsing the cached stream segment until the header information is obtained includes: determining whether the data length of the currently cached stream segment reaches the preset frame length; if the data length of the currently cached stream segment reaches the preset frame length, parsing the data of the preset frame length; determining whether the header information is successfully parsed; if the header information is not successfully parsed, increasing the preset frame length by a preset value and updating the preset frame length; repeating the above steps until the header information is parsed.

[0008] In some embodiments, parsing the cached stream segment until the header information is obtained also includes: when the data length of the currently cached stream segment does not reach the preset frame length, waiting to receive the next stream segment for caching, and re-executing to determine whether the data length of the cached stream segment reaches the preset frame length.

[0009] In some embodiments, decoding the stream segments of the audio stream in each received stream segment according to the header information includes: determining the length of the audio frame according to the header information; and distinguishing different audio frames of the stream segments of the audio stream in each received stream segment for decoding according to the length of the audio frame.

[0010] In some embodiments, according to the length of the audio frame, different audio frames of the stream segments of the audio stream in each received stream segment are distinguished and decoded, including: dividing the audio frames in the current stream segment of the audio stream according to the length of the audio frame and in the order of the data encapsulation format; decoding the complete audio frame in the current stream segment; determining whether the tail data of the current stream segment of the audio stream belongs to an incomplete audio frame; if the tail data of the current stream segment of the audio stream belongs to an incomplete audio frame, caching the incomplete audio frame; after waiting for the next stream segment of the audio stream to be received, splicing the next stream segment with the incomplete audio frame to obtain a spliced ​​stream segment; using the spliced ​​stream segment as the current stream segment of the audio stream, and repeating the above steps until the decoding of the last stream segment of the audio stream is completed.

[0011] In some embodiments, decoding the stream segments of the audio stream in each received stream segment according to the header information until the decoding of the audio stream is completed includes: in the case that decoding of the current stream segment of the audio stream according to the header information fails, parsing the current stream segment or the current stream segment and the stream segment after the current stream segment until new header information is obtained by parsing; decoding the stream segment after the current stream segment according to the new header information until the decoding of the audio stream is completed.

[0012] In some embodiments, parsing the cached stream segments until the header information is obtained includes: calling an Open avformat method in FFmpeg to parse the cached stream segments until the header information is obtained.

[0013] In some embodiments, decoding the stream segments of the audio stream in each received stream segment according to the header information includes: determining whether the data stream includes other data streams besides the audio stream according to the header information; if the data stream includes other data streams besides the audio stream, separating the other data streams from the audio stream; determining the format information of the audio stream according to the header information; transcoding each stream segment of the audio stream into the original audio stream according to the format information of the audio stream; and resampling the original audio stream according to a preset bit rate.

[0014] In some embodiments, the Separate stream method in FFmpeg is called to separate other data streams from the audio stream; the Parse format method in FFmpeg is called to determine the format information of the audio stream based on the header information, and each stream segment of the audio stream is transcoded into the original audio stream according to the format information of the audio stream, and the original audio stream is resampled according to the preset bit rate.

[0015] According to other embodiments of the present disclosure, a decoding device is provided, including: a cache module for caching stream segments of a received data stream, wherein the data stream includes an audio stream; a header information parsing module for parsing the cached stream segments until header information is obtained through the parsing; a header information saving module for saving the header information; and a decoding module for decoding the stream segments of the audio stream in each received stream segment according to the header information until the decoding of the audio stream is completed.

[0016] According to some further embodiments of the present disclosure, a decoding device is provided, comprising: a processor; and a memory coupled to the processor, for storing instructions, wherein when the instructions are executed by the processor, the processor executes the decoding method of any of the aforementioned embodiments.

[0017] According to some further embodiments of the present disclosure, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, wherein the program, when executed by a processor, implements the decoding method of any of the aforementioned embodiments.

[0018] The present disclosure first caches stream segments of received data streams, continuously parses the cached stream segments until header information is obtained, saves the header information, and uses the header information to decode stream segments of the audio stream in each subsequently received stream segment until the audio stream is completely decoded. The method disclosed in the present disclosure can achieve real-time decoding of audio streams, meeting the requirements of real-time decoding of real-time audio streams in artificial intelligence customer service scenarios.

[0019] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0021] Figure 1 A flowchart illustrating a decoding method according to some embodiments of the present disclosure is shown.

[0022] Figure 2 A schematic structural diagram of the audio stream according to some embodiments of the present disclosure is shown.

[0023] Figure 3 A flowchart illustrating decoding methods according to other embodiments of the present disclosure is shown.

[0024] Figure 4 A schematic structural diagram of a decoding device according to some embodiments of the present disclosure is shown.

[0025] Figure 5 A schematic structural diagram of a decoding device according to some other embodiments of the present disclosure is shown.

[0026] Figure 6 A schematic structural diagram of a decoding device according to some further embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0027] The following will be combined with the drawings in the embodiments of the present disclosure to clearly and completely describe the technical solutions in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is in no way intended to limit the present disclosure and its application or use. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present disclosure.

[0028] This disclosure provides a decoding method that can be used to decode audio streams in real time in artificial intelligence customer service scenarios. Figures 1 to 3 Provide a description.

[0029] Figure 1 Flowchart of some embodiments of the decoding method disclosed herein. Figure 1 As shown, the method of this embodiment includes steps S102 to S108.

[0030] In step S102, the stream segments of the received data stream are buffered.

[0031] The data stream includes an audio stream and may also include other data streams besides the audio stream, such as a video stream. When the audio stream and other data streams are mixed, the different streams need to be separated in subsequent steps, which will be described in detail in the following embodiments. The data stream is divided into multiple stream segments during transmission, and each stream segment can be encapsulated into a data packet (Package) for transmission. After receiving the data packet, the decoding device (the device that executes the decoding method of the present disclosure) parses the data packet to obtain stream segments and caches the stream segments.

[0032] The disclosed solution can be implemented based on the FFmpeg API. First, the avformat and aviocontext modules can be initialized (Init avformat / Init avio context), which are used for subsequent header information parsing and audio stream reading, respectively. The Buffer stream method can be called to cache stream segments.

[0033] In step S104, the cached stream segments are parsed until header information is obtained.

[0034] The header information includes, for example, the format information and parameters of the audio stream. The parameters include, for example, at least one of the sampling rate, bit depth, number of channels, and compression ratio, and are not limited to the examples given. Since the division of stream segments is uncertain, it is possible that a stream segment contains complete header information, or it is possible that a stream segment contains only partial header information, and multiple stream segments are required to obtain complete header information. In some embodiments, each time a stream segment is cached, an attempt is made to parse all previously cached stream segments to determine whether the header information is successfully parsed. If the header information is not successfully parsed, the next stream segment is cached and the above process is repeated until the header information is successfully parsed.

[0035] In other embodiments, it is determined whether the data length of the currently cached stream segment reaches the preset frame length; if the data length of the currently cached stream segment reaches the preset frame length, the data of the preset frame length is parsed; it is determined whether the header information is successfully parsed; if the header information is not successfully parsed, the preset frame length is increased by a preset value and the preset frame length is updated; the above steps are repeated until the header information is parsed.

[0036] The preset frame length can be calculated based on the length of header information in historical audio streams. After each stream segment is cached, a determination can be made as to whether the data length of the currently cached stream segment reaches the preset frame length. If the data length of the currently cached stream segment does not reach the preset frame length, the process waits for the next stream segment to be cached and then re-executes the step of determining whether the data length of the cached stream segment reaches the preset frame length. Once the data length of the currently cached stream segment reaches the preset frame length, the process attempts to parse data of the preset frame length. For example, if the preset frame length is 200 bytes, the data from the first byte of the initially cached stream segment to 200 bytes is used as the data to be parsed. The data to be parsed is parsed to determine whether the header information is successfully parsed. If the header information is successfully parsed, the header information parsing process is terminated. If the header information parsing fails, the preset frame length is increased by a preset value, for example, from 200 bytes to 300 bytes. The process then re-starts with the step of determining whether the data length of the currently cached stream segment reaches the preset frame length.

[0037] You can call the Open avformat method in FFmpeg to parse the cached stream segments until the header information is obtained. This method continuously attempts to parse the headers of the cached stream segments, avoiding the problem of unsuccessful parsing when the header information is divided into different stream segments. By determining and correcting the preset frame length, the parsing process is reduced and efficiency is improved.

[0038] In step S106, the header information is saved.

[0039] In step S108, the stream segments of the audio stream in each received stream segment are decoded according to the header information until the decoding of the audio stream is completed.

[0040] In the case where the data stream only contains an audio stream, each received stream segment is directly decoded using the header information. In the case where the data stream contains an audio stream and other data streams, a stream separation operation is required. In some embodiments, whether the data stream includes other data streams besides the audio stream is determined based on the header information; if the data stream includes other data streams besides the audio stream, the other data streams are separated from the audio stream. For example, the Separatestream method in FFmpeg is called to separate the other data streams from the audio stream.

[0041] After separating the stream segments of the audio stream in each received stream segment, the stream segments of the audio stream are decoded using the header information. In some embodiments, the format information of the audio stream is determined based on the header information; the various stream segments of the audio stream are transcoded into the original audio stream based on the format information of the audio stream; and the original audio stream is resampled according to a preset bit rate. The resampled bit rate conforms to the bit rate of the playback device, making it easy to play. For example, the Parse format method in FFmpeg is called to determine the format information of the audio stream based on the header information, transcode the various stream segments of the audio stream into the original audio stream based on the format information of the audio stream, and resample the original audio stream according to a preset bit rate.

[0042] In the case where the audio stream contains only one complete audio file, the saved header information can be used to correctly decode the entire audio stream. In the case where the audio stream contains multiple complete audio files, the header information of different audio files may be different, resulting in failure during the decoding process. To address this issue, in some embodiments, if decoding of the current stream segment of the audio stream fails based on the header information, the current stream segment or the current stream segment and the stream segment after the current stream segment are parsed until new header information is obtained; the stream segment after the current stream segment is decoded based on the new header information until the decoding of the audio stream is completed.

[0043] The method for parsing and obtaining new header information can refer to the method for parsing header information in the above embodiment. The new header information is saved, the previously saved header information can be deleted, and the new header information is used to decode the stream segment received later until the decoding of the audio stream is completed.

[0044] The method of the above embodiment first caches the stream segments of the received data stream, continuously parses the cached stream segments until the header information is obtained, saves the header information, and uses the header information to decode the stream segments of the audio stream in each subsequently received stream segment until the audio stream is completely decoded. The method of the above embodiment can achieve real-time decoding of the audio stream, meeting the requirements of real-time decoding of real-time audio streams in artificial intelligence customer service scenarios.

[0045] Especially for the scenario of using FFmpeg tool to implement audio decoding, the method of the above embodiment caches stream segments through the audio stream buffer, extracts the header information (including the format information and parameters of the audio stream, etc.), parses it and saves it, and the format information and parameters of the audio stream can be parsed according to the header information. The decoder type can be obtained through the format information of the audio stream, and in the stream segments of the audio stream received later, the previously cached decoder type is used to link the corresponding decoder engine, and the subsequent stream segments are decoded according to the parameters of the audio stream. In this case, real-time decoding can be achieved for the audio stream generated by using a standard audio encoder, which solves the problem that the FFmpeg tool cannot decode because most stream segments do not contain header information.

[0046] During audio stream transmission, if the transmitted stream segments are not divided into integer multiples of the audio frame length, there may be incomplete audio frames. Figure 2 As shown, stream segment 1 of the audio stream contains audio frame (Frame) 1, audio frame 2 and a part of audio frame 3, while stream segment 2 contains another part of audio frame 3. At this time, an error will be reported when using the decoder to decode stream segments 1 and 2 according to the header information. In response to the above problem, the present disclosure also provides a solution. In some embodiments, the length of the audio frame is determined based on the header information; based on the length of the audio frame, the stream segments of the audio stream in each received stream segment are distinguished and decoded from different audio frames. The length of the audio frame can be determined based on the parameters contained in the header information. For example, the length of the audio frame can be determined based on the sampling rate, bit depth, number of channels, etc., and the existing technology can be referred to, and the details will not be repeated.

[0047] Further, if Figure 3 As shown, decoding the stream segments of the audio stream in each received stream segment according to the header information includes: steps S302 to S316.

[0048] In step S302, the length of the audio frame is determined according to the header information.

[0049] In step S304, if the stream segment where the header information is located also contains audio data, the stream segment is used as the current stream segment of the audio stream.

[0050] In step S306, the current stream segment is divided into audio frames according to the length of the audio frames and in the order of the data encapsulation format.

[0051] For example, data is arranged in a left-to-right or front-to-back order in a stream segment. Figure 2 As shown, after the stream segment 1 is divided into audio frames, the tail data belongs to the incomplete audio frame 3.

[0052] In step S308, the complete audio frame in the current stream segment is decoded.

[0053] In step S310 , it is determined whether the current stream segment is the last stream segment. If so, the process stops; otherwise, the process goes to step S312 .

[0054] In step S312, it is determined whether the tail data of the current stream segment of the audio stream belongs to an incomplete audio frame. If so, step S314 is executed, otherwise step S313 is executed.

[0055] In step S313, after waiting for the next stream segment of the audio stream to be received, the next stream segment is used as the current stream segment, and the process returns to step S306 and starts again.

[0056] In step S314, the incomplete audio frame is buffered.

[0057] In step S316, after waiting for the next stream segment of the audio stream to be received, the next stream segment is spliced ​​with the incomplete audio frame to obtain the spliced ​​stream segment as the current stream segment, and the process returns to step S306 to start again.

[0058] like Figure 2 As shown, stream segment 2 is spliced ​​with the first half of audio frame 3 in stream segment 1 to form a complete frame.

[0059] The method of the above embodiment considers caching incomplete frame information until the next stream segment is received and then performing splicing processing, thereby solving the problem of being unable to correctly decode when the stream segment contains incomplete audio frames.

[0060] The present disclosure also provides a decoding device, which is described below in conjunction with 4.

[0061] Figure 4 Figure 1 is a structural diagram of some embodiments of the decoding device disclosed herein. Figure 4 As shown, the device 40 of this embodiment includes: a cache module 410 , a header information parsing module 420 , a header information storing module 430 , and a decoding module 440 .

[0062] The buffer module 410 is configured to buffer stream segments of received data streams, where the data streams include audio streams.

[0063] The header information parsing module 420 is used to parse the cached stream segments until the header information is obtained.

[0064] In some embodiments, the header information parsing module 420 is used to determine whether the data length of the currently cached stream segment reaches the preset frame length; if the data length of the currently cached stream segment reaches the preset frame length, parse the data of the preset frame length; determine whether the header information is successfully parsed; if the header information is not successfully parsed, increase the preset frame length by a preset value and update the preset frame length; repeat the above steps until the header information is parsed.

[0065] In some embodiments, the header information parsing module 420 is used to wait for the next stream segment to be received for caching when the data length of the currently cached stream segment does not reach the preset frame length, and then re-execute to determine whether the data length of the cached stream segment reaches the preset frame length.

[0066] In some embodiments, the header information parsing module 420 is configured to call the Open avformat method in FFmpeg to parse the cached stream segments until the header information is obtained.

[0067] The header information storage module 430 is used to store the header information.

[0068] The decoding module 440 is configured to decode the stream segments of the audio stream in each received stream segment according to the header information until the decoding of the audio stream is completed.

[0069] In some embodiments, the decoding module 440 is configured to determine the length of the audio frame according to the header information; and to decode different audio frames of the received audio stream segments according to the length of the audio frame.

[0070] In some embodiments, the decoding module 440 is used to divide the current stream segment of the audio stream into audio frames according to the length of the audio frames and in the order of the data encapsulation format; decode the complete audio frames in the current stream segment; determine whether the tail data of the current stream segment of the audio stream belongs to an incomplete audio frame; if the tail data of the current stream segment of the audio stream belongs to an incomplete audio frame, cache the incomplete audio frame; wait for the next stream segment of the audio stream to be received, and then splice the next stream segment with the incomplete audio frame to obtain a spliced ​​stream segment; use the spliced ​​stream segment as the current stream segment of the audio stream, and repeat the above steps until the decoding of the last stream segment of the audio stream is completed.

[0071] In some embodiments, the decoding module 440 is used to parse the current stream segment or the current stream segment and the stream segment after the current stream segment when decoding of the current stream segment of the audio stream according to the header information fails until new header information is obtained; and decode the stream segment after the current stream segment according to the new header information until the decoding of the audio stream is completed.

[0072] In some embodiments, the decoding module 440 is used to determine whether the data stream includes data streams other than the audio stream based on the header information; if the data stream includes data streams other than the audio stream, separate the other data streams from the audio stream; determine the format information of the audio stream based on the header information; transcode each stream segment of the audio stream into the original audio stream based on the format information of the audio stream; and resample the original audio stream according to a preset bit rate.

[0073] In some embodiments, the decoding module 440 is used to call the Separate stream method in FFmpeg to separate other data streams from the audio stream; call the Parse format method in FFmpeg to determine the format information of the audio stream according to the header information, transcode each stream segment of the audio stream into the original audio stream according to the format information of the audio stream, and resample the original audio stream according to the preset bit rate.

[0074] The decoding device in the embodiment of the present disclosure can be implemented by various computing devices or computer systems. Figure 5 as well as Figure 6 Provide a description.

[0075] Figure 5 Figure 1 is a structural diagram of some embodiments of the decoding device disclosed herein. Figure 5 As shown, the apparatus 50 of this embodiment includes: a memory 510 and a processor 520 coupled to the memory 510 , and the processor 520 is configured to execute the decoding method in any of the embodiments of the present disclosure based on instructions stored in the memory 510 .

[0076] The memory 510 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, a database, and other programs.

[0077] Figure 6 Figure 1 is a structural diagram of some other embodiments of the decoding device disclosed herein. Figure 6As shown, the device 60 of this embodiment includes: a memory 610 and a processor 620, which are similar to the memory 510 and the processor 520, respectively. It may also include an input / output interface 630, a network interface 640, a storage interface 650, etc. These interfaces 630, 640, 650 and the memory 610 and the processor 620 can be connected, for example, via a bus 660. Among them, the input / output interface 630 provides a connection interface for input / output devices such as a display, mouse, keyboard, and touch screen. The network interface 640 provides a connection interface for various networked devices, such as a database server or a cloud storage server. The storage interface 650 provides a connection interface for external storage devices such as SD cards and USB flash drives.

[0078] Those skilled in the art will appreciate that embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable non-transient storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0079] The present disclosure is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present disclosure. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0080] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0081] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0082] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present disclosure should be included in the scope of protection of the present disclosure.

Claims

1. A decoding method, comprising: caching stream segments of a received data stream, wherein the data stream includes an audio stream; Parsing the cached stream segment until header information is obtained through parsing, including: determining whether the data length of the currently cached stream segment reaches a preset frame length; if the data length of the currently cached stream segment reaches the preset frame length, parsing data of the preset frame length to determine whether the header information is successfully parsed; if the header information is not successfully parsed, increasing the preset frame length by a preset value, updating the preset frame length, and repeating the above steps until the header information is parsed; Saving the header information; The stream segments of the audio stream in each received stream segment are decoded according to the header information until the decoding of the audio stream is completed.

2. The decoding method according to claim 1, wherein: The step of parsing the cached stream segments until obtaining header information further includes: In the case that the data length of the currently cached stream segment does not reach the preset frame length, after waiting to receive the next stream segment for cache, it is re-executed to determine whether the data length of the cached stream segment reaches the preset frame length.

3. The decoding method according to claim 1, wherein: The decoding of the stream segments of the audio stream in each received stream segment according to the header information includes: determining the length of the audio frame according to the header information; According to the length of the audio frame, different audio frames of the received stream segments of the audio stream are distinguished and decoded.

4. The decoding method according to claim 3, wherein: The step of distinguishing different audio frames of the received stream segments of the audio stream according to the length of the audio frame and decoding the stream segments includes: For the current stream segment of the audio stream, divide the audio frames according to the length of the audio frames and in the order of the data encapsulation format; Decode the complete audio frame in the current stream segment; Determining whether tail data of a current stream segment of the audio stream belongs to an incomplete audio frame; When tail data of the current stream segment of the audio stream belongs to an incomplete audio frame, buffering the incomplete audio frame; After waiting for receiving a next stream segment of the audio stream, splicing the next stream segment with the incomplete audio frame to obtain a spliced ​​stream segment; The spliced ​​stream segment is used as the current stream segment of the audio stream, and the above steps are repeated until the decoding of the last stream segment of the audio stream is completed.

5. The decoding method according to claim 1, wherein: The decoding of the stream segments of the audio stream in each received stream segment according to the header information until the decoding of the audio stream is completed includes: If decoding of a current stream segment of the audio stream according to the header information fails, parsing the current stream segment or the current stream segment and a stream segment subsequent to the current stream segment until new header information is obtained; The stream segment following the current stream segment is decoded according to the new header information until the decoding of the audio stream is completed. The decoding method according to claim 1 , wherein: The parsing of the cached stream segments until the header information is obtained includes: Call the Open avformat method in FFmpeg to parse the cached stream segments until the header information is obtained.

7. The decoding method according to claim 1, wherein: The decoding of the stream segments of the audio stream in each received stream segment according to the header information includes: determining, according to the header information, whether the data stream includes other data streams other than the audio stream; In a case where the data stream includes other data streams other than the audio stream, separating the other data streams from the audio stream; determining format information of the audio stream according to the header information; transcoding each stream segment of the audio stream into an original audio stream according to the format information of the audio stream; The original audio stream is resampled according to a preset bit rate.

8. The decoding method according to claim 7, wherein: Call the Separate stream method in FFmpeg to separate the other data streams from the audio stream; The Parse format method in FFmpeg is called to determine the format information of the audio stream according to the header information, transcode each stream segment of the audio stream into an original audio stream according to the format information of the audio stream, and resample the original audio stream according to a preset bit rate.

9. A decoding device comprising: a cache module, configured to cache stream segments of a received data stream, wherein the data stream includes an audio stream; a header information parsing module, configured to parse the cached stream segments until the header information is obtained by parsing, including: determining whether the data length of the currently cached stream segments reaches a preset frame length; if the data length of the currently cached stream segments reaches the preset frame length, parsing the data of the preset frame length to determine whether the header information is successfully parsed; if the header information is not successfully parsed, increasing the preset frame length by a preset value, updating the preset frame length, and repeating the above steps until the header information is parsed; A header information storage module, used to store the header information; A decoding module is configured to decode the stream segments of the audio stream in each received stream segment according to the header information until the decoding of the audio stream is completed.

10. A decoding device comprising: processor; as well as A memory coupled to the processor, for storing instructions, wherein when the instructions are executed by the processor, the processor executes the decoding method according to any one of claims 1 to 8.

11. A non-transitory computer-readable storage medium having a computer program stored thereon, wherein: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Video playing method and device, electronic equipment and storage medium

    CN111147942A

  • MPEG audio frequency decoding method

    CN1909657A