Hls resource dynamic conversion method based on mp4 metadata analysis and corresponding device
By parsing MP4 files to generate metadata and obtaining the segment duration in real time, the problem of large storage space occupied by TS files and the inability to adjust the segment duration in existing technologies is solved, realizing dynamic adjustment of HLS segment files and optimization of storage space.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-29
- Publication Date
- 2026-03-31
AI Technical Summary
In the current online video field, the pre-segmentation scheme results in TS files occupying a large amount of storage space and cannot dynamically adjust the segment duration, which cannot meet the needs of different segmentation strategies.
Metadata files are generated by parsing the original MP4 file, the segment duration is obtained in real time, segment details and M3U8 files are generated, and the audio and video frames of the TS segment are repackaged into HLS segment files in binary format.
It reduces storage space usage, enables dynamic changes to HLS sharded files to adapt to different sharding needs, and lowers storage costs.
Smart Images

Figure CN121037587B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of audio and video processing, specifically to a method and corresponding equipment for dynamic conversion of HLS resources based on MP4 metadata parsing. Background Technology
[0002] As an important medium in the digital age, online video is profoundly changing people's lifestyles. Whether for entertainment, education, or information access, online video, with its "intuitive, convenient, and interactive" characteristics, comprehensively improves people's life efficiency and experience, becoming an indispensable tool and carrier in modern society.
[0003] HLS (HTTP Live Streaming) is a streaming media communication protocol based on HTTP. Due to its advantages such as adaptive bitrate, high compatibility, and stability, it is widely used in the field of online video playback. However, users' original videos are usually stored in MP4 format, which is not suitable for direct online streaming transmission. Therefore, converting MP4 to HLS format is a necessary step to meet the needs of online playback, and this conversion process is a key link in modern online video distribution.
[0004] Currently, the mainstream solution for converting MP4 videos to HLS format is pre-segmentation. The core of this solution is to use a professional segmentation tool (such as FFmpeg, an open-source multimedia framework that can easily convert MP4 to HLS format) to pre-cut the MP4 file into multiple TS segments (mpegts format) and generate corresponding M3U8 index files. After the conversion is completed, the HLS file will be stored on a server or CDN. When a user requests playback, the pre-segmented HLS resources can be directly called.
[0005] Although the pre-segmentation method has been widely used in the video-on-demand field, it still has two obvious drawbacks:
[0006] First, TS files take up a large amount of storage space;
[0007] HLS uses the TS format as the segment container by default. Compared with the original MP4 file, TS has lower encoding efficiency and usually results in a 20%-30% increase in size. For large-scale video-on-demand services, storing massive amounts of TS files will significantly increase costs.
[0008] Second, the duration of each segment cannot be dynamically adjusted;
[0009] The pre-segmentation scheme must have a fixed segment duration (e.g., 10 seconds per segment). If a new fixed segment duration (e.g., 5 seconds per segment) or a non-fixed segment duration (e.g., 10 seconds, 5 seconds, 8 seconds, etc.) is required, pre-segmentation must be performed again, which will incur additional file storage costs. If the segmentation strategy used for each playback is different (the segment duration cannot be known in advance), pre-segmentation cannot meet the requirements.
[0010] In summary, the existing online video segmentation schemes suffer from significant space consumption and the inability to dynamically adjust segment durations, which urgently need improvement. Summary of the Invention
[0011] To address one of the aforementioned technical deficiencies, this application provides a method and corresponding equipment for dynamic conversion of HLS resources based on MP4 metadata parsing.
[0012] The first aspect of this application provides a method for dynamic conversion of HLS resources based on MP4 metadata parsing, including:
[0013] S10: Parse the original MP4 file, generate a metadata file, and store it;
[0014] S20, get the slice duration;
[0015] S30 reads and parses the metadata file, and generates shard details and an M3U8 file based on the shard duration and the parsed metadata file;
[0016] S40, based on the segment details, reads the audio and video frames contained in each TS segment of the original MP4 file;
[0017] S50 repackages the audio and video frames contained in each TS segment into a binary HLS segment file.
[0018] In an optional embodiment of this application, step S10, parsing the moov data blocks in the MP4 file to generate a metadata file, includes:
[0019] S101, Start the metadata generation task;
[0020] S102, save the MP4 file to the shared storage space;
[0021] S103, parse the moov data block in the MP4 file;
[0022] S104: Generate a metadata file based on the information in the moov data block and save the metadata file to the shared storage space.
[0023] In an optional embodiment of this application, step S30 involves reading and parsing the metadata file, and generating shard details and an M3U8 file based on the shard duration and the parsed metadata file, including:
[0024] S301 receives HTTP M3U8 requests from end users;
[0025] S302 parses the HTTP M3U8 request to obtain the segment duration information and the ID information of the original MP4 file;
[0026] S303: Based on the ID information of the original MP4 file, extract the metadata file corresponding to the ID information in the shared storage space and parse it to obtain the metadata content;
[0027] S304, Generate fragment details based on metadata content;
[0028] S305 generates an M3U8 file based on the detailed information of the fragments and the duration of each fragment;
[0029] Among them, an HTTP M3U8 request refers to requesting an M3U8 file via the HTTP protocol.
[0030] In an optional embodiment of this application, the fragmentation details include: index, fragmentation duration, start keyframe index, and end keyframe index.
[0031] In an optional embodiment of this application, step S305 generates an M3U8 file based on the fragment details and the duration of each fragment, including:
[0032] S305-1, set the slice duration T, and access the keyframe list starting from the first keyframe;
[0033] S305-2, Create a new shard information list with an initial value of empty; add the new shard information list to the shard information list.
[0034] Set: Fragment duration d = 0;
[0035] S305-3, Calculate the duration t between the next keyframe time and the current keyframe time; Let: d = d + t;
[0036] S305-4, compare the slicing time d with the slice time T;
[0037] If the current keyframe is not the last frame in the keyframe list and the current slice duration d is greater than or equal to the slice duration T, then the current slice ends, the duration field corresponding to the slice is generated, and the slice information list is updated; then, step S305-2 is executed.
[0038] If the current keyframe is not the last frame in the keyframe list and the current slice duration d is less than the slice duration T, then the current slice ends, the duration field corresponding to the slice is generated, and the slice information list is updated; then, step S305-3 is executed.
[0039] If the current keyframe is the last frame in the keyframe list, then generate the duration field corresponding to this slice and update the slice information list; end the slicing process.
[0040] S305-5: Generate and output an M3U8 format string based on the duration field of each fragment in the fragment details list.
[0041] In an optional embodiment of this application, step S50 involves repackaging the audio and video frames contained in each TS segment into a binary format HLS segment file; including:
[0042] S501, Let the index of the TS to be generated be i;
[0043] S502, access the i-th element in the segment details list, and locate the MP4 file to the position of the video keyframe based on the time of the video keyframe;
[0044] S503 reads video and audio frames starting from the position of the video keyframe, and the number of frames read is the number of video frames and audio frames in the segment information list.
[0045] S504 encapsulates the read video and audio frames into TS binary data and outputs them.
[0046] In an optional embodiment of this application, the metadata file is encoded in the following format: category name, attribute name, and attribute description.
[0047] Each category name corresponds to multiple attribute names; each attribute name corresponds to one attribute description.
[0048] The category names include: basic information and keyframe information.
[0049] A second aspect of this application provides an HLS resource dynamic conversion system based on MP4 metadata parsing, comprising: a backend device and a frontend device;
[0050] The backend device includes:
[0051] The MP4 file parsing module is used to parse the original MP4 file, generate metadata files, and store them.
[0052] The front-end device includes:
[0053] The acquisition module is used to obtain the shard duration;
[0054] The metadata file parsing module is used to read and parse metadata files;
[0055] The M3U8 file generation module is used to generate detailed information about the shards and an M3U8 file based on the shard duration and the parsed metadata file.
[0056] The TS segment generation module is used to read the audio and video frames contained in each TS segment of the original MP4 file based on the segment details; and to repackage the audio and video frames contained in each TS segment into a binary HLS segment file.
[0057] A third aspect of this application provides a computer device, including: a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of any of the above methods.
[0058] A fourth aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the steps of the method as described in any of the above.
[0059] The HLS resource dynamic conversion method and corresponding device based on MP4 metadata parsing provided in this application embodiment can pre-analyze MP4 files by parsing the original MP4 file, generating and storing metadata files for subsequent HLS use. When HLS resource conversion is required, the segment duration is obtained in real time, and segment details and M3U8 files are generated using the segment duration and the parsed metadata file. Then, by reading the audio and video frames contained in each TS segment of the MP4 file, the audio and video frames contained in each TS segment are re-encapsulated into binary format HLS segment files. Throughout the process, only a small amount of metadata files need to be pre-stored, without the need to store large amounts of HLS segment files, which reduces the storage space occupied compared with traditional methods. At the same time, by obtaining the segment duration in real time, the output HLS segment files can be dynamically changed according to needs, making it highly practical.
[0060] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by way of what is pointed out in the written description, claims, and drawings. Attached Figure Description
[0061] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0062] Figure 1 A flowchart illustrating a dynamic HLS resource conversion method based on MP4 metadata parsing, provided in one embodiment of this application;
[0063] Figure 2 A flowchart of step S10 in an HLS resource dynamic conversion method based on MP4 metadata parsing provided in an embodiment of this application;
[0064] Figure 3 A flowchart of step S30 in an HLS resource dynamic conversion method based on MP4 metadata parsing provided in an embodiment of this application;
[0065] Figure 4 A flowchart of step S40 in an HLS resource dynamic conversion method based on MP4 metadata parsing provided in an embodiment of this application;
[0066] Figure 5 A flowchart of step S50 in an HLS resource dynamic conversion method based on MP4 metadata parsing provided in an embodiment of this application;
[0067] Figure 6 This is a schematic diagram of the structure of an HLS resource dynamic conversion system based on MP4 metadata parsing, provided in one embodiment of this application.
[0068] In the picture:
[0069] 10 represents backend devices, 20 represents frontend devices, and 30 represents shared storage space;
[0070] 101 is the MP4 file parsing module, and 102 is the task management module.
[0071] 201 is the acquisition module, 202 is the metadata file parsing module, 203 is the M3U8 file generation module, 204 is the TS fragment generation module, and 205 is the HTTP processing module. Detailed Implementation
[0072] The solutions in this application embodiment can be implemented using various computer languages, such as the object-oriented programming language Java and the interpreted scripting language JavaScript.
[0073] To make the technical solutions and advantages of the embodiments of this application clearer, the exemplary embodiments of this application will be described in further detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not an exhaustive list of all embodiments. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of this application can be combined with each other.
[0074] In order to ensure the accuracy of the citations and the fluency of reading, the key technical terms, abbreviations or acronyms used in the text are summarized and explained as follows:
[0075] MP4, MPEG-4 Part 14, is part 14 of the MPEG-4 standard; it mainly defines a multimedia file format (with the extension .MP4) based on MPEG-4, used to store video, audio, subtitles, and other content.
[0076] MPEG, Moving Picture Experts Group;
[0077] moov data blocks, or Movie Boxes, are used to store media metadata.
[0078] HLS, HTTP Live Streaming, is a streaming media transmission protocol based on the HTTP protocol. Its core principle is to divide a continuous audio and video stream into multiple small files based on the MPEG-TS format.
[0079] TS, MPEG Transport Stream, is a container format for audio and video data transmission and storage. It is developed by MPEG and widely used in streaming media, broadcast television, and other fields.
[0080] TS fragmentation is mainly used in the HLS protocol and is the carrier for splitting media streams in the HLS protocol;
[0081] M3U8 is a text-based index file format primarily used in conjunction with the HLS protocol to manage segmented streaming media content. It records information such as the network address and duration of each TS segment. The client parses the M3U8 file to obtain the download address of the TS segment, and then downloads and plays these segments sequentially, thereby enabling audio and video playback.
[0082] The applicant discovered that the existing HLS protocol's slicing method generates a large number of files, and storing or processing these files results in a significant waste of resources.
[0083] Addressing the problems with existing technologies:
[0084] Please see Figure 1 This application provides a method for dynamic conversion of HLS resources based on MP4 metadata parsing, including:
[0085] S10: Parse the original MP4 file, generate a metadata file, and store it;
[0086] S20, get the slice duration;
[0087] S30 reads and parses the metadata file, and generates shard details and an M3U8 file based on the shard duration and the parsed metadata file;
[0088] S40, based on the segment details, reads the audio and video frames contained in each TS segment of the original MP4 file;
[0089] S50 repackages the audio and video frames contained in each TS segment into a binary HLS segment file.
[0090] In this embodiment, by parsing the original MP4 file, generating and storing a metadata file, pre-analysis of the MP4 file can be achieved for subsequent HLS use. When HLS resource conversion is required, the segment duration is obtained in real time, and segment details and an M3U8 file are generated using the segment duration and the parsed metadata file. Then, by reading the audio and video frames contained in each TS segment of the MP4 file, the audio and video frames contained in each TS segment are repackaged into a binary format HLS segment file. Throughout the process, only a small metadata file needs to be pre-stored, without the need to store the large HLS segment file, which reduces the storage space occupied compared to the traditional method. At the same time, by obtaining the segment duration in real time, the output HLS segment file can be dynamically changed according to requirements.
[0091] like Figure 2 As shown, step S10 involves parsing the moov data blocks in the MP4 file to generate a metadata file; this includes:
[0092] S101, Start the metadata generation task;
[0093] S102, save the MP4 file to the shared storage space;
[0094] S103, parse the moov data block in the MP4 file;
[0095] S104: Generate a metadata file based on the information in the moov data block and save the metadata file to the shared storage space.
[0096] In this embodiment, MP4 files can be pre-analyzed for subsequent use by HLS; when in use, the metadata generation task can be initiated actively or by polling.
[0097] The moov data block is the "metadata container" of an MP4 file, corresponding to the mdat (Media Data Box) which stores the actual audio and video frame data. Its core function is to record the structural information and attribute parameters of the audio and video, enabling the player to parse, synchronize, and play the media content.
[0098] Specifically, the moov data block generates and stores the following core metadata types through multiple nested sub-blocks (Boxes). The hierarchical structure of these sub-blocks collectively constitutes the complete metadata system. The sub-blocks include:
[0099] (1) Global video information (mvhd sub-block)
[0100] The mvhd sub-block is the top-level sub-block of the moov data block, storing global metadata for the entire video, including:
[0101] Video creation time and modification time (timestamp);
[0102] Time scale (unit: Hertz, used to calculate actual time);
[0103] Total video duration (a value based on the time scale, duration = total time units / time scale).
[0104] Playback speed, volume;
[0105] Video spatial information (such as default playback size, transformation matrix, etc.).
[0106] (2) Track information (Trak sub-blocks and their subordinate sub-blocks)
[0107] Generally, an MP4 file contains multiple "tracks", such as video tracks, audio tracks, subtitle tracks, etc. The metadata of each track is recorded by the Trak (Track Box) sub-block and its subordinate sub-blocks, specifically including: track basic information sub-block and media information sub-block;
[0108] The basic track information sub-block includes:
[0109] Track ID (unique identifier, such as video track ID=1, audio track ID=2);
[0110] Track type (video / audio / subtitles, etc.);
[0111] Track duration;
[0112] Track status (whether it is enabled, whether it is visible / audible);
[0113] Track dimensions (such as the width and height of the video track, the number of channels of the audio track, etc.).
[0114] The media information includes the track encoding format, sampling information, etc., including:
[0115] Media Header Box (MDHD) data blocks contain track timescales, language encodings, etc.
[0116] The minf data block (Media Information Box) contains specific information about the media data, including:
[0117] The stbl data block (Sample Table Box) records key metadata such as the index, duration, and size of audio and video frames (Samples), and serves as a "map" for the player to parse mdat data;
[0118] (3) Encoding and format information (stsd sub-block)
[0119] The STSD (Sample Description Box) is a sub-block of the STBL data block, used to record the audio and video encoding formats and decoding parameters. It is one of the most critical parts of the metadata. For example:
[0120] Video track, encoding format (such as H.264 / AVC, H.265 / HEVC), resolution, frame rate, bit rate, etc.;
[0121] Audio track, encoding format (such as AAC, MP3), sampling rate (such as 44.1kHz), number of channels (such as stereo), bit rate, etc.
[0122] Furthermore, the process of generating metadata files from moov data blocks is essentially the extraction, organization, and structured storage of raw audio and video information by media packaging tools (such as encoders and transcoding software). Specific processes may include:
[0123] Raw data parsing: The raw audio and video streams output by the encoder contain basic information such as encoding parameters (such as resolution and sampling rate) and timestamps. This information is parsed by encapsulation tools (such as FFmpeg and MP4Box).
[0124] Metadata structuring: The encapsulation tool categorizes the parsed information according to the MP4 format specification and fills it into various sub-blocks of moov; for example, global information is filled into the mvhd sub-block, and encoding format and decoding parameters are filled into the stsd sub-block, etc.
[0125] moov block writing to file: The structured metadata is packaged into moov data blocks and written to the MP4 file along with the mdat blocks that store the actual frame data.
[0126] As can be seen from the above, the moov data block is the "carrier" of MP4 file metadata. It systematically stores key metadata such as global information of audio and video, track attributes, and encoding format through a nested sub-block structure (mvhd, trak, stsd, etc.). This metadata is the "instruction manual" for the player to parse, synchronize, and play media content, and its generation process depends on the media encapsulation tool's standardized processing of the original audio and video information.
[0127] In this embodiment of the application, in step S104, the metadata file is saved to the shared storage space so that it can be used by the front-end device. While the front-end device performs HLS dynamic slicing on the MP4, the back-end device can continue to generate metadata files for other MP4s.
[0128] In the HLS protocol, video is divided into multiple TS format segments, each typically 2 to 10 seconds long (to facilitate playback switching and buffering).
[0129] Generating detailed segment information (detailed information of TS segments) and corresponding M3U8 files is a core part of the HLS (HTTP Live Streaming) streaming media protocol. Generating detailed segment information requires specifying the duration, URL, encoding, and other attributes of each TS file. The M3U8 file is a structured index of this information, used to inform the player of the segment's address, duration, encoding format, and other information.
[0130] In the embodiments of this application, such as Figure 3 As shown, in step S30, the metadata file is read and parsed, and based on the shard duration and the parsed metadata file, shard details and an M3U8 file are generated, including:
[0131] S301 receives HTTP M3U8 requests from end users;
[0132] S302 parses the HTTP M3U8 request to obtain the segment duration information and the ID information of the original MP4 file;
[0133] S303: Based on the ID information of the original MP4 file, extract the metadata file corresponding to the ID information in the shared storage space and parse it to obtain the metadata content;
[0134] S304, Generate fragment details based on metadata content;
[0135] S305 generates an M3U8 file based on the detailed information of the fragments and the duration of each fragment;
[0136] Among them, an HTTP M3U8 request refers to requesting an M3U8 file via the HTTP protocol.
[0137] In this embodiment of the application, after the M3U8 file is generated, it can be sent to the end user via an HTTP response.
[0138] In this embodiment of the application, the fragmentation details include: index, fragmentation duration, start keyframe index, and end keyframe index.
[0139] Specifically, step S305 generates an M3U8 file based on the fragment details and the duration of each fragment, including:
[0140] S305-1, set the slice duration T, and access the keyframe list starting from the first keyframe;
[0141] S305-2, Create a new shard information list with an initial value of empty; add the new shard information list to the shard information list.
[0142] Set: Fragment duration d = 0;
[0143] S305-3, Calculate the duration t between the next keyframe time and the current keyframe time; Let: d = d + t;
[0144] S305-4, compare the slicing time d with the slice time T;
[0145] If the current keyframe is not the last frame in the keyframe list and the current slice duration d is greater than or equal to the slice duration T, then the current slice ends, the duration field corresponding to the slice is generated, and the slice information list is updated; then, step S305-2 is executed.
[0146] If the current keyframe is not the last frame in the keyframe list and the current slice duration d is less than the slice duration T, then the current slice ends, the duration field corresponding to the slice is generated, and the slice information list is updated; then, step S305-3 is executed.
[0147] If the current keyframe is the last frame in the keyframe list, then generate the duration field corresponding to this slice and update the slice information list; end the slicing process.
[0148] S305-5: Generate and output an M3U8 format string based on the duration field of each fragment in the fragment details list.
[0149] like Figure 4 As shown, S40, based on the segment details, reads the audio and video frames contained in each TS segment of the original MP4 file; including:
[0150] S401 receives HTTP TS requests from end users;
[0151] S402 parses the HTTP TS request to obtain the segment duration information and the ID information of the original MP4 file;
[0152] S403 obtains the storage location of the corresponding metadata file based on the ID information of the original MP4 file, and reads and parses the metadata file through memory mapping;
[0153] S404 generates detailed sharding information based on the metadata content and temporarily stores it in memory;
[0154] S405, based on the segment details, extract the original files of all video and audio contained in the segment;
[0155] An HTTP TS request refers to requesting a TS file via the HTTP protocol.
[0156] like Figure 5 As shown, step S50 involves repackaging the audio and video frames contained in each TS segment into a binary format HLS segment file; including:
[0157] S501, Let the index of the TS to be generated be i;
[0158] S502, access the i-th element in the segment details list, and locate the MP4 file to the position of the video keyframe based on the time of the video keyframe;
[0159] S503 reads video and audio frames starting from the position of the video keyframe, and the number of frames read is the number of video frames and audio frames in the segment information list.
[0160] S504 encapsulates the read video and audio frames into TS binary data and outputs them.
[0161] In this embodiment of the application, the encoding format of the metadata file is: category name, attribute name, and attribute description;
[0162] Each category name corresponds to multiple attribute names; each attribute name corresponds to one attribute description.
[0163] The category names include: basic information and keyframe information.
[0164] The metadata encoding is shown in the table below.
[0165]
[0166] In the table above: an audio "keyframe" refers to the first audio frame after a video keyframe; (since all audio frames are keyframes, they are distinguished by double quotes).
[0167] It should be understood that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order constraint on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the diagram may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0168] Please see Figure 6 One embodiment of this application provides an HLS resource dynamic conversion system based on MP4 metadata parsing, including: a backend device 10 and a frontend device 20;
[0169] The backend device 10 includes:
[0170] MP4 file parsing module 101 is used to parse the original MP4 file, generate metadata file and store it;
[0171] The front-end device 20 includes:
[0172] Module 201 is used to obtain the shard duration;
[0173] Metadata file parsing module 202 is used to read and parse metadata files;
[0174] The M3U8 file generation module 203 is used to generate detailed information about the shards and an M3U8 file based on the shard duration and the parsed metadata file.
[0175] The TS segment generation module 204 is used to read the audio and video frames contained in each TS segment of the original MP4 file according to the segment details; and to repackage the audio and video frames contained in each TS segment into a binary format HLS segment file.
[0176] In this embodiment of the application, a shared storage space 30 for storing the original MP4 file and metadata file is also included.
[0177] In this embodiment, the background device 10 is generally operated by an administrator who is responsible for generating the metadata file corresponding to the original MP4 file; this function can be implemented in Java, with Tomcat as the container.
[0178] Specifically, the backend device 10 also includes:
[0179] Task management module 102 is used to manage and monitor metadata generation tasks and provides a console interface.
[0180] Furthermore, the front-end device 20 also includes:
[0181] The HTTP processing module 205 is used to receive and process HTTP M3U8 requests and HTTP TS requests, and send HTTP responses to the end user.
[0182] The HTTP TS request refers to requesting a TS file via the HTTP protocol.
[0183] In this embodiment, M3U8 file streams and TS file streams can be output in real time without needing to be stored in storage, thus reducing storage space usage.
[0184] In this embodiment, only metadata files (each file is in the KB range) are stored, eliminating the need to store all HLS shard files (each group of HLS files is in the MB to GB range), thus reducing storage space usage by more than 95%.
[0185] Furthermore, the duration of the HLS sharded files output in this embodiment can be dynamically changed according to requirements, and the duration of each shard can be precisely customized, making the operation flexible and practical.
[0186] Specific limitations regarding the HLS resource dynamic conversion system based on MP4 metadata parsing can be found in the limitations of the HLS resource dynamic conversion method based on MP4 metadata parsing mentioned above, and will not be repeated here. Each module in the aforementioned HLS resource dynamic conversion system based on MP4 metadata parsing can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the corresponding operations of each module.
[0187] In one embodiment, a computer device is provided, comprising a processor, memory, a network interface, and a database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage medium. The database stores data. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements the above-described method for dynamic conversion of HLS resources based on MP4 metadata parsing. This includes: a memory and a processor; the memory stores a computer program; and the processor executes the computer program to implement any step in the above-described method for dynamic conversion of HLS resources based on MP4 metadata parsing.
[0188] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, can perform any of the steps in the above-described method for dynamic conversion of HLS resources based on MP4 metadata parsing.
[0189] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0190] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0191] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0192] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0193] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.
[0194] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A method for dynamic conversion of HLS resources based on MP4 metadata analysis, characterized in that, The method comprises: S10, parsing an original MP4 file, generating a metadata file and storing; S20, obtaining a segment duration; S30, reading and parsing the metadata file, generating segment detailed information and an M3U8 file according to the segment duration and the parsed metadata file, comprising: S301, receiving an HTTP M3U8 request of a terminal user; S302, parsing the HTTP M3U8 request to obtain segment duration information and ID information of the original MP4 file; S303, according to the ID information of the original MP4 file, extracting and parsing the metadata file corresponding to the ID information in the shared storage space to obtain metadata content; S304, generating segment detailed information according to the metadata content; S305, generating an M3U8 file according to the segment detailed information and the duration of each segment, comprising: S305-1, setting a slice duration T and accessing a key frame list from the first key frame; S305-2, creating a new segment information list with an initial value of null and adding the new segment information list to the segment information list; let: segment duration d = 0; S305-3, calculating the duration t between the next key frame time and the current key frame time; let: d = d + t; S305-4, comparing the segment duration d with the slice duration T; if, the current key frame is not the last frame of the key frame list and the current segment duration d is greater than or equal to the slice duration T; then, the current segment ends, the duration field corresponding to the segment is generated, and the segment information list is updated; then, step S305-2 is executed; if, the current key frame is not the last frame of the key frame list and the current segment duration d is less than the slice duration T; then, the current segment ends, the duration field corresponding to the segment is generated, and the segment information list is updated; then, step S305-3 is executed; if, the current key frame is the last frame of the key frame list, the duration field corresponding to the segment is generated, and the segment information list is updated; end the slice; S305-5, generating an M3U8 format string according to the duration field of each segment in the segment detailed information list and outputting; wherein, the HTTP M3U8 request refers to requesting the M3U8 file through the HTTP protocol; S40, reading audio and video frames contained in each TS segment in the original MP4 file according to the segment detailed information; S50, re-encapsulating the audio and video frames contained in each TS segment into a binary format HLS segment file.
2. The MP4 metadata parsing based HLS resource dynamic conversion method of claim 1, wherein, The S10 comprises: S101, starting a metadata generation task; S102, saving the MP4 file to a shared storage space; S103, parsing a moov data block in the MP4 file; S104, generating a metadata file according to information in the moov data block and saving the metadata file to the shared storage space.
3. The method of claim 2, wherein the MP4 metadata parsing based HLS resource dynamic conversion method is characterized in that, The segment detailed information comprises: an index, a segment duration, a start key frame index and an end key frame index.
4. The method of claim 1, wherein the MP4 metadata parsing based HLS resource dynamic conversion method is characterized in that, The S50 comprises: S501, set the TS index to be generated as i; S502, access the i-th element in the list of detailed information of the fragments, and locate the MP4 file to the position of the video key frame according to the time of the video key frame; S503, read the video frames and audio frames from the position of the video key frame, and the number of readings is the number of video frames and the number of audio frames in the list of fragment information; S504, encapsulate the read video frames and audio frames into TS binary data and output.
5. The method of claim 2, wherein the MP4 metadata parsing based HLS resource dynamic conversion method is characterized in that, The encoding format of the metadata file is: category name, attribute name and attribute description; The category name corresponds to a plurality of attribute names; each attribute name one-to-one corresponds to an attribute description; The category name includes: basic information and key frame information.
6. The system for dynamic conversion of HLS resources based on MP4 metadata parsing, characterized in that, It includes: Background device (10) and front-end device (20); The background device (10) comprises: MP4 file analysis module (101) for analyzing the original MP4 file, generating metadata file and storing; The front-end device (20) comprises: Acquisition module (201) for acquiring the fragment duration; Metadata file analysis module (202) for reading and analyzing the metadata file; M3U8 file generation module (203) for generating detailed information of fragments and M3U8 file according to the fragment duration and the analyzed metadata file, comprising: S301, receiving HTTP M3U8 request of terminal user; S302, analyzing the HTTP M3U8 request to obtain the fragment duration information and the ID information of the original MP4 file; S303, according to the ID information of the original MP4 file, extracting the metadata file corresponding to the ID information in the shared storage space and analyzing to obtain the metadata content; S304, generating detailed information of fragments according to the metadata content; S305, generating M3U8 file according to the detailed information of fragments and the duration of each fragment, comprising: S305-1, set the slice duration T, and access the key frame list from the first key frame; S305-2, create a new slice information list with an initial value of null, add the new slice information list to the slice information list; let: slice duration d = 0; S305-3, calculate the duration t between the next key frame time and the current key frame time; let: d = d + t; S305-4, compare the slice duration d with the slice duration T; if, the current key frame is not the last frame of the key frame list and the current slice duration d is greater than or equal to the slice duration T; then, the current slice ends, generates the duration field corresponding to the slice, and updates the slice information list; then, execute step S305-2; if, the current key frame is not the last frame of the key frame list and the current slice duration d is less than the slice duration T; then, the current slice ends, generates the duration field corresponding to the slice, and updates the slice information list; then, execute step S305-3; if, the current key frame is the last frame of the key frame list, then, generate the duration field corresponding to the slice, and update the slice information list; end the slice; S305-5, generate the M3U8 format string according to the duration field of each slice in the slice detailed information list and output; wherein, the HTTP M3U8 request refers to requesting the M3U8 file through the HTTP protocol; The TS slice generation module (204) is configured to read audio and video frames contained in each TS slice in the original MP4 file according to slice detailed information, and re-encapsulate the audio and video frames contained in each TS slice into a binary format HLS slice file.
7. A computer device comprising: The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 5.
8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 5.
Citation Information
Patent Citations
Video playing method and device, computer equipment and storage medium
CN119946327A
Cross-film video stream non-inductive fusion playing method based on HLS protocol
CN120583275A