PCR synchronization-based HLS slicing method, system, equipment and medium for main and standby equipment
Through the PCR synchronization mechanism and intelligent slicing algorithm, the problem of video instability when switching between primary and backup devices in HLS live broadcast is solved, the consistency of slice files and the unification of naming rules are achieved, and the reliability and resource utilization of the live broadcast system are improved.
Patent Information
- Application Number
- CN202510883385.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-29
- Publication Date
- 2025-10-03
AI Technical Summary
The existing HLS live streaming slicing method makes it difficult to align TS slice timestamps when the primary and backup devices fail over, resulting in video frame skipping or audio and video freezes, affecting the user experience. In addition, the non-uniform slice naming rules reduce the cache hit rate of CDN edge nodes and increase bandwidth costs.
Through the PCR synchronization mechanism, a unified time base is established, and the PCR timestamp is used to synchronize the slices of the master and backup devices. Combined with the preset slice duration and timeout mechanism, the consistency of the slice files and the unified naming rules are ensured to realize the intelligent slicing algorithm.
It solves the problems of video frame skipping and freezing when switching between primary and backup devices, improves the reliability and disaster recovery capabilities of the live broadcast system, increases the CDN cache hit rate, reduces bandwidth costs, and is suitable for a variety of live broadcast scenarios.
Smart Images

Figure CN120750477A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of streaming media transmission technology, and specifically relates to a method, system, device and medium for HLS slicing of master and backup devices based on PCR synchronization. Background Art
[0002] HLS, short for HTTP Live Streaming, is an HTTP-based streaming protocol used to implement live and on-demand video streaming.
[0003] In live streaming, the stability and reliability of streaming transmission are directly related to the quality of the user experience. The HLS protocol has become a mainstream standard due to its compatibility and adaptability, and is widely used in mobile live streaming. However, existing live streaming slicing methods have significant problems when switching between primary and backup devices: First, since the primary and backup servers run independently, the timestamps of the generated TS slices are difficult to align, resulting in video frame skipping or audio and video freezes when switching between the primary and backup screens, seriously affecting the user experience. In addition, non-uniform slice naming rules can easily lead to a decrease in the cache hit rate of CDN edge nodes and increase bandwidth costs. These problems seriously affect the reliability of the live streaming system and the user experience, especially in live streaming scenarios with high concurrency and large-scale user access, the defects of the traditional slicing method will be further amplified.
[0004] In summary, traditional streaming media slicing methods cannot solve the synchronization problem between primary and backup devices, especially in scenarios with high reliability and low latency requirements. Therefore, a method that can ensure the consistency of slices between primary and backup devices through clock synchronization mechanisms and intelligent slicing algorithms is urgently needed to improve disaster recovery capabilities and optimize resource utilization. Summary of the Invention
[0005] In a first aspect, an embodiment of the present application provides an HLS slicing method for a master / slave device based on PCR synchronization, comprising the following steps: S1. Establish a unified time base based on the PCR timestamp and initialize the slice flag, the next PCR timestamp variable, and the timeout flag; S2. The primary and backup devices synchronously receive the TS stream and parse the PCR timestamp in each TS packet in the TS stream; S3. When it is detected that the PCR timestamp is greater than the next PCR timestamp, the flag can be set to slice, and the next PCR timestamp is aligned according to the preset slice duration. At the same time, the timeout is set according to the preset slice duration, and the timer is started. When the timeout is reached, the timeout flag is set; S4. When the slicing flag is valid, detect the key frame and timeout flag in the TS packet. When there is a key frame or the timeout flag is valid in the TS packet, perform the slicing operation, and set the slicing flag to invalid, and return to step S2.
[0006] Furthermore, in step S1, the initial slicing flag is false, the next PCR timestamp variable is initialized to 0, and the timeout flag is initialized to false.
[0007] Furthermore, in step S2, the master and slave devices receive the TS stream, parse a TS packet, and determine whether the slice-enabled flag in the TS packet is true; If yes, go to step S3; If so, go to step S4.
[0008] Furthermore, the specific steps of step S3 are as follows: S31. The master and standby devices determine whether the parsed TS contains a PCR timestamp; If yes, go to step S32; If not, return to step S2; S32 obtains the PCR timestamp and determines whether the PCR timestamp is greater than the next PCR timestamp; If yes, go to step S33; If not, return to step S2; S33. Set the sliceable flag to true; S34. Align the PCR timestamp upward to a multiple of the slice duration T and record it in the next PCR timestamp variable; S35. Set the timeout period to half of the preset slice duration T, start the timer, and when the timeout period is met, set the timeout flag to true and return to step 2.
[0009] Furthermore, in step S34, PCR timestamps are aligned by the following steps:
[0010] Among them, T is the preset slice duration, is the ceiling function.
[0011] Furthermore, the specific steps of step S4 are as follows: S41. The master and slave devices determine whether there are key frames in the parsed TS; If yes, go to step 43; If not, proceed to step S42; S42. Determine whether the timeout flag is true; If yes, go to step S43; If not, return to step S2; S43. Execute the slicing operation and name the slice file based on the system timestamp; S44. Inject the slice file into the CDN queue and set the slice-enabled flag to false.
[0012] Furthermore, in step S43, a slicing operation is performed by saving the data before the currently received TS packet as a slice file; The slice files are named based on the system timestamp as follows:
[0013] Among them, T is the preset slice duration, is the floor function.
[0014] In a second aspect, an embodiment of the present application further provides an HLS slicing system for master and backup devices based on PCR synchronization, a slicing initialization module, which establishes a unified time reference according to the PCR timestamp and initializes a slicing flag, a next PCR timestamp variable, and a timeout flag; PCR extraction module, synchronously receives TS stream and parses the PCR timestamp in each TS packet in the TS stream; The PCR alignment module is configured to set a slicing flag when detecting that a PCR timestamp is greater than a next PCR timestamp, and perform alignment on the next PCR timestamp according to a preset slicing duration. At the same time, the module sets a timeout according to the preset slicing duration, starts a timer, and sets a timeout flag when the timeout is reached. The slicing trigger module is used to detect the key frame and timeout flag in the TS packet when the slicing flag is valid. When there is a key frame or the timeout flag is valid in the TS packet, the slicing operation is performed and the slicing flag is invalid.
[0015] In a third aspect, an embodiment of the present application further provides an electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the master-slave device HLS slicing method based on PCR synchronization as described in the first aspect are implemented.
[0016] In a fourth aspect, an embodiment of the present application further provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the master-slave device HLS slicing method based on PCR synchronization as described in the first aspect are implemented.
[0017] It can be seen from the above technical solutions that this application has the following advantages: The HLS slicing method, system, device and medium for master and backup devices based on PCR synchronization provided in this application solve the problems of video frame skipping and stuttering when the master and backup devices switch through precise clock synchronization and intelligent slicing algorithms, ensure the smoothness and stability of live broadcast, and provide users with a high-quality live broadcast experience; achieve consistency and synchronization of master and backup device slices, enhance the disaster recovery capability of the live broadcast system, and reduce the risk of live broadcast interruption due to equipment failure or network problems; unified slice naming rules and synchronization strategies improve the cache hit rate of CDN edge nodes, reduce bandwidth costs, and avoid redundant waste of resources; slice duration can be dynamically adjusted according to actual needs, and is suitable for a variety of live broadcast scenarios, whether it is interactive live broadcast with high low latency requirements or large-scale event live broadcast with extremely high stability requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for the description. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0019] Figure 1 This is a flow chart of an embodiment of the HLS slicing method for master and standby devices based on PCR synchronization of the present invention.
[0020] Figure 2 This is a flow chart of another embodiment of the HLS slicing method for master / slave devices based on PCR synchronization of the present invention.
[0021] Figure 3 Schematic diagram of the HLS slicing system of the master and standby devices based on PCR synchronization of the present invention. DETAILED DESCRIPTION
[0022] The specific steps of the master-slave HLS slicing method based on PCR synchronization will be described in detail below, and various embodiments of the present disclosure will be described more comprehensively. The present disclosure can have various embodiments, and adjustments and changes can be made therein. However, it should be understood that there is no intention to limit the various embodiments of the present disclosure to the specific embodiments disclosed herein, but rather that the present disclosure should be understood to cover all adjustments, equivalents, and / or alternatives that fall within the spirit and scope of the various embodiments of the present disclosure.
[0023] For example, in today's live streaming field, the stability and reliability of streaming media transmission is directly related to the quality of user experience. The HLS protocol, with its excellent compatibility and wide adaptability, has occupied a dominant position in mobile live streaming and has been adopted by many live streaming platforms. However, the existing live streaming slicing method exposes many problems when switching between primary and backup devices. On the one hand, since the primary and backup servers run independently, it is difficult for the generated TS slice timestamps to be completely consistent. This makes it easy for the user end to experience video frame skipping or audio and video freezes at the moment of switching between the primary and backup screens, which greatly damages the user's viewing experience. On the other hand, the inconsistency of slice naming rules leads to a decrease in the cache hit rate of CDN edge nodes, thereby increasing bandwidth costs. These problems have a serious negative impact on the reliability of the live streaming system and user satisfaction. Especially in popular live streaming scenarios with high concurrency and large-scale user access, the disadvantages of the traditional slicing method are becoming more and more prominent.
[0024] Traditional streaming media slicing methods cannot solve the synchronization problem between primary and backup devices, especially in scenarios with strict requirements for high reliability and low latency, such as live sports events and real-time news broadcasts. Therefore, a new method is urgently needed. This method can ensure that the slice files generated by the primary and backup devices are completely consistent in content and file names through clock synchronization mechanisms and intelligent slicing algorithms. This will improve the system's disaster recovery capabilities, optimize resource utilization, ensure the smoothness and stability of live broadcasts, and meet users' expectations for a high-quality live broadcast experience.
[0025] To address the above issues, this embodiment provides an HLS slicing method for master and backup devices based on PCR synchronization, which solves the problems of video frame skipping and freezes when the master and backup devices switch, and enhances the reliability and disaster recovery capabilities of the live broadcast system; slicing synchronization improves the CDN cache hit rate and reduces bandwidth costs.
[0026] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0027] See also Figure 1 FIG2 is a flowchart of a method for HLS slicing of a master / slave device based on PCR synchronization in a specific embodiment, the method comprising the following steps: S1. Establish a unified time base based on the PCR timestamp and initialize the slice flag, the next PCR timestamp variable, and the timeout flag; It should be noted that by establishing a unified time base based on the PCR timestamp and initializing related flags and variables, a unified time reference and initial state are provided for the synchronous slicing of the primary and backup devices, ensuring the orderly start of the slicing process and providing a foundation for the accurate execution of subsequent steps; S2. The primary and backup devices synchronously receive the TS stream and parse the PCR timestamp in each TS packet in the TS stream; It should be noted that TS is transport stream and PCR is short for Program Clock Reference, which is a time reference in the TS stream and is used to synchronize the playback of video and audio. The master and backup devices synchronously receive the TS stream and parse the PCR timestamps in the TS packets, enabling them to process the video stream in the same time dimension. This provides a data basis for slicing synchronization and helps to timely discover and utilize key time information in the TS stream. S3. When it is detected that the PCR timestamp is greater than the next PCR timestamp, the flag can be set to slice, and the next PCR timestamp is aligned according to the preset slice duration. At the same time, the timeout is set according to the preset slice duration, and the timer is started. When the timeout is reached, the timeout flag is set; It should be noted that when it is detected that the PCR timestamp is greater than the next PCR timestamp, the slicing flag is set and the timestamp alignment and timeout setting operations are performed to ensure the accurate determination of the slicing moment. At the same time, the timeout mechanism provides redundancy to prevent slicing from being delayed due to reasons such as waiting for key frames, thereby ensuring the reliability and timeliness of the slicing operation. S4. When the slicing flag is valid, detect the key frame and timeout flag in the TS packet. When the key frame or timeout flag is valid in the TS packet, perform the slicing operation and set the slicing flag position to invalid, and return to step S2; It should be noted that by detecting key frames and timeout flags to decide whether to perform the slicing operation, and resetting the slicing flag after slicing, it is ensured that the slicing operation is performed promptly and accurately when the conditions are met, while avoiding repeated slicing or incorrect slicing, ensuring the standardization and continuity of the slicing process, and providing the slice files to the CDN for distribution in a timely manner, ensuring the normal progress of the live broadcast.
[0028] This embodiment improves the reliability and disaster recovery capabilities of the live broadcast system. Through precise clock synchronization and intelligent slicing algorithms, it solves the problems of video frame skipping and freezing when switching between primary and backup devices, ensuring the smoothness and stability of live broadcasts.
[0029] Furthermore, as a refinement and expansion of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, as shown below: Figure 2As shown, another HLS slicing method for master and backup devices based on PCR synchronization is provided, which includes the following steps: S1. Establish a unified time base based on the PCR timestamp and initialize the slice flag, the next PCR timestamp variable, and the timeout flag; In step S1, the initial slicing flag is false, the next PCR timestamp variable is initialized to 0, and the timeout flag is initialized to false; It should be noted that the specific settings of initialization ensure the orderly starting point of the slicing process, provide a clear initial state for the execution of subsequent steps, and avoid slicing errors caused by confusion in the initial state; S2. The primary and backup devices synchronously receive the TS stream and parse the PCR timestamp in each TS packet in the TS stream; It should be noted that TS is transport stream and PCR is short for Program Clock Reference, which is a time reference in the TS stream and is used to synchronize the playback of video and audio. In step S2, the master and slave devices receive the TS stream, parse a TS packet, and determine whether the slice-capable flag in the TS packet is true; If yes, go to step S3; If yes, go to step S4; It should be noted that by limiting the judgment logic of the primary and backup devices when receiving TS streams, the devices can quickly and accurately enter the corresponding processing steps based on the validity of the slice-capable flag, thereby improving the execution efficiency of the process; S3. When it is detected that the PCR timestamp is greater than the next PCR timestamp, the flag can be set to slice, and the next PCR timestamp is aligned according to the preset slice duration. At the same time, the timeout is set according to the preset slice duration, and the timer is started. When the timeout is reached, the timeout flag is set; The specific steps of step S3 are as follows: S31. The master and standby devices determine whether the parsed TS contains a PCR timestamp; If yes, go to step S32; If not, return to step S2; S32 obtains the PCR timestamp and determines whether the PCR timestamp is greater than the next PCR timestamp; If yes, go to step S33; If not, return to step S2; S33. Set the sliceable flag to true; S34. Align the PCR timestamp upward to a multiple of the slice duration T and record it in the next PCR timestamp variable; In step S34, PCR timestamps are aligned by the following steps:
[0030] Among them, T is the preset slice duration, is the ceiling function; For example, T can be 5 seconds. Taking the PCR timestamp of 103 as an example, the value aligned upward to a multiple of 5 is 105, and the calculation formula is ⌈103÷5⌉×5=105; It should be noted that the PCR timestamp alignment method ensures the precise consistency of slice moments and enhances the accuracy of slice synchronization; S35 sets the timeout period to half of the preset slice duration T, starts the timer, and when the timeout period is met, sets the timeout flag to true and returns to step 2; It should be noted that through step-by-step judgment and processing, slice preparation is ensured only when the PCR timestamp meets the conditions. In addition, a timeout mechanism is introduced as a redundancy guarantee, further improving the reliability and timeliness of slicing. S4. When the slicing flag is valid, detect the key frame and timeout flag in the TS packet. When the key frame or timeout flag is valid in the TS packet, perform the slicing operation and set the slicing flag position to invalid, and return to step S2; The specific steps of step S4 are as follows: S41. The master and slave devices determine whether there are key frames in the parsed TS; If yes, go to step 43; If not, proceed to step S42; S42. Determine whether the timeout flag is true; If yes, go to step S43; If not, return to step S2; S43. Execute the slicing operation and name the slice file based on the system timestamp; In step S43, a slicing operation is performed by saving the data before the currently received TS packet as a slice file; The slice files are named based on the system timestamp as follows:
[0031] Among them, T is the preset slice duration, is the floor function; For example, the preset slice duration is 5 seconds. The server's system timestamp is rounded down to a multiple of 5 to get a value. For example, if the system timestamp is 104, the value is 105 (⌊104 ÷ 5⌋ × 5 = 105). This value is used as the slice file name. In this way, since the primary and backup devices use a unified rule, the file name can be consistent. It should be noted that specific restrictions are placed on the generation and naming of slice files. By normalizing system timestamps, the slice file names are unified, which facilitates CDN management and caching, further improving cache hit rates and resource management efficiency. S44. Inject the slice file into the CDN queue and set the slice flag to false; It should be noted that CDN is short for Content Delivery Network. A content delivery network is a way to quickly distribute content by placing node servers throughout the network. In this application, CDN backsources content from live slicing devices to ensure the reliability and high concurrency of video distribution and improve user experience. By performing key frame detection, timeout judgment, file processing after slicing, and flag reset, the integrity and standardization of slicing operations are ensured. At the same time, sliced files are injected into the CDN queue in a timely manner, ensuring the rapid distribution of live content. This application improves the CDN cache hit rate and reduces bandwidth costs through slice synchronization; at the same time, the dynamic adjustment capability of slice duration makes it suitable for a variety of live broadcast scenarios, whether it is interactive live broadcast with high low latency requirements or large-scale event live broadcast with extremely high stability requirements.
[0032] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0033] like Figure 3 As shown, the following is an embodiment of the master-slave device HLS slicing system based on PCR synchronization provided by an embodiment of the present disclosure. This system and the master-slave device HLS slicing method based on PCR synchronization in the above-mentioned embodiments belong to the same inventive concept. For details not fully described in the embodiment of the master-slave device HLS slicing system based on PCR synchronization, please refer to the above-mentioned embodiment of the master-slave device HLS slicing method based on PCR synchronization.
[0034] The system includes: The slice initialization module establishes a unified time base based on the PCR timestamp and initializes the slice flag, the next PCR timestamp variable and the timeout flag; PCR extraction module, synchronously receives TS stream and parses the PCR timestamp in each TS packet in the TS stream; The PCR alignment module is configured to set a slicing flag when detecting that a PCR timestamp is greater than a next PCR timestamp, and perform alignment on the next PCR timestamp according to a preset slicing duration. At the same time, the module sets a timeout according to the preset slicing duration, starts a timer, and sets a timeout flag when the timeout is reached. The slicing trigger module is used to detect the key frame and timeout flag in the TS packet when the slicing flag is valid. When there is a key frame or the timeout flag is valid in the TS packet, the slicing operation is performed and the slicing flag is invalid.
[0035] This embodiment improves the disaster recovery capability and user experience of the live broadcast system through the interactive collaboration of the slice initialization module, PCR extraction module, PCR alignment module and slice trigger module, ensures the consistency of slices of primary and backup devices, reduces the risk of freezes, and improves CDN cache efficiency.
[0036] The master-slave device HLS slicing method based on PCR synchronization provided in the embodiment of the present application can be applied to electronic devices. Those skilled in the art will understand that the electronic device structure involved in the embodiment of the present invention does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange components differently. In the embodiment of the present invention, the electronic device includes but is not limited to laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of the present application described and / or required herein.
[0037] The electronic device may include a processor, an external memory interface, an internal memory, a universal serial bus (USB) interface, a charging management module, a power management module, a battery, a wireless communication module, an audio module, a speaker, a microphone, a sensor module, a button, a camera, a display, and a SIM card interface, etc.
[0038] It is understood that the structures illustrated in the embodiments of the present application do not constitute specific limitations on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown, or combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0039] A processor may include one or more processing units, such as a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.
[0040] The processor can be the nerve center and command center of the electronic device. The controller can generate operation control signals based on the instruction opcode and timing signal to complete the control of instruction fetching and execution.
[0041] The processor may also include a memory for storing instructions and data. In some embodiments, the memory in the processor is a cache memory. This memory can store instructions or data that the processor has just used or is reusing. If the processor needs to use the instruction or data again, it can directly call it from the memory. This avoids repeated accesses, reduces processor latency, and thus improves system efficiency.
[0042] The above-mentioned electronic device implements the HLS slicing method of the master-slave device based on PCR synchronization of the present application, which establishes a unified time base according to the PCR timestamp, and initializes the slicing flag, the next PCR timestamp variable and the timeout flag; the master and standby devices synchronously receive the TS stream and parse the PCR timestamp in each TS packet in the TS stream; when it is detected that the PCR timestamp is greater than the next PCR timestamp, the slicing flag is set, and the next PCR timestamp is aligned according to the preset slicing duration. At the same time, the timeout time is set according to the preset slicing duration, the timer is started, and the timeout flag is set when the timeout time is reached; when the slicing flag is valid, the key frame and the timeout flag in the TS packet are detected. When there is a key frame in the TS packet or the timeout flag is valid, the slicing operation is performed, and the slicing flag is set to invalid. The technical solution improves the reliability and disaster recovery capability of the live broadcast system, solves the video frame skipping and freeze problems during the switching of the master and standby devices through precise clock synchronization and intelligent slicing algorithm, and ensures the beneficial effect of the smoothness and stability of the live broadcast.
[0043] The storage medium provided in the present application stores a program product that can implement the HLS slicing method of master and standby devices based on PCR synchronization.
[0044] The HLS slicing method of the master and standby devices based on PCR synchronization includes: establishing a unified time base according to the PCR timestamp, and initializing the slice-enabled flag, the next PCR timestamp variable and the timeout flag; the master and standby devices synchronously receive the TS stream and parse the PCR timestamp in each TS packet in the TS stream; when it is detected that the PCR timestamp is greater than the next PCR timestamp, the slice-enabled flag is set, and the next PCR timestamp is aligned according to the preset slice duration. At the same time, the timeout time is set according to the preset slice duration, the timer is started, and the timeout flag is set when the timeout time is reached; when the slice-enabled flag is valid, the key frame and the timeout flag in the TS packet are detected. When there is a key frame in the TS packet or the timeout flag is valid, the slicing operation is performed and the slice-enabled flag is invalidated.
[0045] In some possible embodiments, the master-slave device HLS slicing method based on PCR synchronization disclosed herein can be implemented in the form of a program product, which includes program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps described in the above "Exemplary Method" section of this specification according to various exemplary embodiments of the present disclosure.
[0046] The storage medium of the present disclosure can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0047] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for HLS slicing of master and backup devices based on PCR synchronization, characterized in that: The steps include: S1. Establish a unified time base based on the PCR timestamp and initialize the slice flag, the next PCR timestamp variable, and the timeout flag; S2. The primary and backup devices synchronously receive the TS stream and parse the PCR timestamp in each TS packet in the TS stream; S3. When it is detected that the PCR timestamp is greater than the next PCR timestamp, the flag can be set to slice, and the next PCR timestamp is aligned according to the preset slice duration. At the same time, the timeout is set according to the preset slice duration, and the timer is started. When the timeout is reached, the timeout flag is set; S4. When the slicing flag is valid, detect the key frame and timeout flag in the TS packet. When there is a key frame or the timeout flag is valid in the TS packet, perform the slicing operation, and set the slicing flag to invalid, and return to step S2.
2. The HLS slicing method for master and backup devices based on PCR synchronization according to claim 1, characterized in that: In step S1, the initial slicing flag is false, the next PCR timestamp variable is initialized to 0, and the timeout flag is initialized to false.
3. The HLS slicing method for master and standby devices based on PCR synchronization according to claim 2, characterized in that: In step S2, the master and slave devices receive the TS stream, parse a TS packet, and determine whether the slice-capable flag in the TS packet is true; If yes, go to step S3; If so, go to step S4.
4. The HLS slicing method for master and backup devices based on PCR synchronization according to claim 3, characterized in that: The specific steps of step S3 are as follows: S31. The master and standby devices determine whether the parsed TS contains a PCR timestamp; If yes, go to step S32; If not, return to step S2; S32 obtains the PCR timestamp and determines whether the PCR timestamp is greater than the next PCR timestamp; If yes, go to step S33; If not, return to step S2; S33. Set the sliceable flag to true; S34. Align the PCR timestamp upward to a multiple of the slice duration T and record it in the next PCR timestamp variable; S35. Set the timeout period to half of the preset slice duration T, start the timer, and when the timeout period is met, set the timeout flag to true and return to step 2.
5. The HLS slicing method for master and standby devices based on PCR synchronization according to claim 4, characterized in that: In step S34, PCR timestamps are aligned by the following steps: Among them, T is the preset slice duration, is the ceiling function.
6. The HLS slicing method for master and backup devices based on PCR synchronization according to claim 4, characterized in that: The specific steps of step S4 are as follows: S41. The master and slave devices determine whether there are key frames in the parsed TS; If yes, go to step 43; If not, proceed to step S42; S42. Determine whether the timeout flag is true; If yes, go to step S43; If not, return to step S2; S43. Execute the slicing operation and name the slice file based on the system timestamp; S44. Inject the slice file into the CDN queue and set the slice-enabled flag to false.
7. The HLS slicing method for master and standby devices based on PCR synchronization according to claim 6, characterized in that: In step S43, a slicing operation is performed by saving the data before the currently received TS packet as a slice file; The slice files are named based on the system timestamp as follows: Among them, T is the preset slice duration, is the floor function.
8. A master-slave HLS slicing system based on PCR synchronization, characterized in that: include: The slice initialization module establishes a unified time base based on the PCR timestamp and initializes the slice flag, the next PCR timestamp variable and the timeout flag; PCR extraction module, synchronously receives TS stream and parses the PCR timestamp in each TS packet in the TS stream; The PCR alignment module is configured to set a slicing flag when detecting that a PCR timestamp is greater than a next PCR timestamp, and perform alignment on the next PCR timestamp according to a preset slicing duration. At the same time, the module sets a timeout according to the preset slicing duration, starts a timer, and sets a timeout flag when the timeout is reached. The slicing trigger module is used to detect the key frame and timeout flag in the TS packet when the slicing flag is valid. When there is a key frame or the timeout flag is valid in the TS packet, the slicing operation is performed and the slicing flag is invalid.
9. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method implements the steps of the master-slave device HLS slicing method based on PCR synchronization as claimed in any one of claims 1 to 7.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the master-slave device HLS slicing method based on PCR synchronization as described in any one of claims 1 to 7 are implemented.