MP4 media reading method and device based on HTTP protocol

By setting the buffer area and optimizing the data reading order, the problem of repeated data reading in MP4 media reading under the HTTP protocol is solved, which improves reading efficiency and reduces bandwidth usage, and achieves more efficient online playback.

CN118945412APending Publication Date: 2024-11-12BEIJING FUNSHION ONLINE TECH LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411006652.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-25
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

MP4 media reading based on HTTP protocol has problems with repeated data reading, resulting in low data reading efficiency and increased bandwidth usage.

Method used

By setting the corresponding number of buffers based on the number of data types of MP4 files, we can determine whether the required data exists in the buffer one by one. If it does not exist, judge the next buffer, refresh and read the data. If it is not read successfully, Read data from CDN to reduce the probability of repeated reads.

Benefits of technology

It reduces the probability of repeated reading of HTTP reading MP4 files, reduces the bandwidth usage of data reading from CDN, and improves the operation efficiency of the program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118945412A_ABST
    Figure CN118945412A_ABST
Patent Text Reader

Abstract

The invention relates to an MP4 media reading method and device based on an HTTP protocol, and the method comprises the steps: setting a corresponding number of buffer regions according to the number of data types of MP4 files; judging whether the required data exists in the buffer one by one, and if not, judging whether the required data exists in the next buffer; if yes, the data state of the corresponding buffer in the cache region is refreshed, data are read from the corresponding buffer in the cache region, whether all needed data are read or not is judged, if yes, the needed data are successfully read, and if not, the initial position and size of the needed data are updated, and whether the needed data exist in the next buffer in the cache region or not is judged; and if the required data is not successfully read after the buffer of all the cache regions is judged, reading the data from the CDN. According to the invention, the probability of repeated reading is reduced, and the bandwidth usage for directly reading the data application from the CDN is reduced; according to the invention, under the condition that a movie does not need to be repressed, the bandwidth use of online playing of the MP4 file is reduced, and the running efficiency of a program is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for reading MP4 media based on HTTP protocol. Background Art

[0002] HTTP-based streaming MP4 on-demand service, since the streaming MP4 file contains multiple tracks such as video track, audio track, subtitle track, etc., one track contains multiple chunks, and each chunk contains a continuous sample. Due to the different compression parameters of MP4, the size of the chunks is different, and the media playback is based on the display time to interleave the reading of video samples, audio samples, and subtitle samples. This leads to a single cache mechanism based on HTTP data reading, which will read back and forth in different chunks, resulting in repeated reading of the same block of data, reducing the data reading efficiency. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a method and device for reading MP4 media based on HTTP protocol to overcome the deficiencies in the above-mentioned prior art.

[0004] The technical solution of the present invention to solve the above technical problem is as follows: A method for reading MP4 media based on HTTP protocol, comprising the following steps:

[0005] Step S01: according to the number of data types of the MP4 file, a corresponding number of buffers are set;

[0006] Step S02: When reading media data, determine whether the required data exists in the buffer one by one.

[0007] If not, determine whether the required data exists in the next buffer;

[0008] If yes, refresh the data status of the corresponding buffer, read data from the corresponding buffer, and determine whether all required data has been read. If yes, the required data has been read successfully. If not, update the starting position and size of the required data, and determine whether the required data exists in the next buffer.

[0009] Step S03: Repeat step S02, and after determining that all buffers are in the buffer area, if the required data is not read successfully, then read the data from the CDN.

[0010] The beneficial effects of the present invention are as follows: the present invention solves the problem of repeated reading of HTTP requests in multiple chunks, thereby reducing the probability of repeated reading of MP4 files by HTTP. According to the number of data types of the MP4 files, a corresponding number of cache buffers are set to process video, audio and subtitles accordingly. Since each chunk contains a continuous sample, when HTTP reads discontinuously, it just corresponds to another chunk. Eventually, different chunks will fall into different caches, thereby reducing the probability of repeated reading and reducing the bandwidth usage of applications that directly read data from CDNs. Without the need to re-compress the film, the bandwidth usage of online playback of MP4 files can be reduced, and the operating efficiency of the program can be improved.

[0011] Based on the above technical solution, the present invention can also be improved as follows.

[0012] Further, the step S03 of reading data from the CDN specifically includes the following steps:

[0013] Step S31: Obtain fixed-length data from the CDN via HTTP;

[0014] Step S32: Determine whether the buffers need to be refreshed one by one.

[0015] If yes, the fixed-length data is written into the corresponding buffer area, and data exchange is performed to exchange the fixed-length data to the last buffer area, completing step S03;

[0016] If not, determine whether the next buffer needs to be refreshed;

[0017] Step S33: Repeat step S32, and after determining all the buffers, if the fixed-length data is not written into the buffers, write the fixed-length data into the first buffer, and perform data exchange, and exchange the fixed-length data to the last buffer, and complete step S03.

[0018] Furthermore, the data exchange specifically includes determining whether there is data in the next buffer area of ​​the buffer where the fixed-length data is located. If so, the data of the two buffer areas are exchanged, and the operation is repeated until the fixed-length data is exchanged to the last buffer area.

[0019] Further, it is determined whether the buffer area needs to be refreshed, including:

[0020] If the difference between the starting position of the fixed-length data and the starting position of the data in the buffer is greater than 3MB, or the unused data in the buffer is less than 1024 bytes, the corresponding buffer needs to be refreshed.

[0021] Furthermore, refreshing the data status of the corresponding buffer in step S02 specifically includes refreshing the size of the data used by the corresponding buffer.

[0022] Furthermore, the data types in step S01 include video track, audio track and subtitle track.

[0023] An MP4 media reading device based on HTTP protocol, including a client on-demand system, wherein the client on-demand system includes a media data reading module and a media playing module;

[0024] The media data reading module is used to set a corresponding number of buffers according to the number of data types of the MP4 file, and read the media data according to a method of MP4 media reading based on the HTTP protocol.

[0025] The media playing module is used to play media data. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 It is a structural framework diagram of the present invention;

[0027] Figure 2 It is the overall framework diagram of the present invention;

[0028] Figure 3 A schematic diagram of obtaining data from a local cache according to the present invention;

[0029] Figure 4 A schematic diagram of a local cache refresh mechanism according to the present invention. DETAILED DESCRIPTION

[0030] The principles and features of the present invention are described below in conjunction with the accompanying drawings. The examples given are only used to explain the present invention and are not used to limit the scope of the present invention.

[0031] like Figure 1 to Figure 4 As shown, in Example 1, a method for reading MP4 media based on HTTP protocol includes the following steps:

[0032] Step S01: according to the number of data types of the MP4 file, a corresponding number of buffers are set;

[0033] Step S02: When reading media data, determine whether the required data exists in the buffer one by one.

[0034] If not, determine whether the required data exists in the next buffer;

[0035] If yes, refresh the data status of the corresponding buffer, read data from the corresponding buffer, and determine whether all required data has been read. If yes, the required data has been read successfully. If not, update the starting position and size of the required data, and determine whether the required data exists in the next buffer.

[0036] Step S03: Repeat step S02, and after determining that all buffers are in the buffer area, if the required data is not read successfully, then read the data from the CDN.

[0037] The present invention solves the problem of repeated reading of HTTP requests in multiple chunks, thereby reducing the probability of repeated reading of MP4 files by HTTP. According to the number of data types of the MP4 file, a corresponding number of buffers are set to process video, audio and subtitles accordingly. Since each chunk contains a continuous sample, when HTTP reads discontinuously, it just corresponds to another chunk. Finally, different chunks will fall into different caches, thereby reducing the probability of repeated reading and reducing the bandwidth usage of applications that directly read data from CDN. In the case of not needing to re-compress the movie, the bandwidth usage of online playback of MP4 files can be reduced, and the running efficiency of the program can be improved.

[0038] Embodiment 2: This embodiment is a further improvement on the basis of embodiment 1, and its details are as follows:

[0039] Reading data from the CDN in step S03 specifically includes the following steps:

[0040] Step S31: Obtain fixed-length data from the CDN via HTTP;

[0041] Step S32: Determine whether the buffers need to be refreshed one by one.

[0042] If yes, the fixed-length data is written into the corresponding buffer area, and data exchange is performed to exchange the fixed-length data to the last buffer area, completing step S03;

[0043] If not, determine whether the next buffer needs to be refreshed;

[0044] Step S33: Repeat step S32, and after determining all the buffers, if the fixed-length data is not written into the buffers, write the fixed-length data into the first buffer, and perform data exchange, and exchange the fixed-length data to the last buffer, and complete step S03.

[0045] By exchanging the buffers, the data with the largest starting position is always in the last buffer, ensuring that the data in the buffer is arranged in ascending order according to the starting position, so as to facilitate subsequent reading.

[0046] Embodiment 3, this embodiment is a further improvement on the basis of embodiment 2, and its details are as follows:

[0047] The data exchange specifically includes determining whether there is data in the next buffer area of ​​the buffer where the fixed-length data is located. If so, the data of the two buffer areas are exchanged, and this operation is repeated until the fixed-length data is exchanged to the last buffer area.

[0048] Embodiment 4: This embodiment is a further improvement on the basis of embodiment 2, and its details are as follows:

[0049] Determine whether the buffer needs to be refreshed, including:

[0050] If the difference between the starting position of the fixed-length data and the starting position of the data in the buffer is greater than 3MB, or the unused data in the buffer is less than 1024 bytes, the corresponding buffer needs to be refreshed.

[0051] Embodiment 5, this embodiment is a further improvement on the basis of embodiment 1, and its details are as follows:

[0052] Refreshing the data status of the corresponding buffer in step S02 specifically includes refreshing the size of the data used in the corresponding buffer.

[0053] Embodiment 6: This embodiment is a further improvement on the basis of any one of Embodiments 1 to 5, and its details are as follows:

[0054] The data types in step S01 include video track, audio track and subtitle track.

[0055] Embodiment 7, an MP4 media reading device based on HTTP protocol, comprising a client on-demand system, wherein the client on-demand system comprises a media data reading module and a media playing module;

[0056] A media data reading module, which is used to set a corresponding number of buffers according to the number of data types of the MP4 file, and read the media data according to a method for reading MP4 media based on the HTTP protocol in any one of embodiments 1 to 6,

[0057] The media playing module is used to play media data. Specific embodiment:

[0059] 1. Read data from the cache (see Figure 3 ):

[0060]

[201] : Read media data. According to the parsed MP4 file format, read the video sample, audio sample or subtitle sample data from the specified location;

[0061]

[202] : Determine whether the data read in

[201] is contained in the buffer buffer1 cache according to the starting position;

[0062]

[203] : If

[202] is judged as "yes", refresh the data status of the buffer area buffer1 (including the size of the used data, etc.);

[0063]

[204] : Determine whether the buffer area buffer1 contains all the data read in

[202] . If yes, execute

[209] and the data is read successfully.

[0064]

[205] : If

[204] is judged as "no", read the existing data in the buffer area buffer1, and update the starting position and size of the data to be read in

[202] ;

[0065]

[206] : If

[202] or

[204] is determined to be "no", determine whether the data to be read is contained in the buffer buffer2;

[0066]

[207] : If

[206] is judged as "yes", refresh the data status of the buffer area buffer2 (including the size of the data used, etc.);

[0067]

[208] : Determine whether the buffer area buffer2 contains all the data read in

[202] . If "yes", execute

[209] and the data is read successfully;

[0068]

[209] : Data read successfully;

[0069]

[210] : If

[206] or

[208] is determined to be "no", determine whether the data to be read is included in the buffer3 cache;

[0070]

[211] : If

[210] is judged as "yes", refresh the data status of the buffer area buffer3 (including the size of the used data, etc.);

[0071]

[212] : Determine whether the buffer area buffer3 contains all the data read in

[202] . If "yes", execute

[209] and the data is read successfully;

[0072]

[213] : If

[210] or

[212] is judged as "No", obtain data directly from the CDN via HTTP.

[0073] 2. Refresh local cache mechanism (see Figure 4 ):

[0074]

[301] : After obtaining data of a fixed length from the CDN via HTTP;

[0075]

[302] : Determine whether the cached data in buffer1 needs to be refreshed. The determination is based on:

[0076]

[301] The difference between the starting position of the data read in and the starting position of the buffer area buffer1 is greater than 3MB or the unused data in the buffer area buffer1 is less than 1024 bytes;

[0077]

[303] : If

[302] is judged as "yes", the data read in

[301] is written to buffer1;

[0078]

[304] : Determine whether there is currently any data cached in the buffer area buffer2;

[0079]

[305] : If

[304] is determined to be "yes", the buffers pointed to by buffer1 and buffer2 are swapped to ensure that the starting position of buffer1 is smaller than that of buffer2;

[0080]

[306] : If the answer of

[302] is “No”, determine whether the cached data in buffer 2 needs to be refreshed, using the same judgment rule as that for buffer 1 in

[302] ;

[0081]

[307] : If

[306] is judged as "yes", the data read in

[301] is written into the buffer area buffer2;

[0082]

[308] : Determine whether there is any data currently cached in buffer3;

[0083]

[309] : If

[308] is determined to be "yes", the buffers pointed to by buffer2 and buffer3 are swapped to ensure that the starting position of buffer2 is smaller than that of buffer3;

[0084]

[310] : If the answer of

[306] is "no", it is determined whether the cached data in buffer 3 needs to be refreshed, and the determination is based on the same determination rule as that of buffer 1 in

[302] ;

[0085]

[311] : If

[310] is judged as "yes", the data read in

[301] is written into the cache buffer3; if

[310] is judged as "no", the data read in

[301] is written into buffer1.

[0086] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.

Claims

1. A method for reading MP4 media based on HTTP protocol, characterized in that: The steps include: Step S01: according to the number of data types of the MP4 file, a corresponding number of buffers are set; Step S02: When reading media data, determine whether the required data exists in the buffer area one by one. If not, determine whether the required data exists in the next buffer; If yes, then refresh the data status of the corresponding buffer, read data from the corresponding buffer, and determine whether all required data have been read. If yes, the required data is read successfully. If not, update the starting position and size of the required data, and determine whether the required data exists in the next buffer. Step S03: Repeat step S02 to determine if the required data is not read successfully after all the buffers in the buffer area, and then read the data from the CDN.

2. The method for reading MP4 media based on HTTP protocol according to claim 1, characterized in that: The step S03 of reading data from the CDN specifically includes the following steps: Step S31: Obtain fixed-length data from the CDN via HTTP; Step S32: Determine whether the buffers need to be refreshed one by one. If yes, the fixed-length data is written into the corresponding buffer, and data exchange is performed to exchange the fixed-length data to the last buffer, completing step S03; If not, determine whether the next buffer area needs to be refreshed; Step S33: Repeat step S32, and after determining that all the cache buffers have not had the fixed-length data written into the cache buffers, write the fixed-length data into the first cache buffer, and perform data exchange, and exchange the fixed-length data to the last cache buffer, completing step S03.

3. The method for reading MP4 media based on HTTP protocol according to claim 2, characterized in that: The data exchange specifically includes determining whether there is data in the next buffer area of ​​the buffer where the fixed-length data is located. If so, exchanging the data of the two buffer areas, and repeating this operation until the fixed-length data is exchanged to the last buffer area.

4. The method for reading MP4 media based on HTTP protocol according to claim 2, characterized in that: The determining whether the buffer area needs to be refreshed specifically includes: If the difference between the starting position of the fixed-length data and the starting position of the data in the cache buffer is greater than 3MB, or the unused data in the cache buffer is less than 1024 bytes, the corresponding cache buffer needs to be refreshed.

5. The method for reading MP4 media based on HTTP protocol according to claim 1, characterized in that: Refreshing the data status corresponding to the buffer in step S02 specifically includes refreshing the size of data used by the buffer.

6. A method for reading MP4 media based on HTTP protocol according to any one of claims 1 to 5, characterized in that: The data types in step S01 include video track, audio track and subtitle track.

7. An MP4 media reading device based on HTTP protocol, characterized in that: It includes a client on-demand system, which includes a media data reading module and a media playing module; The media data reading module is used to set a corresponding number of buffers according to the number of data types of the MP4 file, and read the media data according to the method for reading MP4 media based on the HTTP protocol according to any one of claims 1 to 6, The media playing module is used to play the media data.