HLS video stream playing method and device, equipment and medium
Through the multi-threaded sharded rotation downloading and caching technology of the local proxy module, the problem of buffering lag in HLS video streams when the network fluctuates is solved, achieving a smoother video playback experience.
Patent Information
- Application Number
- CN202411025922.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-08-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
HLS video streaming causes video buffering and freezes when the network fluctuates, affecting user experience.
The local proxy module is used to download and cache HLS video stream shards in turn through multi-thread sharding, including main threads and secondary threads. The download and caching strategy is dynamically adjusted according to user bandwidth and video stream type to ensure smooth video playback.
In network fluctuation scenarios, the number of buffering times is minimized, the smoothness of HLS video stream playback is improved, and the user experience is improved.
Smart Images

Figure CN118555449A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of audio and video playback, and provides an HLS video stream playback method, device, equipment and medium. Background Art
[0002] As we all know, HLS (HTTP Live streaming) is a streaming media transmission protocol based on HTTP. It is widely used in the field of live video broadcasting. It achieves the purpose of downloading and playing by cutting audio and video streams into small transport stream (TS) slices, generating m3u8 playlist files, and downloading the playlist files through the HTTP protocol by the playback client. The slice files are downloaded and played in the order specified in the playlist file, which is similar to the effect of real-time online playback.
[0003] However, although the HLS protocol has the advantages of simple client support, good network compatibility, good CDN support, and built-in multi-bitrate adaptive mechanism, it also has obvious disadvantages. For example, the delay is high and it cannot be used in scenarios with strict delay requirements, such as interactive live broadcasting. There are many TS slices, especially real-time video streams, which require dynamic generation and deletion of TS slice files. Therefore, as more and more video sources are played using the HLS protocol, its problems are gradually emerging. Specifically, during the playback process, the video picture buffering is stuck due to network fluctuations, which in turn makes the user experience worse.
[0004] Therefore, how to minimize the number of buffering times to ensure user experience has become an urgent problem to be solved. Summary of the invention
[0005] The present application provides an HLS video stream playback method, device, equipment and medium, which are used to solve the problem of poor user experience caused by video picture buffering jamming in the prior art.
[0006] On the one hand, a method for playing an HLS video stream is provided, the method comprising: The terminal player sends a media playback request to the server through the local proxy module; wherein the media playback request is used to request playback media description information of the target HLS video stream; In response to the media playback request, the server returns the first-level fragment information of the target HLS video stream to the local proxy module; wherein the first-level fragment information includes a plurality of second-level fragment information; The local proxy module is used to perform multi-threaded segmentation downloading and caching of the plurality of secondary segmentation information in turn, so as to obtain a plurality of video stream segments; wherein the threads include a main thread and a plurality of secondary threads; The terminal player is used to play the multiple video stream segments.
[0007] Optionally, the step of using the local proxy module to perform multi-threaded segment downloading and caching on the multiple secondary segment information in turn to obtain multiple video stream segments includes: Using the local proxy module, processing the primary sharding information to determine the user bandwidth; According to the user bandwidth, downloading the multiple secondary fragment information included in the primary fragment information to obtain the multiple secondary fragment information; The local proxy module is used to perform multi-threaded segment downloading and caching in turn on the video stream segments corresponding to the plurality of secondary segment information, so as to obtain a plurality of video stream segments.
[0008] Optionally, the step of using the local proxy module to perform multi-threaded segment downloading and caching in turn on the video stream segments corresponding to the plurality of secondary segment information to obtain the plurality of video stream segments includes: Using the local proxy module, determine the type of the target HLS video stream; wherein the type includes a LIVE video stream and a VOD video stream; For any secondary fragment information, determine the target processing flow of any secondary fragment information according to the type of the target HLS video stream; wherein the target processing flow includes a dynamic download flow and an overall download flow; According to the target processing flow, any of the secondary fragment information is downloaded, cached and played.
[0009] Optionally, the step of determining a target processing flow of any one of the secondary fragment information according to the type of the target HLS video stream includes: If it is determined that the type of the target HLS video stream is a LIVE video stream, then determining that the target processing flow of any secondary fragment information is a dynamic download flow; If it is determined that the type of the target HLS video stream is a VOD video stream, then the target processing flow of any secondary fragment information is determined to be an overall download flow.
[0010] Optionally, the step of downloading, caching and playing any one of the secondary fragment information according to the target processing flow includes: According to the dynamic download process, the local proxy module is used to update the video stream segment corresponding to any secondary segment information in real time; Determine if there is an adaptive option or an active resolution switching option in the user interface; If it is determined that there is an adaptive option or an active resolution switching option in the user interface, any one of the secondary sharding information is downloaded and updated according to the address list in the primary sharding information.
[0011] Optionally, the step of downloading, caching and playing any one of the secondary fragment information according to the target processing flow includes: According to the overall download process, the local proxy module is used to overall download the video stream fragment corresponding to any secondary fragment information once; Determine if there is an adaptive option or a specific resolution option in the user interface; If it is determined that there is an adaptive option or an active resolution switching option in the user interface, any one of the secondary sharding information is downloaded and updated according to the address list in the primary sharding information.
[0012] Optionally, the main thread is a high priority thread, the secondary thread is a low priority thread, and the step of using the local proxy module to perform multi-threaded segmentation downloading and caching on the video stream segments corresponding to the plurality of secondary segmentation information in turn to obtain the plurality of video stream segments includes: Using the local proxy module, the first video stream segment among the video stream segments corresponding to the plurality of secondary segment information is downloaded and cached by a main thread, and the remaining video stream segments are downloaded and cached by multiple secondary threads; After the first video stream segment is played, the main thread is set to a low priority, and the next video stream segment that has not been downloaded is downloaded and cached again; For any secondary thread, when the video stream segment cached by any secondary thread starts to play, the priority of any secondary thread is set to be high.
[0013] On the one hand, a HLS video stream playback device is provided, the device comprising: A media playback request sending unit, used to use a terminal player to send a media playback request to a server through a local proxy module; wherein the media playback request is used to request playback media description information of a target HLS video stream; A media playback request response unit, configured to respond to the media playback request and use the server to return the primary fragment information of the target HLS video stream to the local proxy module; wherein the primary fragment information includes a plurality of secondary fragment information; The video stream fragment downloading unit is used to use the local proxy module to perform multi-threaded fragment downloading and caching on the multiple secondary fragment information in turn to obtain multiple video stream fragments; wherein the thread includes a main thread and multiple secondary threads; The video stream segment playing unit is used to play the multiple video stream segments using the terminal player.
[0014] On the one hand, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein any one of the above methods is implemented when the processor executes the computer program.
[0015] In one aspect, a storage medium is provided, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, any of the above methods is implemented.
[0016] Compared with the prior art, the beneficial effects of this application are: In an embodiment of the present application, when playing an HLS video stream, first, a terminal player can be used to send a media playback request to a server through a local proxy module; wherein the media playback request can be used to request the playback media description information of the target HLS video stream; then, in response to the media playback request, the server can be used to return the first-level fragmentation information of the target HLS video stream to the local proxy module; wherein the first-level fragmentation information includes multiple second-level fragmentation information; finally, a local proxy module can be used to perform multi-threaded fragmentation download and cache of multiple second-level fragmentation information in turn to obtain multiple video stream fragments; wherein the thread includes a main thread and multiple secondary threads; finally, a terminal player can be used to play multiple video stream fragments. Therefore, in an embodiment of the present application, since a local proxy module is directly used to implement the download and cache of the HLS video stream, in the case of occasional network fluctuations, there is no need to modify the original terminal player, which can maximize the compatibility of the terminal player's playback logic, and the playback cost is low. In addition, since multi-threaded fragments are downloaded and cached in turn, the playback of HLS video streams can be less affected by network fluctuations, which can better ensure the smoothness of HLS video stream playback, minimize the number of buffering times, and ensure user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0018] Figure 1 An electronic device provided in an embodiment of the present application; Figure 2 A schematic diagram of an HLS video stream playback method provided in an embodiment of the present application; Figure 3A schematic diagram of the first-level sharding information provided in an embodiment of the present application; Figure 4 A schematic diagram of a LIVE video stream processing process provided in an embodiment of the present application; Figure 5 A schematic diagram of a VOD video stream processing process provided in an embodiment of the present application; Figure 6 A schematic diagram of multi-threaded slice downloading in turn provided in an embodiment of the present application; Figure 7 A schematic diagram of an HLS video stream playback device provided in an embodiment of the present application.
[0019] Markings in the figure: 10-HLS video stream playback device, 101-processor, 102-memory, 103-I / O interface, 104-database, 70-HLS video stream playback device, 701-media playback request sending unit, 702-media playback request response unit, 703-video stream segment downloading unit, 704-video stream segment playback unit. DETAILED DESCRIPTION
[0020] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other arbitrarily. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.
[0021] HLS (HTTP Live streaming) is a streaming media transmission protocol based on HTTP. It is widely used in the field of live video broadcasting. It achieves the purpose of downloading and playing by cutting audio and video streams into small transport stream (TS) slices, generating m3u8 playlist files, and downloading the playlist files through the HTTP protocol on the playback client. It also downloads and plays the slice files in the order specified in the playlist files, which is similar to the effect of real-time online playback.
[0022] However, although the HLS protocol has the advantages of simple client support, good network compatibility, good CDN support, and built-in multi-bitrate adaptive mechanism, it also has obvious disadvantages. For example, the delay is high and it cannot be used in scenarios with strict delay requirements, such as interactive live broadcasting. There are many TS slices, especially real-time video streams, which require dynamic generation and deletion of TS slice files. Therefore, as more and more video sources are played using the HLS protocol, its problems are gradually emerging. Specifically, during the playback process, the video picture buffering is stuck due to network fluctuations, which in turn makes the user experience worse.
[0023] Based on this, an embodiment of the present application provides an HLS video stream playback method, in which, first, a terminal player can be used to send a media playback request to a server through a local proxy module; wherein the media playback request can be used to request the playback media description information of the target HLS video stream; then, in response to the media playback request, the server can be used to return the first-level fragmentation information of the target HLS video stream to the local proxy module; wherein the first-level fragmentation information contains multiple second-level fragmentation information; finally, a local proxy module can be used to perform multi-threaded fragmentation download and cache of multiple second-level fragmentation information in turn to obtain multiple video stream fragments; wherein the thread includes a main thread and multiple secondary threads; finally, a terminal player can be used to play multiple video stream fragments. Therefore, in an embodiment of the present application, since the local proxy module is directly used to realize the download and cache of the HLS video stream, in the case of occasional network fluctuations, the original terminal player does not need to be modified, and the playback logic of the terminal player can be maximized, and the playback cost is low. In addition, since multi-threaded fragments are downloaded and cached in turn, the playback of HLS video streams can be less affected by network fluctuations, which can better ensure the smoothness of HLS video stream playback, minimize the number of buffering times, and ensure user experience.
[0024] After introducing the design ideas of the embodiments of the present application, the following briefly introduces the application scenarios to which the technical solutions of the embodiments of the present application can be applied. It should be noted that the application scenarios introduced below are only used to illustrate the embodiments of the present application and are not limited. In the specific implementation process, the technical solutions provided by the embodiments of the present application can be flexibly applied according to actual needs.
[0025] like Figure 1 As shown, an electronic device provided in an embodiment of the present application is provided, and the electronic device may specifically be an HLS video stream playback device 10.
[0026] Among them, the HLS video stream playback device 10 can be used to smoothly play the HLS video stream, for example, it can be a personal computer (PC), a server and a laptop. The HLS video stream playback device 10 may include one or more processors 101, a memory 102, an I / O interface 103 and a database 104. Specifically, the processor 101 may be a central processing unit (CPU), or a digital processing unit, etc. The memory 102 may be a volatile memory (volatile memory), such as a random-access memory (RAM); the memory 102 may also be a non-volatile memory (non-volatile memory), such as a read-only memory, a flash memory (flash memory), a hard disk drive (HDD) or a solid-state drive (SSD); or the memory 102 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 102 may be a combination of the above memories. The memory 102 may store some program instructions of the HLS video stream playback method provided in the embodiment of the present application, and these program instructions can be used to implement the steps of the HLS video stream playback method provided in the embodiment of the present application when executed by the processor 101, so as to solve the problem of poor user experience caused by video picture buffering jamming in the prior art. The database 104 may be used to store data such as media playback requests, primary fragmentation information, multiple secondary fragmentation information, video stream fragmentation, and target HLS video stream involved in the solution provided in the embodiment of the present application.
[0027] In the embodiment of the present application, the HLS video stream playback device 10 can obtain a media playback request through the I / O interface 103, and then the processor 101 of the HLS video stream playback device 10 will minimize the number of buffering times according to the program instructions of the HLS video stream playback method provided in the embodiment of the present application in the memory 102 to ensure the user experience. In addition, data such as the media playback request, the primary fragment information, the multiple secondary fragment information, the video stream fragments, and the target HLS video stream can also be stored in the database 104.
[0028] Of course, the method provided in the embodiment of the present application is not limited to Figure 1 The application scenarios shown can also be used in other possible application scenarios, and the embodiments of the present application are not limited thereto. Figure 1The functions that can be realized by each device in the application scenario shown will be described in the subsequent method embodiments, and will not be described in detail here. Below, the method of the embodiment of the present application will be introduced in conjunction with the accompanying drawings.
[0029] like Figure 2 FIG. 1 is a schematic diagram of a method for playing HLS video streams provided by an embodiment of the present application. The method can be performed by Figure 1 The HLS video stream playback device 10 is used to perform the method. Specifically, the process of the method is described as follows.
[0030] Step 201: Use a terminal player to send a media play request to a server via a local proxy module.
[0031] In the embodiment of the present application, the media playback request can be used to request the playback media description information of the target HLS video stream. Moreover, the local proxy module is the core module of this technical solution. It is a module independently developed and designed by the user. It is mainly responsible for receiving the media playback request of the terminal player and synchronously downloading, caching and merging network requests through a multi-threaded mechanism to achieve the maximum smooth playback of the video.
[0032] Specifically, the local proxy module may be initialized, that is, the local proxy module may be started through an application, and an http proxy service and a port number may be established to start the proxy service of the local proxy module.
[0033] Furthermore, when the user wants to play the target HLS video stream, the terminal player can send a media playback request to the local proxy module. Then, the local proxy module will establish an http session with the server based on the media playback request, and based on the http session, forward the received media playback request to the server to request the playback media description information of the target HLS video stream.
[0034] Step 202: In response to the media playback request, the server returns the primary segmentation information of the target HLS video stream to the local proxy module.
[0035] In the embodiment of the present application, the first-level fragmentation information includes multiple second-level fragmentation information, wherein the first-level fragmentation information also includes the number of fragments, fragmentation sequence number, fragmentation duration, fragmentation name address, etc.
[0036] Specifically, when the server receives a media playback request, the server will respond to the media playback request and query the database for the corresponding first-level fragment information based on the media playback request, that is, query the first-level fragment information of the target HLS video stream, and then, the server will return the first-level fragment information of the target HLS video stream to the local proxy module.
[0037] Step 203: Using a local proxy module, download and cache multiple secondary fragment information in a multi-threaded manner in turn to obtain multiple video stream fragments.
[0038] In the embodiments of the present application, Figure 2 As described above, threads can include a main thread ( Figure 2 The thread corresponding to shard 1) and multiple secondary threads ( Figure 2 Threads corresponding to shards 2, 3, etc.).
[0039] Specifically, after the local proxy module receives the first-level fragment information of the target HLS video stream returned by the server, first, the local proxy module can be used to process the first-level fragment information to determine the user bandwidth. For example, the download time of the first-level fragment information can be measured, and then the average download bandwidth of the user can be calculated based on the download time and file size of the first-level fragment information, thereby determining the user's bandwidth; then, based on the user's bandwidth, the first-level fragment information can be downloaded to obtain multiple second-level fragment information. Figure 3 As shown, it is a schematic diagram of the primary fragmentation information provided by the embodiment of the present application. Among them, the primary fragmentation information (main m3u8 file) includes three secondary fragmentation information (three sub-m3u8 files), and these three secondary fragmentation information are 480p.m3u8 with a maximum bit rate of 1.28MB and an average bit rate of 1MB, 720p.m3u8 with a maximum bit rate of 2.56MB and an average bit rate of 2MB, and 1080p.m3u8 with a maximum bit rate of 7.68MB and an average bit rate of 6MB. Furthermore, according to the average bit rate of these three sub-m3u8 files, the average bit rate of the main m3u8 file can be calculated, that is, the average download bandwidth of the user is calculated.
[0040] Finally, a local proxy module can be used to perform multi-threaded segment downloading and caching of the video stream segments corresponding to the multiple secondary segment information to obtain multiple video stream segments. Furthermore, since the segment downloading mechanism can speed up buffering as much as possible and ensure sufficient buffering data, it can not only enable playback to continue during network fluctuations without affecting playback, but also continue buffering when the network is restored to minimize buffering jams.
[0041] Step 204: Use a terminal player to play the multiple video stream segments.
[0042] In an embodiment of the present application, after the video stream fragments are cached in the buffer center of the local proxy module, the buffer center will return the cached video stream fragments to the terminal player according to the fragment sequence number (for example, fragment 1, 2, 3, etc.). Finally, the terminal player can be used to play multiple video stream fragments in sequence according to the fragment sequence number.
[0043] Furthermore, since multi-threaded and multi-segment synchronous downloading is adopted, the playback of HLS video stream is less affected by network fluctuations, which can better ensure the smoothness of video playback, minimize the number of buffering times, and ensure the user experience.
[0044] In a possible implementation, in order to further minimize the number of buffering times, in an embodiment of the present application, multi-threaded fragments are downloaded and cached in turn for each of the video stream fragments corresponding to multiple secondary fragment information, and different processing flows may be adopted depending on the type of the target HLS video stream.
[0045] Specifically, first, a local proxy module can be used to determine the type of the target HLS video stream according to the label in the secondary fragment information; wherein the types include LIVE video stream (live video stream) and VOD video stream (on-demand video stream); then, when downloading and caching the secondary fragment information, for any secondary fragment information, the target processing flow of any secondary fragment information can be determined according to the type of the target HLS video stream; wherein the target processing flow includes a dynamic download flow and an overall download flow; finally, any secondary fragment information can be downloaded, cached and played according to the target processing flow.
[0046] In a possible implementation, when determining the target processing flow of any secondary fragment information, if the type of the target HLS video stream is determined to be a LIVE video stream, then the target processing flow of any secondary fragment information can be determined to be a dynamic download flow, that is, it is necessary to obtain multiple video stream fragments through dynamic download to ensure the real-time nature of the video stream fragments; if the type of the target HLS video stream is determined to be a VOD video stream, then the target processing flow of any secondary fragment information can be determined to be an overall download flow, that is, all video stream fragments can be obtained through only one download.
[0047] In one possible implementation, after determining that the target processing flow of any secondary fragment information is a dynamic download process, a local proxy module can be used to update the video stream fragment corresponding to any secondary fragment information in real time according to the dynamic download process, wherein the time of the real-time update depends on the length of the video time retained by the secondary fragment information.
[0048] Then, since there is no update of the file content in the primary fragmentation information, only when it involves providing a user interface setting option with an adaptive option or an active resolution switching option, will the secondary fragmentation information be updated from the m3u8 address of the primary fragmentation information switching different resolutions. Therefore, after updating the video stream fragment corresponding to any secondary fragmentation information in real time, it can also be determined whether there is an adaptive option or an active resolution switching option in the user interface.
[0049] If it is determined that there is an adaptive option or an active resolution switching option in the user interface, any secondary fragment information can be downloaded and updated according to the address list in the primary fragment information to obtain new secondary fragment information under the current bandwidth bit rate. At the same time, when the thread is idle and available, the video stream fragment with fragment number T that has been downloaded by the local proxy module before the bit rate switching is replaced with the video stream fragment with fragment number T+1 downloaded by the new secondary fragment information after the bit rate switching, so as to ensure seamless connection of the video bit rate switching cache video time and video continuity.
[0050] For ease of understanding, the following is a detailed introduction using m3u8 video stream as an example. Figure 4 , which is a schematic diagram of the LIVE video stream processing process provided in an embodiment of the present application.
[0051] Among them, the m3u8 video stream has three video stream segments corresponding to the secondary segment information. According to "EXTINF:10.000000", it can be known that the segment duration of each video stream segment is 10s. Video stream segment 1 (H1s1.ts) will be downloaded and played, and video stream segment 2 (H1s2.ts) and video stream segment 3 (H1s3.ts) will be cached. In addition, the parsed code does not contain "EXT-X-ENDLIST", so it can be determined that the type of the target HLS video stream is a LIVE video stream.
[0052] When the last video stream segment 3 starts to be cached, if the thread of video stream segment 1 is idle, then the new secondary segment information can be immediately updated and downloaded from the server to ensure the latest LIVE live stream.
[0053] In a possible implementation, after determining that the target processing flow of any secondary fragment information is the overall download flow, the local proxy module may be used to overall download the video stream fragment corresponding to any secondary fragment information once according to the overall download flow.
[0054] Then, since the segment information of the VOD video stream is fixed, it is usually not necessary to regularly update the secondary segment information, and the secondary segment information update will only appear when there is an adaptive option or a specific resolution option in the user interface setting options, otherwise there is no need to download any secondary segment information. Therefore, after the video stream segment corresponding to any secondary segment information is updated in real time, it can also be determined whether there is an adaptive option or a specific resolution option in the user interface.
[0055] If it is determined that there are adaptive options or specific resolution options in the user interface, any secondary fragment information can be downloaded and updated according to the address list in the primary fragment information to obtain new secondary fragment information under the current bandwidth bit rate. At the same time, when the thread is idle and available, the video stream fragment with fragment number T that has been downloaded by the local proxy module before switching the bit rate is replaced with the video stream fragment with fragment number T+1 downloaded by the new secondary fragment information after switching the bit rate, so as to ensure seamless connection of the video bit rate switching cache video time and video continuity.
[0056] For ease of understanding, the following is a detailed introduction using m3u8 video stream as an example. Figure 5 , which is a schematic diagram of the VOD video stream processing process provided in an embodiment of the present application.
[0057] Among them, since the code ends with H1s100.ts, it can be seen that the m3u8 video stream has a total of 100 video stream segments corresponding to the secondary segment information, and according to "EXTINF:10.000000", it can be known that the segment length of each video stream segment is 10s, and video stream segment 1 (H1s1.ts) will be downloaded and played, and video stream segment 2 (H1s2.ts) to video stream segment 100 (H1s100.ts) will be cached. In addition, since the code is parsed to have "EXT-X-ENDLIST", it can be determined that the type of the target HLS video stream is a VOD video stream.
[0058] In a possible implementation, in an embodiment of the present application, in order to improve the user experience, when performing multi-threaded fragment downloading in turn, the main thread can be set as a high-priority thread and the secondary thread can be set as a low-priority thread. Furthermore, when performing multi-threaded fragment downloading and caching in turn for the video stream fragments corresponding to multiple secondary fragment information, first, a local proxy module can be used to perform main thread download and cache for the first video stream fragment among the video stream fragments corresponding to the multiple secondary fragment information, and at the same time, multiple secondary threads download and cache for the remaining video stream fragments; then, after the first video stream fragment is played, the main thread can be set to a low priority, giving up the priority authority to the fragment thread being read by the terminal player, and re-downloading and caching the next video stream fragment that has not been downloaded; finally, for any secondary thread, when any video stream fragment cached by any secondary thread starts to play, any secondary thread can be set to a high priority.
[0059] Specifically, the multithreading can be set to 3 threads (1 main thread, 2 secondary threads). The main thread is a high-priority thread and can be executed first during CPU scheduling; the secondary thread is a low-priority thread (the secondary thread is a buffer thread, which pre-buffers and downloads the next or next few video stream segments to be played until the buffer center is full). When downloading the secondary segment information, the first secondary segment information can be handed over to the main thread for download to ensure that the first video stream segment to be played is downloaded first; other video stream segments are downloaded through the secondary thread and saved to the buffer center after downloading. When the terminal player starts to read any video stream segment for playback, the thread corresponding to any video stream segment can be reset to a high-priority thread to ensure that the high-priority thread can obtain more CPU scheduling resources, thereby ensuring that the video stream segment being played is buffered and played smoothly.
[0060] like Figure 6 As shown, it is a schematic diagram of multi-threaded slice downloading in turn provided by an embodiment of the present application. The main thread downloads the video stream slice 1 being played, and at the same time, the secondary thread respectively pre-buffers the video stream slice 2 and the video stream slice 3 to the buffer center 2 and the buffer center 3 in turn, until the buffer center is full and the buffering is stopped. When the video stream slice 1 downloaded by the main thread is played, the main thread can be set to a low priority, and the video stream slice 4 is downloaded and pre-buffered in turn. At the same time, the secondary thread 2 is set to a high priority, and the terminal player reads the playback data from the buffer center 2, and so on.
[0061] In a possible implementation, the buffer center can be responsible for caching, reading, and writing operations of the segmented data. When a video stream segment is downloaded, the acquired data is stored in the buffer center, which can be a ring buffer center. The ring buffer center is a first-in-first-out closed-loop storage space. It plans a continuous and equally divided ring memory in the memory, and then reads and writes the data in the buffer center through the write pointer and the read pointer respectively. The specific scenarios are as follows: When video stream segment 1 is downloaded and written to buffer center 1, the terminal player reads the data of buffer center 1, forming a production consumer model until the download and playback of video stream segment 1 is completed.
[0062] While video stream segment 1 is being downloaded and played, video stream segment 2 is also being downloaded, and the requested stream data is written into buffer center 2. When buffer center 2 is full, writing stops. At this time, after waiting for video stream segment 1 to be played, the data of video stream segment 2 is read and played, and video stream segment 2 continues to be downloaded. The same goes for video stream segment 3, video stream segment 4, and so on.
[0063] Furthermore, since video stream fragment 2 has already buffered some data when playing video stream fragment 1, if network fluctuations occur occasionally during the playback of video stream fragment 2, not only data can be buffered, but also smooth playback can be performed. And since network fluctuations are generally short-lived, downloading and playback can be continued after the network is restored, so the smoothness of playback can be maximized.
[0064] Furthermore, compared to the traditional single-thread single-segment downloading method (the single thread will first obtain video stream segment 1, and after video stream segment 1 is played, it will then obtain video stream segment 2, play video stream segment 2, and so on), this application can download segments in multiple threads according to network speed for caching. Furthermore, if network fluctuations occur, it can better ensure the smoothness of HLS video stream playback, minimize buffering times, and ensure user experience.
[0065] In summary, in the embodiment of the present application, since the local proxy module is directly used to realize the download and cache of the HLS video stream, there is no need to modify the original terminal player in the scenario of occasional network fluctuations, which can maximize the compatibility of the terminal player's playback logic and reduce the playback cost. In addition, since multi-threaded sharding is used to download and cache in turn, the playback of the HLS video stream can be less affected by network fluctuations, which can better ensure the smoothness of the HLS video stream playback, minimize the number of buffering times, and ensure the user experience.
[0066] Based on the same inventive concept, the present application embodiment provides an HLS video stream playback device 70, such as Figure 7 As shown, the HLS video stream playback device 70 includes: The media playback request sending unit 701 is used to use the terminal player to send a media playback request to the server through the local proxy module; wherein the media playback request is used to request playback media description information of the target HLS video stream; The media playback request response unit 702 is used to respond to the media playback request and use the server to return the first-level fragment information of the target HLS video stream to the local proxy module; wherein the first-level fragment information includes multiple second-level fragment information; The video stream segment downloading unit 703 is used to use a local proxy module to perform multi-threaded segment downloading and caching on multiple secondary segment information in turn to obtain multiple video stream segments; wherein the thread includes a main thread and multiple secondary threads; The video stream segment playing unit 704 is used to play multiple video stream segments using a terminal player.
[0067] Optionally, the video stream segment downloading unit 703 is further used for: A local proxy module is used to process the primary shard information and determine the user bandwidth; According to the user bandwidth, multiple secondary fragment information contained in the primary fragment information is downloaded to obtain multiple secondary fragment information; A local proxy module is used to perform multi-threaded segment downloading and caching in turn for the video stream segments corresponding to the multiple secondary segment information, so as to obtain multiple video stream segments.
[0068] Optionally, the video stream segment downloading unit 703 is further used for: Using a local proxy module, determine the type of the target HLS video stream; wherein the type includes LIVE video stream and VOD video stream; For any secondary fragment information, determine the target processing flow of any secondary fragment information according to the type of the target HLS video stream; wherein the target processing flow includes a dynamic download flow and an overall download flow; According to the target processing flow, any secondary fragment information is downloaded, cached and played.
[0069] Optionally, the video stream segment downloading unit 703 is further used for: If it is determined that the type of the target HLS video stream is a LIVE video stream, then the target processing flow of any secondary fragment information is determined to be a dynamic download flow; If it is determined that the type of the target HLS video stream is a VOD video stream, then the target processing flow of any secondary fragment information is determined to be the overall download flow.
[0070] Optionally, the video stream segment downloading unit 703 is further used for: According to the dynamic download process, the local proxy module is used to update the video stream segment corresponding to any secondary segment information in real time; Determine if there is an adaptive option or an active resolution switching option in the user interface; If it is determined that there is an adaptive option or an active resolution switching option in the user interface, any secondary shard information is downloaded and updated according to the address list in the primary shard information.
[0071] Optionally, the video stream segment downloading unit 703 is further used for: According to the overall download process, a local proxy module is used to download the video stream segment corresponding to any secondary segment information once; Determine if there is an adaptive option or a specific resolution option in the user interface; If it is determined that there is an adaptive option or an active resolution switching option in the user interface, any secondary shard information is downloaded and updated according to the address list in the primary shard information.
[0072] Optionally, the video stream segment downloading unit 703 is further used for: A local proxy module is used to perform main thread download and cache for the first video stream segment among the video stream segments corresponding to the multiple secondary segment information, and multiple secondary threads are used to download and cache for the remaining video stream segments; When the first video stream segment is played, the main thread is set to low priority, and the next undownloaded video stream segment is downloaded and cached again; For any secondary thread, when a video stream segment cached by any secondary thread starts to play, any secondary thread is set to a high priority.
[0073] The HLS video stream playback device 70 can be used to perform Figure 2-Figure 6 The method implemented in the embodiment shown in FIG. 1 is a method implemented in the embodiment shown in FIG. 1 . Therefore, for the functions that can be implemented by each functional module of the HLS video stream playback device 70, reference can be made to FIG. Figure 2-Figure 6 The description of the illustrated embodiment is not repeated in detail.
[0074] In some possible implementations, various aspects of the method provided in the present application may also be implemented in the form of a program part, which includes a program code. When the program part is run on a computer device, the program code is used to enable the computer device to execute the steps of the method according to various exemplary embodiments of the present application described above in this specification. For example, the computer device may execute the following steps: Figure 2-Figure 6 The method performed in the illustrated embodiment.
[0075] Those skilled in the art can understand that all or part of the steps of the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above method embodiment are executed; and the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks or optical disks. Alternatively, if the above integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent part, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or in other words, the part that contributes to the prior art can be embodied in the form of a software part, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in various embodiments of the present invention. And the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0076] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0077] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for playing an HLS video stream, characterized in that: The method comprises: The terminal player sends a media playback request to the server through the local proxy module; wherein the media playback request is used to request playback media description information of the target HLS video stream; In response to the media playback request, the server returns the first-level fragment information of the target HLS video stream to the local proxy module; wherein the first-level fragment information includes a plurality of second-level fragment information; The local proxy module is used to perform multi-threaded segmentation downloading and caching of the plurality of secondary segmentation information in turn, so as to obtain a plurality of video stream segments; wherein the threads include a main thread and a plurality of secondary threads; The terminal player is used to play the multiple video stream segments.
2. The method according to claim 1, characterized in that The step of using the local proxy module to perform multi-threaded segment downloading and caching on the multiple secondary segment information in turn to obtain multiple video stream segments includes: Using the local proxy module, processing the primary sharding information to determine the user bandwidth; According to the user bandwidth, downloading the multiple secondary fragment information included in the primary fragment information to obtain the multiple secondary fragment information; The local proxy module is used to perform multi-threaded segment downloading and caching in turn on the video stream segments corresponding to the plurality of secondary segment information, so as to obtain a plurality of video stream segments.
3. The method according to claim 2, characterized in that The step of using the local proxy module to perform multi-threaded segment downloading and caching in turn on the video stream segments corresponding to the plurality of secondary segment information to obtain the plurality of video stream segments comprises: Using the local proxy module, determine the type of the target HLS video stream; wherein the type includes a LIVE video stream and a VOD video stream; For any secondary fragment information, determine the target processing flow of any secondary fragment information according to the type of the target HLS video stream; wherein the target processing flow includes a dynamic download flow and an overall download flow; According to the target processing flow, any of the secondary fragment information is downloaded, cached and played.
4. The method according to claim 3, characterized in that The step of determining the target processing flow of any one of the secondary fragment information according to the type of the target HLS video stream comprises: If it is determined that the type of the target HLS video stream is a LIVE video stream, then determining that the target processing flow of any secondary fragment information is a dynamic download flow; If it is determined that the type of the target HLS video stream is a VOD video stream, then the target processing flow of any secondary fragment information is determined to be an overall download flow.
5. The method according to claim 4, characterized in that The step of downloading, caching and playing any one of the secondary fragment information according to the target processing flow includes: According to the dynamic download process, the local proxy module is used to update the video stream segment corresponding to any secondary segment information in real time; Determine if there is an adaptive option or an active resolution switching option in the user interface; If it is determined that there is an adaptive option or an active resolution switching option in the user interface, any one of the secondary sharding information is downloaded and updated according to the address list in the primary sharding information.
6. The method according to claim 4, characterized in that The step of downloading, caching and playing any one of the secondary fragment information according to the target processing flow includes: According to the overall download process, the local proxy module is used to overall download the video stream fragment corresponding to any secondary fragment information once; Determine if there is an adaptive option or a specific resolution option in the user interface; If it is determined that there is an adaptive option or an active resolution switching option in the user interface, any one of the secondary sharding information is downloaded and updated according to the address list in the primary sharding information.
7. The method according to claim 2, characterized in that The main thread is a high priority thread, the secondary thread is a low priority thread, and the local proxy module is used to perform multi-threaded segmentation and take turns downloading and caching the video stream segments corresponding to the plurality of secondary segmentation information to obtain the plurality of video stream segments, including: Using the local proxy module, the first video stream fragment among the video stream fragments corresponding to the plurality of secondary fragment information is downloaded and cached by a main thread, and the remaining video stream fragments are downloaded and cached by multiple secondary threads; After the first video stream segment is played, the main thread is set to a low priority, and the next video stream segment that has not been downloaded is downloaded and cached again; For any secondary thread, when the video stream segment cached by any secondary thread starts to play, the priority of any secondary thread is set to be high.
8. An HLS video stream playback device, characterized in that: The device comprises: A media playback request sending unit, used to use a terminal player to send a media playback request to a server through a local proxy module; wherein the media playback request is used to request playback media description information of a target HLS video stream; A media playback request response unit, configured to respond to the media playback request and use the server to return the primary fragment information of the target HLS video stream to the local proxy module; wherein the primary fragment information includes a plurality of secondary fragment information; The video stream fragment downloading unit is used to use the local proxy module to perform multi-threaded fragment downloading and caching on the multiple secondary fragment information in turn to obtain multiple video stream fragments; wherein the thread includes a main thread and multiple secondary threads; The video stream segment playing unit is used to play the multiple video stream segments using the terminal player.
9. An electronic device, characterized in that: The device comprises: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute any method according to claims 1-7 according to the obtained program instructions.
10. A storage medium, characterized in that: The storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute any one of the methods of claims 1-7.
Citation Information
Patent Citations
Play start speed improving method, video player and electronic device
CN105898535A
Method for implementing network acceleration
CN107484040A
Video resolution switching method and device, equipment and storage medium
CN113438513A
Intelligent mobile terminal in mobile network environment and multimedia stream processing method thereof
CN116346785A
