Method for slicing mp4 file and method for generating mp4 file

CN117041690BActive Publication Date: 2025-11-11GUANGZHOU AVA ELECTRONICS TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310978413.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-03
Publication Date
2025-11-11
Estimated Expiration
2043-08-03

AI Technical Summary

Technical Problem

然而,在实际的业务里,浏览器访问请求hls的机会更多,而下载mp4的机会则比较少,若采用存储格式mp4格式的视频的话,需要进行转封装的几率也更大,会长期占用cpu资源

Benefits of technology

[0037]本发明中,在对mp4文件进行切片的过程中,保存源mp4文件中的除mdat外的所有box,按照源mp4文件中的mdat中的音视频编码数据的存储顺序转封装生成ts切片,使得重新生成mp4格式文件逆向转封装成mdat时,让重新生成到mdat的音视频编码数据与源mp4文件中的音视频编码数据的存储顺序相同,从而实现两种格式的文件能够共享相同的编码后的数据帧,在快速为客户端提供两种不同格式的文件的同时,又节省了存储空间。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117041690B_ABST
    Figure CN117041690B_ABST
Patent Text Reader

Abstract

This invention discloses a method for slicing MP4 files and a method for generating MP4 files. The MP4 file slicing method includes: acquiring a source MP4 file; reading all boxes except the .mdat file from the source MP4 file and saving all the read boxes to a virtual MP4 file; and transcoding the audio and video encoded data in the .mdat file of the source MP4 file into .TS segments according to the storage order of the audio and video encoded data in the .mdat file. This invention enables two file formats to share the same encoded data frames, quickly providing clients with two different file formats while saving storage space.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of Internet video-on-demand and digital media, and more specifically, to a method for slicing MP4 files and a method for generating MP4 files. Background Technology

[0002] Business servers typically handle both web playback and video download services. HLS format files are commonly used for web playback due to their good browser compatibility, ease of dynamically switching resolutions, and suitability for encrypted playback. MP4 format files, on the other hand, are frequently used for video downloads because of their versatility and ease of storage. However, since HLS and MP4 files are not the same file format, the conventional approach to meet download requirements is to save both formats locally, which undoubtedly increases local storage overhead.

[0003] To address the technical issue of high storage overhead, patent CN103957469B proposes a solution that stores only MP4 format videos. When a user needs an HLS format file, the MP4 video is converted, thus achieving the effect of outputting two format files while storing only one format. However, in actual business scenarios, browsers request HLS files more often than downloading MP4 files. Storing MP4 videos would require more frequent transcoding, leading to prolonged CPU resource consumption. Summary of the Invention

[0004] To overcome the technical problem of excessive repackaging and long-term CPU resource consumption in existing technologies, this invention provides a method for slicing MP4 files and a method for generating MP4 files. The technical solution adopted by this invention is as follows.

[0005] In a first aspect, the present invention provides a method for slicing mp4 files, comprising:

[0006] Get the source mp4 file;

[0007] Read all boxes except mdat from the source mp4 file and save all the read boxes except mdat to a virtual mp4 file;

[0008] Following the storage order of the audio and video encoded data in the mdat file of the source mp4 file, the audio and video encoded data in the mdat file of the source mp4 file is transcoded into TS slices.

[0009] In one implementation, the method further includes: when each TS slice is formed, writing the offset position of the last frame encoded data in the source mp4 in the TS slice to the transcapsulation offset index table.

[0010] In one implementation, the method further includes modifying the moov in the virtual mp4 file so that the modified moov can be placed before mdat when the moov of the source mp4 file is placed after mdat.

[0011] In one implementation, the process of modifying the moov in the virtual mp4 file includes:

[0012] The offset position and size of each box in the source mp4 file are recursively analyzed, and the boxes in the stco are modified according to the offset position and size.

[0013] Secondly, the present invention provides a method for generating mp4 files, comprising:

[0014] Receive download requests for MP4 files;

[0015] Locate the corresponding virtual mp4 file based on the download request;

[0016] The data in the corresponding virtual mp4 file is read based on the offset in the download request, and the read data is encapsulated into mp4 file format;

[0017] The process of reading data from the corresponding virtual mp4 file based on the offset in the download request includes:

[0018] When a position other than mdat is encountered, the corresponding data in the virtual mp4 file is read.

[0019] When the start position of mdat is read, the corresponding ts file is found according to the download request. The ts slices in the ts file are transcoded according to the ts list order, and the transcoded audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated. The ts file is generated using the slicing method of any of the above embodiments.

[0020] In one implementation, it further includes:

[0021] Locate the transpose offset index table corresponding to the virtual mp4 file;

[0022] The process of reading data from the corresponding virtual mp4 file based on the offset in the download request further includes:

[0023] When rereading from a non-starting position in mdat, the corresponding TS number is obtained according to the current offset and the transcapsulation offset index table. Starting from the TS number, the TS slices are transcapsulated according to the TS list order, and the transcapsulated audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

[0024] Thirdly, the present invention provides an mp4 file slicing device, comprising:

[0025] The acquisition module is used to acquire the source mp4 file;

[0026] The reading module is used to read all boxes except mdat from the source mp4 file and save all the read boxes except mdat to a virtual mp4 file;

[0027] The slicing module is used to encapsulate the audio and video encoded data in the mdat file of the source mp4 file into TS slices according to the storage order of the audio and video encoded data in the mdat file of the source mp4 file.

[0028] Fourthly, the present invention provides an apparatus for generating mp4 files, comprising:

[0029] The receiving module is used to receive download requests for MP4 files.

[0030] The search module is used to find the corresponding virtual mp4 file based on the download request;

[0031] The generation module is used to read data from the corresponding virtual mp4 file based on the offset in the download request, and encapsulate the read data into mp4 file format;

[0032] The generation module, in performing the process of reading data from the corresponding virtual mp4 file based on the offset in the download request, includes the following steps:

[0033] When a position other than mdat is encountered, the corresponding data in the virtual mp4 file is read.

[0034] When the beginning position of mdat is read, the TS slices are transcoded according to the TS list order, and the transcoded audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

[0035] Fifthly, the present invention provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method of any of the above embodiments.

[0036] In a sixth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that the program, when executed by a processor, implements the method of any of the above embodiments.

[0037] In this invention, during the slicing of an MP4 file, all boxes except the .mdat file in the original MP4 file are saved. The .ts slices are generated by transcoding and encapsulating the audio and video encoded data in the .mdat file of the original MP4 file according to their storage order. This ensures that when the MP4 file is regenerated and transcoded back into .mdat, the audio and video encoded data in the regenerated .mdat file has the same storage order as the audio and video encoded data in the original MP4 file. This allows the two file formats to share the same encoded data frames, providing the client with two different file formats quickly while saving storage space. Attached Figure Description

[0038] Figure 1 This is a flowchart illustrating Embodiment 1 of the present invention.

[0039] Figure 2 This is a schematic diagram of an MP4 file encapsulation structure.

[0040] Figure 3 This is a schematic diagram of another MP4 file encapsulation structure.

[0041] Figure 4 This is a flowchart illustrating Embodiment 2 of the present invention.

[0042] Figure 5 This is a schematic diagram of the overall structure of Embodiment 3 of the present invention.

[0043] Figure 6 This is a schematic diagram of the overall structure of Embodiment 4 of the present invention. Detailed Implementation

[0044] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

[0045] It should be noted that the terms "first, second, ..." used in the embodiments of the present invention are merely used to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, ..." can be interchanged in a specific order or sequence where permissible. It should be understood that the objects distinguished by "first, second, ..." can be interchanged where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein.

[0046] Example 1

[0047] Please see Figure 1 , Figure 1 This is a flowchart illustrating a method for slicing an MP4 file according to Embodiment 1 of the present invention, including steps S110, S120, and S130. It should be noted that steps S110, S120, and S130 are merely reference numerals used to clearly explain the embodiment and the accompanying drawings. Figure 1 The correspondence is not intended to limit the order of steps in this embodiment.

[0048] Step S110: Obtain the source mp4 file;

[0049] Step S120: Read all boxes except mdat from the source mp4 file and save all the read boxes except mdat to a virtual mp4 file;

[0050] Step S130: According to the storage order of the audio and video encoded data in the mdat of the source mp4 file, the audio and video encoded data in the mdat of the source mp4 file is transcoded into TS slices.

[0051] An MP4 file mainly consists of three parts: ftyp, moov, and mdat. Among them, mdat occupies the most storage space. mdat stores the actual audio and video data, i.e., the encoded audio and video data, with video and audio alternating (index information is provided by moov). Meanwhile, HLS consists of TS segments and M3U8 files. The data actually stored in the TS segments is also encoded audio and video data, with video and audio alternating (taking H.264 video encoding and AAC audio encoding as an example). Of course, there are differences between the two. In video, each keyframe in a TS segment needs to include SPS and PPS data, while in MP4, SPS and PPS are stored in the AVC box of moov. In audio, each AAC frame in a TS segment needs to include an ADTS header, while in MP4, audio sampling rate information, etc., is also stored in moov. It's actually easy to understand. An MP4 file is a complete video file, and the encoding parameters only need to be stored once. However, the TS segment method stores a series of video segments. For the browser, each segment is independent, so decoding information is required every time a segment is loaded.

[0052] Clearly, these two video formats are essentially different only in their container encapsulation methods; the actual audio and video data are still encoded data frames (e.g., H.264 and AAC encoding), which are identical. If files of both formats can share the same encoded data frames, it is possible to quickly provide clients with two different file formats while saving storage space. This method is based on this idea.

[0053] In step S120, all boxes except the mdat file in the source mp4 file are read and saved. These boxes are unique to mp4 files and not found in HLS format files; they cannot be shared, so they need to be saved for use when generating the mp4 file.

[0054] Step S130 involves slicing the audio and video encoded data of the .mdat file in the source mp4 file. This method optimizes this process to achieve the goal of sharing audio and video encoded data. Specifically, by interpreting the media file encoding information, timestamps, and data frame lengths of the source mp4 file, .ts slices and corresponding .m3u8 playback indexes are formed. When transcoding into .ts slices, the audio and video data must be transcoded strictly according to the storage order in the .mdat file. This is to ensure that when regenerating the mp4 file and reverse transcoding into the .mdat audio and video encoded data format, the corresponding audio and video frames can correspond to the index information in the .moov file.

[0055] In this method, during the slicing of the MP4 file, all boxes except the .mdat file in the source MP4 file are saved. The .ts slices are generated by transcoding and encapsulating the audio and video encoded data in the .mdat file of the source MP4 file according to the storage order of the audio and video encoded data. This ensures that when the MP4 file is regenerated and transcoded back into .mdat, the audio and video encoded data can correspond to the information in the MOOV file. This allows the two file formats to share the same encoded data frames, providing the client with two different file formats quickly while saving storage space.

[0056] In one embodiment, the slicing method for the mp4 file further includes step S140.

[0057] Step S140: When a TS slice is formed, the offset position of the last frame encoded data in the source mp4 in the TS slice is written to the transcapsulation offset index table.

[0058] When a slice is formed, the offset of the last frame of encoded data in the TS slice to the target file is written to the transcapsulation offset index table. The transcapsulation offset index table records the offsets of the MP4 header and media data to the target file. The offset of the MP4 header corresponds to the total size of the boxes before the .mdat file in the regenerated MP4 format (the positional relationship of the boxes after regenerating the MP4 format is as follows...). Figure 2 As shown, the size of the mp4 header is equal to the size of the ftyp; if as... Figure 3 As shown, the size of the MP4 header is equal to the sum of the sizes of the FTYP and Moov files, and the offset of the media data corresponds to the offset of the TS segment mapped to the target MP4 file. The advantage of this approach is that it supports seek operations during the subsequent regeneration of the MP4 file. Given an MP4 offset, the corresponding TS segment can be found through the index file, and the MP4 content can be transcoded starting from that TS segment, thus shortening the offset calculation time.

[0059] In one implementation, step S150 is also included.

[0060] In step S150, when the moov of the source mp4 file is placed after mdat, the moov in the virtual mp4 file is modified so that the modified moov can be placed before mdat.

[0061] like Figure 2As shown, MP4 files typically have the `moov` container at the end. An MP4 file sequentially includes three parts: B1, B2, and B3. Part B1 contains the file type container `ftpy`, and some MP4 files may also include free boxes. Part B2 contains the media data container `mdat`. Part B3 contains the metadata container `moov`. The metadata container `moov` follows the media data container `mdat`, and it records the index information of the media data.

[0062] At the same time, mp4 files also have a moov prefix (such as...). Figure 3 The type shown is MP4. This type of MP4 file has higher usability, such as being easier for browsers to load and achieving a fast playback effect. To make the generated MP4 files also highly usable, this implementation method adjusts the settings so that the regenerated MP4 files are all in a MOOV-prefixed manner. Of course, if the source MP4 file itself is MOOV-prefixed, no adjustments are needed; adjustments are only made when the MP4 file is MOOV-postfixed. To move MOOV forward, the index information of the media data recorded by MOOV needs to be modified accordingly.

[0063] In one implementation, the process of modifying moov in a virtual mp4 file includes: step S151.

[0064] Step S151: Recursively analyze the offset position and size of each box in the source mp4 file, and modify the STCO boxes according to the offset position and size.

[0065] After parsing the obtained source MP4 file, the positions of each box in the source MP4 file are obtained. Having obtained the positions of each box in the source MP4 file, we actually know how... Figure 2 The positions and sizes of B1, B2, and B3 in the mp4 file are shown. Knowing their positions and sizes, we can calculate the offset positions and sizes of each box after the Moov file is shifted forward. Based on these offset positions and sizes, we can modify the STCO (chunk offset, the offset of each chunk; the sample offset can be calculated from other boxes) boxes in the Moov file to obtain boxes that can be used for... Figure 3 The moov file of the mp4 type shown is now available.

[0066] Example 2

[0067] Corresponding to the method in Embodiment 1, the present invention also provides a method for generating an mp4 file using the slices obtained by the method in Embodiment 1. Please see below. Figure 4 , Figure 4 This is a flowchart illustrating a method for generating an MP4 file according to Embodiment 2 of the present invention, including steps S410, S420, and S430. It should be noted that steps S410, S420, and S430 are merely reference numerals used to clearly explain the embodiment and the accompanying drawings. Figure 4 The correspondence is not intended to limit the order of steps in this embodiment.

[0068] Step S410: Receive a download request for an mp4 file;

[0069] Step S420: Locate the corresponding virtual mp4 file according to the download request;

[0070] Step S430: Read the data from the corresponding virtual mp4 file according to the offset in the download request, and encapsulate the read data into mp4 file format.

[0071] The process of reading data from the corresponding virtual mp4 file according to the offset in the download request in step S430 includes steps S431 and S432.

[0072] Step S431: When a non-mdat position is read, read the corresponding data in the virtual mp4 file;

[0073] Step S432: When the start position of mdat is read, the corresponding ts file is found according to the download request, the ts slices in the ts file are transcoded according to the ts list order, and the transcoded audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

[0074] When a download request for an MP4 file is received, the system searches for a virtual MP4 file saved using the method described in Example 1. These files contain the boxes (excluding the .mdat) from the MP4 file, so we need to transmit this information. When a non-.mdat position is encountered, the system directly reads the content from the virtual MP4 file.

[0075] The .mdat file in the MP4 file to be generated stores audio and video encoded data. Following the slicing method in Example 1, this data is saved in the .ts slice. Therefore, when the beginning of the .mdat file is read, the audio and video encoded data from the .ts file needs to be reassembled into the .mdat file of the MP4 file to be generated. Since Example 1 slices the MP4 file according to the storage order of the audio and video encoded data in the .mdat file, as long as the transpilation and reading are performed from the beginning according to the .ts list order, the reassembled audio and video encoded data in the .mdat file will naturally have the same storage order as the audio and video encoded data in the source MP4 file. Once all the read audio and video encoded data is written into the .mdat file of the MP4 file to be generated, the regeneration of the .mdat file is complete.

[0076] In this method, during the regeneration of the sliced ​​MP4 file, when a non-mdat position is read, the data in the corresponding box of the virtual MP4 file is directly read. When the mdat position is read, the TS is reverse-encapsulated according to the TS list order and the audio and video encoded data is read. The read audio and video encoded data is written into the mdat, so that the mdat in the target MP4 file is consistent with the mdat in the source MP4 file. This allows the two file formats to share the same encoded data frames, quickly providing the client with two different file formats while saving storage space.

[0077] In one embodiment, the method for generating the mp4 file further includes step S440.

[0078] Step S440: Locate the transpose offset index table corresponding to the virtual mp4 file.

[0079] The process of reading data from the corresponding virtual mp4 file based on the offset in the download request in step S430 further includes step S433.

[0080] Step S433: When rereading from a non-starting position of mdat, obtain the corresponding TS number according to the current offset and the transcapsulation displacement index table. Starting from the TS number, transcapitalize the TS slices according to the TS list order and read the transcapitalized audio and video encoded data. Write the read audio and video encoded data into the mdat of the mp4 file to be generated.

[0081] This implementation method is applicable to scenarios where the download is interrupted due to network or service anomalies, and after recovery, it is necessary to start reading from a specific position in the target file. Step S140 in Embodiment 1 generates a transcapsulation offset index table. This table records the offset of the media data corresponding to the offset of the TS segment mapped to the target MP4 file. Therefore, in this implementation method, by using the current offset and the transcapsulation offset index table, it is possible to determine which TS segment the current offset falls into, obtain the corresponding TS sequence number, find the TS file path corresponding to the m3u8 using this sequence number, and start reading the media data in the TS format from the TS file corresponding to that TS sequence number, encapsulating it into the MP4 MDAT audio and video data format. This process continues until the accumulated transcapsulated data reaches the offset, at which point the normal download process resumes.

[0082] Example 3

[0083] Corresponding to the method in Example 1, such as Figure 5 As shown, the present invention also provides an MP4 file slicing device, including: an acquisition module 510, a reading module 520, and a slicing module 530.

[0084] Module 510 is used to acquire the source mp4 file;

[0085] The reading module 520 is used to read all boxes except mdat from the source mp4 file and save all the read boxes except mdat to a virtual mp4 file;

[0086] The slicing module 530 is used to encapsulate the audio and video encoded data in the mdat of the source mp4 file into TS slices according to the storage order of the audio and video encoded data in the mdat of the source mp4 file.

[0087] In one embodiment, the slicing device for the mp4 file further includes a list generation module.

[0088] The list generation module is used to write the offset position of the last frame encoded data in the source MP4 in the transcapsulation offset index table when each TS slice is formed.

[0089] In one embodiment, the slicing device for the mp4 file further includes a rewriting module.

[0090] The rewrite module is used to modify the moov in a virtual mp4 file when the moov in the source mp4 file is placed after the mdat, so that the modified moov is placed before the mdat.

[0091] In one implementation, the rewriting module, in performing the process of modifying the moov in the virtual mp4 file, includes:

[0092] The offset position and size of each box in the source mp4 file are recursively analyzed, and the boxes in the stco are modified according to the offset position and size.

[0093] In this device, during the slicing of an MP4 file, all boxes except the .mdat file in the source MP4 file are saved. The .ts slices are generated by transcoding and encapsulating the audio and video encoded data in the .mdat file of the source MP4 file according to the storage order of the audio and video encoded data. This allows the audio and video encoded data to correspond with the information in the MOOV file when the MP4 file is regenerated and transcoded back into .mdat. This enables the two file formats to share the same encoded data frames, providing the client with two different file formats quickly while saving storage space.

[0094] Example 4

[0095] Corresponding to the method in Example 2, such as Figure 6 As shown, the present invention also provides an mp4 file generation device, including: a receiving module 610, a searching module 620, and a generation module 630.

[0096] The receiving module 610 is used to receive download requests for mp4 files;

[0097] The search module 620 is used to search for the corresponding virtual mp4 file according to the download request;

[0098] The generation module 630 is used to read the data from the corresponding virtual mp4 file according to the offset in the download request, and encapsulate the read data into mp4 file format.

[0099] The generation module 630 performs the process of reading data from the corresponding virtual mp4 file based on the offset in the download request, including the following steps:

[0100] When a position other than mdat is encountered, the corresponding data in the virtual mp4 file is read.

[0101] When the beginning position of mdat is read, the TS slices are transcoded according to the TS list order, and the transcoded audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

[0102] In one embodiment, the search module is further configured to search the transpose offset index table corresponding to the corresponding virtual mp4 file;

[0103] The generation module 630, in the process of reading data from the corresponding virtual mp4 file based on the offset in the download request, further includes the following steps:

[0104] When rereading from a non-starting position in mdat, the corresponding TS number is obtained according to the current offset and the transcapsulation offset index table. Starting from the TS number, the TS slices are transcapsulated according to the TS list order, and the transcapsulated audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

[0105] In this device, during the regeneration of the sliced ​​MP4 file, when a non-mdat position is read, the data in the corresponding box of the virtual MP4 file is directly read. When the mdat position is read, TS transcoding is performed according to the TS list order, and the audio and video encoded data is read. The read audio and video encoded data is written into mdat, so that the audio and video encoded data regenerated into mdat has the same storage order as the audio and video encoded data in the source MP4 file. This allows the two file formats to share the same encoded data frames, quickly providing the client with two different file formats while saving storage space.

[0106] Example 5

[0107] This invention also provides a storage medium storing computer instructions that, when executed by a processor, implement the mp4 file slicing method and the mp4 file generation method of any of the above embodiments.

[0108] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, random access memory (RAM), read-only memory (ROM), magnetic disks, or optical disks.

[0109] Alternatively, if the integrated units of this invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this invention, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, terminal, or network device, etc.) to execute all or part of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, RAM, ROM, magnetic disks, or optical disks.

[0110] Corresponding to the computer storage medium described above, one embodiment also provides a computer device, which includes a memory, an encoder, and a computer program stored in the memory and executable on the encoder. When the encoder executes the program, it implements any of the mp4 file slicing methods and mp4 file generation methods described in the above embodiments.

[0111] The aforementioned computer device, during the process of slicing an MP4 file, saves all boxes except for the .mdat file in the original MP4 file, and transcodes and generates .ts slices according to the storage order of the audio and video encoded data in the .mdat file of the original MP4 file. This ensures that when the MP4 file is regenerated and transcoded back into .mdat, the audio and video encoded data in the regenerated .mdat file has the same storage order as the audio and video encoded data in the original MP4 file. This allows the two file formats to share the same encoded data frames, quickly providing the client with two different file formats while saving storage space.

[0112] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0113] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the implementation of the present invention. Those skilled in the art can make other variations or modifications based on the above description. It is neither necessary nor possible to exhaustively describe all embodiments here. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the claims of the present invention.

Claims

1. A method for slicing MP4 files, characterized in that, include: Get the source mp4 file; Read all boxes except mdat from the source mp4 file and save all the read boxes except mdat to a virtual mp4 file; Following the storage order of the audio and video encoded data in the mdat file of the source mp4 file, the audio and video encoded data in the mdat file of the source mp4 file is transcoded and encapsulated into TS slices for saving.

2. The method for slicing mp4 files according to claim 1, characterized in that, Also includes: When a TS slice is formed, the offset position of the last frame of encoded data in the source MP4 in the TS slice is written to the transcapsulation offset index table.

3. The method for slicing mp4 files according to claim 1 or 2, characterized in that, Also includes: When the moov of the source mp4 file is placed after mdat, the moov in the virtual mp4 file is modified so that the modified moov can be placed before mdat.

4. The method for slicing mp4 files according to claim 3, characterized in that, The process of modifying the moov in the virtual mp4 file includes: The offset position and size of each box in the source mp4 file are recursively analyzed, and the boxes in the stco are modified according to the offset position and size.

5. A method for generating an MP4 file, characterized in that, include: Receive download requests for MP4 files; Locate the corresponding virtual mp4 file based on the download request; The data in the corresponding virtual mp4 file is read based on the offset in the download request, and the read data is encapsulated into mp4 file format; The process of reading data from the corresponding virtual mp4 file based on the offset in the download request includes: When a position other than mdat is encountered, the corresponding data in the virtual mp4 file is read. When the beginning position of mdat is read, the TS slices are transcoded according to the TS list order, and the transcoded audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

6. The method for generating mp4 files according to claim 5, characterized in that, Also includes: Locate the transpose offset index table corresponding to the virtual mp4 file; The process of reading data from the corresponding virtual mp4 file based on the offset in the download request further includes: When rereading from a non-starting position in mdat, the corresponding TS number is obtained according to the current offset and the transcapsulation offset index table. Starting from the TS number, the TS slices are transcapsulated according to the TS list order, and the transcapsulated audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

7. A device for slicing MP4 files, characterized in that, include: The acquisition module is used to acquire the source mp4 file; The reading module is used to read all boxes except mdat from the source mp4 file and save all the read boxes except mdat to a virtual mp4 file; The slicing module is used to encapsulate the audio and video encoded data in the mdat file of the source mp4 file into TS slices for saving, according to the storage order of the audio and video encoded data in the mdat file of the source mp4 file.

8. An apparatus for generating mp4 files, characterized in that, include: The receiving module is used to receive download requests for MP4 files. The search module is used to find the corresponding virtual mp4 file based on the download request; The generation module is used to read data from the corresponding virtual mp4 file based on the offset in the download request, and encapsulate the read data into mp4 file format; The generation module, in performing the process of reading data from the corresponding virtual mp4 file based on the offset in the download request, includes the following steps: When a position other than mdat is encountered, the corresponding data in the virtual mp4 file is read. When the beginning position of mdat is read, the TS slices are transcoded according to the TS list order, and the transcoded audio and video encoded data is read. The read audio and video encoded data is written into the mdat of the mp4 file to be generated.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-6.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Internet video-on-demand method and system based on real-time transcapsulation

    CN103957469B

  • Video-on-demand system and method for converting mp4 formatted file into hls formatted file

    CN108156478A

  • Method for fragmentation and transcoding / composition and flash splicing to MP4 file based on object storage

    CN109195012A