CN108600368B - HLS network video downloading optimization method and device - Google Patents

HLS network video downloading optimization method and device Download PDF

Info

Publication number
CN108600368B
CN108600368B CN201810377996.6A CN201810377996A CN108600368B CN 108600368 B CN108600368 B CN 108600368B CN 201810377996 A CN201810377996 A CN 201810377996A CN 108600368 B CN108600368 B CN 108600368B
Authority
CN
China
Prior art keywords
downloading
segment
download
progress
current
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810377996.6A
Other languages
Chinese (zh)
Other versions
CN108600368A (en
Inventor
魏勇邦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hisense Visual Technology Co Ltd
Original Assignee
Hisense Visual Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hisense Visual Technology Co Ltd filed Critical Hisense Visual Technology Co Ltd
Priority to CN201810377996.6A priority Critical patent/CN108600368B/en
Publication of CN108600368A publication Critical patent/CN108600368A/en
Application granted granted Critical
Publication of CN108600368B publication Critical patent/CN108600368B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/06Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/83Generation or processing of protective or descriptive data associated with content; Content structuring
    • H04N21/845Structuring of content, e.g. decomposing content into time segments
    • H04N21/8456Structuring of content, e.g. decomposing content into time segments by decomposing the content in the time domain, e.g. in time segments

Landscapes

  • Engineering & Computer Science (AREA)
  • Signal Processing (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Multimedia (AREA)
  • Information Transfer Between Computers (AREA)
  • Two-Way Televisions, Distribution Of Moving Picture Or The Like (AREA)

Abstract

The application discloses a method and a device for optimizing HLS network video downloading, wherein the method comprises the following steps: acquiring and analyzing an m3u8 file of a video to be played to obtain a ts fragment in the m3u8 file; starting a plurality of threads to download the ts segments, and judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions or not; if yes, adopting multithreading to download the ts segments corresponding to each thread concurrently, judging whether the subsequent ts segments still accord with the concurrent downloading condition according to the playing progress and the downloading progress, and carrying out single-thread or multithreading downloading according to the judgment result; if not, the current ts segment is downloaded by adopting the single thread, whether the subsequent ts segment meets the concurrent downloading condition or not is judged according to the playing progress and the downloading progress, and the single thread or multi-thread downloading is carried out according to the judgment result. The download optimization method flexibly selects the multithreading or single-thread download data according to the play progress and the download progress, and reduces the situations of network bandwidth waste and play jam.

Description

HLS network video downloading optimization method and device
Technical Field
The application relates to the technical field of network video downloading, in particular to an optimization method and device for HLS network video downloading.
Background
The HLS (HTTP Live Streaming) Protocol is a Streaming media transmission interactive Protocol based on HTTP (HyperText Transfer Protocol) defined by Apple, and generally downloads an m3u8 file when playing HLS film sources, then parses the HLS file to obtain all ts segments from the m3u8 file, arranges all ts segments according to a playing sequence, and then sequentially downloads and plays the ts segments by a player.
Currently, there are two methods for downloading ts fragments: one is to download ts segments in a single-thread sequence, and start a thread to download ts segments one by one when a video is played, as shown in fig. 3, a certain HLS network video includes x ts segments, each ts segment is used as a download task, and one download task needs to go through three stages: creating http connection, downloading data, disconnecting the http connection, downloading ts segments one by one according to a playing sequence, and playing the downloaded ts segments according to the playing sequence; the other is to download ts segments by multiple threads, taking 2 threads as an example, when a video is played, 2 threads are started, one thread downloads one ts segment, for example, thread 1 downloads the first segment (1-1.ts segment), thread 2 downloads the second segment (1-2.ts segment), and two ts segments are downloaded in parallel according to the sequence of the playlist.
However, when the ts segments are downloaded by a single thread, due to factors such as a three-way handshake mechanism of a TCP protocol, network delay, a slow start and congestion control mechanism of the TCP protocol, the data transmission amount during the switching of two adjacent ts segments is very small, which causes the waste of network bandwidth; when the single-thread downloading is changed into the multi-thread downloading of the ts segments, although the overall downloading speed can be improved by downloading the multiple segments simultaneously, the 1-2.ts segments occupy the network bandwidth of the 1-1.ts segments, so that the downloading speed of the 1-1.ts segments is easily reduced, and the situations that the downloading speed is lower than the playing speed are easily caused, and the slow playing start and the pause playing are caused.
Disclosure of Invention
The application provides an HLS network video downloading optimization method and device, and aims to solve the technical problems that network bandwidth is wasted, playing is slow and playing is unsmooth easily caused by downloading of video segments of the HLS network video at present.
In order to solve the technical problem, the embodiment of the application discloses the following technical scheme:
in a first aspect, an embodiment of the present application discloses an HLS network video download optimization method, including:
acquiring and analyzing an m3u8 file of a video to be played to obtain all ts segments contained in the m3u8 file;
starting a plurality of threads to download the ts segments, and judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions or not;
if yes, adopting multithreading to download the ts segments corresponding to each thread concurrently, judging whether the subsequent ts segments still accord with the concurrent downloading condition according to the playing progress and the downloading progress, and carrying out single-thread or multithreading downloading according to the judgment result;
if not, the current ts segment is downloaded by adopting the single thread, whether the subsequent ts segment meets the concurrent downloading condition or not is judged according to the playing progress and the downloading progress, and the single thread or multi-thread downloading is carried out according to the judgment result.
In a second aspect, an embodiment of the present application discloses an HLS network video downloading optimization apparatus, including:
the acquisition module is used for acquiring and analyzing an m3u8 file of a video to be played to obtain all ts segments contained in the m3u8 file;
the judging module is used for judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions or not;
the multithreading downloading module is used for downloading the ts fragments corresponding to each thread in a multithreading concurrent manner when the ts fragments needing to be downloaded currently meet concurrent downloading conditions, judging whether the subsequent ts fragments still meet the concurrent downloading conditions or not according to the playing progress and the downloading progress, and downloading in a single thread or a multithreading manner according to the judgment result;
and the single-thread downloading module is used for downloading the current ts fragment by adopting the single thread when the ts fragment needing to be downloaded does not accord with the concurrent downloading condition currently, judging whether the subsequent ts fragment accords with the concurrent downloading condition or not according to the playing progress and the downloading progress, and downloading the single thread or the multiple threads according to the judgment result.
Compared with the prior art, the beneficial effect of this application is:
the embodiment of the application provides an HLS network video downloading optimization method and device, and the downloading optimization method comprises the following steps: acquiring and analyzing an m3u8 file of a video to be played to obtain all ts segments contained in the m3u8 file; starting a plurality of threads to download the ts segments, and judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions or not; if yes, adopting multithreading to download the ts segments corresponding to each thread concurrently, judging whether the subsequent ts segments still accord with the concurrent downloading condition according to the playing progress and the downloading progress, and carrying out single-thread or multithreading downloading according to the judgment result; if not, the current ts segment is downloaded by adopting the single thread, whether the subsequent ts segment meets the concurrent downloading condition or not is judged according to the playing progress and the downloading progress, and the single thread or multi-thread downloading is carried out according to the judgment result. According to the HLS network video downloading optimization method, multithreading or single-thread downloading data can be dynamically adopted according to the playing progress and the downloading progress, the network bandwidth is fully utilized, and multithreading concurrent downloading of ts segments is adopted if concurrent downloading conditions are met in the ts segment downloading process, so that the downloading speed can be increased, and the influence of network downloading speed fluctuation is reduced; if the concurrent downloading condition is not met, single-thread downloading is adopted, the data which is needed most urgently can be downloaded preferentially, and the blocking condition in the video playing process is reduced.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
In order to more clearly explain the technical solution of the present application, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious to those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a diagram illustrating network latency in downloading a ts fragment with a single thread;
FIG. 2 is a schematic diagram illustrating a congestion control mechanism in a single-threaded ts segment downloading process in the prior art;
FIG. 3 is a diagram illustrating a conventional single-threaded ts segment download process;
fig. 4 is a flowchart of a method for optimizing HLS network video downloading according to an embodiment of the present disclosure;
fig. 5 is a detailed flowchart of S300 in a method for optimizing video downloading over an HLS network according to an embodiment of the present application;
fig. 6 is a schematic diagram of a playing progress and a downloading progress provided in the embodiment of the present application;
fig. 7 is a schematic structural diagram of an HLS network video download optimization apparatus according to an embodiment of the present application.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
HLS (HTTP Live Streaming) is a Streaming media protocol defined by Apple, and generally, when playing HLS film source, an m3u8 file is downloaded first, then all ts segments in the m3u8 file are obtained by parsing, a playlist is composed of the ts segments, and then the ts segments are downloaded and played by the player. The M3u8 file is typically as follows, "# extinn: the value following "is the play duration of the corresponding ts segment.
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXTINF:10
1-1.ts
#EXTINF:11
1-2.ts
#EXTINF:9
1-3.ts
#EXTINF:11
1-4.ts
#EXTINF:11
1-5.ts
#EXT-X-ENDLIST
The current data download schemes mainly have two types:
the first scheme is as follows: the ts segments are downloaded in a single threaded order, with each ts segment being downloaded sequentially as follows.
Downloading ts segment _0 Downloading ts segment _1 Downloading ts segment _ last
Each ts segment is downloaded as a download task, which goes through three phases: creating http connection, downloading data and disconnecting the http connection. Creating an http connection, because of a three-way handshake mechanism based on a TCP protocol and a factor of adding network delay, may cause a certain time consumption at this stage, as shown in fig. 1, taking a network delay of 28ms as an example, creating an http connection takes 84ms, because the amount of data transmission during this period is very small and can be almost ignored, the download speed in this 84ms is equivalent to 0, which causes bandwidth waste.
In addition, during data downloading, due to the slow start and congestion control mechanism of the TCP protocol, a certain time consumption is required for the downloading speed to reach a higher value, as shown in fig. 2, the amount of data sent by the server to the client at the first time is gradually increased, and when data is lost, the amount of data sent at the first time is decreased.
Thus, for the above two stages of problems, the whole network video downloading process is as shown in fig. 3, there will be a complete bandwidth waste from t1 to t2 and a partial bandwidth waste from t2 to t3 during the two segment switching process, and there will be several such processes in the whole data downloading process.
Scheme II: simply downloading ts fragments using multiple threads. Taking 2 threads as an example, the scheme is such that when a video is played, i.e. 2 threads are started, one thread downloads one ts segment, taking m3u8 as an example, thread 1 downloads 1-1.ts segment, and thread 2 downloads 1-2.ts segment, however, such a scheme has a problem: although downloading 2 segments simultaneously increases the overall download speed, the download speed of the first segment 1-1.ts segment is reduced due to the network bandwidth being overwhelmed by the download of the second segment 1-2. ts. Therefore, for the player, the ts segments are played in sequence, and when 1-1.ts is played, the downloading module downloads 1-1.ts and 1-2.ts simultaneously, which is likely to cause the situation that the downloading speed is lower than the playing speed, resulting in slow start and pause playing.
In order to overcome the problems, the HLS network video downloading optimization method can dynamically download data in a multi-thread mode or a single thread mode according to the HLS video playing progress and the downloading progress, and adopts multi-thread concurrent downloading under the condition that the conditions allow, so that the downloading speed can be increased, and the influence of network downloading speed fluctuation is reduced; and single-thread downloading is adopted under the condition that the conditions are not allowed, so that the data which is needed most urgently can be downloaded preferentially, and the jamming is reduced.
As shown in fig. 4, a method for optimizing HLS network video downloading provided in an embodiment of the present application includes:
s100: and acquiring and analyzing the m3u8 file of the video to be played to obtain all ts fragments contained in the m3u8 file.
And acquiring an m3u8 file of the video to be played, analyzing the m3u8 file to obtain all ts fragments contained in the file, and forming a ts fragment list by the ts fragments according to the playing sequence.
S200: and starting a plurality of threads to download the ts segments, and judging whether the ts segments needing to be downloaded currently meet the concurrent downloading condition.
When the video is played, two threads are started, the 2 threads respectively create http connection for the first segment0 and the second segment1, and respectively obtain the size0 bytes and the size1 bytes of the two segments, then the segment0 is downloaded, and simultaneously the overall downloading speed is recorded as speed bps, and the second segment1 is in a state of connection but data is not downloaded. When the first segment0 is downloaded, the second segment1 is immediately put into the download state, and an http connection is created to the third segment2, so as to obtain the size2 bytes of the third segment 2. When the second segment1 is downloaded, it is determined whether the third segment2 meets the concurrent download condition.
S300: if yes, adopting multithreading to download the ts segments corresponding to each thread concurrently, judging whether the subsequent ts segments still accord with the concurrent downloading condition according to the playing progress and the downloading progress, and carrying out single-thread or multithreading downloading according to the judgment result.
When the ts segments needing to be downloaded currently meet the concurrent downloading condition, a plurality of threads are adopted to download the ts segments needing to be downloaded currently, after a certain time, whether the subsequent ts segments of the currently downloaded ts segments still meet the concurrent downloading condition is judged, and if yes, the currently downloaded ts segments and the subsequent ts segments are downloaded concurrently; and if not, the single thread downloads the ts segment currently downloaded. The specific steps are shown in fig. 5.
S301: when the ts segments needing to be downloaded currently meet the concurrent downloading condition, a plurality of threads concurrently download the ts segments corresponding to each thread;
and when the ts segments meet the concurrent downloading condition, the multiple threads download the ts segments corresponding to each thread concurrently, and arrange the downloaded ts segments into a table according to the downloading sequence.
S302: and playing the downloaded ts segments according to the downloading sequence, and acquiring the current playing progress from the player.
The downloading sequence of the Ts segments is downloading according to the playing sequence, after one Ts segment is downloaded, the Ts segment can be played, and the current playing progress can be obtained from the player and set as the position.
S303: and calculating the downloading progress according to the downloaded ts fragments.
Assuming that the downloading of segment X is being executed, segment X has downloaded downloadedX byte data, the size byte of segment X is sizeX, and in addition, after the m3u8 file is analyzed, the playing time duration corresponding to each ts segment can be obtained, so that the progress of the current downloading can be calculated according to the following formula.
Progress=duration0+duration1+…+duration(X-1)+durationX*(downloadedX/sizeX)
S304: and calculating to obtain the downloading time dt of the residual data of the current downloading segment X according to the bytes of the current downloading segment X, the downloaded bytes and the downloading speed.
After obtaining the current playing progress position and the downloading progress, as shown in fig. 6, if two segments, segment X and segment (X +1), are downloaded concurrently, after a certain time, it is determined whether the two segments still meet the concurrent downloading condition, and the method thereof is as follows:
if the data download of segment (X +1) is not stopped, the download speed of segment X will be halved to speed/2, in this case,
segment x remaining data download time dt ═ 2 × (sizeX-downloaded x)/speed.
S305: and calculating to obtain the playing time dd of the residual data of the current download segment X according to the time length of the current download segment X and the time length of the downloaded data.
And calculating the playing time length of the segment residual data of the segment X according to the playing time length of the segment X currently downloaded and the downloaded data downloadedX.
The play duration dd of the segment x remaining data is duration x-duration x (downloadedX/sizeX).
S306: and judging whether the difference between the downloading progress and the current playing progress is larger than the difference between the downloading time dt of the residual data of the current downloading segment X and the playing time dd of the residual data.
Comparing the calculated download time dt of the residual data of the currently downloaded segment segmentX and the play time dd of the residual data with the current play progress position and the download progress, and if it is ensured that the segment (X +1) does not influence the download of the segment segmentX, the situation of playing card pause cannot occur, the progress-position + dd & gt dt, namely the progress-position & gt-dd, must be enabled. If the condition is satisfied, go to step S307; otherwise, step S308 is executed.
S307: if yes, continuing to download the current download segment X and the next segment (X +1) in parallel.
When progress-position > dt-dd, it indicates that the downloading of the next segment (X +1) does not affect the playing, and the currently downloaded segment X and the next segment (X +1) satisfy the concurrent downloading condition, and the currently downloaded segment X and the next segment (X +1) can be downloaded in parallel.
S308: if not, continuing to download the current download segment X and suspending downloading the next segment (X + 1).
When progress-position is less than or equal to dt-dd, it indicates that the downloading of the next segment (X +1) will slow down the downloading speed of the currently downloaded segment X, and when the remaining data of the segment X is played, the remaining data of the segment X is still not downloaded, which will cause the playing to be paused and affect the viewing effect. When the situation occurs, the segment X currently downloaded is continuously downloaded, the data downloading of the segment (X +1) is suspended, the segment (X +1) is in the state of http connection and suspension, and the segment (X +1) is downloaded after the segment X segment is downloaded. Meanwhile, segment (X +2) is judged, whether the segment meets the concurrent downloading condition is judged, single-thread or multi-thread downloading is adopted according to the judgment result until all ts segments of the played video are completely downloaded
S400: if not, the current ts segment is downloaded by adopting the single thread, whether the subsequent ts segment meets the concurrent downloading condition or not is judged according to the playing progress and the downloading progress, and the single thread or multi-thread downloading is carried out according to the judgment result.
When the ts segments needing to be downloaded currently do not accord with the concurrent downloading condition, the current ts segments are downloaded by adopting a single thread, after a certain time, whether the subsequent ts segments of the current ts segments accord with the concurrent downloading condition or not is judged, and if so, the current ts segments and the subsequent ts segments are downloaded concurrently; if not, the ts fragment is continuously downloaded by adopting the single thread. The method comprises the following specific steps:
s401: and when the ts segments needing to be downloaded currently do not accord with the concurrent downloading condition, adopting a single thread to download the ts segments one by one according to the playing sequence.
And when the ts fragments do not accord with the concurrent downloading condition, adopting a single thread to download the ts fragments one by one, and arranging the downloaded ts fragments into a table according to the downloading sequence.
S402: and playing the downloaded ts segments according to the downloading sequence, and acquiring the current playing progress from the player.
The downloading sequence of the Ts segments is downloaded according to the playing sequence, after one Ts segment is downloaded, the Ts segment can be played, and the current playing progress can be obtained from the player and set as the position.
S403: and calculating the downloading progress according to the downloaded ts fragments.
Assuming that the downloading of segment X is being executed, segment X has downloaded downloadedX byte data, the size byte of segment X is sizeX, and in addition, after the m3u8 file is analyzed, the playing time duration corresponding to each ts segment can be obtained, so that the progress of the current downloading can be calculated according to the following formula.
Progress=duration0+duration1+…+duration(X-1)+durationX(downloadedX/sizeX)
S404: and calculating to obtain the downloading time dt of the residual data of the current downloading segment X according to the bytes of the current downloading segment X, the downloaded bytes and the downloading speed.
After obtaining the current playing progress position and downloading progress, if the next segment (X +1) is in a connected and suspended state, judging whether the segment (X +1) meets the concurrent downloading condition, wherein the method comprises the following steps:
if segment (X +1) initiates data download, the download speed of segment X is halved to speed/2, in which case the download time dt of the remaining segment X data is 2X (sizeX-downloadedX)/speed.
S405: and calculating to obtain the playing time dd of the residual data of the current download segment X according to the time length of the current download segment X and the time length of the downloaded data.
And calculating the playing time length of the segment X residual data according to the playing time length of the segment X currently downloaded and the downloaded data downloadedX.
The play duration dd of the segment x remaining data is duration x-duration x (downloadedX/sizeX).
S406: and judging whether the difference value between the downloading progress and the current playing progress and the calculated error value is larger than the difference value between the downloading time dt of the residual data of the current downloading segment X and the playing time dd of the residual data.
Comparing the calculated download time dt of the remaining data of the current download segment X and the play time dd of the remaining data with the current play progress position and the download progress, if it is ensured that the segment (X +1) is downloaded concurrently and the play card pause cannot occur, the progress-position + dd > dt, that is, the progress-position > dt-dd, is required to be ensured, a constant T (T > 0) is set in consideration of the calculation error caused by network speed fluctuation and uneven code rate, and the result is adjusted to the progress-position > dt-dd + T. If the condition is satisfied, go to step S407; if not, go to step S408.
S407: if yes, the current download segment X and the next segment (X +1) are downloaded in parallel.
When progress-position > dt-dd + T, it indicates that the situation of playing card pause does not occur in the parallel downloading of the next segment (X +1), and the currently downloaded segment X and the next segment (X +1) meet the concurrent downloading condition, and the currently downloaded segment X and the next segment (X +1) can be downloaded in parallel.
S408: if not, the current downloading fragment X is continuously downloaded by the single thread.
When progress-position is less than or equal to dt-dd + T, it indicates that the downloading of the next segment (X +1) will cause the occurrence of playing pause, and affect the viewing effect. When the situation occurs, the current segment segmentX is continuously downloaded by the single thread, and after the segment segmentX segment is downloaded completely or for a certain time, whether the subsequent segments meet the concurrent downloading condition is continuously judged, and the single-thread or multi-thread downloading is adopted according to the judgment result until all ts segments of the played video are downloaded completely.
The HLS network video downloading optimization method provided by the embodiment of the application comprises the following steps: acquiring and analyzing an m3u8 file of a video to be played to obtain all ts segments contained in the m3u8 file; starting a plurality of threads to download the ts segments, and judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions or not; if yes, adopting multithreading to download the ts segments corresponding to each thread concurrently, judging whether the subsequent ts segments still accord with the concurrent downloading condition according to the playing progress and the downloading progress, and carrying out single-thread or multithreading downloading according to the judgment result; if not, the current ts segment is downloaded by adopting the single thread, whether the subsequent ts segment meets the concurrent downloading condition or not is judged according to the playing progress and the downloading progress, and the single thread or multi-thread downloading is carried out according to the judgment result. According to the HLS network video downloading optimization method, multithreading or single-thread downloading data can be dynamically adopted according to the playing progress and the downloading progress, the network bandwidth is fully utilized, and in the ts segment downloading process, if the ts segment meets the concurrent downloading condition, multithreading concurrent downloading of the ts segment is adopted, so that the downloading speed is increased, and the influence of network downloading speed fluctuation is reduced; if the ts fragment does not accord with the concurrent downloading condition, the single-thread downloading is adopted, the data which is needed most urgently is guaranteed to be downloaded preferentially, and the blocking condition in the video playing process is reduced. The download optimization method dynamically selects single-thread download or multi-thread download according to the play progress and the download progress, so that not only is the network bandwidth fully utilized, but also the smoothness of video play is ensured.
Based on the HLS network video downloading optimization method provided by the embodiment of the present application, an HLS network video downloading optimization device is also provided by the embodiment of the present application, as shown in fig. 7.
The HLS network video downloading optimization apparatus provided in the embodiment of the present application includes an obtaining module 100, a determining module 200, a multi-threaded downloading module 300 and a single-threaded downloading module 400, wherein the obtaining module 100 is in signal connection with the determining module 200, the multi-threaded downloading module 300 and the single-threaded downloading module 400 are respectively connected with the determining module 200, wherein,
the obtaining module 100 is configured to obtain and parse an m3u8 file with a playing video, so as to obtain all ts segments included in the m3u8 file.
The judging module 200: and the method is used for judging whether the ts segments needing to be downloaded currently meet the concurrent downloading condition. After the ts segments are obtained, starting a plurality of threads to download the ts segments, when the ts segments are downloaded, firstly judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions, and if yes, selecting the multithreading downloading module 300 to download the ts segments concurrently; if not, the single-thread downloading module 400 is selected to download ts segments one by one.
And the multithreading download module 300 is configured to download the ts segments corresponding to each thread concurrently in multiple threads when the ts segments currently required to be downloaded meet the concurrent download condition, determine whether the subsequent ts segments still meet the concurrent download condition according to the playing progress and the downloading progress, and perform single-thread or multi-thread downloading according to the determination result.
The multithreading download module 300 includes a first progress obtaining module 301, a first calculating module 302, and a first determining module 303, where the first progress obtaining module 301 is configured to obtain a current playing progress from a player. And playing the ts segments downloaded by the multithread downloading module 300 according to the playing sequence, and then acquiring the current playing progress position from the player.
The first calculating module 302 is configured to calculate a download progress according to the downloaded ts segment, and calculate a download progress according to the play duration of the ts segment, where the download progress is 0+ 1+ … + duration (X-1) + duration (downloaddx/sizeX).
The first determining module 303 is configured to determine whether the ts segment currently downloaded and the subsequent ts segment still meet the concurrent downloading condition according to the current playing progress and the downloading progress, and perform single-thread or multi-thread downloading according to the determination result. The first determining module 303 includes a first calculating submodule 3031, a second calculating submodule 3032 and a first determining submodule 3033, wherein,
the first calculating submodule 3031 is configured to calculate, according to the byte of the current download segment X, the downloaded byte, and the download speed, the download time dt of the remaining data of the current download segment X. If the download of segment X is being performed, segment X has downloaded downloadedX byte data, the size byte of segment X is sizeX, and if segment X and segment (X +1) are downloaded concurrently, the remaining data download time dt of segment X is 2 (sizeX-downloadedX)/speed.
The second calculating submodule 3032 is configured to calculate, according to the duration of the current download segment X and the duration of the downloaded data, the play duration dd of the remaining data of the current download segment X. If the download of segment x is being performed, segment x has downloaded downloadedX byte data, the size byte of segment x is sizeX, and the play time length of segment x residual data can be calculated according to the play time length of segment x and the downloaded data downloadedX, where the play time length dd of segment x residual data is duration-duration x (downloadedX/sizeX).
A first determining submodule 3033, configured to determine whether a difference between the download progress and the current play progress is greater than a difference between the download time dt of the remaining data of the current download segment X and the play time dd of the remaining data, and if so, continue to download the current download segment X and a next segment (X +1) in parallel; if not, continuing to download the current download segment, and suspending downloading the next segment (X + 1). Comparing the download time dt of the current download segment X residual data obtained by calculation, the play time dd of the residual data with the current play progress position and the download progress, if it is ensured that segment (X +1) cannot cause play pause, the progress-position dt-dd must be satisfied, if the condition is satisfied, it is indicated that segment (X +1) satisfies the concurrent download condition, and segment X and segment (X +1) can be downloaded in parallel; if the condition is not met, the segment (X +1) does not meet the concurrent downloading condition, and the segment X and the segment (X +1) are downloaded by adopting a single thread.
The single-thread downloading module 400 is configured to, when a ts segment to be currently downloaded does not meet a concurrent downloading condition, download the current ts segment by using a single thread, determine whether a subsequent ts segment meets the concurrent downloading condition according to a playing progress and a downloading progress, and perform single-thread or multi-thread downloading according to a determination result.
The single-thread downloading module 400 includes a second progress obtaining module 401, a second calculating module 402, and a second determining module 403, where the second progress obtaining module 401 is configured to obtain a current playing progress from the player. And playing the ts segments downloaded by the single-thread downloading module 400 according to the playing sequence, and then acquiring the current playing progress position from the player.
A second calculating module 402, configured to calculate a download progress according to the downloaded ts segment, and calculate a download progress according to the play duration of the ts segment, where the download progress is 0+ 1+ … + duration (X-1) + duration (downloaddx/sizeX).
The second determining module 403 is configured to determine whether the ts segment currently downloaded and the subsequent ts segment meet the concurrent downloading condition according to the current playing progress and the downloading progress, and perform single-thread or multi-thread downloading according to the determination result. The second decision module 403 comprises a third calculation sub-module 4031, a fourth calculation sub-module 4032 and a second decision sub-module 4033, wherein,
the third calculation sub-module 4031 is configured to calculate, according to the bytes of the current download segment X, the downloaded bytes, and the download speed, a download time dt for obtaining the remaining data of the current download segment X. If the download of segment X is being performed, segment X has downloaded downloadedX bytes of data, the size byte of segment X is sizeX, and if segment (X +1) initiates the data download, segment X has a remaining data download time dt equal to 2 × (sizeX-downloadedX)/speed.
The fourth calculating sub-module 4032 is configured to calculate, according to the duration of the current download segment X and the duration of the downloaded data, the playing duration dd of the remaining data of the current download segment X. If the download of segment x is being performed, segment x has downloaded downloadedX byte data, the size byte of segment x is sizeX, and the play time length of segment x residual data can be calculated according to the play time length of segment x and the downloaded data downloadedX, where the play time length dd of segment x residual data is duration-duration x (downloadedX/sizeX).
A second determining submodule 4033, configured to determine whether a difference between the download progress, the current play progress, and the calculated error value is greater than a difference between a download time dt of the remaining data of the current download segment X and a play time dd of the remaining data, and if so, download the current download segment X and a next segment (X +1) in parallel; if not, the current downloading segment is continuously downloaded by the single thread. Comparing the download time dt of the current download segment X residual data obtained by calculation, the play time dd of the residual data with the current play progress position and the download progress, if it is ensured that segment (X +1) cannot cause play card pause, the result must meet the progress-position dt-dd, considering the calculation error caused by network speed fluctuation and uneven code rate, setting a constant T (T0), adjusting the constant T to be the progress-position dt-dd + T, and if the result meets the condition, indicating that segment (X +1) meets the concurrent download condition and downloading segment X and segment (X +1) in parallel; if the condition is not met, the segment (X +1) is not met with the concurrent downloading condition, and the single thread is continuously adopted to download the segment X.
It should be noted that, for the specific description of some modules in the HLS network video download optimization apparatus provided in the embodiment of the present application, reference may be made to corresponding contents in the method embodiment, and details are not described here again in this embodiment.
It is noted that, in this specification, relational terms such as "first" and "second," and the like, are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a circuit structure, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such circuit structure, article, or apparatus. Without further limitation, the presence of an element identified by the phrase "comprising an … …" does not exclude the presence of other like elements in a circuit structure, article or device comprising the element.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
The above-described embodiments of the present application do not limit the scope of the present application.

Claims (10)

1. An HLS network video downloading optimization method is characterized by comprising the following steps:
acquiring and analyzing an m3u8 file of a video to be played to obtain all ts segments contained in the m3u8 file;
starting a plurality of threads to download the ts segments, and judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions or not; the concurrent downloading condition is whether the difference value between the downloading progress and the current playing progress is larger than the difference value between the downloading time dt of the residual data of the current downloading ts segment and the playing time dd of the residual data;
if yes, adopting multithreading to download the ts segments corresponding to each thread concurrently, judging whether the subsequent ts segments still accord with the concurrent downloading condition according to the playing progress and the downloading progress, and carrying out single-thread or multithreading downloading according to the judgment result;
if not, the current ts segment is downloaded by adopting a single thread, whether the difference value of the downloading progress, the current playing progress and the calculated error value is larger than the difference value of the residual data downloading time dt and the residual data playing time dd of the current ts segment is judged, and the single thread or multi-thread downloading is carried out according to the judgment result.
2. The method of claim 1, wherein starting a plurality of threads to download ts segments and determining whether ts segments currently needed to be downloaded meet concurrent downloading conditions comprises:
starting two threads when a video is played, wherein the two threads respectively establish http connection for a first ts fragment and a second ts fragment;
downloading the first ts fragment and the second ts fragment through a single thread respectively;
and when the second ts segment is downloaded, creating http connection for a third ts segment, and simultaneously judging whether the third ts segment meets the concurrent downloading condition.
3. The method of claim 1, wherein the multithreading is adopted to download the ts segments corresponding to each thread concurrently, and whether the subsequent ts segments still meet the concurrent downloading condition is judged according to the playing progress and the downloading progress, comprising:
when the ts segments needing to be downloaded currently meet the concurrent downloading condition, a plurality of threads concurrently download the ts segments corresponding to each thread;
playing the downloaded ts segments according to the downloading sequence, and acquiring the current playing progress from the player;
calculating to obtain a downloading progress according to the downloaded ts fragments;
and judging whether the current ts downloading segment and the subsequent ts segment still accord with the concurrent downloading condition according to the downloading progress and the current playing progress, and carrying out single-thread or multi-thread downloading according to the judgment result.
4. The method of claim 3, wherein the step of judging whether the ts segments currently downloaded and the ts segments subsequently downloaded still meet the concurrent downloading condition according to the downloading progress and the current playing progress, and the step of performing single-thread or multi-thread downloading according to the judgment result comprises:
calculating to obtain the download time dt of the residual data of the current download segment X according to the bytes of the current download segment X, the downloaded bytes and the download speed;
calculating to obtain the playing time dd of the residual data of the current download segment X according to the time length of the current download segment X and the time length of the downloaded data;
judging whether the difference value of the downloading progress and the current playing progress is larger than the difference value of the residual data downloading time dt and the residual data playing time dd of the current downloading segment X;
if yes, continuing to download the current download segment X and the next segment (X +1) in parallel;
if not, continuing to download the current download segment X and suspending downloading the next segment (X + 1).
5. The method of claim 1, wherein the current ts segment is downloaded with a single thread, and thereafter comprising:
when the ts segments needing to be downloaded do not conform to concurrent downloading, the ts segments are downloaded one by adopting a single thread according to a playing sequence;
playing the downloaded ts segments according to the downloading sequence, and acquiring the current playing progress from the player;
calculating to obtain a downloading progress according to the downloaded ts fragments;
and judging whether the current ts downloading segment and the subsequent ts segment accord with the parallel downloading condition or not according to the downloading progress and the current playing progress, and carrying out single-thread or multi-thread downloading according to the judgment result.
6. The method of claim 5, wherein the step of judging whether the ts segments currently downloaded and the ts segments subsequently downloaded meet the parallel downloading condition according to the downloading progress and the current playing progress, and the step of performing single-thread or multi-thread downloading according to the judgment result comprises:
calculating to obtain the download time dt of the residual data of the current download segment X according to the bytes of the current download segment X, the downloaded bytes and the download speed;
calculating to obtain the playing time dd of the residual data of the current download segment X according to the time length of the current download segment X and the time length of the downloaded data;
judging whether the difference value between the downloading progress, the current playing progress and the calculated error value is larger than the difference value between the downloading time dt of the residual data of the current downloading segment X and the playing time dd of the residual data;
if yes, downloading the current downloading segment X and the next segment (X +1) in parallel;
if not, the current downloading fragment X is continuously downloaded by the single thread.
7. An HLS network video download optimization apparatus, comprising:
the acquisition module is used for acquiring and analyzing an m3u8 file of a video to be played to obtain all ts segments contained in the m3u8 file;
the judging module is used for judging whether the ts segments needing to be downloaded currently meet concurrent downloading conditions or not; the concurrent downloading condition is whether the difference value between the downloading progress and the current playing progress is larger than the difference value between the downloading time dt of the residual data of the current downloading ts segment and the playing time dd of the residual data;
the multithreading downloading module is used for downloading the ts fragments corresponding to each thread in a multithreading concurrent manner when the ts fragments needing to be downloaded currently meet concurrent downloading conditions, judging whether the subsequent ts fragments still meet the concurrent downloading conditions or not according to the playing progress and the downloading progress, and downloading in a single thread or a multithreading manner according to the judgment result;
and the single-thread downloading module is used for downloading the current ts segment by adopting a single thread when the ts segment needing to be downloaded does not accord with the concurrent downloading condition, judging whether the difference value of the downloading progress, the current playing progress and the calculated error value is larger than the difference value of the residual data downloading time dt and the residual data playing time dd of the current ts segment, and downloading the single thread or the multithreading according to the judgment result.
8. The apparatus of claim 7, wherein the multi-threaded download module comprises:
the first progress acquisition module is used for acquiring the current playing progress from the player;
the first calculation module is used for calculating to obtain a downloading progress according to the downloaded ts fragments;
and the first judgment module is used for judging whether the ts fragments currently downloaded and the subsequent ts fragments still accord with the concurrent downloading condition according to the current playing progress and the downloading progress and carrying out single-thread or multi-thread downloading according to the judgment result.
9. The apparatus of claim 8, wherein the first determining module comprises:
the first calculation submodule is used for calculating and obtaining the download time dt of the residual data of the current download segment X according to the bytes of the current download segment X, the downloaded bytes and the download speed;
the second calculation submodule is used for calculating and obtaining the playing time dd of the residual data of the current download segment X according to the time length of the current download segment X and the time length of the downloaded data;
a first judging submodule, configured to judge whether a difference between the download progress and the current play progress is greater than a difference between a download time dt of remaining data of the current download segment X and a play time dd of the remaining data, and if so, continue to download the current download segment X and a next segment (X +1) in parallel; if not, continuing to download the current download segment, and suspending downloading the next segment (X + 1).
10. The apparatus of claim 7, wherein the single threaded download module comprises:
the second progress acquisition module is used for acquiring the current playing progress from the player;
the second calculation module is used for calculating to obtain a downloading progress according to the downloaded ts fragments;
and the second judgment module is used for judging whether the ts fragments currently downloaded and the subsequent ts fragments accord with concurrent downloading conditions or not according to the current playing progress and the downloading near end, and carrying out single-thread or multi-thread downloading according to a judgment result.
CN201810377996.6A 2018-04-25 2018-04-25 HLS network video downloading optimization method and device Active CN108600368B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810377996.6A CN108600368B (en) 2018-04-25 2018-04-25 HLS network video downloading optimization method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810377996.6A CN108600368B (en) 2018-04-25 2018-04-25 HLS network video downloading optimization method and device

Publications (2)

Publication Number Publication Date
CN108600368A CN108600368A (en) 2018-09-28
CN108600368B true CN108600368B (en) 2021-10-08

Family

ID=63609168

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810377996.6A Active CN108600368B (en) 2018-04-25 2018-04-25 HLS network video downloading optimization method and device

Country Status (1)

Country Link
CN (1) CN108600368B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111277867B (en) * 2020-03-03 2022-02-18 广州市百果园信息技术有限公司 Video downloading method, device, server and storage medium
CN111417031B (en) * 2020-04-28 2022-05-31 北京金山云网络技术有限公司 File transmission method and device and electronic equipment
CN111787105B (en) * 2020-07-01 2023-07-07 深圳市有方科技股份有限公司 File transmission method, device, computer equipment and storage medium
GB2603751A (en) * 2021-01-28 2022-08-17 Openwave Mobility Inc A Method for Determining a Play Duration Estimate of an Adaptive Bit Rate Media Presentation
CN113891170B (en) * 2021-11-23 2024-05-03 维沃移动通信有限公司 Downloading method, downloading device, electronic equipment and storage medium
CN116886940B (en) * 2023-09-07 2023-12-01 园测信息科技股份有限公司 Multipath video reasoning concurrent preprocessing acceleration method, system, medium and equipment

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7383389B1 (en) * 2004-04-28 2008-06-03 Sybase, Inc. Cache management system providing improved page latching methodology
CN101681260B (en) * 2007-06-20 2013-04-17 富士通株式会社 Arithmetic unit
JP5034960B2 (en) * 2008-01-10 2012-09-26 ソニー株式会社 Display generation apparatus, display generation method, program, and content download system
CN102368249B (en) * 2011-09-26 2014-05-14 奇智软件(北京)有限公司 Page downloading control method and system for IE (Internet Explorer) core browser
CN104244083B (en) * 2014-10-08 2019-07-26 联想(北京)有限公司 A kind of method for down loading and electronic equipment of Online Video
CN105025343A (en) * 2015-07-21 2015-11-04 无锡天脉聚源传媒科技有限公司 Caching method and device of TS video
CN105188079B (en) * 2015-10-20 2018-08-10 武汉虹信技术服务有限责任公司 The system and method that stream media quality is evaluated and tested and mobile network quality is promoted

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Parabilis: Speeding up Single-Threaded Applications by Extracting Fine-Grained Threads for Multi-core Execution;Ademola Fawibe等;《2011 10th International Symposium on Parallel and Distributed Computing》;20111222;全文 *
基于Peercast的P2P直播系统改进;李游等;《计算机工程》;20090505;全文 *

Also Published As

Publication number Publication date
CN108600368A (en) 2018-09-28

Similar Documents

Publication Publication Date Title
CN108600368B (en) HLS network video downloading optimization method and device
US9060207B2 (en) Adaptive video streaming over a content delivery network
US11621989B2 (en) Tiered content streaming
CA2888218C (en) Playback stall avoidance in adaptive media streaming
KR102110627B1 (en) Methods and devices for bandwidth allocation in adaptive bitrate streaming
EP2300928B1 (en) Client side stream switching
US8341284B2 (en) Method and system for selecting a delivery method for media on demand
US9167007B2 (en) Stream complexity mapping
EP3039832B1 (en) Http streaming client adaptation algorithm based on proportional-integral control
WO2020155959A1 (en) Definition switching method and apparatus, computer device, and readable storage medium
US11509949B2 (en) Packager for segmenter fluidity
CN110022498B (en) Method and device for realizing code rate switching
WO2017001289A1 (en) Low latency media streaming
CN111510789A (en) Video playing method, system, computer equipment and computer readable storage medium
CN108833968B (en) Method for caching video and related equipment
US11095699B1 (en) Streaming media file management
WO2016112641A1 (en) Client, streaming media data receiving method and streaming media data transmission system
CN106454417B (en) Streaming Media speed playback method and device
US11082741B2 (en) Dynamic multi-content delivery network selection during video playback
Zhang et al. A QOE-driven approach to rate adaptation for dynamic adaptive streaming over http
US10021159B2 (en) Method of stabilized adaptive video streaming for high dynamic range (HDR)
US9350796B2 (en) Method and device for receiving multimedia data
WO2018219487A1 (en) Methods and apparatus for streaming data
Wisniewski et al. On optimizing adaptive algorithms based on rebuffering probability
EP3799432A1 (en) Video stream transmission method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 266555 Qingdao economic and Technological Development Zone, Shandong, Hong Kong Road, No. 218

Applicant after: Hisense Video Technology Co., Ltd

Address before: 266555 Qingdao economic and Technological Development Zone, Shandong, Hong Kong Road, No. 218

Applicant before: HISENSE ELECTRIC Co.,Ltd.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant