Method and system for quickly and accurately skipping and playing HLS (HTTP Live Streaming) video
By building a bidirectional linked list and multiple caching strategies for TS segments and combining them with FFmpeg tools, we optimized the Seek mechanism and solved the long waiting time for Seek operations during HLS video playback. This enabled fast and accurate jump playback, improving user experience and system efficiency.
Patent Information
- Application Number
- CN202510856973.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-25
- Publication Date
- 2025-09-26
AI Technical Summary
The existing HLS video playback technology has a long waiting time for the Seek operation when processing long TS segments, especially under poor network conditions, resulting in a poor user experience. In addition, the existing technology has problems of resource waste and server-side performance overhead when optimizing file management.
By building a bidirectional linked list of TS segments, combining it with FFmpeg tools, adopting multiple cache strategies and precise Seek mechanisms, we optimize Seek operations and achieve fast and precise jump playback.
Significantly reduce the waiting time of Seek operations, improve user viewing experience, increase file management efficiency, reduce the impact of network fluctuations on playback, and ensure video smoothness and stability.
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of video playback technology, and in particular to a fast and accurate jump playback method for HLS (HTTP Live Streaming) recordings. Background Art
[0002] With the widespread adoption of security and video surveillance systems, the demand for video playback, real-time viewing, and efficient retrieval of surveillance footage is growing. In this field, quickly and accurately locating specific time points in a video is crucial for scenarios such as event retracing, anomaly detection, and evidence collection. As a widely adopted streaming media transmission protocol, HLS has gained widespread application in security and video surveillance systems due to its excellent compatibility and scalability. In current HLS (HTTP Live Streaming) video playback technology, FFmpeg, as a powerful multimedia processing tool, is widely used for parsing m3u8 files (HLS index files) and pulling video streams. Existing technical solutions primarily rely on FFmpeg to parse the TS (Transport Stream) segment addresses listed in the m3u8 file and locate specific TS segments for download and playback based on user seek operations.
[0003] Specifically, when a user initiates a Seek request, the system first searches the m3u8 file for the corresponding TS segment address based on the Seek time. Once found, the system begins downloading data from the start of the TS segment and simultaneously uses FFmpeg to demultiplex the data and extract the video frames. After receiving the video frame, the player determines whether the user-specified Seek time has been reached based on the timestamp information in the frame. If so, the player begins decoding and playing the video frame; if not, the player continues downloading and processing subsequent data.
[0004] However, this traditional method is particularly inefficient when processing long TS segments. Since HLS recordings are usually cut into multiple TS segments to adapt to network transmission, the length of the segments may vary depending on various factors such as encoding parameters and video content. When the TS segment is too long, even if it is only necessary to jump to a specific time point in the segment, the system has to download the entire file from the beginning until it reaches the required position. This method not only wastes network resources, but also greatly increases the waiting time of the Seek operation. Especially in poor network conditions, the Seek waiting time is long and the user experience is poor.
[0005] In addition, although overly short TS segments can reduce the waiting time for Seek, they will increase the number of fragmented files on the server, which will bring inconvenience to file management and maintenance. Although there are technical documents that point out that the difficulty of storage service management and poor read and write performance can be solved by aggregating shards, it requires building a complex node service, and each time a shard server is requested at a different time point, it may need to re-aggregate the shards, which increases the performance overhead of the server and is not universal. Therefore, how to simply and efficiently implement fast and accurate Seek operations while ensuring file management efficiency has become an urgent problem to be solved in the current HLS video playback technology. Summary of the Invention
[0006] The present invention aims to provide a method for fast and accurate jump playback of HLS recordings, and proposes a corresponding system. The system mainly solves the problem of long waiting time for users when performing Seek operations when processing long TS segments and under poor network conditions in the existing technology. By optimizing the Seek mechanism, fast jump playback is achieved, thereby significantly improving the user viewing experience in security and video surveillance scenarios.
[0007] The technical solution of the present invention is a method for quickly and accurately jumping to play HLS video recordings. In step 11, after the playback end sends a request to play the HLS video recording, the playback end system downloads and parses the m3u8 index file from the server; Step 12: Construct a bidirectional linked list of TS segments, which records the associated order of the segments, the start time and duration of the segments, the URL download address, and the name; Step 13: Obtain the total number of bytes of the TS segment according to the URL download address and store it in the detailed structure of the TS segment; Step 14: Use a multi-cache method to download and store the TS segments in the local cache, use the FFmpeg tool to pull the data in the local cache, and then demultiplex, decode and render; For a Seek request, the playback system performs the following operations: 1. First, find the target TS segment at the target time point based on the Seek time point, the start time and the end time of the TS segment; 2. Use the Seek time point to subtract the start time of the target TS segment to get the relative Seek time point, and offset a certain time before the relative Seek time point to get the number of seconds to start downloading; 3. Calculate the byte point at which the target TS segment should start downloading: the sub-node to start downloading = the number of seconds from the start of downloading * the total byte size of the TS segment / the total duration of the TS segment; 4. Download the target TS segment from the calculated download start point. 5. The playback system uses FFmpeg to pull the downloaded cache data and demultiplex the TS stream. After demultiplexing, the system caches the undecoded video frames again into the to-be-decoded linked list; 6. The decoding thread then pulls the frames to be decoded from the to-be-decoded linked list, decodes them, and caches the decoded video frames in the to-be-played linked list; 7. Finally, the rendering and playback thread pulls the video frame from the linked list to be played and determines the video frame timestamp. It starts rendering and playback when the video frame timestamp is greater than or equal to the Seek time point.
[0008] Preferably, a binary search method is used to find the target TS segment at the target time point.
[0009] Furthermore, when the user clicks pause, play, and double-speed playback, the streaming logic is: stop downloading the TS segment when paused, and continue downloading and caching the TS segment at the paused time point from the paused time point when resuming playback, and set it as the priority download. Other TS segments are downloaded at a reduced speed. The cache strategy and decoding rate are adjusted during double-speed playback. If decoding is not timely, the smoothness of the video is ensured by dropping frames.
[0010] A system for fast and accurate jump playback of HLS videos, including a module for downloading and parsing m3u8 index files, a module for building a bidirectional linked list of TS segments, a module for obtaining the total number of bytes of TS segments, a multi-cache module, an FFmpeg tool module, and a Seek jump module. Described download and parse m3u8 index file module downloads and parses m3u8 index file from server; The TS segment bidirectional linked list construction module constructs a bidirectional linked list of TS segments, which records the associated order of the segments, the start time and duration of the segments, the URL download address, and the name; The TS segment total byte number acquisition module acquires the total byte number of the TS segment according to the URL download address and stores it in the detailed structure of the TS segment; The multi-caching module downloads and stores the TS segments in a local cache; The FFmpeg tool module pulls the data in the local cache, and then demultiplexes, decodes and renders; The Seek jump module executes the following procedures: 1. First, find the target TS segment at the target time point based on the Seek time point, the start time and the end time of the TS segment; 2. Use the Seek time point to subtract the start time of the target TS segment to get the relative Seek time point, and offset a certain time before the relative Seek time point to get the number of seconds to start downloading; 3. Calculate the byte point at which the target TS segment should start downloading: the sub-node to start downloading = the number of seconds from the start of downloading * the total byte size of the TS segment / the total duration of the TS segment; 4. Download the target TS segment from the calculated download start point. 5. The playback system uses FFmpeg to pull the downloaded cache data and demultiplex the TS stream. After demultiplexing, the system caches the undecoded video frames again into the to-be-decoded linked list; 6. The decoding thread then pulls the frames to be decoded from the to-be-decoded linked list, decodes them, and caches the decoded video frames in the to-be-played linked list; 7. Finally, the rendering and playback thread pulls the video frame from the linked list to be played and determines the video frame timestamp. It starts rendering and playback when the video frame timestamp is greater than or equal to the Seek time point.
[0011] Beneficial effects of the present invention: by downloading and parsing m3u8 files, building a bidirectional linked list of TS segments, and combining the real-time processing capability of FFmpeg, it is achieved that when Seek, the TS segments near the target time point can be quickly located, and intelligently shift forward a certain time to start downloading data. This design not only effectively reduces the waiting time of Seek operation under long TS segments, but also takes into account the convenience of file management, and provides users with a smoother and more efficient viewing experience. At the same time, the present invention also optimizes the processing of cache management, stream pulling logic and pause, playback, speed doubling functions during playback, ensuring that a stable and smooth playback experience can be provided under various network environments. DETAILED DESCRIPTION
[0012] HLS, or HTTP Live Streaming, is an adaptive bitrate streaming protocol developed by Apple, primarily used for audio and video services. Based on HTTP, it distributes audio and video content by slicing the stream into a series of small TS (Transport Stream) segments and creating an m3u8 playlist file. The client first downloads the m3u8 playlist file via HTTP, then downloads the corresponding TS segments according to the URLs in the file and plays them sequentially. This achieves a download-as-you-play experience, providing users with a similar experience to live streaming. Due to its high efficiency and wide compatibility, HLS is widely used in video-on-demand and live streaming, supporting audio and video services on PCs and Apple devices. HLS's three core components are: the m3u8 index file, which controls the playback order; the TS segments, which contain the actual audio and video data; and the key encryption string file, which encrypts the content.
[0013] FFmpeg is a popular open source cross-platform multimedia processing tool with powerful audio and video processing capabilities. It can perform a variety of operations such as recording, conversion, and streaming. In terms of recording, FFmpeg can capture audio and video data from a variety of input sources, such as cameras, microphones, and computer screens. In terms of conversion, it supports converting audio and video files from one format to another, and supports multiple codecs to meet the needs of different scenarios. The streaming function allows FFmpeg to transmit audio and video content to the network in the form of a stream, supporting multiple streaming protocols, which greatly facilitates the provision of online audio and video services. In addition to these basic functions, FFmpeg also provides a series of advanced processing functions such as video editing, merging, adding watermarks, scaling, transcoding, etc., making it the tool of choice for multimedia developers and enthusiasts.
[0014] Seek is a basic function in audio and video playback, which allows users to jump to any time point in the audio and video content for playback. With the Seek function, users can quickly locate the part they are interested in without having to watch it from the beginning, which is especially useful when watching long videos. The implementation of the Seek function depends on the player's ability to quickly and accurately locate the data at a specified time point, and to be able to seamlessly decode and play it after locating it. In segment-based streaming media transmission protocols such as HLS, the Seek operation usually involves finding the TS segment corresponding to the time point and starting playback from that segment. This not only improves the user experience but also optimizes playback efficiency.
[0015] This technical solution aims to optimize the playback experience of HLS (HTTP Live Streaming) video streams, particularly when processing large collections of TS (Transport Stream) segments. Through a series of carefully designed steps, it enables fast and accurate jump playback. This innovation not only improves the efficiency and smoothness of video viewing, but also significantly enhances the user experience under poor network conditions.
[0016] 1. Deep analysis and efficient index construction Step 11: After the player sends a request to play the HLS video, the player system downloads and parses the m3u8 index file from the server. This process is the basis for efficient processing of HLS streams. The m3u8 file, as the core of HLS, contains key information such as the URL address, start time, and duration of the TS segment; Step 12: After downloading the M3U8 file, the player system traverses the TS segments and constructs a detailed list of TS segments based on the start time, end time, duration, and download address of the TS segments. Based on this information, an optimized bidirectional linked list structure is established. This bidirectional linked list not only records the associated order of the segments, but also integrates metadata such as the start time, duration, URL download address, and name of the segment; Step 13: Get the total number of bytes of the TS segment according to the URL download address and store it in the detailed structure of the TS segment. This field is the core field of this solution and provides a solid foundation for subsequent rapid positioning and jumping together with other information.
[0017] 2. Caching Strategy and Real-time Stream Processing Step 21: During the download process, the playback system uses an advanced caching mechanism. Reference counting is used for data transfer to reduce data copying. Multiple caches are used for demultiplexing, decoding, and rendering to ensure that TS segment files can be downloaded and stored in the local cache efficiently. This strategy effectively reduces playback interruptions caused by network fluctuations and reduces computer CPU resource usage. Step 22: Using FFmpeg, a powerful multimedia processing framework, the system can pull data from the cache in real time, perform demultiplexing and decoding operations, and output high-quality video frames for player rendering. The integration of multiple cache mechanisms and FFmpeg not only improves video processing efficiency but also ensures the compatibility and stability of video decoding.
[0018] 3. Precise Seek Mechanism and Fast Jump The core innovation of the present invention lies in its unique Seek mechanism.
[0019] Step 31: When the user initiates a Seek request, the playback system does not simply download the corresponding TS segment from the beginning, but first uses a fast search algorithm to find the target TS segment based on the Seek time point, the start time and the end time of the TS segment; Step 32: Subtract the start time of the target TS segment from the Seek time point to obtain the relative Seek time point (Relative Seek time point = Seek time point - TS segment start time). Then, the playback system is set to use the relative Seek time point as the reference point and offset it a certain time (e.g., 5 seconds) to obtain the number of seconds to start downloading (number of seconds to start downloading = relative Seek time point - offset seconds). Step 33: Calculate the starting point of downloading of the target TS segment based on the total number of bytes, total duration, and the number of seconds from the start of downloading: (sub-node for starting downloading = number of seconds from the start of downloading * total byte size of the TS segment / total duration of the TS segment); Step 34: Download the target TS file from the calculated download starting point. This strategy effectively reduces the waiting time caused by network delay or insufficient buffering. Step 35: The playback system uses FFmpeg to pull the downloaded cache data and demultiplex the TS stream. After demultiplexing, the system caches the undecoded video frames again into the to-be-decoded linked list. Step 36: The decoding thread then extracts the frames to be decoded from the to-be-decoded linked list, decodes them, and caches the decoded video frames in the to-be-played linked list; Step 37: Finally, the rendering and playback thread will pull the video frame from the linked list to be played and determine the video frame timestamp. It will start rendering and playback when the video frame timestamp is greater than or equal to the Seek time point.
[0020] The efficient downloading, caching, streaming, decoding and rendering process ensures that the system can quickly and accurately jump to playback from any time point.
[0021] 4. Flexible playback control logic In addition, this technical solution also fully considers the various needs of users in actual use, such as pause, play and double-speed play. The system stops downloading TS segments when paused through the careful design of the streaming logic. When resuming playback, it continues downloading and caching the TS segments at the paused time point, and sets them as the priority download. Other TS segments are downloaded at a reduced speed. When playing at double speed, the cache strategy and decoding rate are adjusted. If decoding is not timely, a frame drop strategy will be adopted to ensure that when these operations occur, the video stream can smoothly transition, avoiding playback freezes or interruptions caused by improper operation. Especially in double-speed playback mode, the system can intelligently adjust the cache strategy and decoding rate, use reference counting for data transmission, reduce data copying, and use multiple caches for demultiplexing, decoding and rendering to ensure that TS segment files can be efficiently downloaded and stored in the local cache. When decoding is not timely, a frame drop strategy is adopted to ensure that the video content can be played smoothly at the speed set by the user.
[0022] Detailed explanation of the embodiment: Take the playback of a 30-minute HLS video scene as an example. Assume that the TS segment of the HLS video is 2 minutes, and the user wants to start watching from 5 minutes and 00 seconds during playback. For the traditional solution, we traverse according to the Seek time point to find the corresponding TS segment as the third segment, and then download the third TS file from the beginning. The timestamp of the third TS file data starts from 4 minutes and 00 seconds. If we want to jump to 5 minutes and 00 seconds accurately, we must first download at least 1 minute of video data, then decode and wait for the video frame data timestamp to be greater than or equal to 5 minutes and 00 seconds before starting to render and play. If the network conditions are not good, we will have to wait a long time before playing, and the user experience is very bad. If we use this technical solution, we can achieve it through the following steps: Step 11: When the operator has a playback requirement, click Play, and the playback system downloads and parses the m3u8 file from the server.
[0023] Step 12: Construct a bidirectional linked list of TS file segments. Taking a TS segment length of 2 minutes (120 seconds) as an example, the linked list contains TS files with a duration of 120 seconds, and the start and end times are distributed as [[0, 120), [120, 240), [240, 360), ...], as well as the file name and URL download address.
[0024] Step 13: Use the TS segment file download address parameter in step 12 to obtain the most important field through the HTTP Get method, which is the byte size of the entire TS segment file, for example, 50M (50x1024x104=52,428,800 bytes).
[0025] The video is then cached and played normally: Step 21: Download the TS segment and cache it in a linked list.
[0026] Step 22: Take the data out of the cache list and demultiplex, decode and render it.
[0027] When a user initiates a Seek request to view 5 minutes and 00 seconds (300 seconds): Step 31: First, use the fast search algorithm to quickly locate the target TS segment at the target time point according to the Seek time point, the start time and the end time of the TS segment, which is the third TS file. For example, if the current Seek time point is 5 minutes and 00 seconds (300 seconds) and the TS segment length is 2 minutes (120 seconds), then the start time and end time of the TS segment doubly linked list are [[0, 120), [120, 240), [240, 360), ...]. Here, the binary search method is used to match the target Seek time point of 300 seconds to the third TS file (240<= 300&&300<360), so the target TS segment is located as the third segment.
[0028] Step 32: Subtract the start time of the target TS segment from the Seek time point to obtain a relative Seek time point of 60 seconds (relative Seek time point 60 seconds = Seek time point 300 seconds - target TS segment start time 240 seconds). Then, offset 5 seconds forward from the relative Seek time point to obtain the number of seconds to start downloading as 55 seconds (55 seconds to start downloading = 60 seconds relative to the Seek time point - offset seconds 5 seconds).
[0029] Step 33: Calculate the starting point for downloading the target TS file based on the total number of bytes, total duration, and seconds from the start of downloading of the target TS segment. For example, if the total size of the target TS segment currently obtained in step 13 is 50M (52,428,800 bytes), and the total duration of the segments obtained from the target TS segment is 120 seconds, and the starting seconds for downloading calculated in step 32 are 55 seconds, then the starting point for downloading the target TS file is calculated as 24,029,866 bytes according to the formula (starting point for downloading 24,029,866 bytes = starting seconds for downloading 55 seconds * total byte size of TS segment 52,428,800 bytes / total duration of TS segment 120 seconds).
[0030] Step 34, finally, start downloading the target TS segment file from the calculated starting point for downloading. To accurately jump to 5 minutes and 00 seconds for playback, you only need to download 5 seconds of video data in advance. Even in the case of poor network conditions, the download can be completed quickly. For example, according to step 33, the starting point for downloading the target TS file is 24,029,866 bytes. When using the Http Get method to download, we add the Http request header "Range: bytes=24,029,866-", which means starting from 24,029,866 bytes. Download the file until the end of the file, and then use asynchronous download to put the downloaded data into the cache queue while downloading for subsequent decoding and playback. This can save 24,029,866 bytes (about 22.9M) compared to the traditional method of downloading TS files starting from 0 bytes, which can greatly shorten the download waiting time under poor network conditions. At the same time, accurately jumping to 5 minutes and 00 seconds (300 seconds) for playback will not start decoding from the start time of 240 seconds of the target TS file. According to the current download strategy, the timestamp of the frame starting to be decoded is approximately equal to 295 seconds (295 seconds = target Seek time point 300 seconds - offset seconds 5 seconds). In this way, only about 5 seconds of data need to be decoded to wait until the video frame corresponding to the target Seek time point is reached and start rendering and playback, saving decoding resource usage and waiting time.
[0031] Step 35: During the download process, the system uses FFmpeg to pull the downloaded cache data and demultiplex the TS stream in real time. After demultiplexing, the system will cache the undecoded video frames again into the to-be-decoded linked list.
[0032] Step 36: The decoding thread then pulls data from the to-be-decoded linked list for decoding and caches the decoded video frames in the to-be-played linked list.
[0033] Step 37: Finally, the rendering and playback thread will pull the video frame from the linked list to be played and determine the video frame timestamp. Rendering and playback will begin when the video frame timestamp is greater than or equal to 5 minutes and 00 seconds.
[0034] This series of association strategies ensures that users can watch the video content at the target time with almost no delay. In addition, during the playback process, users can pause, resume, or play at double the speed at any time. The system can ensure smooth and stable playback through flexible streaming logic and cache management strategies.
[0035] In summary, this technical solution successfully solves many challenges faced by HLS recording in fast jump playback through a series of innovative designs and practices, bringing users a more efficient and smooth viewing experience.
[0036] Summary of the core technical points of the present invention: First, the most outstanding technical point of the present invention lies in its unique precise Seek mechanism and intelligent preloading technology. By deeply parsing the m3u8 file, building an optimized TS segment index, and combining the intelligent forward offset strategy during the user's Seek request, it is possible to quickly jump to the target segment from any time point and preload some data to reduce waiting time. This innovation significantly improves the response speed of the Seek operation, allowing users to jump to the target location with almost no delay. Compared with traditional methods, its advantage is that it significantly reduces the waiting time caused by network delays or insufficient buffering, greatly enhancing the user experience.
[0037] Secondly, efficient caching strategy and real-time stream processing mechanism are another key technical point of the present invention. The system adopts advanced cache management, data transmission uses reference counting, reduces data copying, demultiplexing, decoding and rendering use multiple caches, ensure that TS segment files can be efficiently downloaded and efficiently stored in the local cache, and when decoding is not timely, a frame loss strategy will be adopted. At the same time, the FFmpeg framework is used for real-time demultiplexing, decoding and video frame output. This integrated solution not only improves the efficiency of video processing, but also ensures the compatibility and stability of video decoding. Compared with the prior art, the caching strategy of the present invention effectively reduces the impact of network fluctuations on playback and reduces the occurrence of playback interruptions, while the introduction of FFmpeg further enhances the flexibility and adaptability of video processing.
[0038] Furthermore, optimized index construction and bidirectional linked list management are also essential technical features of this invention. By constructing a comprehensive TS segment index through an intelligent parsing algorithm and managing it in an optimized bidirectional linked list format, this invention provides a solid data foundation for rapid location and navigation. This index structure not only improves data retrieval efficiency but also reduces system resource consumption, making the system more efficient and stable when processing large-scale TS segment collections.
[0039] Finally, the present invention fully considers the diverse needs of users in actual use and designs flexible playback control logic. Whether pausing, playing, or playing at double speed, the system ensures smooth transitions and playback fluency through carefully designed streaming logic and cache management strategies. In double-speed playback mode, in particular, the system intelligently adjusts cache strategies and decoding rates to meet diverse user viewing needs, a feature that is often difficult to implement or ineffective in existing technologies.
Claims
1. A method for quickly and accurately jumping and playing HLS videos, characterized by: Step 11: After the player sends a request to play the HLS video, the player system downloads and parses the m3u8 index file from the server; Step 12: Construct a bidirectional linked list of TS segments, which records the associated order of the segments, the start time and duration of the segments, the URL download address, and the name; Step 13: Obtain the total number of bytes of the TS segment according to the URL download address and store it in the detailed structure of the TS segment; Step 14: Use a multi-cache method to download and store the TS segments in the local cache, use the FFmpeg tool to pull the data in the local cache, and then demultiplex, decode and render; For a Seek request, the playback system performs the following operations:
1. First, find the target TS segment at the target time point based on the Seek time point, the start time and the end time of the TS segment; 2. Use the Seek time point to subtract the start time of the target TS segment to get the relative Seek time point, and offset a certain time before the relative Seek time point to get the number of seconds to start downloading; 3. Calculate the byte point at which the target TS segment should start downloading: the sub-node to start downloading = the number of seconds to start downloading * the total byte size of the TS segment / the total duration of the TS segment; 4. Download the target TS segment from the calculated download start point.
5. The playback system uses FFmpeg to pull the downloaded cache data and demultiplex the TS stream. After demultiplexing, the system caches the undecoded video frames again into the to-be-decoded linked list; 6. The decoding thread then pulls the frames to be decoded from the to-be-decoded linked list, decodes them, and caches the decoded video frames in the to-be-played linked list; 7. Finally, the rendering and playback thread pulls the video frame from the linked list to be played and determines the video frame timestamp. It starts rendering and playback when the video frame timestamp is greater than or equal to the Seek time point.
2. The method for quickly and accurately jumping and playing HLS videos according to claim 1 is characterized by: The binary search method is used to find the target TS segment where the target time point is located.
3. The method for quickly and accurately jumping and playing HLS videos according to claim 1 is characterized by: When the user clicks pause, play, or double-speed playback, the streaming logic is as follows: stop downloading the TS segment when pausing; continue downloading and caching the TS segment at the paused time point when resuming playback, and set it as the priority download. Other TS segments are downloaded at a reduced speed; adjust the cache strategy and decoding rate when playing at double speed; if decoding is not timely, ensure the smoothness of the video by dropping frames.
4. A system for fast and accurate jump playback of HLS videos, characterized by: Contains a module for downloading and parsing m3u8 index files, a module for building a bidirectional linked list of TS segments, a module for obtaining the total number of bytes of TS segments, a multiple cache module, an FFmpeg tool module, and a Seek jump module; Described download and parse m3u8 index file module downloads and parses m3u8 index file from server; The TS segment bidirectional linked list construction module constructs a bidirectional linked list of TS segments, which records the associated order of the segments, the start time and duration of the segments, the URL download address, and the name; The TS segment total byte number acquisition module acquires the total byte number of the TS segment according to the URL download address and stores it in the detailed structure of the TS segment; The multi-caching module downloads and stores the TS segments in a local cache; The FFmpeg tool module pulls the data in the local cache, and then demultiplexes, decodes and renders; The Seek jump module executes the following procedures:
1. First, find the target TS segment at the target time point based on the Seek time point, the start time and the end time of the TS segment; 2. Use the Seek time point to subtract the start time of the target TS segment to get the relative Seek time point, and offset a certain time before the relative Seek time point to get the number of seconds to start downloading; 3. Calculate the byte point at which the target TS segment should start downloading: the sub-node to start downloading = the number of seconds to start downloading * the total byte size of the TS segment / the total duration of the TS segment; 4. Download the target TS segment from the calculated starting point for downloading.
5. The playback system uses FFmpeg to pull the downloaded cache data and demultiplex the TS stream. After demultiplexing, the system caches the undecoded video frames again into the to-be-decoded linked list; 6. The decoding thread then pulls the frames to be decoded from the to-be-decoded linked list, decodes them, and caches the decoded video frames in the to-be-played linked list; 7. Finally, the rendering and playback thread pulls the video frame from the linked list to be played and determines the video frame timestamp. It starts rendering and playback when the video frame timestamp is greater than or equal to the Seek time point.
Citation Information
Cited By
Time sequence processing method based on HLS slicing
CN121636746A
Positioning playing method and related device
CN121888013A
