Time shifting implementation method for playing mpegts based on browser side

The method optimizes browser-based MPEG-TS video playback by dynamically adjusting loading and caching to address memory and network issues, enabling efficient time-shifting with reduced memory usage and improved responsiveness.

CN120321447APending Publication Date: 2025-07-15GUANGXI RADIO & TELEVISION NEW MEDIA LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510463628.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-14
Publication Date
2025-07-15

AI Technical Summary

Technical Problem

When playing mpegts video on the browser, the video file takes up too much memory and the download time is long, resulting in the inability to implement the time shift function.

Method used

By dynamically adjusting the video file loading range on the browser side, combining cache management and network conditions, the time-shifting function is quickly initialized, reducing memory usage and improving response speed.

Benefits of technology

It realizes the fast time-shifting function of mpegts video on the browser side, avoids memory overload and network delay, and provides a better user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120321447A_ABST
    Figure CN120321447A_ABST
Patent Text Reader

Abstract

The invention discloses a time shifting implementation method for playing mpegts based on a browser side. The method comprises the following steps: S1, initializing a player to obtain the size of a video file; s2, the player is initialized to obtain the maximum display time maxpts and the minimum display time minpts; and S3, acquiring the percentage p of the time point of the time shifting position in the total duration. The method comprises the following steps: recording starting positions and display time pts of all downloaded and analyzed frames in a video file, acquiring the percentage of a time point of a time shifting position in the total duration, then calculating the range of loading the video file according to the percentage and the size of a package loaded each time, loading a section of video file from the position, and displaying the video file. According to the method and the device, the pts of the video file and the corresponding file position are analyzed, so that quick initialization of the mpegts video played by the browser is realized, and a quick time shifting function is realized under the condition of not occupying too large memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of audio and video players, and particularly to a method for implementing time-shifting function for playing mpegts on the browser side. Background Art

[0002] The mpegts video format is widely used in the fields of radio and television and IPTV. To implement playing on the browser side, it is necessary to implement its own player. When playing mpegts video on the TV side or set-top box, the implementation of time-shifting depends on the accurate positioning of the video by the backend server, or the slices have been pre-set and the information of each slice has been saved in advance, and then the data starting from the IDR frame at the time-shifting position is returned to the set-top box side or the TV side for decoding and playing to complete the time-shifting function.

[0003] In the actual application process of the existing method, in the case of no slices or accurate positioning by the backend server, when playing on the pure browser side to complete the time-shifting function, parsing the positions of all IDR frames in the video file and the positions of the time-shifting time points in the video requires reading the entire video file to locate all the frames. However, playing on the browser side requires a network, and due to browser limitations, the file is stored in memory. If the video file is too large, it will occupy too much memory and even cause memory overflow. Moreover, if the network is slow, the download time will be very long. Therefore, at present, many implementations of playing mpegts video on the browser side do not have the time-shifting function. Summary of the Invention

[0004] The purpose of the present invention is to provide a method for implementing time-shifting for playing mpegts on the browser side to solve the problem in the above background art that for playing on the browser side, it requires a network. If the video file is very large, the browser memory occupancy is large and the waiting time for downloading the file is long. Therefore, at present, many implementations of playing mpegts video on the browser side do not have the time-shifting function.

[0005] To achieve the above purpose, the present invention provides the following technical solution: A method for implementing time-shifting for playing mpegts on the browser side, including the following steps:

[0006] S1. The player initializes to obtain the size size of the video file;

[0007] S2. The player initializes to obtain the maximum display time maxpts and the minimum display time minpts;

[0008] S3. Obtain the percentage p of the time point at the time-shifting position in the total duration;

[0009] S4. Calculate the range for loading the video file based on the percentage and the size of each loaded package, and dynamically adjust the size of each loaded video file according to the network condition and memory usage to adapt to the current bandwidth situation;

[0010] S5. Extract all the presentation time stamps (pts) ranges of the video segments in step S4, and cache the already loaded video segments so that when the user performs fast forward or rewind operations, data can be directly read from the cache;

[0011] S6. Calculate the pts corresponding to the time shift point to determine whether the loaded video file contains the time shift time point;

[0012] S7. Determine whether the pts in step S6 is within the range of the pts extracted in step S5. If so, it indicates that the time shift frame is within the currently loaded video range, that is, ranPts is greater than rMinPts and less than rMaxPts, which means a hit. After a hit, it is necessary to search forward to the nearest IDR frame and start decoding from that frame;

[0013] S8. If there is no hit, continue to calculate the start position and end position of the next segment of data based on the above data, and decide whether to preload the video segment according to the network condition and cache situation;

[0014] S9. If still not found, based on the start position and end position in step S8, repeat step S8 until found.

[0015] Preferably, in step S1, the process of initializing the player is as follows: Initialize an http request to obtain the size of the video file.

[0016] Preferably, in step S2, the maximum presentation time is obtained by extracting the last (or multiple consecutive) video segments of appropriate size, and the minimum presentation time is obtained by extracting the first (or multiple consecutive) video segments, generally with the standard of obtaining one GOP.

[0017] Preferably, in step S3, the process of obtaining the percentage of the time shift position time point in the total duration is as follows: First, obtain the total duration of the video based on the maximum presentation time and the minimum presentation time, then obtain the current time shift position time point, and finally calculate the percentage of the time shift position time point in the total duration.

[0018] Preferably, in step S4, in the calculation of the range for loading the video file, when calculating, take the integer multiple of the packet length up and down, including the following steps:

[0019] S41. Preset the single - load size psize according to the total size and total duration of the video;

[0020] S42. Calculate the starting position of the loading file. The starting position is the position of the percentage P in S3 within the total video size, and take half of the single - loading size psize by rounding down.

[0021] S43. Load a video segment of size psize according to the starting position.

[0022] S44. Use a cache to store the downloaded video segments for the user to perform fast - forward and rewind operations. So that when the user performs fast - forward and rewind operations, data can be directly read from the cache, reducing the number of requests to the server.

[0023] S45. Use the LRU cache algorithm to manage the video segments in the cache to improve the cache hit rate.

[0024] Preferably, in step S5, the display time pts range of the extracted video is: rMinPts - rMaxPts.

[0025] Preferably, in step S6, the pts corresponding to the time - shift point is the time - shift point percentage P * total video duration.

[0026] Preferably, in step S8, the steps of continuing to calculate the start position and end position of the next segment include the following steps:

[0027] S81. If ranPts is greater than rMaxPts, search upward for the end position of the current segment.

[0028] S82. If ranPts is less than rMaxPts, search downward from the start position of the current segment.

[0029] S83. Then repeat step S5.

[0030] Preferably, in step S8, the process of determining whether to pre - load video segments according to the network condition and cache situation is as follows: When the network condition is good, more video segments can be pre - loaded to provide a faster response speed and a better user experience; when the network condition is poor, the size of the loaded video segments can be dynamically adjusted according to the real - time bandwidth situation to avoid network congestion and video playback stuttering.

[0031] Preferably, in step S9, the steps of repeating step S8 include the following steps:

[0032] S91. Determine whether the pts of the video extracted in step S8 is within the range of the pts extracted in step S5, that is, whether the time - shifted frames are within the currently loaded video range.

[0033] S92. If the PTS of the video extracted in step S8 is not within the range, based on the start and end of this step S8, repeat step S8 to calculate the start position and end position of the next segment of data again;

[0034] S93. If the PTS of the video extracted in step S8 is within the range, find the PTS of this segment of the video file and the corresponding file position.

[0035] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0036] 1. In this method, by recording the start position and display time PTS of all frames that have been downloaded and parsed in the video file, obtaining the percentage of the time point of the time shift position in the total duration, and then calculating the range of the loaded video file according to the percentage and the size of each loaded package, loading a segment of the video file from this position, and parsing the PTS of this segment of the video file and the corresponding file position, so as to realize the rapid initialization of the mpegts video of the browser player and achieve a relatively fast time shift function without occupying too much memory.

[0037] 2. In this method, by using a cache to store the downloaded video segments, so that when the user performs fast forward and rewind operations, the data can be directly read from the cache, reducing the number of requests to the server. By managing the video segments in the cache, the cache hit rate is improved. When the network condition is good, more video segments can be pre-loaded to provide a faster response speed and a better user experience. When the network condition is poor, the size of the loaded video segments can be dynamically adjusted according to the real-time bandwidth situation to avoid network congestion and video playback stuttering. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a flowchart of a method for realizing time shift of playing mpegts based on the browser side of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0039] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0040] Please refer to Figure 1 , the present invention provides a technical solution: a method for realizing time shift of playing mpegts based on the browser side, including the following steps:

[0041] Step 1: The player initializes to obtain the size size of the video file. Specifically, the process of initializing the player is as follows: Initialize an HTTP request to obtain the size of the video file.

[0042] Step 2: The player initializes to obtain the maximum display time maxpts and the minimum display time minpts. According to the total duration of the video file displayed on the interface, obtain the maximum display time, and obtain the minimum display time by dragging the progress bar or viewing the time display.

[0043] Among them, the maximum display time is obtained by extracting the last (or multiple consecutive) video segments of appropriate size, and the minimum display time is obtained by extracting the first (or multiple consecutive) video segments, generally taking obtaining a GOP as the standard.

[0044] Step 3: Obtain the percentage p of the time point of the time-shift position in the total duration. Among them, the process of obtaining the percentage of the time point of the time-shift position in the total duration is as follows: First, obtain the total duration of the video according to the maximum display time and the minimum display time, then obtain the current time point of the time-shift position, and finally calculate the percentage of the time point of the time-shift position in the total duration.

[0045] Step 4: Calculate the range for loading the video file according to the percentage and the size of each loaded package, and dynamically adjust the size of each loaded video file according to the network condition and memory usage to adapt to the current bandwidth situation, avoid network congestion and slow video loading, load a segment of the video file from this position, and parse the pts and the corresponding file position of this segment of the video file.

[0046] Specifically, in calculating the range for loading the video file, when calculating, round up and down to an integer multiple of the package length, including the following steps:

[0047] 41) Preset the single-load size psize according to the total size and total duration of the video.

[0048] 42) Calculate the starting position for loading the file. The starting position is the position of the percentage P in the total size of the video in S3, and round down to half of the single-load size psize.

[0049] 43) Load a video segment of size psize according to the starting position.

[0050] 44) Use a cache to store the downloaded video segments for the user to perform fast forward and rewind operations.

[0051] 45) Use the LRU cache algorithm to manage the video segments in the cache.

[0052] Step 5: Extract the display time PTS range of the video clip in Step 4 and cache the already loaded video clip so that when the user performs fast forward or rewind operations, data can be directly read from the cache to improve the response speed. Among them, the extracted display time PTS range of the video is: rMinPts - rMaxPts;

[0053] Step 6: Calculate the PTS corresponding to the time shift point to determine whether the loaded video file contains the time shift time point. Among them, the calculated PTS corresponding to the time shift point is the time shift point percentage P * the total video duration;

[0054] Step 7: Determine whether the PTS in Step 6 is within the PTS range extracted in Step 5. If so, it indicates that the time shift frame is within the currently loaded video range, that is, ranPts is greater than rMinPts and less than rMaxPts, which means the time shift point is found;

[0055] Step 8: If not hit, continue to calculate the start position and end position of the next segment of data based on the above data, and decide whether to preload the video clip in advance according to the network status and cache situation to improve the user experience;

[0056] Specifically, continuing to calculate the start position and end position of the next segment of data includes the following steps:

[0057] 81) If ranPts is greater than rMaxPts, search upward from the end position of the current segment;

[0058] 82) If ranPts is less than rMaxPts, search downward from the start position of the current segment;

[0059] 83) Then repeat Step S5.

[0060] Among them, the process of deciding whether to preload the video clip according to the network status and cache situation is as follows: When the network status is good, more video clips can be preloaded in advance to provide a faster response speed and a better user experience; when the network status is poor, the size of the loaded video clip can be dynamically adjusted according to the real-time bandwidth situation to avoid network congestion and video playback stuttering;

[0061] Step 9: If still not found, based on the start position and end position in Step 8, repeat Step 8 until found;

[0062] Specifically, repeating Step 8 includes the following steps:

[0063] 91) Determine whether the PTS of the video extracted in Step 8 is within the PTS range extracted in Step 5, that is, whether the time shift frame is within the currently loaded video range;

[0064] 92) If the PTS of the video extracted in step eight is not within the range, then based on the start and end of this step eight, repeat step eight to calculate the start position and end position of the next segment of data again;

[0065] 93) If the PTS of the video extracted in step eight is within the range, then find the PTS of this segment of the video file and the corresponding file position;

[0066] In this method, by recording the start position and display time PTS of all frames that have been downloaded and parsed in the video file, then based on the recorded data, estimate the approximate position of the time-shifted time point in the file, and then load a segment of the video file from this position, parse the PTS of this segment of the video file and the corresponding file position. If not found, then based on the information parsed from this segment of the video file, re-locate the start position of the next file until found. If the bandwidth is sufficient, such as accessing within the intranet, in most cases, the time-shifted point can be found at the file point estimated and located for the first time, and at most the data point can also be located for the second time. Use a cache to store the video segments that have been downloaded so that when the user performs fast forward or rewind operations, data can be directly read from the cache, reducing the number of requests to the server. By managing the video segments in the cache, the cache hit rate can be improved. When the network condition is good, more video segments can be pre-loaded to provide a faster response speed and a better user experience. And when the network condition is poor, the size of the loaded video segments can be dynamically adjusted according to the real-time bandwidth situation to avoid network congestion and video playback stuttering. By directly decoding and re-encoding the video during the time-shift process, the playback position of the video can be dynamically adjusted according to the user's operation.

[0067] Although the present invention has been described in detail with reference to the foregoing embodiments, for those skilled in the art, they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for implementing time shift in playing mpegts on the browser side, characterized in that, It includes the following steps: S1. The player initializes to obtain the size size of the video file; S2. The player initializes to obtain the maximum display time maxpts, the minimum display time minpts, and calculates the total duration; S3. Obtain the percentage p of the time point at the time-shift position in the total duration; S4. Calculate the range for loading the video file according to the percentage and the size of each loaded packet, and dynamically adjust the size of each loaded video file according to the network condition and memory usage to adapt to the current bandwidth situation; S5. Extract all the display time pts ranges of the video segments in step S4, and cache the already loaded video segments so that when the user performs fast forward or rewind operations, data can be directly read from the cache; S6. Calculate the pts corresponding to the time-shift point, which is used to determine whether the loaded video file contains the time-shift time point; S7. Judge whether the pts in step S6 is within the range of the pts extracted in step S5. If so, it indicates that the time-shifted frame is within the currently loaded video range, that is, ranPts is greater than rMinPts and less than rMaxPts, which means a hit. After a hit, it is necessary to search forward to the nearest IDR frame and start decoding from that frame; S8. If there is no hit, continue to calculate the start position and end position of the next segment of data according to the above data, and decide whether to pre-load video segments according to the network condition and cache situation; S9. If it still cannot be found, based on the start position and end position in step S8, repeat step S8 until it is found.

2. The time-shift implementation method for playing mpegts based on the browser side according to claim 1, wherein In step S1, the process of initializing the player is as follows: initialize an http request to obtain the size of the video file.

3. A time-shifting implementation method for playing mpegts based on the browser side according to claim 1, characterized in that, In step S2, the maximum display time is obtained by extracting the last (or multiple consecutive) appropriate video segments, and the minimum display time is obtained by extracting the first (or multiple consecutive) video segments, generally with obtaining a gop as the standard.

4. A time-shift implementation method for playing mpegts based on the browser side according to claim 1, characterized in that, In step S3, the process of obtaining the percentage of the time point at the time-shift position in the total duration is as follows: first obtain the total duration of the video according to the maximum display time and the minimum display time, then obtain the current time-shift position time point, and finally calculate the percentage of the time-shift position time point in the total duration.

5. A time-shifting implementation method for playing mpegts based on the browser side according to claim 1, characterized in that, In step S4, in the calculation of the range for loading the video file, when calculating, take the integer multiple of the packet length up and down, including the following steps: S41. Preset the single-load size psize according to the total size and total duration of the video; S42. Calculate the start position of the loaded file. The start position is the position of the percentage P in step S3 in the total size of the video, and take half of the single-load size psize downward; S43. Load a video segment of size psize according to the start position; S44. Use the cache to store the already downloaded video segments for the user to perform fast forward and rewind operations, so that when the user performs fast forward and rewind operations, data can be directly read from the cache to reduce the number of requests to the server; S45. Use the LRU cache algorithm to manage the video segments in the cache to improve the cache hit rate.

6. A time-shift implementation method for playing mpegts based on the browser side according to claim 1, characterized in that In step S5, the display time pts range of the extracted video is: rMinPts - rMaxPts.

7. A time-shifting implementation method for playing mpegts based on the browser side according to claim 1, characterized in that In step S6, the pts corresponding to the time-shifted point in the calculation is the time-shifted point percentage P * the total video duration.

8. A time-shifting implementation method for playing mpegts based on the browser side according to claim 1, characterized in that, In step S8, the steps for continuing to calculate the start position and end position of the next segment of data include the following steps: S81. If ranPts is greater than rMaxPts, search upward for the end position of the current segment; S82. If ranPts is less than rMaxPts, search downward from the start position of the current segment; S83. Then repeat step S5.

9. A time-shift implementation method for playing mpegts based on the browser side according to claim 1, characterized in that, In step S8, the process of determining whether to pre-load video segments according to the network condition and cache situation is as follows: When the network condition is good, more video segments can be pre-loaded to provide a faster response speed and a better user experience; when the network condition is poor, the size of the loaded video segments can be dynamically adjusted according to the real-time bandwidth situation to avoid network congestion and video playback stuttering.

10. A method for implementing time shift of playing mpegts based on the browser side according to claim 1, characterized in that, In step S9, the steps for repeating step S8 include the following steps: S91. Determine whether the pts of the video extracted in step S8 is within the range of the pts extracted in step S5, that is, whether the time-shifted frames are within the range of the currently loaded video; S92. If the pts of the video extracted in step S8 is not within the range, based on the start and end of this step S8, repeat step S8 to calculate the start position and end position of the next segment of data again; S93. If the pts of the video extracted in step S8 is within the range, find the pts of this segment of the video file and the corresponding file position.